setupOutputFileSystem.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = setupOutputFileSystem;
  6. var _path = _interopRequireDefault(require("path"));
  7. var _memfs = require("memfs");
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function setupOutputFileSystem(context) {
  10. let outputFileSystem;
  11. if (context.options.outputFileSystem) {
  12. // eslint-disable-next-line no-shadow
  13. const {
  14. outputFileSystem: outputFileSystemFromOptions
  15. } = context.options; // Todo remove when we drop webpack@4 support
  16. if (typeof outputFileSystemFromOptions.join !== "function") {
  17. throw new Error("Invalid options: options.outputFileSystem.join() method is expected");
  18. } // Todo remove when we drop webpack@4 support
  19. if (typeof outputFileSystemFromOptions.mkdirp !== "function") {
  20. throw new Error("Invalid options: options.outputFileSystem.mkdirp() method is expected");
  21. }
  22. outputFileSystem = outputFileSystemFromOptions;
  23. } else {
  24. outputFileSystem = (0, _memfs.createFsFromVolume)(new _memfs.Volume()); // TODO: remove when we drop webpack@4 support
  25. outputFileSystem.join = _path.default.join.bind(_path.default);
  26. }
  27. const compilers = context.compiler.compilers || [context.compiler];
  28. for (const compiler of compilers) {
  29. // eslint-disable-next-line no-param-reassign
  30. compiler.outputFileSystem = outputFileSystem;
  31. } // eslint-disable-next-line no-param-reassign
  32. context.outputFileSystem = outputFileSystem;
  33. }