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.

ConcordMainPlugin.js 1.2KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const path = require("path");
  7. const concord = require("./concord");
  8. const DescriptionFileUtils = require("./DescriptionFileUtils");
  9. module.exports = class ConcordMainPlugin {
  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("ConcordMainPlugin", (request, resolveContext, callback) => {
  18. if(request.path !== request.descriptionFileRoot) return callback();
  19. const concordField = DescriptionFileUtils.getField(request.descriptionFileData, "concord");
  20. if(!concordField) return callback();
  21. const mainModule = concord.getMain(request.context, concordField);
  22. if(!mainModule) return callback();
  23. const obj = Object.assign({}, request, {
  24. request: mainModule
  25. });
  26. const filename = path.basename(request.descriptionFilePath);
  27. return resolver.doResolve(target, obj, "use " + mainModule + " from " + filename, resolveContext, callback);
  28. });
  29. }
  30. };