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.

ConcordExtensionsPlugin.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const concord = require("./concord");
  7. const DescriptionFileUtils = require("./DescriptionFileUtils");
  8. const forEachBail = require("./forEachBail");
  9. module.exports = class ConcordExtensionsPlugin {
  10. constructor(source, options, target) {
  11. this.source = source;
  12. this.options = options;
  13. this.target = target;
  14. }
  15. apply(resolver) {
  16. const target = resolver.ensureHook(this.target);
  17. resolver.getHook(this.source).tapAsync("ConcordExtensionsPlugin", (request, resolveContext, callback) => {
  18. const concordField = DescriptionFileUtils.getField(request.descriptionFileData, "concord");
  19. if(!concordField) return callback();
  20. const extensions = concord.getExtensions(request.context, concordField);
  21. if(!extensions) return callback();
  22. forEachBail(extensions, (appending, callback) => {
  23. const obj = Object.assign({}, request, {
  24. path: request.path + appending,
  25. relativePath: request.relativePath && (request.relativePath + appending)
  26. });
  27. resolver.doResolve(target, obj, "concord extension: " + appending, resolveContext, callback);
  28. }, (err, result) => {
  29. if(err) return callback(err);
  30. // Don't allow other processing
  31. if(result === undefined) return callback(null, null);
  32. callback(null, result);
  33. });
  34. });
  35. }
  36. };