Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DescriptionFilePlugin.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DescriptionFileUtils = require("./DescriptionFileUtils");
  7. module.exports = class DescriptionFilePlugin {
  8. constructor(source, filenames, target) {
  9. this.source = source;
  10. this.filenames = [].concat(filenames);
  11. this.target = target;
  12. }
  13. apply(resolver) {
  14. const target = resolver.ensureHook(this.target);
  15. resolver.getHook(this.source).tapAsync("DescriptionFilePlugin", (request, resolveContext, callback) => {
  16. const directory = request.path;
  17. DescriptionFileUtils.loadDescriptionFile(resolver, directory, this.filenames, resolveContext, (err, result) => {
  18. if(err) return callback(err);
  19. if(!result) {
  20. if(resolveContext.missing) {
  21. this.filenames.forEach((filename) => {
  22. resolveContext.missing.add(resolver.join(directory, filename));
  23. });
  24. }
  25. if(resolveContext.log) resolveContext.log("No description file found");
  26. return callback();
  27. }
  28. const relativePath = "." + request.path.substr(result.directory.length).replace(/\\/g, "/");
  29. const obj = Object.assign({}, request, {
  30. descriptionFilePath: result.path,
  31. descriptionFileData: result.content,
  32. descriptionFileRoot: result.directory,
  33. relativePath: relativePath
  34. });
  35. resolver.doResolve(target, obj, "using description file: " + result.path + " (relative path: " + relativePath + ")", resolveContext, (err, result) => {
  36. if(err) return callback(err);
  37. // Don't allow other processing
  38. if(result === undefined) return callback(null, null);
  39. callback(null, result);
  40. });
  41. });
  42. });
  43. }
  44. };