IgnoreErrorModuleFactory.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Ivan Kopeykin @vankop
  4. */
  5. "use strict";
  6. const ModuleFactory = require("./ModuleFactory");
  7. /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
  8. /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
  9. /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
  10. /**
  11. * Ignores error when module is unresolved
  12. */
  13. class IgnoreErrorModuleFactory extends ModuleFactory {
  14. /**
  15. * @param {NormalModuleFactory} normalModuleFactory normalModuleFactory instance
  16. */
  17. constructor(normalModuleFactory) {
  18. super();
  19. this.normalModuleFactory = normalModuleFactory;
  20. }
  21. /**
  22. * @param {ModuleFactoryCreateData} data data object
  23. * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
  24. * @returns {void}
  25. */
  26. create(data, callback) {
  27. this.normalModuleFactory.create(data, (err, result) => {
  28. return callback(null, result);
  29. });
  30. }
  31. }
  32. module.exports = IgnoreErrorModuleFactory;