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.
- package/LICENSE +20 -20
- package/README.md +761 -758
- package/SECURITY.md +9 -9
- package/buildin/amd-define.js +3 -3
- package/buildin/amd-options.js +2 -2
- package/buildin/global.js +20 -20
- package/buildin/harmony-module.js +24 -24
- package/buildin/module.js +22 -22
- package/buildin/system.js +7 -7
- package/hot/dev-server.js +61 -61
- package/hot/emitter.js +2 -2
- package/hot/log-apply-result.js +44 -44
- package/hot/log.js +45 -45
- package/hot/only-dev-server.js +105 -105
- package/hot/poll.js +40 -37
- package/hot/signal.js +62 -62
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +87 -87
- package/lib/AsyncDependencyToInitialChunkError.js +31 -31
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +117 -117
- package/lib/BasicEvaluatedExpression.js +211 -211
- package/lib/CachePlugin.js +102 -102
- package/lib/CaseSensitiveModulesWarning.js +67 -67
- package/lib/Chunk.js +833 -811
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkRenderError.js +32 -32
- package/lib/CommentCompilationWarning.js +2 -2
- package/lib/CompatibilityPlugin.js +70 -70
- package/lib/Compilation.js +46 -15
- package/lib/ConcurrentCompilationError.js +19 -19
- package/lib/ConstPlugin.js +258 -258
- package/lib/ContextExclusionPlugin.js +28 -17
- package/lib/ContextModule.js +844 -739
- package/lib/ContextModuleFactory.js +262 -256
- package/lib/ContextReplacementPlugin.js +133 -133
- package/lib/DefinePlugin.js +49 -0
- package/lib/DelegatedModule.js +5 -0
- package/lib/DelegatedModuleFactoryPlugin.js +95 -89
- package/lib/DelegatedPlugin.js +39 -39
- package/lib/DependenciesBlock.js +1 -1
- package/lib/Dependency.js +10 -4
- package/lib/DllModule.js +60 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/DllPlugin.js +44 -44
- package/lib/DllReferencePlugin.js +132 -84
- package/lib/EntryModuleNotFoundError.js +21 -21
- package/lib/Entrypoint.js +54 -54
- package/lib/EnvironmentPlugin.js +72 -65
- package/lib/ErrorHelpers.js +60 -60
- package/lib/EvalDevToolModulePlugin.js +27 -27
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
- package/lib/EvalSourceMapDevToolPlugin.js +41 -41
- package/lib/ExportPropertyMainTemplatePlugin.js +53 -53
- package/lib/ExternalModule.js +165 -159
- package/lib/ExternalsPlugin.js +23 -23
- package/lib/FlagDependencyExportsPlugin.js +146 -146
- package/lib/FlagInitialModulesAsUsedPlugin.js +36 -36
- package/lib/FunctionModuleTemplatePlugin.js +100 -100
- package/lib/Generator.js +60 -52
- package/lib/HarmonyLinkingError.js +17 -17
- package/lib/HashedModuleIdsPlugin.js +53 -53
- package/lib/HotModuleReplacementPlugin.js +411 -413
- package/lib/IgnorePlugin.js +90 -90
- package/lib/JavascriptGenerator.js +229 -229
- package/lib/JavascriptModulesPlugin.js +179 -179
- package/lib/JsonGenerator.js +55 -55
- package/lib/JsonModulesPlugin.js +30 -30
- package/lib/JsonParser.js +27 -27
- package/lib/LibManifestPlugin.js +86 -86
- package/lib/LibraryTemplatePlugin.js +153 -153
- package/lib/LoaderOptionsPlugin.js +53 -53
- package/lib/LoaderTargetPlugin.js +24 -24
- package/lib/MemoryOutputFileSystem.js +5 -5
- package/lib/Module.js +431 -391
- package/lib/ModuleBuildError.js +52 -52
- package/lib/ModuleDependencyError.js +35 -35
- package/lib/ModuleDependencyWarning.js +25 -25
- package/lib/ModuleError.js +36 -36
- package/lib/ModuleFilenameHelpers.js +178 -178
- package/lib/ModuleNotFoundError.js +23 -23
- package/lib/ModuleParseError.js +57 -57
- package/lib/ModuleTemplate.js +93 -93
- package/lib/ModuleWarning.js +36 -36
- package/lib/MultiCompiler.js +283 -283
- package/lib/MultiModule.js +87 -81
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiStats.js +92 -92
- package/lib/MultiWatching.js +38 -38
- package/lib/NamedChunksPlugin.js +29 -29
- package/lib/NamedModulesPlugin.js +57 -57
- package/lib/NoEmitOnErrorsPlugin.js +20 -20
- package/lib/NoModeWarning.js +23 -23
- package/lib/NodeStuffPlugin.js +197 -179
- package/lib/NormalModule.js +542 -536
- package/lib/NormalModuleFactory.js +526 -526
- package/lib/NormalModuleReplacementPlugin.js +51 -51
- package/lib/NullFactory.js +12 -12
- package/lib/OptionsApply.js +10 -10
- package/lib/OptionsDefaulter.js +84 -84
- package/lib/Parser.js +2202 -2193
- package/lib/ParserHelpers.js +103 -103
- package/lib/PrefetchPlugin.js +37 -37
- package/lib/ProgressPlugin.js +246 -246
- package/lib/ProvidePlugin.js +86 -86
- package/lib/RawModule.js +56 -56
- package/lib/RecordIdsPlugin.js +230 -230
- package/lib/RemovedPluginError.js +11 -11
- package/lib/RequestShortener.js +83 -83
- package/lib/RequireJsStuffPlugin.js +69 -69
- package/lib/ResolverFactory.js +64 -64
- package/lib/RuntimeTemplate.js +12 -0
- package/lib/SetVarMainTemplatePlugin.js +69 -69
- package/lib/SingleEntryPlugin.js +6 -1
- package/lib/SizeFormatHelpers.js +24 -24
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -49
- package/lib/SourceMapDevToolPlugin.js +301 -301
- package/lib/Stats.js +28 -5
- package/lib/TemplatedPathPlugin.js +173 -173
- package/lib/UnsupportedFeatureWarning.js +22 -22
- package/lib/UseStrictPlugin.js +54 -54
- package/lib/WarnCaseSensitiveModulesPlugin.js +37 -37
- package/lib/WarnNoModeSetPlugin.js +17 -17
- package/lib/WatchIgnorePlugin.js +100 -100
- package/lib/Watching.js +194 -194
- package/lib/WebpackOptionsApply.js +92 -10
- package/lib/WebpackOptionsDefaulter.js +368 -354
- package/lib/debug/ProfilingPlugin.js +430 -430
- package/lib/dependencies/AMDPlugin.js +250 -250
- package/lib/dependencies/AMDRequireArrayDependency.js +49 -49
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependency.js +135 -135
- package/lib/dependencies/AMDRequireItemDependency.js +22 -22
- package/lib/dependencies/CommonJsPlugin.js +161 -161
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -23
- package/lib/dependencies/CommonJsRequireDependency.js +22 -22
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +6 -0
- package/lib/dependencies/ConstDependency.js +33 -33
- package/lib/dependencies/ContextDependency.js +68 -68
- package/lib/dependencies/ContextDependencyHelpers.js +142 -142
- package/lib/dependencies/ContextDependencyTemplateAsId.js +42 -42
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +38 -38
- package/lib/dependencies/ContextElementDependency.js +21 -21
- package/lib/dependencies/CriticalDependencyWarning.js +20 -20
- package/lib/dependencies/DelegatedSourceDependency.js +18 -18
- package/lib/dependencies/DllEntryDependency.js +20 -20
- package/lib/dependencies/HarmonyAcceptDependency.js +45 -45
- package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -31
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +92 -92
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +139 -139
- package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -30
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependency.js +109 -109
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +222 -222
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -31
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +167 -167
- package/lib/dependencies/HarmonyInitDependency.js +60 -60
- package/lib/dependencies/HarmonyModulesPlugin.js +146 -146
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -26
- package/lib/dependencies/ImportContextDependency.js +23 -23
- package/lib/dependencies/ImportDependenciesBlock.js +18 -18
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +263 -263
- package/lib/dependencies/ImportPlugin.js +82 -82
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/LoaderPlugin.js +18 -1
- package/lib/dependencies/LocalModule.js +23 -23
- package/lib/dependencies/LocalModulesHelpers.js +52 -52
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -17
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -17
- package/lib/dependencies/ModuleHotAcceptDependency.js +23 -23
- package/lib/dependencies/ModuleHotDeclineDependency.js +23 -23
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/PrefetchDependency.js +18 -18
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -56
- package/lib/dependencies/RequireContextPlugin.js +143 -143
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -33
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -116
- package/lib/dependencies/RequireEnsureDependency.js +58 -58
- package/lib/dependencies/RequireEnsureItemDependency.js +21 -21
- package/lib/dependencies/RequireEnsurePlugin.js +74 -74
- package/lib/dependencies/RequireHeaderDependency.js +26 -26
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -23
- package/lib/dependencies/RequireIncludePlugin.js +61 -61
- package/lib/dependencies/RequireResolveContextDependency.js +23 -23
- package/lib/dependencies/RequireResolveDependency.js +22 -22
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +85 -85
- package/lib/dependencies/RequireResolveHeaderDependency.js +26 -26
- package/lib/dependencies/SystemPlugin.js +125 -125
- package/lib/dependencies/UnsupportedDependency.js +27 -27
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -29
- package/lib/dependencies/WebAssemblyImportDependency.js +48 -48
- package/lib/dependencies/WebpackMissingModule.js +20 -20
- package/lib/formatLocation.js +75 -61
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeEnvironmentPlugin.js +28 -28
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplate.runtime.js +27 -27
- package/lib/node/NodeMainTemplatePlugin.js +323 -323
- package/lib/node/NodeOutputFileSystem.js +22 -22
- package/lib/node/NodeSourcePlugin.js +144 -144
- package/lib/node/NodeTargetPlugin.js +18 -18
- package/lib/node/NodeTemplatePlugin.js +31 -31
- package/lib/node/NodeWatchFileSystem.js +99 -99
- package/lib/node/ReadFileCompileWasmTemplatePlugin.js +61 -61
- package/lib/optimize/AggressiveMergingPlugin.js +87 -87
- package/lib/optimize/AggressiveSplittingPlugin.js +287 -287
- package/lib/optimize/ConcatenatedModule.js +5 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -70
- package/lib/optimize/FlagIncludedChunksPlugin.js +99 -99
- package/lib/optimize/LimitChunkCountPlugin.js +66 -66
- package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -78
- package/lib/optimize/MinChunkSizePlugin.js +77 -77
- package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +61 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +103 -0
- package/lib/optimize/OccurrenceOrderPlugin.js +135 -133
- package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -42
- package/lib/optimize/RemoveParentModulesPlugin.js +127 -127
- package/lib/optimize/RuntimeChunkPlugin.js +41 -41
- package/lib/optimize/SideEffectsFlagPlugin.js +168 -168
- package/lib/optimize/SplitChunksPlugin.js +866 -850
- package/lib/performance/AssetsOverSizeLimitWarning.js +30 -30
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +30 -30
- package/lib/performance/NoAsyncChunksWarning.js +21 -21
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StackedSetMap.js +144 -135
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/cachedMerge.js +35 -35
- package/lib/util/deterministicGrouping.js +251 -251
- package/lib/util/identifier.js +103 -103
- package/lib/util/objectToMap.js +16 -16
- package/lib/validateSchema.js +67 -67
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +17 -17
- package/lib/wasm/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm/WebAssemblyGenerator.js +16 -2
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +147 -133
- package/lib/wasm/WebAssemblyParser.js +174 -174
- package/lib/wasm/WebAssemblyUtils.js +59 -59
- package/lib/web/FetchCompileWasmTemplatePlugin.js +37 -37
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplate.runtime.js +65 -65
- package/lib/web/JsonpMainTemplatePlugin.js +1 -1
- package/lib/web/JsonpTemplatePlugin.js +23 -23
- package/lib/web/WebEnvironmentPlugin.js +18 -18
- package/lib/webpack.js +5 -0
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +65 -65
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +196 -196
- package/lib/webworker/WebWorkerTemplatePlugin.js +25 -25
- package/package.json +22 -13
- package/schemas/WebpackOptions.json +2062 -2036
- package/schemas/ajv.absolutePath.js +55 -55
- package/schemas/plugins/BannerPlugin.json +96 -96
- package/schemas/plugins/DllPlugin.json +32 -32
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +10 -0
- 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
|
-
|
12
|
-
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
/** @typedef {import("./
|
18
|
-
/** @typedef {import("./
|
19
|
-
/** @typedef {import("
|
20
|
-
/** @typedef {import("
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
* @
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
*
|
30
|
-
* @param {Module}
|
31
|
-
* @
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
/** @typedef {(
|
37
|
-
/** @typedef {(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
if (
|
42
|
-
return
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
*
|
48
|
-
* @param {ChunkGroup}
|
49
|
-
* @
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if (
|
54
|
-
return
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
*
|
60
|
-
* @param {Module}
|
61
|
-
* @
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
if (a.identifier()
|
66
|
-
return
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
* @
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
* @
|
85
|
-
* @
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
* @
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
*
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
/** @private */
|
128
|
-
this._groups = new SortableSet(undefined, sortChunkGroupById);
|
129
|
-
/** @
|
130
|
-
this.
|
131
|
-
/** @type {
|
132
|
-
this.
|
133
|
-
/** @type {
|
134
|
-
this.
|
135
|
-
/** @type {
|
136
|
-
this.
|
137
|
-
/** @type {
|
138
|
-
this.
|
139
|
-
/** @type {string=} */
|
140
|
-
this.
|
141
|
-
/** @type {
|
142
|
-
this.
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
* @
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
* @
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
return
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
return
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
const
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
*
|
363
|
-
* @
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
*
|
375
|
-
* @
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
}
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
hash.update(`${this.
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
return isAvailable(
|
454
|
-
} else {
|
455
|
-
return
|
456
|
-
}
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
*
|
470
|
-
* @
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
const
|
476
|
-
? options.
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
* @
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
const
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
* @
|
566
|
-
* @property {Record<string|number, string>}
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
/** @type {Record<string|number,
|
577
|
-
const
|
578
|
-
/** @type {Record<string|number, string
|
579
|
-
const
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
list.
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
if (
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
const
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
* @
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
/** @type {Record<string|number, string>} */
|
688
|
-
const
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
*
|
718
|
-
* @
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
}
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
});
|
786
|
-
|
787
|
-
// TODO remove in webpack 5
|
788
|
-
Object.defineProperty(Chunk.prototype, "
|
789
|
-
configurable: false,
|
790
|
-
get() {
|
791
|
-
throw new Error("Chunk.
|
792
|
-
},
|
793
|
-
set() {
|
794
|
-
throw new Error("Chunk.
|
795
|
-
}
|
796
|
-
});
|
797
|
-
|
798
|
-
// TODO remove in webpack 5
|
799
|
-
Object.defineProperty(Chunk.prototype, "
|
800
|
-
configurable: false,
|
801
|
-
get() {
|
802
|
-
throw new Error(
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
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;
|