a zip code crypto-currency system good for red ONLY

RemoveParentModulesPlugin.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. function hasModule(chunk, module, checkedChunks) {
  7. if(chunk.containsModule(module)) return [chunk];
  8. if(chunk.parents.length === 0) return false;
  9. return allHaveModule(chunk.parents.filter((c) => {
  10. return !checkedChunks.has(c);
  11. }), module, checkedChunks);
  12. }
  13. function allHaveModule(someChunks, module, checkedChunks) {
  14. if(!checkedChunks) checkedChunks = new Set();
  15. var chunks = new Set();
  16. for(var i = 0; i < someChunks.length; i++) {
  17. checkedChunks.add(someChunks[i]);
  18. var subChunks = hasModule(someChunks[i], module, checkedChunks);
  19. if(!subChunks) return false;
  20. for(var index = 0; index < subChunks.length; index++) {
  21. var item = subChunks[index];
  22. chunks.add(item);
  23. }
  24. }
  25. return chunks;
  26. }
  27. class RemoveParentModulesPlugin {
  28. apply(compiler) {
  29. compiler.plugin("compilation", (compilation) => {
  30. compilation.plugin(["optimize-chunks-basic", "optimize-extracted-chunks-basic"], (chunks) => {
  31. for(var index = 0; index < chunks.length; index++) {
  32. var chunk = chunks[index];
  33. if(chunk.parents.length === 0) continue;
  34. // TODO consider Map when performance has improved https://gist.github.com/sokra/b36098368da7b8f6792fd7c85fca6311
  35. var cache = Object.create(null);
  36. var modules = chunk.getModules();
  37. for(var i = 0; i < modules.length; i++) {
  38. var module = modules[i];
  39. var dId = module.getChunkIdsIdent();
  40. var parentChunksWithModule;
  41. if(dId === null) {
  42. parentChunksWithModule = allHaveModule(chunk.parents, module);
  43. } else if(dId in cache) {
  44. parentChunksWithModule = cache[dId];
  45. } else {
  46. parentChunksWithModule = cache[dId] = allHaveModule(chunk.parents, module);
  47. }
  48. if(parentChunksWithModule) {
  49. module.rewriteChunkInReasons(chunk, Array.from(parentChunksWithModule));
  50. chunk.removeModule(module);
  51. }
  52. }
  53. }
  54. });
  55. });
  56. }
  57. }
  58. module.exports = RemoveParentModulesPlugin;