a zip code crypto-currency system good for red ONLY

CompatibilityPlugin.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ConstDependency = require("./dependencies/ConstDependency");
  7. const NullFactory = require("./NullFactory");
  8. const jsonLoaderPath = require.resolve("json-loader");
  9. const matchJson = /\.json$/i;
  10. class CompatibilityPlugin {
  11. apply(compiler) {
  12. compiler.plugin("compilation", (compilation, params) => {
  13. compilation.dependencyFactories.set(ConstDependency, new NullFactory());
  14. compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
  15. params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
  16. if(typeof parserOptions.browserify !== "undefined" && !parserOptions.browserify)
  17. return;
  18. parser.plugin("call require", (expr) => {
  19. // support for browserify style require delegator: "require(o, !0)"
  20. if(expr.arguments.length !== 2) return;
  21. const second = parser.evaluateExpression(expr.arguments[1]);
  22. if(!second.isBoolean()) return;
  23. if(second.asBool() !== true) return;
  24. const dep = new ConstDependency("require", expr.callee.range);
  25. dep.loc = expr.loc;
  26. if(parser.state.current.dependencies.length > 1) {
  27. const last = parser.state.current.dependencies[parser.state.current.dependencies.length - 1];
  28. if(last.critical && last.request === "." && last.userRequest === "." && last.recursive)
  29. parser.state.current.dependencies.pop();
  30. }
  31. parser.state.current.addDependency(dep);
  32. return true;
  33. });
  34. });
  35. params.normalModuleFactory.plugin("after-resolve", (data, done) => {
  36. // if this is a json file and there are no loaders active, we use the json-loader in order to avoid parse errors
  37. // @see https://github.com/webpack/webpack/issues/3363
  38. if(matchJson.test(data.request) && data.loaders.length === 0) {
  39. data.loaders.push({
  40. loader: jsonLoaderPath
  41. });
  42. }
  43. done(null, data);
  44. });
  45. });
  46. }
  47. }
  48. module.exports = CompatibilityPlugin;