ConcordExtensionsPlugin.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. var concord = require("./concord");
  6. var DescriptionFileUtils = require("./DescriptionFileUtils");
  7. var forEachBail = require("./forEachBail");
  8. var createInnerCallback = require("./createInnerCallback");
  9. function ConcordExtensionsPlugin(source, options, target) {
  10. this.source = source;
  11. this.options = options;
  12. this.target = target;
  13. }
  14. module.exports = ConcordExtensionsPlugin;
  15. ConcordExtensionsPlugin.prototype.apply = function(resolver) {
  16. var target = this.target;
  17. resolver.plugin(this.source, function(request, callback) {
  18. var concordField = DescriptionFileUtils.getField(request.descriptionFileData, "concord");
  19. if(!concordField) return callback();
  20. var extensions = concord.getExtensions(request.context, concordField);
  21. if(!extensions) return callback();
  22. var topLevelCallback = callback;
  23. forEachBail(extensions, function(appending, callback) {
  24. var obj = Object.assign({}, request, {
  25. path: request.path + appending,
  26. relativePath: request.relativePath && (request.relativePath + appending)
  27. });
  28. resolver.doResolve(target, obj, "concord extension: " + appending, createInnerCallback(callback, topLevelCallback));
  29. }, function(err, result) {
  30. if(arguments.length > 0) return callback(err, result);
  31. callback(null, null);
  32. });
  33. });
  34. };