You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
882 B

4 years ago
  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;