a zip code crypto-currency system good for red ONLY

DelegatedModule.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Module = require("./Module");
  7. const OriginalSource = require("webpack-sources").OriginalSource;
  8. const RawSource = require("webpack-sources").RawSource;
  9. const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
  10. const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
  11. const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
  12. class DelegatedModule extends Module {
  13. constructor(sourceRequest, data, type, userRequest, originalRequest) {
  14. super();
  15. this.sourceRequest = sourceRequest;
  16. this.request = data.id;
  17. this.meta = data.meta;
  18. this.type = type;
  19. this.originalRequest = originalRequest;
  20. this.userRequest = userRequest;
  21. this.built = false;
  22. this.delegated = true;
  23. this.delegateData = data;
  24. }
  25. libIdent(options) {
  26. return typeof this.originalRequest === "string" ? this.originalRequest : this.originalRequest.libIdent(options);
  27. }
  28. identifier() {
  29. return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`;
  30. }
  31. readableIdentifier() {
  32. return `delegated ${this.userRequest} from ${this.sourceRequest}`;
  33. }
  34. needRebuild() {
  35. return false;
  36. }
  37. build(options, compilation, resolver, fs, callback) {
  38. this.built = true;
  39. this.builtTime = Date.now();
  40. this.cacheable = true;
  41. this.dependencies.length = 0;
  42. this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
  43. this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true));
  44. callback();
  45. }
  46. unbuild() {
  47. this.built = false;
  48. super.unbuild();
  49. }
  50. source() {
  51. const sourceModule = this.dependencies[0].module;
  52. let str;
  53. if(!sourceModule) {
  54. str = WebpackMissingModule.moduleCode(this.sourceRequest);
  55. } else {
  56. str = `module.exports = (__webpack_require__(${JSON.stringify(sourceModule.id)}))`;
  57. switch(this.type) {
  58. case "require":
  59. str += `(${JSON.stringify(this.request)})`;
  60. break;
  61. case "object":
  62. str += `[${JSON.stringify(this.request)}]`;
  63. break;
  64. }
  65. str += ";";
  66. }
  67. if(this.useSourceMap) {
  68. return new OriginalSource(str, this.identifier());
  69. } else {
  70. return new RawSource(str);
  71. }
  72. }
  73. size() {
  74. return 42;
  75. }
  76. updateHash(hash) {
  77. hash.update(this.type);
  78. hash.update(JSON.stringify(this.request));
  79. super.updateHash(hash);
  80. }
  81. }
  82. module.exports = DelegatedModule;