Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FileExistsPlugin.js 1.0KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. module.exports = class FileExistsPlugin {
  7. constructor(source, target) {
  8. this.source = source;
  9. this.target = target;
  10. }
  11. apply(resolver) {
  12. const target = resolver.ensureHook(this.target);
  13. const fs = resolver.fileSystem;
  14. resolver.getHook(this.source).tapAsync("FileExistsPlugin", (request, resolveContext, callback) => {
  15. const file = request.path;
  16. fs.stat(file, (err, stat) => {
  17. if(err || !stat) {
  18. if(resolveContext.missing) resolveContext.missing.add(file);
  19. if(resolveContext.log) resolveContext.log(file + " doesn't exist");
  20. return callback();
  21. }
  22. if(!stat.isFile()) {
  23. if(resolveContext.missing) resolveContext.missing.add(file);
  24. if(resolveContext.log) resolveContext.log(file + " is not a file");
  25. return callback();
  26. }
  27. resolver.doResolve(target, request, "existing file: " + file, resolveContext, callback);
  28. });
  29. });
  30. }
  31. };