a zip code crypto-currency system good for red ONLY

ConcordModulesPlugin.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 createInnerCallback = require("./createInnerCallback");
  8. var getInnerRequest = require("./getInnerRequest");
  9. function ConcordModulesPlugin(source, options, target) {
  10. this.source = source;
  11. this.options = options;
  12. this.target = target;
  13. }
  14. module.exports = ConcordModulesPlugin;
  15. ConcordModulesPlugin.prototype.apply = function(resolver) {
  16. var target = this.target;
  17. resolver.plugin(this.source, function(request, callback) {
  18. var innerRequest = getInnerRequest(resolver, request);
  19. if(!innerRequest) return callback();
  20. var concordField = DescriptionFileUtils.getField(request.descriptionFileData, "concord");
  21. if(!concordField) return callback();
  22. var data = concord.matchModule(request.context, concordField, innerRequest);
  23. if(data === innerRequest) return callback();
  24. if(data === undefined) return callback();
  25. if(data === false) {
  26. var ignoreObj = Object.assign({}, request, {
  27. path: false
  28. });
  29. return callback(null, ignoreObj);
  30. }
  31. var obj = Object.assign({}, request, {
  32. path: request.descriptionFileRoot,
  33. request: data
  34. });
  35. resolver.doResolve(target, obj, "aliased from description file " + request.descriptionFilePath + " with mapping '" + innerRequest + "' to '" + data + "'", createInnerCallback(function(err, result) {
  36. if(arguments.length > 0) return callback(err, result);
  37. // Don't allow other aliasing or raw request
  38. callback(null, null);
  39. }, callback));
  40. });
  41. };