webpack 4.15.0 → 4.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +761 -758
  3. package/SECURITY.md +9 -9
  4. package/buildin/amd-define.js +3 -3
  5. package/buildin/amd-options.js +2 -2
  6. package/buildin/global.js +20 -20
  7. package/buildin/harmony-module.js +24 -24
  8. package/buildin/module.js +22 -22
  9. package/buildin/system.js +7 -7
  10. package/hot/dev-server.js +61 -61
  11. package/hot/emitter.js +2 -2
  12. package/hot/log-apply-result.js +44 -44
  13. package/hot/log.js +45 -45
  14. package/hot/only-dev-server.js +105 -105
  15. package/hot/poll.js +40 -37
  16. package/hot/signal.js +62 -62
  17. package/lib/APIPlugin.js +84 -84
  18. package/lib/AmdMainTemplatePlugin.js +87 -87
  19. package/lib/AsyncDependencyToInitialChunkError.js +31 -31
  20. package/lib/AutomaticPrefetchPlugin.js +1 -1
  21. package/lib/BannerPlugin.js +117 -117
  22. package/lib/BasicEvaluatedExpression.js +211 -211
  23. package/lib/CachePlugin.js +102 -102
  24. package/lib/CaseSensitiveModulesWarning.js +67 -67
  25. package/lib/Chunk.js +833 -811
  26. package/lib/ChunkGroup.js +4 -4
  27. package/lib/ChunkRenderError.js +32 -32
  28. package/lib/CommentCompilationWarning.js +2 -2
  29. package/lib/CompatibilityPlugin.js +70 -70
  30. package/lib/Compilation.js +46 -15
  31. package/lib/ConcurrentCompilationError.js +19 -19
  32. package/lib/ConstPlugin.js +258 -258
  33. package/lib/ContextExclusionPlugin.js +28 -17
  34. package/lib/ContextModule.js +844 -739
  35. package/lib/ContextModuleFactory.js +262 -256
  36. package/lib/ContextReplacementPlugin.js +133 -133
  37. package/lib/DefinePlugin.js +49 -0
  38. package/lib/DelegatedModule.js +5 -0
  39. package/lib/DelegatedModuleFactoryPlugin.js +95 -89
  40. package/lib/DelegatedPlugin.js +39 -39
  41. package/lib/DependenciesBlock.js +1 -1
  42. package/lib/Dependency.js +10 -4
  43. package/lib/DllModule.js +60 -54
  44. package/lib/DllModuleFactory.js +29 -29
  45. package/lib/DllPlugin.js +44 -44
  46. package/lib/DllReferencePlugin.js +132 -84
  47. package/lib/EntryModuleNotFoundError.js +21 -21
  48. package/lib/Entrypoint.js +54 -54
  49. package/lib/EnvironmentPlugin.js +72 -65
  50. package/lib/ErrorHelpers.js +60 -60
  51. package/lib/EvalDevToolModulePlugin.js +27 -27
  52. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
  53. package/lib/EvalSourceMapDevToolPlugin.js +41 -41
  54. package/lib/ExportPropertyMainTemplatePlugin.js +53 -53
  55. package/lib/ExternalModule.js +165 -159
  56. package/lib/ExternalsPlugin.js +23 -23
  57. package/lib/FlagDependencyExportsPlugin.js +146 -146
  58. package/lib/FlagInitialModulesAsUsedPlugin.js +36 -36
  59. package/lib/FunctionModuleTemplatePlugin.js +100 -100
  60. package/lib/Generator.js +60 -52
  61. package/lib/HarmonyLinkingError.js +17 -17
  62. package/lib/HashedModuleIdsPlugin.js +53 -53
  63. package/lib/HotModuleReplacementPlugin.js +411 -413
  64. package/lib/IgnorePlugin.js +90 -90
  65. package/lib/JavascriptGenerator.js +229 -229
  66. package/lib/JavascriptModulesPlugin.js +179 -179
  67. package/lib/JsonGenerator.js +55 -55
  68. package/lib/JsonModulesPlugin.js +30 -30
  69. package/lib/JsonParser.js +27 -27
  70. package/lib/LibManifestPlugin.js +86 -86
  71. package/lib/LibraryTemplatePlugin.js +153 -153
  72. package/lib/LoaderOptionsPlugin.js +53 -53
  73. package/lib/LoaderTargetPlugin.js +24 -24
  74. package/lib/MemoryOutputFileSystem.js +5 -5
  75. package/lib/Module.js +431 -391
  76. package/lib/ModuleBuildError.js +52 -52
  77. package/lib/ModuleDependencyError.js +35 -35
  78. package/lib/ModuleDependencyWarning.js +25 -25
  79. package/lib/ModuleError.js +36 -36
  80. package/lib/ModuleFilenameHelpers.js +178 -178
  81. package/lib/ModuleNotFoundError.js +23 -23
  82. package/lib/ModuleParseError.js +57 -57
  83. package/lib/ModuleTemplate.js +93 -93
  84. package/lib/ModuleWarning.js +36 -36
  85. package/lib/MultiCompiler.js +283 -283
  86. package/lib/MultiModule.js +87 -81
  87. package/lib/MultiModuleFactory.js +23 -23
  88. package/lib/MultiStats.js +92 -92
  89. package/lib/MultiWatching.js +38 -38
  90. package/lib/NamedChunksPlugin.js +29 -29
  91. package/lib/NamedModulesPlugin.js +57 -57
  92. package/lib/NoEmitOnErrorsPlugin.js +20 -20
  93. package/lib/NoModeWarning.js +23 -23
  94. package/lib/NodeStuffPlugin.js +197 -179
  95. package/lib/NormalModule.js +542 -536
  96. package/lib/NormalModuleFactory.js +526 -526
  97. package/lib/NormalModuleReplacementPlugin.js +51 -51
  98. package/lib/NullFactory.js +12 -12
  99. package/lib/OptionsApply.js +10 -10
  100. package/lib/OptionsDefaulter.js +84 -84
  101. package/lib/Parser.js +2202 -2193
  102. package/lib/ParserHelpers.js +103 -103
  103. package/lib/PrefetchPlugin.js +37 -37
  104. package/lib/ProgressPlugin.js +246 -246
  105. package/lib/ProvidePlugin.js +86 -86
  106. package/lib/RawModule.js +56 -56
  107. package/lib/RecordIdsPlugin.js +230 -230
  108. package/lib/RemovedPluginError.js +11 -11
  109. package/lib/RequestShortener.js +83 -83
  110. package/lib/RequireJsStuffPlugin.js +69 -69
  111. package/lib/ResolverFactory.js +64 -64
  112. package/lib/RuntimeTemplate.js +12 -0
  113. package/lib/SetVarMainTemplatePlugin.js +69 -69
  114. package/lib/SingleEntryPlugin.js +6 -1
  115. package/lib/SizeFormatHelpers.js +24 -24
  116. package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -49
  117. package/lib/SourceMapDevToolPlugin.js +301 -301
  118. package/lib/Stats.js +28 -5
  119. package/lib/TemplatedPathPlugin.js +173 -173
  120. package/lib/UnsupportedFeatureWarning.js +22 -22
  121. package/lib/UseStrictPlugin.js +54 -54
  122. package/lib/WarnCaseSensitiveModulesPlugin.js +37 -37
  123. package/lib/WarnNoModeSetPlugin.js +17 -17
  124. package/lib/WatchIgnorePlugin.js +100 -100
  125. package/lib/Watching.js +194 -194
  126. package/lib/WebpackOptionsApply.js +92 -10
  127. package/lib/WebpackOptionsDefaulter.js +368 -354
  128. package/lib/debug/ProfilingPlugin.js +430 -430
  129. package/lib/dependencies/AMDPlugin.js +250 -250
  130. package/lib/dependencies/AMDRequireArrayDependency.js +49 -49
  131. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  132. package/lib/dependencies/AMDRequireDependency.js +135 -135
  133. package/lib/dependencies/AMDRequireItemDependency.js +22 -22
  134. package/lib/dependencies/CommonJsPlugin.js +161 -161
  135. package/lib/dependencies/CommonJsRequireContextDependency.js +23 -23
  136. package/lib/dependencies/CommonJsRequireDependency.js +22 -22
  137. package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +6 -0
  138. package/lib/dependencies/ConstDependency.js +33 -33
  139. package/lib/dependencies/ContextDependency.js +68 -68
  140. package/lib/dependencies/ContextDependencyHelpers.js +142 -142
  141. package/lib/dependencies/ContextDependencyTemplateAsId.js +42 -42
  142. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +38 -38
  143. package/lib/dependencies/ContextElementDependency.js +21 -21
  144. package/lib/dependencies/CriticalDependencyWarning.js +20 -20
  145. package/lib/dependencies/DelegatedSourceDependency.js +18 -18
  146. package/lib/dependencies/DllEntryDependency.js +20 -20
  147. package/lib/dependencies/HarmonyAcceptDependency.js +45 -45
  148. package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -31
  149. package/lib/dependencies/HarmonyDetectionParserPlugin.js +92 -92
  150. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +139 -139
  151. package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -30
  152. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  153. package/lib/dependencies/HarmonyImportDependency.js +109 -109
  154. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +222 -222
  155. package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -31
  156. package/lib/dependencies/HarmonyImportSpecifierDependency.js +167 -167
  157. package/lib/dependencies/HarmonyInitDependency.js +60 -60
  158. package/lib/dependencies/HarmonyModulesPlugin.js +146 -146
  159. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -26
  160. package/lib/dependencies/ImportContextDependency.js +23 -23
  161. package/lib/dependencies/ImportDependenciesBlock.js +18 -18
  162. package/lib/dependencies/ImportDependency.js +34 -34
  163. package/lib/dependencies/ImportEagerDependency.js +32 -32
  164. package/lib/dependencies/ImportParserPlugin.js +263 -263
  165. package/lib/dependencies/ImportPlugin.js +82 -82
  166. package/lib/dependencies/ImportWeakDependency.js +34 -34
  167. package/lib/dependencies/LoaderPlugin.js +18 -1
  168. package/lib/dependencies/LocalModule.js +23 -23
  169. package/lib/dependencies/LocalModulesHelpers.js +52 -52
  170. package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -17
  171. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -17
  172. package/lib/dependencies/ModuleHotAcceptDependency.js +23 -23
  173. package/lib/dependencies/ModuleHotDeclineDependency.js +23 -23
  174. package/lib/dependencies/NullDependency.js +20 -20
  175. package/lib/dependencies/PrefetchDependency.js +18 -18
  176. package/lib/dependencies/RequireContextDependency.js +22 -22
  177. package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -56
  178. package/lib/dependencies/RequireContextPlugin.js +143 -143
  179. package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -33
  180. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -116
  181. package/lib/dependencies/RequireEnsureDependency.js +58 -58
  182. package/lib/dependencies/RequireEnsureItemDependency.js +21 -21
  183. package/lib/dependencies/RequireEnsurePlugin.js +74 -74
  184. package/lib/dependencies/RequireHeaderDependency.js +26 -26
  185. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -23
  186. package/lib/dependencies/RequireIncludePlugin.js +61 -61
  187. package/lib/dependencies/RequireResolveContextDependency.js +23 -23
  188. package/lib/dependencies/RequireResolveDependency.js +22 -22
  189. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +85 -85
  190. package/lib/dependencies/RequireResolveHeaderDependency.js +26 -26
  191. package/lib/dependencies/SystemPlugin.js +125 -125
  192. package/lib/dependencies/UnsupportedDependency.js +27 -27
  193. package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -29
  194. package/lib/dependencies/WebAssemblyImportDependency.js +48 -48
  195. package/lib/dependencies/WebpackMissingModule.js +20 -20
  196. package/lib/formatLocation.js +75 -61
  197. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  198. package/lib/node/NodeEnvironmentPlugin.js +28 -28
  199. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  200. package/lib/node/NodeMainTemplate.runtime.js +27 -27
  201. package/lib/node/NodeMainTemplatePlugin.js +323 -323
  202. package/lib/node/NodeOutputFileSystem.js +22 -22
  203. package/lib/node/NodeSourcePlugin.js +144 -144
  204. package/lib/node/NodeTargetPlugin.js +18 -18
  205. package/lib/node/NodeTemplatePlugin.js +31 -31
  206. package/lib/node/NodeWatchFileSystem.js +99 -99
  207. package/lib/node/ReadFileCompileWasmTemplatePlugin.js +61 -61
  208. package/lib/optimize/AggressiveMergingPlugin.js +87 -87
  209. package/lib/optimize/AggressiveSplittingPlugin.js +287 -287
  210. package/lib/optimize/ConcatenatedModule.js +5 -0
  211. package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -70
  212. package/lib/optimize/FlagIncludedChunksPlugin.js +99 -99
  213. package/lib/optimize/LimitChunkCountPlugin.js +66 -66
  214. package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -78
  215. package/lib/optimize/MinChunkSizePlugin.js +77 -77
  216. package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
  217. package/lib/optimize/OccurrenceChunkOrderPlugin.js +61 -0
  218. package/lib/optimize/OccurrenceModuleOrderPlugin.js +103 -0
  219. package/lib/optimize/OccurrenceOrderPlugin.js +135 -133
  220. package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -42
  221. package/lib/optimize/RemoveParentModulesPlugin.js +127 -127
  222. package/lib/optimize/RuntimeChunkPlugin.js +41 -41
  223. package/lib/optimize/SideEffectsFlagPlugin.js +168 -168
  224. package/lib/optimize/SplitChunksPlugin.js +866 -850
  225. package/lib/performance/AssetsOverSizeLimitWarning.js +30 -30
  226. package/lib/performance/EntrypointsOverSizeLimitWarning.js +30 -30
  227. package/lib/performance/NoAsyncChunksWarning.js +21 -21
  228. package/lib/performance/SizeLimitsPlugin.js +105 -105
  229. package/lib/util/SortableSet.js +1 -0
  230. package/lib/util/StackedSetMap.js +144 -135
  231. package/lib/util/TrackingSet.js +35 -35
  232. package/lib/util/cachedMerge.js +35 -35
  233. package/lib/util/deterministicGrouping.js +251 -251
  234. package/lib/util/identifier.js +103 -103
  235. package/lib/util/objectToMap.js +16 -16
  236. package/lib/validateSchema.js +67 -67
  237. package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +17 -17
  238. package/lib/wasm/WasmFinalizeExportsPlugin.js +1 -1
  239. package/lib/wasm/WebAssemblyGenerator.js +16 -2
  240. package/lib/wasm/WebAssemblyJavascriptGenerator.js +147 -133
  241. package/lib/wasm/WebAssemblyParser.js +174 -174
  242. package/lib/wasm/WebAssemblyUtils.js +59 -59
  243. package/lib/web/FetchCompileWasmTemplatePlugin.js +37 -37
  244. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  245. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  246. package/lib/web/JsonpMainTemplate.runtime.js +65 -65
  247. package/lib/web/JsonpMainTemplatePlugin.js +1 -1
  248. package/lib/web/JsonpTemplatePlugin.js +23 -23
  249. package/lib/web/WebEnvironmentPlugin.js +18 -18
  250. package/lib/webpack.js +5 -0
  251. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  252. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  253. package/lib/webworker/WebWorkerMainTemplate.runtime.js +65 -65
  254. package/lib/webworker/WebWorkerMainTemplatePlugin.js +196 -196
  255. package/lib/webworker/WebWorkerTemplatePlugin.js +25 -25
  256. package/package.json +22 -13
  257. package/schemas/WebpackOptions.json +2062 -2036
  258. package/schemas/ajv.absolutePath.js +55 -55
  259. package/schemas/plugins/BannerPlugin.json +96 -96
  260. package/schemas/plugins/DllPlugin.json +32 -32
  261. package/schemas/plugins/DllReferencePlugin.json +99 -99
  262. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  263. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  264. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  265. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  266. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  267. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  268. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  269. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
  270. package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +10 -0
  271. package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +10 -0
package/lib/Chunk.js CHANGED
@@ -1,811 +1,833 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const util = require("util");
8
- const SortableSet = require("./util/SortableSet");
9
- const intersect = require("./util/SetHelpers").intersect;
10
- const GraphHelpers = require("./GraphHelpers");
11
- let debugId = 1000;
12
- const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
13
- const ERR_CHUNK_INITIAL =
14
- "Chunk.initial was removed. Use canBeInitial/isOnlyInitial()";
15
-
16
- /** @typedef {import("./Module.js")} Module */
17
- /** @typedef {import("./ChunkGroup")} ChunkGroup */
18
- /** @typedef {import("./ModuleReason.js")} ModuleReason */
19
- /** @typedef {import("webpack-sources").Source} Source */
20
- /** @typedef {import("./util/createHash").Hash} Hash */
21
-
22
- /**
23
- * @typedef {Object} WithId an object who has an id property *
24
- * @property {string | number} id the id of the object
25
- */
26
-
27
- /**
28
- * Compare two Modules based on their ids for sorting
29
- * @param {Module} a module
30
- * @param {Module} b module
31
- * @returns {-1|0|1} sort value
32
- */
33
-
34
- // TODO use @callback
35
- /** @typedef {(a: Module, b: Module) => -1|0|1} ModuleSortPredicate */
36
- /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
37
- /** @typedef {(c: Chunk) => boolean} ChunkFilterPredicate */
38
-
39
- const sortModuleById = (a, b) => {
40
- if (a.id < b.id) return -1;
41
- if (b.id < a.id) return 1;
42
- return 0;
43
- };
44
-
45
- /**
46
- * Compare two ChunkGroups based on their ids for sorting
47
- * @param {ChunkGroup} a chunk group
48
- * @param {ChunkGroup} b chunk group
49
- * @returns {-1|0|1} sort value
50
- */
51
- const sortChunkGroupById = (a, b) => {
52
- if (a.id < b.id) return -1;
53
- if (b.id < a.id) return 1;
54
- return 0;
55
- };
56
-
57
- /**
58
- * Compare two Identifiables , based on their ids for sorting
59
- * @param {Module} a first object with ident fn
60
- * @param {Module} b second object with ident fn
61
- * @returns {-1|0|1} The order number of the sort
62
- */
63
- const sortByIdentifier = (a, b) => {
64
- if (a.identifier() > b.identifier()) return 1;
65
- if (a.identifier() < b.identifier()) return -1;
66
- return 0;
67
- };
68
-
69
- /**
70
- * @returns {string} a concatenation of module identifiers sorted
71
- * @param {SortableSet} set to pull module identifiers from
72
- */
73
- const getModulesIdent = set => {
74
- set.sort();
75
- let str = "";
76
- for (const m of set) {
77
- str += m.identifier() + "#";
78
- }
79
- return str;
80
- };
81
-
82
- /**
83
- * @template T
84
- * @param {SortableSet<T>} set the sortable set to convert to array
85
- * @returns {Array<T>} the array returned from Array.from(set)
86
- */
87
- const getArray = set => Array.from(set);
88
-
89
- /**
90
- * @param {SortableSet<Module>} set the sortable Set to get the count/size of
91
- * @returns {number} the size of the modules
92
- */
93
- const getModulesSize = set => {
94
- let size = 0;
95
- for (const module of set) {
96
- size += module.size();
97
- }
98
- return size;
99
- };
100
-
101
- /**
102
- * A Chunk is a unit of encapsulation for Modules.
103
- * Chunks are "rendered" into bundles that get emitted when the build completes.
104
- */
105
- class Chunk {
106
- /**
107
- * @param {string=} name of chunk being created, is optional (for subclasses)
108
- */
109
- constructor(name) {
110
- /** @type {number | null} */
111
- this.id = null;
112
- /** @type {number[] | null} */
113
- this.ids = null;
114
- /** @type {number} */
115
- this.debugId = debugId++;
116
- /** @type {string} */
117
- this.name = name;
118
- /** @type {boolean} */
119
- this.preventIntegration = false;
120
- /** @type {Module=} */
121
- this.entryModule = undefined;
122
- /** @private @type {SortableSet<Module>} */
123
- this._modules = new SortableSet(undefined, sortByIdentifier);
124
- /** @type {string?} */
125
- this.filenameTemplate = undefined;
126
-
127
- /** @private */
128
- this._groups = new SortableSet(undefined, sortChunkGroupById);
129
- /** @private @type {SortableSet<ChunkGroup>} */
130
- this._groups = new SortableSet(undefined, sortChunkGroupById);
131
- /** @type {string[]} */
132
- this.files = [];
133
- /** @type {boolean} */
134
- this.rendered = false;
135
- /** @type {string=} */
136
- this.hash = undefined;
137
- /** @type {Object} */
138
- this.contentHash = Object.create(null);
139
- /** @type {string=} */
140
- this.renderedHash = undefined;
141
- /** @type {string=} */
142
- this.chunkReason = undefined;
143
- /** @type {boolean} */
144
- this.extraAsync = false;
145
- this.removedModules = undefined;
146
- }
147
-
148
- /**
149
- * @deprecated Chunk.entry has been deprecated. Please use .hasRuntime() instead
150
- * @returns {never} Throws an error trying to access this property
151
- */
152
- get entry() {
153
- throw new Error(ERR_CHUNK_ENTRY);
154
- }
155
-
156
- /**
157
- * @deprecated .entry has been deprecated. Please use .hasRuntime() instead
158
- * @param {never} data The data that was attempting to be set
159
- * @returns {never} Throws an error trying to access this property
160
- */
161
- set entry(data) {
162
- throw new Error(ERR_CHUNK_ENTRY);
163
- }
164
-
165
- /**
166
- * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
167
- * @returns {never} Throws an error trying to access this property
168
- */
169
- get initial() {
170
- throw new Error(ERR_CHUNK_INITIAL);
171
- }
172
-
173
- /**
174
- * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
175
- * @param {never} data The data attempting to be set
176
- * @returns {never} Throws an error trying to access this property
177
- */
178
- set initial(data) {
179
- throw new Error(ERR_CHUNK_INITIAL);
180
- }
181
-
182
- /**
183
- * @returns {boolean} whether or not the Chunk will have a runtime
184
- */
185
- hasRuntime() {
186
- for (const chunkGroup of this._groups) {
187
- // We only need to check the first one
188
- return chunkGroup.isInitial() && chunkGroup.getRuntimeChunk() === this;
189
- }
190
- return false;
191
- }
192
-
193
- /**
194
- * @returns {boolean} whether or not this chunk can be an initial chunk
195
- */
196
- canBeInitial() {
197
- for (const chunkGroup of this._groups) {
198
- if (chunkGroup.isInitial()) return true;
199
- }
200
- return false;
201
- }
202
-
203
- /**
204
- * @returns {boolean} whether this chunk can only be an initial chunk
205
- */
206
- isOnlyInitial() {
207
- if (this._groups.size <= 0) return false;
208
- for (const chunkGroup of this._groups) {
209
- if (!chunkGroup.isInitial()) return false;
210
- }
211
- return true;
212
- }
213
-
214
- /**
215
- * @returns {boolean} if this chunk contains the entry module
216
- */
217
- hasEntryModule() {
218
- return !!this.entryModule;
219
- }
220
-
221
- /**
222
- * @param {Module} module the module that will be added to this chunk.
223
- * @returns {boolean} returns true if the chunk doesn't have the module and it was added
224
- */
225
- addModule(module) {
226
- if (!this._modules.has(module)) {
227
- this._modules.add(module);
228
- return true;
229
- }
230
- return false;
231
- }
232
-
233
- /**
234
- * @param {Module} module the module that will be removed from this chunk
235
- * @returns {boolean} returns true if chunk exists and is successfully deleted
236
- */
237
- removeModule(module) {
238
- if (this._modules.delete(module)) {
239
- module.removeChunk(this);
240
- return true;
241
- }
242
- return false;
243
- }
244
-
245
- /**
246
- * @param {Module[]} modules the new modules to be set
247
- * @returns {void} set new modules to this chunk and return nothing
248
- */
249
- setModules(modules) {
250
- this._modules = new SortableSet(modules, sortByIdentifier);
251
- }
252
-
253
- /**
254
- * @returns {number} the amount of modules in chunk
255
- */
256
- getNumberOfModules() {
257
- return this._modules.size;
258
- }
259
-
260
- /**
261
- * @returns {SortableSet} return the modules SortableSet for this chunk
262
- */
263
- get modulesIterable() {
264
- return this._modules;
265
- }
266
-
267
- /**
268
- * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added
269
- * @returns {boolean} returns true if chunk is not apart of chunkGroup and is added successfully
270
- */
271
- addGroup(chunkGroup) {
272
- if (this._groups.has(chunkGroup)) return false;
273
- this._groups.add(chunkGroup);
274
- return true;
275
- }
276
-
277
- /**
278
- * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from
279
- * @returns {boolean} returns true if chunk does exist in chunkGroup and is removed
280
- */
281
- removeGroup(chunkGroup) {
282
- if (!this._groups.has(chunkGroup)) return false;
283
- this._groups.delete(chunkGroup);
284
- return true;
285
- }
286
-
287
- /**
288
- * @param {ChunkGroup} chunkGroup the chunkGroup to check
289
- * @returns {boolean} returns true if chunk has chunkGroup reference and exists in chunkGroup
290
- */
291
- isInGroup(chunkGroup) {
292
- return this._groups.has(chunkGroup);
293
- }
294
-
295
- /**
296
- * @returns {number} the amount of groups said chunk is in
297
- */
298
- getNumberOfGroups() {
299
- return this._groups.size;
300
- }
301
-
302
- /**
303
- * @returns {SortableSet<ChunkGroup>} the chunkGroups that said chunk is referenced in
304
- */
305
- get groupsIterable() {
306
- return this._groups;
307
- }
308
-
309
- /**
310
- * @param {Chunk} otherChunk the chunk to compare itself with
311
- * @returns {-1|0|1} this is a comparitor function like sort and returns -1, 0, or 1 based on sort order
312
- */
313
- compareTo(otherChunk) {
314
- this._modules.sort();
315
- otherChunk._modules.sort();
316
- if (this._modules.size > otherChunk._modules.size) return -1;
317
- if (this._modules.size < otherChunk._modules.size) return 1;
318
- const a = this._modules[Symbol.iterator]();
319
- const b = otherChunk._modules[Symbol.iterator]();
320
- // eslint-disable-next-line no-constant-condition
321
- while (true) {
322
- const aItem = a.next();
323
- const bItem = b.next();
324
- if (aItem.done) return 0;
325
- const aModuleIdentifier = aItem.value.identifier();
326
- const bModuleIdentifier = bItem.value.identifier();
327
- if (aModuleIdentifier < bModuleIdentifier) return -1;
328
- if (aModuleIdentifier > bModuleIdentifier) return 1;
329
- }
330
- }
331
-
332
- /**
333
- * @param {Module} module Module to check
334
- * @returns {boolean} returns true if module does exist in this chunk
335
- */
336
- containsModule(module) {
337
- return this._modules.has(module);
338
- }
339
-
340
- getModules() {
341
- return this._modules.getFromCache(getArray);
342
- }
343
-
344
- getModulesIdent() {
345
- return this._modules.getFromUnorderedCache(getModulesIdent);
346
- }
347
-
348
- remove() {
349
- // cleanup modules
350
- // Array.from is used here to create a clone, because removeChunk modifies this._modules
351
- for (const module of Array.from(this._modules)) {
352
- module.removeChunk(this);
353
- }
354
- for (const chunkGroup of this._groups) {
355
- chunkGroup.removeChunk(this);
356
- }
357
- }
358
-
359
- /**
360
- *
361
- * @param {Module} module module to move
362
- * @param {Chunk} otherChunk other chunk to move it to
363
- * @returns {void}
364
- */
365
- moveModule(module, otherChunk) {
366
- GraphHelpers.disconnectChunkAndModule(this, module);
367
- GraphHelpers.connectChunkAndModule(otherChunk, module);
368
- module.rewriteChunkInReasons(this, [otherChunk]);
369
- }
370
-
371
- /**
372
- *
373
- * @param {Chunk} otherChunk the chunk to integrate with
374
- * @param {ModuleReason} reason reason why the module is being integrated
375
- * @returns {boolean} returns true or false if integration succeeds or fails
376
- */
377
- integrate(otherChunk, reason) {
378
- if (!this.canBeIntegrated(otherChunk)) {
379
- return false;
380
- }
381
-
382
- // Array.from is used here to create a clone, because moveModule modifies otherChunk._modules
383
- for (const module of Array.from(otherChunk._modules)) {
384
- otherChunk.moveModule(module, this);
385
- }
386
- otherChunk._modules.clear();
387
-
388
- for (const chunkGroup of otherChunk._groups) {
389
- chunkGroup.replaceChunk(otherChunk, this);
390
- this.addGroup(chunkGroup);
391
- }
392
- otherChunk._groups.clear();
393
-
394
- if (this.name && otherChunk.name) {
395
- if (this.name.length !== otherChunk.name.length) {
396
- this.name =
397
- this.name.length < otherChunk.name.length
398
- ? this.name
399
- : otherChunk.name;
400
- } else {
401
- this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
402
- }
403
- }
404
-
405
- return true;
406
- }
407
-
408
- /**
409
- * @param {Chunk} newChunk the new chunk that will be split out of, and then chunk raphi twil=
410
- * @returns {void}
411
- */
412
- split(newChunk) {
413
- for (const chunkGroup of this._groups) {
414
- chunkGroup.insertChunk(newChunk, this);
415
- newChunk.addGroup(chunkGroup);
416
- }
417
- }
418
-
419
- isEmpty() {
420
- return this._modules.size === 0;
421
- }
422
-
423
- updateHash(hash) {
424
- hash.update(`${this.id} `);
425
- hash.update(this.ids ? this.ids.join(",") : "");
426
- hash.update(`${this.name || ""} `);
427
- for (const m of this._modules) {
428
- hash.update(m.hash);
429
- }
430
- }
431
-
432
- canBeIntegrated(otherChunk) {
433
- const isAvailable = (a, b) => {
434
- const queue = new Set(b.groupsIterable);
435
- for (const chunkGroup of queue) {
436
- if (a.isInGroup(chunkGroup)) continue;
437
- if (chunkGroup.isInitial()) return false;
438
- for (const parent of chunkGroup.parentsIterable) {
439
- queue.add(parent);
440
- }
441
- }
442
- return true;
443
- };
444
-
445
- if (this.preventIntegration || otherChunk.preventIntegration) {
446
- return false;
447
- }
448
-
449
- if (this.hasRuntime() !== otherChunk.hasRuntime()) {
450
- if (this.hasRuntime()) {
451
- return isAvailable(this, otherChunk);
452
- } else if (otherChunk.hasRuntime()) {
453
- return isAvailable(otherChunk, this);
454
- } else {
455
- return false;
456
- }
457
- }
458
-
459
- if (this.hasEntryModule() || otherChunk.hasEntryModule()) {
460
- return false;
461
- }
462
-
463
- return true;
464
- }
465
-
466
- /**
467
- *
468
- * @param {number} size the size
469
- * @param {Object} options the options passed in
470
- * @returns {number} the multiplier returned
471
- */
472
- addMultiplierAndOverhead(size, options) {
473
- const overhead =
474
- typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
475
- const multiplicator = this.canBeInitial()
476
- ? options.entryChunkMultiplicator || 10
477
- : 1;
478
-
479
- return size * multiplicator + overhead;
480
- }
481
-
482
- /**
483
- * @returns {number} the size of all modules
484
- */
485
- modulesSize() {
486
- return this._modules.getFromUnorderedCache(getModulesSize);
487
- }
488
-
489
- /**
490
- * @param {Object} options the size display options
491
- * @returns {number} the chunk size
492
- */
493
- size(options) {
494
- return this.addMultiplierAndOverhead(this.modulesSize(), options);
495
- }
496
-
497
- /**
498
- * @param {Chunk} otherChunk the other chunk
499
- * @param {TODO} options the options for this function
500
- * @returns {number | false} the size, or false if it can't be integrated
501
- */
502
- integratedSize(otherChunk, options) {
503
- // Chunk if it's possible to integrate this chunk
504
- if (!this.canBeIntegrated(otherChunk)) {
505
- return false;
506
- }
507
-
508
- let integratedModulesSize = this.modulesSize();
509
- // only count modules that do not exist in this chunk!
510
- for (const otherModule of otherChunk._modules) {
511
- if (!this._modules.has(otherModule)) {
512
- integratedModulesSize += otherModule.size();
513
- }
514
- }
515
-
516
- return this.addMultiplierAndOverhead(integratedModulesSize, options);
517
- }
518
-
519
- /**
520
- * @param {function(Module, Module): -1|0|1=} sortByFn a predicate function used to sort modules
521
- * @returns {void}
522
- */
523
- sortModules(sortByFn) {
524
- this._modules.sortWith(sortByFn || sortModuleById);
525
- }
526
-
527
- sortItems() {
528
- this.sortModules();
529
- }
530
-
531
- /**
532
- * @returns {Set<Chunk>} a set of all the async chunks
533
- */
534
- getAllAsyncChunks() {
535
- const queue = new Set();
536
- const chunks = new Set();
537
-
538
- const initialChunks = intersect(
539
- Array.from(this.groupsIterable, g => new Set(g.chunks))
540
- );
541
-
542
- for (const chunkGroup of this.groupsIterable) {
543
- for (const child of chunkGroup.childrenIterable) {
544
- queue.add(child);
545
- }
546
- }
547
-
548
- for (const chunkGroup of queue) {
549
- for (const chunk of chunkGroup.chunks) {
550
- if (!initialChunks.has(chunk)) {
551
- chunks.add(chunk);
552
- }
553
- }
554
- for (const child of chunkGroup.childrenIterable) {
555
- queue.add(child);
556
- }
557
- }
558
-
559
- return chunks;
560
- }
561
-
562
- /**
563
- * @typedef {Object} ChunkMaps
564
- * @property {Record<string|number, string>} hash
565
- * @property {Record<string|number, Record<string, string>>} contentHash
566
- * @property {Record<string|number, string>} name
567
- */
568
-
569
- /**
570
- * @param {boolean} realHash should the full hash or the rendered hash be used
571
- * @returns {ChunkMaps} the chunk map information
572
- */
573
- getChunkMaps(realHash) {
574
- /** @type {Record<string|number, string>} */
575
- const chunkHashMap = Object.create(null);
576
- /** @type {Record<string|number, Record<string, string>>} */
577
- const chunkContentHashMap = Object.create(null);
578
- /** @type {Record<string|number, string>} */
579
- const chunkNameMap = Object.create(null);
580
-
581
- for (const chunk of this.getAllAsyncChunks()) {
582
- chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
583
- for (const key of Object.keys(chunk.contentHash)) {
584
- if (!chunkContentHashMap[key]) {
585
- chunkContentHashMap[key] = Object.create(null);
586
- }
587
- chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
588
- }
589
- if (chunk.name) {
590
- chunkNameMap[chunk.id] = chunk.name;
591
- }
592
- }
593
-
594
- return {
595
- hash: chunkHashMap,
596
- contentHash: chunkContentHashMap,
597
- name: chunkNameMap
598
- };
599
- }
600
-
601
- /**
602
- * @returns {Record<string, Set<TODO>[]>} a record object of names to lists of child ids(?)
603
- */
604
- getChildIdsByOrders() {
605
- const lists = new Map();
606
- for (const group of this.groupsIterable) {
607
- if (group.chunks[group.chunks.length - 1] === this) {
608
- for (const childGroup of group.childrenIterable) {
609
- // TODO webpack 5 remove this check for options
610
- if (typeof childGroup.options === "object") {
611
- for (const key of Object.keys(childGroup.options)) {
612
- if (key.endsWith("Order")) {
613
- const name = key.substr(0, key.length - "Order".length);
614
- let list = lists.get(name);
615
- if (list === undefined) lists.set(name, (list = []));
616
- list.push({
617
- order: childGroup.options[key],
618
- group: childGroup
619
- });
620
- }
621
- }
622
- }
623
- }
624
- }
625
- }
626
- const result = Object.create(null);
627
- for (const [name, list] of lists) {
628
- list.sort((a, b) => {
629
- const cmp = b.order - a.order;
630
- if (cmp !== 0) return cmp;
631
- // TOOD webpack 5 remove this check of compareTo
632
- if (a.group.compareTo) {
633
- return a.group.compareTo(b.group);
634
- }
635
- return 0;
636
- });
637
- result[name] = Array.from(
638
- list.reduce((set, item) => {
639
- for (const chunk of item.group.chunks) {
640
- set.add(chunk.id);
641
- }
642
- return set;
643
- }, new Set())
644
- );
645
- }
646
- return result;
647
- }
648
-
649
- getChildIdsByOrdersMap(includeDirectChildren) {
650
- const chunkMaps = Object.create(null);
651
-
652
- const addChildIdsByOrdersToMap = chunk => {
653
- const data = chunk.getChildIdsByOrders();
654
- for (const key of Object.keys(data)) {
655
- let chunkMap = chunkMaps[key];
656
- if (chunkMap === undefined) {
657
- chunkMaps[key] = chunkMap = Object.create(null);
658
- }
659
- chunkMap[chunk.id] = data[key];
660
- }
661
- };
662
-
663
- if (includeDirectChildren) {
664
- addChildIdsByOrdersToMap(this);
665
- }
666
-
667
- for (const chunk of this.getAllAsyncChunks()) {
668
- addChildIdsByOrdersToMap(chunk);
669
- }
670
-
671
- return chunkMaps;
672
- }
673
-
674
- /**
675
- * @typedef {Object} ChunkModuleMaps
676
- * @property {Record<string|number, (string|number)[]>} id
677
- * @property {Record<string|number, string>} hash
678
- */
679
-
680
- /**
681
- * @param {ModuleFilterPredicate} filterFn function used to filter modules
682
- * @returns {ChunkModuleMaps} module map information
683
- */
684
- getChunkModuleMaps(filterFn) {
685
- /** @type {Record<string|number, (string|number)[]>} */
686
- const chunkModuleIdMap = Object.create(null);
687
- /** @type {Record<string|number, string>} */
688
- const chunkModuleHashMap = Object.create(null);
689
-
690
- for (const chunk of this.getAllAsyncChunks()) {
691
- /** @type {(string|number)[]} */
692
- let array;
693
- for (const module of chunk.modulesIterable) {
694
- if (filterFn(module)) {
695
- if (array === undefined) {
696
- array = [];
697
- chunkModuleIdMap[chunk.id] = array;
698
- }
699
- array.push(module.id);
700
- chunkModuleHashMap[module.id] = module.renderedHash;
701
- }
702
- }
703
- if (array !== undefined) {
704
- array.sort();
705
- }
706
- }
707
-
708
- return {
709
- id: chunkModuleIdMap,
710
- hash: chunkModuleHashMap
711
- };
712
- }
713
-
714
- /**
715
- *
716
- * @param {function(Module): boolean} filterFn predicate function used to filter modules
717
- * @param {function(Chunk): boolean} filterChunkFn predicate function used to filter chunks
718
- * @returns {boolean} return true if module exists in graph
719
- */
720
- hasModuleInGraph(filterFn, filterChunkFn) {
721
- const queue = new Set(this.groupsIterable);
722
- const chunksProcessed = new Set();
723
-
724
- for (const chunkGroup of queue) {
725
- for (const chunk of chunkGroup.chunks) {
726
- if (!chunksProcessed.has(chunk)) {
727
- chunksProcessed.add(chunk);
728
- if (!filterChunkFn || filterChunkFn(chunk)) {
729
- for (const module of chunk.modulesIterable) {
730
- if (filterFn(module)) {
731
- return true;
732
- }
733
- }
734
- }
735
- }
736
- }
737
- for (const child of chunkGroup.childrenIterable) {
738
- queue.add(child);
739
- }
740
- }
741
- return false;
742
- }
743
-
744
- toString() {
745
- return `Chunk[${Array.from(this._modules).join()}]`;
746
- }
747
- }
748
-
749
- // TODO remove in webpack 5
750
- Object.defineProperty(Chunk.prototype, "forEachModule", {
751
- configurable: false,
752
- value: util.deprecate(function(fn) {
753
- this._modules.forEach(fn);
754
- }, "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead")
755
- });
756
-
757
- // TODO remove in webpack 5
758
- Object.defineProperty(Chunk.prototype, "mapModules", {
759
- configurable: false,
760
- value: util.deprecate(function(fn) {
761
- return Array.from(this._modules, fn);
762
- }, "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead")
763
- });
764
-
765
- // TODO remove in webpack 5
766
- Object.defineProperty(Chunk.prototype, "chunks", {
767
- configurable: false,
768
- get() {
769
- throw new Error("Chunk.chunks: Use ChunkGroup.getChildren() instead");
770
- },
771
- set() {
772
- throw new Error("Chunk.chunks: Use ChunkGroup.add/removeChild() instead");
773
- }
774
- });
775
-
776
- // TODO remove in webpack 5
777
- Object.defineProperty(Chunk.prototype, "parents", {
778
- configurable: false,
779
- get() {
780
- throw new Error("Chunk.parents: Use ChunkGroup.getParents() instead");
781
- },
782
- set() {
783
- throw new Error("Chunk.parents: Use ChunkGroup.add/removeParent() instead");
784
- }
785
- });
786
-
787
- // TODO remove in webpack 5
788
- Object.defineProperty(Chunk.prototype, "blocks", {
789
- configurable: false,
790
- get() {
791
- throw new Error("Chunk.blocks: Use ChunkGroup.getBlocks() instead");
792
- },
793
- set() {
794
- throw new Error("Chunk.blocks: Use ChunkGroup.add/removeBlock() instead");
795
- }
796
- });
797
-
798
- // TODO remove in webpack 5
799
- Object.defineProperty(Chunk.prototype, "entrypoints", {
800
- configurable: false,
801
- get() {
802
- throw new Error(
803
- "Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead"
804
- );
805
- },
806
- set() {
807
- throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
808
- }
809
- });
810
-
811
- module.exports = Chunk;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const util = require("util");
8
+ const SortableSet = require("./util/SortableSet");
9
+ const intersect = require("./util/SetHelpers").intersect;
10
+ const GraphHelpers = require("./GraphHelpers");
11
+ const Entrypoint = require("./Entrypoint");
12
+ let debugId = 1000;
13
+ const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
14
+ const ERR_CHUNK_INITIAL =
15
+ "Chunk.initial was removed. Use canBeInitial/isOnlyInitial()";
16
+
17
+ /** @typedef {import("./Module")} Module */
18
+ /** @typedef {import("./ChunkGroup")} ChunkGroup */
19
+ /** @typedef {import("./ModuleReason")} ModuleReason */
20
+ /** @typedef {import("webpack-sources").Source} Source */
21
+ /** @typedef {import("./util/createHash").Hash} Hash */
22
+
23
+ /**
24
+ * @typedef {Object} WithId an object who has an id property *
25
+ * @property {string | number} id the id of the object
26
+ */
27
+
28
+ /**
29
+ * Compare two Modules based on their ids for sorting
30
+ * @param {Module} a module
31
+ * @param {Module} b module
32
+ * @returns {-1|0|1} sort value
33
+ */
34
+
35
+ // TODO use @callback
36
+ /** @typedef {(a: Module, b: Module) => -1|0|1} ModuleSortPredicate */
37
+ /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
38
+ /** @typedef {(c: Chunk) => boolean} ChunkFilterPredicate */
39
+
40
+ const sortModuleById = (a, b) => {
41
+ if (a.id < b.id) return -1;
42
+ if (b.id < a.id) return 1;
43
+ return 0;
44
+ };
45
+
46
+ /**
47
+ * Compare two ChunkGroups based on their ids for sorting
48
+ * @param {ChunkGroup} a chunk group
49
+ * @param {ChunkGroup} b chunk group
50
+ * @returns {-1|0|1} sort value
51
+ */
52
+ const sortChunkGroupById = (a, b) => {
53
+ if (a.id < b.id) return -1;
54
+ if (b.id < a.id) return 1;
55
+ return 0;
56
+ };
57
+
58
+ /**
59
+ * Compare two Identifiables , based on their ids for sorting
60
+ * @param {Module} a first object with ident fn
61
+ * @param {Module} b second object with ident fn
62
+ * @returns {-1|0|1} The order number of the sort
63
+ */
64
+ const sortByIdentifier = (a, b) => {
65
+ if (a.identifier() > b.identifier()) return 1;
66
+ if (a.identifier() < b.identifier()) return -1;
67
+ return 0;
68
+ };
69
+
70
+ /**
71
+ * @returns {string} a concatenation of module identifiers sorted
72
+ * @param {SortableSet} set to pull module identifiers from
73
+ */
74
+ const getModulesIdent = set => {
75
+ set.sort();
76
+ let str = "";
77
+ for (const m of set) {
78
+ str += m.identifier() + "#";
79
+ }
80
+ return str;
81
+ };
82
+
83
+ /**
84
+ * @template T
85
+ * @param {SortableSet<T>} set the sortable set to convert to array
86
+ * @returns {Array<T>} the array returned from Array.from(set)
87
+ */
88
+ const getArray = set => Array.from(set);
89
+
90
+ /**
91
+ * @param {SortableSet<Module>} set the sortable Set to get the count/size of
92
+ * @returns {number} the size of the modules
93
+ */
94
+ const getModulesSize = set => {
95
+ let size = 0;
96
+ for (const module of set) {
97
+ size += module.size();
98
+ }
99
+ return size;
100
+ };
101
+
102
+ /**
103
+ * A Chunk is a unit of encapsulation for Modules.
104
+ * Chunks are "rendered" into bundles that get emitted when the build completes.
105
+ */
106
+ class Chunk {
107
+ /**
108
+ * @param {string=} name of chunk being created, is optional (for subclasses)
109
+ */
110
+ constructor(name) {
111
+ /** @type {number | null} */
112
+ this.id = null;
113
+ /** @type {number[] | null} */
114
+ this.ids = null;
115
+ /** @type {number} */
116
+ this.debugId = debugId++;
117
+ /** @type {string} */
118
+ this.name = name;
119
+ /** @type {boolean} */
120
+ this.preventIntegration = false;
121
+ /** @type {Module=} */
122
+ this.entryModule = undefined;
123
+ /** @private @type {SortableSet<Module>} */
124
+ this._modules = new SortableSet(undefined, sortByIdentifier);
125
+ /** @type {string?} */
126
+ this.filenameTemplate = undefined;
127
+ /** @private @type {SortableSet<ChunkGroup>} */
128
+ this._groups = new SortableSet(undefined, sortChunkGroupById);
129
+ /** @type {string[]} */
130
+ this.files = [];
131
+ /** @type {boolean} */
132
+ this.rendered = false;
133
+ /** @type {string=} */
134
+ this.hash = undefined;
135
+ /** @type {Object} */
136
+ this.contentHash = Object.create(null);
137
+ /** @type {string=} */
138
+ this.renderedHash = undefined;
139
+ /** @type {string=} */
140
+ this.chunkReason = undefined;
141
+ /** @type {boolean} */
142
+ this.extraAsync = false;
143
+ this.removedModules = undefined;
144
+ }
145
+
146
+ /**
147
+ * @deprecated Chunk.entry has been deprecated. Please use .hasRuntime() instead
148
+ * @returns {never} Throws an error trying to access this property
149
+ */
150
+ get entry() {
151
+ throw new Error(ERR_CHUNK_ENTRY);
152
+ }
153
+
154
+ /**
155
+ * @deprecated .entry has been deprecated. Please use .hasRuntime() instead
156
+ * @param {never} data The data that was attempting to be set
157
+ * @returns {never} Throws an error trying to access this property
158
+ */
159
+ set entry(data) {
160
+ throw new Error(ERR_CHUNK_ENTRY);
161
+ }
162
+
163
+ /**
164
+ * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
165
+ * @returns {never} Throws an error trying to access this property
166
+ */
167
+ get initial() {
168
+ throw new Error(ERR_CHUNK_INITIAL);
169
+ }
170
+
171
+ /**
172
+ * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
173
+ * @param {never} data The data attempting to be set
174
+ * @returns {never} Throws an error trying to access this property
175
+ */
176
+ set initial(data) {
177
+ throw new Error(ERR_CHUNK_INITIAL);
178
+ }
179
+
180
+ /**
181
+ * @returns {boolean} whether or not the Chunk will have a runtime
182
+ */
183
+ hasRuntime() {
184
+ for (const chunkGroup of this._groups) {
185
+ // We only need to check the first one
186
+ return (
187
+ chunkGroup.isInitial() &&
188
+ chunkGroup instanceof Entrypoint &&
189
+ chunkGroup.getRuntimeChunk() === this
190
+ );
191
+ }
192
+ return false;
193
+ }
194
+
195
+ /**
196
+ * @returns {boolean} whether or not this chunk can be an initial chunk
197
+ */
198
+ canBeInitial() {
199
+ for (const chunkGroup of this._groups) {
200
+ if (chunkGroup.isInitial()) return true;
201
+ }
202
+ return false;
203
+ }
204
+
205
+ /**
206
+ * @returns {boolean} whether this chunk can only be an initial chunk
207
+ */
208
+ isOnlyInitial() {
209
+ if (this._groups.size <= 0) return false;
210
+ for (const chunkGroup of this._groups) {
211
+ if (!chunkGroup.isInitial()) return false;
212
+ }
213
+ return true;
214
+ }
215
+
216
+ /**
217
+ * @returns {boolean} if this chunk contains the entry module
218
+ */
219
+ hasEntryModule() {
220
+ return !!this.entryModule;
221
+ }
222
+
223
+ /**
224
+ * @param {Module} module the module that will be added to this chunk.
225
+ * @returns {boolean} returns true if the chunk doesn't have the module and it was added
226
+ */
227
+ addModule(module) {
228
+ if (!this._modules.has(module)) {
229
+ this._modules.add(module);
230
+ return true;
231
+ }
232
+ return false;
233
+ }
234
+
235
+ /**
236
+ * @param {Module} module the module that will be removed from this chunk
237
+ * @returns {boolean} returns true if chunk exists and is successfully deleted
238
+ */
239
+ removeModule(module) {
240
+ if (this._modules.delete(module)) {
241
+ module.removeChunk(this);
242
+ return true;
243
+ }
244
+ return false;
245
+ }
246
+
247
+ /**
248
+ * @param {Module[]} modules the new modules to be set
249
+ * @returns {void} set new modules to this chunk and return nothing
250
+ */
251
+ setModules(modules) {
252
+ this._modules = new SortableSet(modules, sortByIdentifier);
253
+ }
254
+
255
+ /**
256
+ * @returns {number} the amount of modules in chunk
257
+ */
258
+ getNumberOfModules() {
259
+ return this._modules.size;
260
+ }
261
+
262
+ /**
263
+ * @returns {SortableSet} return the modules SortableSet for this chunk
264
+ */
265
+ get modulesIterable() {
266
+ return this._modules;
267
+ }
268
+
269
+ /**
270
+ * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added
271
+ * @returns {boolean} returns true if chunk is not apart of chunkGroup and is added successfully
272
+ */
273
+ addGroup(chunkGroup) {
274
+ if (this._groups.has(chunkGroup)) return false;
275
+ this._groups.add(chunkGroup);
276
+ return true;
277
+ }
278
+
279
+ /**
280
+ * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from
281
+ * @returns {boolean} returns true if chunk does exist in chunkGroup and is removed
282
+ */
283
+ removeGroup(chunkGroup) {
284
+ if (!this._groups.has(chunkGroup)) return false;
285
+ this._groups.delete(chunkGroup);
286
+ return true;
287
+ }
288
+
289
+ /**
290
+ * @param {ChunkGroup} chunkGroup the chunkGroup to check
291
+ * @returns {boolean} returns true if chunk has chunkGroup reference and exists in chunkGroup
292
+ */
293
+ isInGroup(chunkGroup) {
294
+ return this._groups.has(chunkGroup);
295
+ }
296
+
297
+ /**
298
+ * @returns {number} the amount of groups said chunk is in
299
+ */
300
+ getNumberOfGroups() {
301
+ return this._groups.size;
302
+ }
303
+
304
+ /**
305
+ * @returns {SortableSet<ChunkGroup>} the chunkGroups that said chunk is referenced in
306
+ */
307
+ get groupsIterable() {
308
+ return this._groups;
309
+ }
310
+
311
+ /**
312
+ * @param {Chunk} otherChunk the chunk to compare itself with
313
+ * @returns {-1|0|1} this is a comparitor function like sort and returns -1, 0, or 1 based on sort order
314
+ */
315
+ compareTo(otherChunk) {
316
+ this._modules.sort();
317
+ otherChunk._modules.sort();
318
+ if (this._modules.size > otherChunk._modules.size) return -1;
319
+ if (this._modules.size < otherChunk._modules.size) return 1;
320
+ const a = this._modules[Symbol.iterator]();
321
+ const b = otherChunk._modules[Symbol.iterator]();
322
+ // eslint-disable-next-line no-constant-condition
323
+ while (true) {
324
+ const aItem = a.next();
325
+ const bItem = b.next();
326
+ if (aItem.done) return 0;
327
+ const aModuleIdentifier = aItem.value.identifier();
328
+ const bModuleIdentifier = bItem.value.identifier();
329
+ if (aModuleIdentifier < bModuleIdentifier) return -1;
330
+ if (aModuleIdentifier > bModuleIdentifier) return 1;
331
+ }
332
+ }
333
+
334
+ /**
335
+ * @param {Module} module Module to check
336
+ * @returns {boolean} returns true if module does exist in this chunk
337
+ */
338
+ containsModule(module) {
339
+ return this._modules.has(module);
340
+ }
341
+
342
+ getModules() {
343
+ return this._modules.getFromCache(getArray);
344
+ }
345
+
346
+ getModulesIdent() {
347
+ return this._modules.getFromUnorderedCache(getModulesIdent);
348
+ }
349
+
350
+ remove() {
351
+ // cleanup modules
352
+ // Array.from is used here to create a clone, because removeChunk modifies this._modules
353
+ for (const module of Array.from(this._modules)) {
354
+ module.removeChunk(this);
355
+ }
356
+ for (const chunkGroup of this._groups) {
357
+ chunkGroup.removeChunk(this);
358
+ }
359
+ }
360
+
361
+ /**
362
+ *
363
+ * @param {Module} module module to move
364
+ * @param {Chunk} otherChunk other chunk to move it to
365
+ * @returns {void}
366
+ */
367
+ moveModule(module, otherChunk) {
368
+ GraphHelpers.disconnectChunkAndModule(this, module);
369
+ GraphHelpers.connectChunkAndModule(otherChunk, module);
370
+ module.rewriteChunkInReasons(this, [otherChunk]);
371
+ }
372
+
373
+ /**
374
+ *
375
+ * @param {Chunk} otherChunk the chunk to integrate with
376
+ * @param {ModuleReason} reason reason why the module is being integrated
377
+ * @returns {boolean} returns true or false if integration succeeds or fails
378
+ */
379
+ integrate(otherChunk, reason) {
380
+ if (!this.canBeIntegrated(otherChunk)) {
381
+ return false;
382
+ }
383
+
384
+ // Array.from is used here to create a clone, because moveModule modifies otherChunk._modules
385
+ for (const module of Array.from(otherChunk._modules)) {
386
+ otherChunk.moveModule(module, this);
387
+ }
388
+ otherChunk._modules.clear();
389
+
390
+ for (const chunkGroup of otherChunk._groups) {
391
+ chunkGroup.replaceChunk(otherChunk, this);
392
+ this.addGroup(chunkGroup);
393
+ }
394
+ otherChunk._groups.clear();
395
+
396
+ if (this.name && otherChunk.name) {
397
+ if (this.name.length !== otherChunk.name.length) {
398
+ this.name =
399
+ this.name.length < otherChunk.name.length
400
+ ? this.name
401
+ : otherChunk.name;
402
+ } else {
403
+ this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
404
+ }
405
+ }
406
+
407
+ return true;
408
+ }
409
+
410
+ /**
411
+ * @param {Chunk} newChunk the new chunk that will be split out of, and then chunk raphi twil=
412
+ * @returns {void}
413
+ */
414
+ split(newChunk) {
415
+ for (const chunkGroup of this._groups) {
416
+ chunkGroup.insertChunk(newChunk, this);
417
+ newChunk.addGroup(chunkGroup);
418
+ }
419
+ }
420
+
421
+ isEmpty() {
422
+ return this._modules.size === 0;
423
+ }
424
+
425
+ updateHash(hash) {
426
+ hash.update(`${this.id} `);
427
+ hash.update(this.ids ? this.ids.join(",") : "");
428
+ hash.update(`${this.name || ""} `);
429
+ for (const m of this._modules) {
430
+ hash.update(m.hash);
431
+ }
432
+ }
433
+
434
+ canBeIntegrated(otherChunk) {
435
+ const isAvailable = (a, b) => {
436
+ const queue = new Set(b.groupsIterable);
437
+ for (const chunkGroup of queue) {
438
+ if (a.isInGroup(chunkGroup)) continue;
439
+ if (chunkGroup.isInitial()) return false;
440
+ for (const parent of chunkGroup.parentsIterable) {
441
+ queue.add(parent);
442
+ }
443
+ }
444
+ return true;
445
+ };
446
+
447
+ if (this.preventIntegration || otherChunk.preventIntegration) {
448
+ return false;
449
+ }
450
+
451
+ if (this.hasRuntime() !== otherChunk.hasRuntime()) {
452
+ if (this.hasRuntime()) {
453
+ return isAvailable(this, otherChunk);
454
+ } else if (otherChunk.hasRuntime()) {
455
+ return isAvailable(otherChunk, this);
456
+ } else {
457
+ return false;
458
+ }
459
+ }
460
+
461
+ if (this.hasEntryModule() || otherChunk.hasEntryModule()) {
462
+ return false;
463
+ }
464
+
465
+ return true;
466
+ }
467
+
468
+ /**
469
+ *
470
+ * @param {number} size the size
471
+ * @param {Object} options the options passed in
472
+ * @returns {number} the multiplier returned
473
+ */
474
+ addMultiplierAndOverhead(size, options) {
475
+ const overhead =
476
+ typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
477
+ const multiplicator = this.canBeInitial()
478
+ ? options.entryChunkMultiplicator || 10
479
+ : 1;
480
+
481
+ return size * multiplicator + overhead;
482
+ }
483
+
484
+ /**
485
+ * @returns {number} the size of all modules
486
+ */
487
+ modulesSize() {
488
+ return this._modules.getFromUnorderedCache(getModulesSize);
489
+ }
490
+
491
+ /**
492
+ * @param {Object} options the size display options
493
+ * @returns {number} the chunk size
494
+ */
495
+ size(options) {
496
+ return this.addMultiplierAndOverhead(this.modulesSize(), options);
497
+ }
498
+
499
+ /**
500
+ * @param {Chunk} otherChunk the other chunk
501
+ * @param {TODO} options the options for this function
502
+ * @returns {number | false} the size, or false if it can't be integrated
503
+ */
504
+ integratedSize(otherChunk, options) {
505
+ // Chunk if it's possible to integrate this chunk
506
+ if (!this.canBeIntegrated(otherChunk)) {
507
+ return false;
508
+ }
509
+
510
+ let integratedModulesSize = this.modulesSize();
511
+ // only count modules that do not exist in this chunk!
512
+ for (const otherModule of otherChunk._modules) {
513
+ if (!this._modules.has(otherModule)) {
514
+ integratedModulesSize += otherModule.size();
515
+ }
516
+ }
517
+
518
+ return this.addMultiplierAndOverhead(integratedModulesSize, options);
519
+ }
520
+
521
+ /**
522
+ * @param {function(Module, Module): -1|0|1=} sortByFn a predicate function used to sort modules
523
+ * @returns {void}
524
+ */
525
+ sortModules(sortByFn) {
526
+ this._modules.sortWith(sortByFn || sortModuleById);
527
+ }
528
+
529
+ sortItems() {
530
+ this.sortModules();
531
+ }
532
+
533
+ /**
534
+ * @returns {Set<Chunk>} a set of all the async chunks
535
+ */
536
+ getAllAsyncChunks() {
537
+ const queue = new Set();
538
+ const chunks = new Set();
539
+
540
+ const initialChunks = intersect(
541
+ Array.from(this.groupsIterable, g => new Set(g.chunks))
542
+ );
543
+
544
+ for (const chunkGroup of this.groupsIterable) {
545
+ for (const child of chunkGroup.childrenIterable) {
546
+ queue.add(child);
547
+ }
548
+ }
549
+
550
+ for (const chunkGroup of queue) {
551
+ for (const chunk of chunkGroup.chunks) {
552
+ if (!initialChunks.has(chunk)) {
553
+ chunks.add(chunk);
554
+ }
555
+ }
556
+ for (const child of chunkGroup.childrenIterable) {
557
+ queue.add(child);
558
+ }
559
+ }
560
+
561
+ return chunks;
562
+ }
563
+
564
+ /**
565
+ * @typedef {Object} ChunkMaps
566
+ * @property {Record<string|number, string>} hash
567
+ * @property {Record<string|number, Record<string, string>>} contentHash
568
+ * @property {Record<string|number, string>} name
569
+ */
570
+
571
+ /**
572
+ * @param {boolean} realHash should the full hash or the rendered hash be used
573
+ * @returns {ChunkMaps} the chunk map information
574
+ */
575
+ getChunkMaps(realHash) {
576
+ /** @type {Record<string|number, string>} */
577
+ const chunkHashMap = Object.create(null);
578
+ /** @type {Record<string|number, Record<string, string>>} */
579
+ const chunkContentHashMap = Object.create(null);
580
+ /** @type {Record<string|number, string>} */
581
+ const chunkNameMap = Object.create(null);
582
+
583
+ for (const chunk of this.getAllAsyncChunks()) {
584
+ chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
585
+ for (const key of Object.keys(chunk.contentHash)) {
586
+ if (!chunkContentHashMap[key]) {
587
+ chunkContentHashMap[key] = Object.create(null);
588
+ }
589
+ chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
590
+ }
591
+ if (chunk.name) {
592
+ chunkNameMap[chunk.id] = chunk.name;
593
+ }
594
+ }
595
+
596
+ return {
597
+ hash: chunkHashMap,
598
+ contentHash: chunkContentHashMap,
599
+ name: chunkNameMap
600
+ };
601
+ }
602
+
603
+ /**
604
+ * @returns {Record<string, Set<TODO>[]>} a record object of names to lists of child ids(?)
605
+ */
606
+ getChildIdsByOrders() {
607
+ const lists = new Map();
608
+ for (const group of this.groupsIterable) {
609
+ if (group.chunks[group.chunks.length - 1] === this) {
610
+ for (const childGroup of group.childrenIterable) {
611
+ // TODO webpack 5 remove this check for options
612
+ if (typeof childGroup.options === "object") {
613
+ for (const key of Object.keys(childGroup.options)) {
614
+ if (key.endsWith("Order")) {
615
+ const name = key.substr(0, key.length - "Order".length);
616
+ let list = lists.get(name);
617
+ if (list === undefined) lists.set(name, (list = []));
618
+ list.push({
619
+ order: childGroup.options[key],
620
+ group: childGroup
621
+ });
622
+ }
623
+ }
624
+ }
625
+ }
626
+ }
627
+ }
628
+ const result = Object.create(null);
629
+ for (const [name, list] of lists) {
630
+ list.sort((a, b) => {
631
+ const cmp = b.order - a.order;
632
+ if (cmp !== 0) return cmp;
633
+ // TODO webpack 5 remove this check of compareTo
634
+ if (a.group.compareTo) {
635
+ return a.group.compareTo(b.group);
636
+ }
637
+ return 0;
638
+ });
639
+ result[name] = Array.from(
640
+ list.reduce((set, item) => {
641
+ for (const chunk of item.group.chunks) {
642
+ set.add(chunk.id);
643
+ }
644
+ return set;
645
+ }, new Set())
646
+ );
647
+ }
648
+ return result;
649
+ }
650
+
651
+ getChildIdsByOrdersMap(includeDirectChildren) {
652
+ const chunkMaps = Object.create(null);
653
+
654
+ const addChildIdsByOrdersToMap = chunk => {
655
+ const data = chunk.getChildIdsByOrders();
656
+ for (const key of Object.keys(data)) {
657
+ let chunkMap = chunkMaps[key];
658
+ if (chunkMap === undefined) {
659
+ chunkMaps[key] = chunkMap = Object.create(null);
660
+ }
661
+ chunkMap[chunk.id] = data[key];
662
+ }
663
+ };
664
+
665
+ if (includeDirectChildren) {
666
+ addChildIdsByOrdersToMap(this);
667
+ }
668
+
669
+ for (const chunk of this.getAllAsyncChunks()) {
670
+ addChildIdsByOrdersToMap(chunk);
671
+ }
672
+
673
+ return chunkMaps;
674
+ }
675
+
676
+ /**
677
+ * @typedef {Object} ChunkModuleMaps
678
+ * @property {Record<string|number, (string|number)[]>} id
679
+ * @property {Record<string|number, string>} hash
680
+ */
681
+
682
+ /**
683
+ * @param {ModuleFilterPredicate} filterFn function used to filter modules
684
+ * @returns {ChunkModuleMaps} module map information
685
+ */
686
+ getChunkModuleMaps(filterFn) {
687
+ /** @type {Record<string|number, (string|number)[]>} */
688
+ const chunkModuleIdMap = Object.create(null);
689
+ /** @type {Record<string|number, string>} */
690
+ const chunkModuleHashMap = Object.create(null);
691
+
692
+ for (const chunk of this.getAllAsyncChunks()) {
693
+ /** @type {(string|number)[]} */
694
+ let array;
695
+ for (const module of chunk.modulesIterable) {
696
+ if (filterFn(module)) {
697
+ if (array === undefined) {
698
+ array = [];
699
+ chunkModuleIdMap[chunk.id] = array;
700
+ }
701
+ array.push(module.id);
702
+ chunkModuleHashMap[module.id] = module.renderedHash;
703
+ }
704
+ }
705
+ if (array !== undefined) {
706
+ array.sort();
707
+ }
708
+ }
709
+
710
+ return {
711
+ id: chunkModuleIdMap,
712
+ hash: chunkModuleHashMap
713
+ };
714
+ }
715
+
716
+ /**
717
+ *
718
+ * @param {function(Module): boolean} filterFn predicate function used to filter modules
719
+ * @param {function(Chunk): boolean} filterChunkFn predicate function used to filter chunks
720
+ * @returns {boolean} return true if module exists in graph
721
+ */
722
+ hasModuleInGraph(filterFn, filterChunkFn) {
723
+ const queue = new Set(this.groupsIterable);
724
+ const chunksProcessed = new Set();
725
+
726
+ for (const chunkGroup of queue) {
727
+ for (const chunk of chunkGroup.chunks) {
728
+ if (!chunksProcessed.has(chunk)) {
729
+ chunksProcessed.add(chunk);
730
+ if (!filterChunkFn || filterChunkFn(chunk)) {
731
+ for (const module of chunk.modulesIterable) {
732
+ if (filterFn(module)) {
733
+ return true;
734
+ }
735
+ }
736
+ }
737
+ }
738
+ }
739
+ for (const child of chunkGroup.childrenIterable) {
740
+ queue.add(child);
741
+ }
742
+ }
743
+ return false;
744
+ }
745
+
746
+ toString() {
747
+ return `Chunk[${Array.from(this._modules).join()}]`;
748
+ }
749
+ }
750
+
751
+ // TODO remove in webpack 5
752
+ Object.defineProperty(Chunk.prototype, "forEachModule", {
753
+ configurable: false,
754
+ value: util.deprecate(
755
+ /**
756
+ * @deprecated
757
+ * @this {Chunk}
758
+ * @typedef {function(any, any, Set<any>): void} ForEachModuleCallback
759
+ * @param {ForEachModuleCallback} fn Callback function
760
+ * @returns {void}
761
+ */
762
+ function(fn) {
763
+ this._modules.forEach(fn);
764
+ },
765
+ "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead"
766
+ )
767
+ });
768
+
769
+ // TODO remove in webpack 5
770
+ Object.defineProperty(Chunk.prototype, "mapModules", {
771
+ configurable: false,
772
+ value: util.deprecate(
773
+ /**
774
+ * @deprecated
775
+ * @this {Chunk}
776
+ * @typedef {function(any, number): any} MapModulesCallback
777
+ * @param {MapModulesCallback} fn Callback function
778
+ * @returns {TODO[]} result of mapped modules
779
+ */
780
+ function(fn) {
781
+ return Array.from(this._modules, fn);
782
+ },
783
+ "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead"
784
+ )
785
+ });
786
+
787
+ // TODO remove in webpack 5
788
+ Object.defineProperty(Chunk.prototype, "chunks", {
789
+ configurable: false,
790
+ get() {
791
+ throw new Error("Chunk.chunks: Use ChunkGroup.getChildren() instead");
792
+ },
793
+ set() {
794
+ throw new Error("Chunk.chunks: Use ChunkGroup.add/removeChild() instead");
795
+ }
796
+ });
797
+
798
+ // TODO remove in webpack 5
799
+ Object.defineProperty(Chunk.prototype, "parents", {
800
+ configurable: false,
801
+ get() {
802
+ throw new Error("Chunk.parents: Use ChunkGroup.getParents() instead");
803
+ },
804
+ set() {
805
+ throw new Error("Chunk.parents: Use ChunkGroup.add/removeParent() instead");
806
+ }
807
+ });
808
+
809
+ // TODO remove in webpack 5
810
+ Object.defineProperty(Chunk.prototype, "blocks", {
811
+ configurable: false,
812
+ get() {
813
+ throw new Error("Chunk.blocks: Use ChunkGroup.getBlocks() instead");
814
+ },
815
+ set() {
816
+ throw new Error("Chunk.blocks: Use ChunkGroup.add/removeBlock() instead");
817
+ }
818
+ });
819
+
820
+ // TODO remove in webpack 5
821
+ Object.defineProperty(Chunk.prototype, "entrypoints", {
822
+ configurable: false,
823
+ get() {
824
+ throw new Error(
825
+ "Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead"
826
+ );
827
+ },
828
+ set() {
829
+ throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
830
+ }
831
+ });
832
+
833
+ module.exports = Chunk;