NodeJsInputFileSystem.js 882 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const fs = require("graceful-fs");
  7. class NodeJsInputFileSystem {
  8. readdir(path, callback) {
  9. fs.readdir(path, (err, files) => {
  10. callback(
  11. err,
  12. files &&
  13. files.map(file => {
  14. return file.normalize ? file.normalize("NFC") : file;
  15. })
  16. );
  17. });
  18. }
  19. readdirSync(path) {
  20. const files = fs.readdirSync(path);
  21. return (
  22. files &&
  23. files.map(file => {
  24. return file.normalize ? file.normalize("NFC") : file;
  25. })
  26. );
  27. }
  28. }
  29. const fsMethods = [
  30. "stat",
  31. "statSync",
  32. "readFile",
  33. "readFileSync",
  34. "readlink",
  35. "readlinkSync"
  36. ];
  37. for (const key of fsMethods) {
  38. Object.defineProperty(NodeJsInputFileSystem.prototype, key, {
  39. configurable: true,
  40. writable: true,
  41. value: fs[key].bind(fs)
  42. });
  43. }
  44. module.exports = NodeJsInputFileSystem;