a zip code crypto-currency system good for red ONLY

ModulesInHierachicDirectoriesPlugin.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. var createInnerCallback = require("./createInnerCallback");
  6. var forEachBail = require("./forEachBail");
  7. var getPaths = require("./getPaths");
  8. function ModulesInHierachicDirectoriesPlugin(source, directories, target) {
  9. this.source = source;
  10. this.directories = [].concat(directories);
  11. this.target = target;
  12. }
  13. module.exports = ModulesInHierachicDirectoriesPlugin;
  14. ModulesInHierachicDirectoriesPlugin.prototype.apply = function(resolver) {
  15. var directories = this.directories;
  16. var target = this.target;
  17. resolver.plugin(this.source, function(request, callback) {
  18. var fs = this.fileSystem;
  19. var topLevelCallback = callback;
  20. var addrs = getPaths(request.path).paths.map(function(p) {
  21. return directories.map(function(d) {
  22. return this.join(p, d);
  23. }, this);
  24. }, this).reduce(function(array, p) {
  25. array.push.apply(array, p);
  26. return array;
  27. }, []);
  28. forEachBail(addrs, function(addr, callback) {
  29. fs.stat(addr, function(err, stat) {
  30. if(!err && stat && stat.isDirectory()) {
  31. var obj = Object.assign({}, request, {
  32. path: addr,
  33. request: "./" + request.request
  34. });
  35. var message = "looking for modules in " + addr;
  36. return resolver.doResolve(target, obj, message, createInnerCallback(callback, topLevelCallback));
  37. }
  38. if(topLevelCallback.log) topLevelCallback.log(addr + " doesn't exist or is not a directory");
  39. if(topLevelCallback.missing) topLevelCallback.missing.push(addr);
  40. return callback();
  41. });
  42. }, callback);
  43. });
  44. };