webpack 5.90.2 → 5.91.0
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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -5
- package/bin/webpack.js +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +263 -94
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +4 -1
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/CssModule.js +0 -3
- package/lib/DefinePlugin.js +4 -2
- package/lib/DelegatedModule.js +2 -1
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +3 -1
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +120 -25
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +54 -5
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +61 -17
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +239 -86
- package/lib/NormalModuleFactory.js +163 -32
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +4 -2
- package/lib/ResolverFactory.js +5 -1
- package/lib/RuntimeModule.js +6 -5
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +12 -5
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +5 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +220 -392
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +5 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +3 -2
- package/lib/container/RemoteModule.js +2 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +6 -5
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -55
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +3 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedModule.js +2 -1
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/memoize.js +2 -0
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +11 -5
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1772 -673
@@ -19,8 +19,10 @@ const InnerGraph = require("./InnerGraph");
|
|
19
19
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
20
20
|
/** @typedef {import("../Compiler")} Compiler */
|
21
21
|
/** @typedef {import("../Dependency")} Dependency */
|
22
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
22
23
|
/** @typedef {import("../dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
|
23
24
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
25
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
24
26
|
/** @typedef {import("./InnerGraph").InnerGraph} InnerGraph */
|
25
27
|
/** @typedef {import("./InnerGraph").TopLevelSymbol} TopLevelSymbol */
|
26
28
|
|
@@ -123,7 +125,10 @@ class InnerGraphPlugin {
|
|
123
125
|
if (parser.scope.topLevelScope === true) {
|
124
126
|
if (
|
125
127
|
statement.type === "ClassDeclaration" &&
|
126
|
-
parser.isPure(
|
128
|
+
parser.isPure(
|
129
|
+
statement,
|
130
|
+
/** @type {Range} */ (statement.range)[0]
|
131
|
+
)
|
127
132
|
) {
|
128
133
|
const name = statement.id ? statement.id.name : "*default*";
|
129
134
|
const fn = InnerGraph.tagTopLevelSymbol(parser, name);
|
@@ -137,10 +142,12 @@ class InnerGraphPlugin {
|
|
137
142
|
if (
|
138
143
|
(decl.type === "ClassExpression" ||
|
139
144
|
decl.type === "ClassDeclaration") &&
|
140
|
-
parser.isPure(decl, decl.range[0])
|
145
|
+
parser.isPure(decl, /** @type {Range} */ (decl.range)[0])
|
141
146
|
) {
|
142
147
|
classWithTopLevelSymbol.set(decl, fn);
|
143
|
-
} else if (
|
148
|
+
} else if (
|
149
|
+
parser.isPure(decl, /** @type {Range} */ (statement.range)[0])
|
150
|
+
) {
|
144
151
|
statementWithTopLevelSymbol.set(statement, fn);
|
145
152
|
if (
|
146
153
|
!decl.type.endsWith("FunctionExpression") &&
|
@@ -164,11 +171,19 @@ class InnerGraphPlugin {
|
|
164
171
|
const name = decl.id.name;
|
165
172
|
if (
|
166
173
|
decl.init.type === "ClassExpression" &&
|
167
|
-
parser.isPure(
|
174
|
+
parser.isPure(
|
175
|
+
decl.init,
|
176
|
+
/** @type {Range} */ (decl.id.range)[1]
|
177
|
+
)
|
168
178
|
) {
|
169
179
|
const fn = InnerGraph.tagTopLevelSymbol(parser, name);
|
170
180
|
classWithTopLevelSymbol.set(decl.init, fn);
|
171
|
-
} else if (
|
181
|
+
} else if (
|
182
|
+
parser.isPure(
|
183
|
+
decl.init,
|
184
|
+
/** @type {Range} */ (decl.id.range)[1]
|
185
|
+
)
|
186
|
+
) {
|
172
187
|
const fn = InnerGraph.tagTopLevelSymbol(parser, name);
|
173
188
|
declWithTopLevelSymbol.set(decl, fn);
|
174
189
|
if (
|
@@ -214,9 +229,11 @@ class InnerGraphPlugin {
|
|
214
229
|
return;
|
215
230
|
default: {
|
216
231
|
const dep = new PureExpressionDependency(
|
217
|
-
purePart.range
|
232
|
+
/** @type {Range} */ (purePart.range)
|
218
233
|
);
|
219
|
-
dep.loc =
|
234
|
+
dep.loc =
|
235
|
+
/** @type {DependencyLocation} */
|
236
|
+
(statement.loc);
|
220
237
|
dep.usedByExports = usedByExports;
|
221
238
|
parser.state.module.addDependency(dep);
|
222
239
|
break;
|
@@ -238,7 +255,9 @@ class InnerGraphPlugin {
|
|
238
255
|
fn &&
|
239
256
|
parser.isPure(
|
240
257
|
expr,
|
241
|
-
statement.id
|
258
|
+
statement.id
|
259
|
+
? /** @type {Range} */ (statement.id.range)[1]
|
260
|
+
: /** @type {Range} */ (statement.range)[0]
|
242
261
|
)
|
243
262
|
) {
|
244
263
|
InnerGraph.setTopLevelSymbol(parser.state, fn);
|
@@ -272,7 +291,9 @@ class InnerGraphPlugin {
|
|
272
291
|
!element.static ||
|
273
292
|
parser.isPure(
|
274
293
|
expression,
|
275
|
-
element.key
|
294
|
+
element.key
|
295
|
+
? /** @type {Range} */ (element.key.range)[1]
|
296
|
+
: /** @type {Range} */ (element.range)[0]
|
276
297
|
)
|
277
298
|
) {
|
278
299
|
InnerGraph.setTopLevelSymbol(parser.state, fn);
|
@@ -284,9 +305,11 @@ class InnerGraphPlugin {
|
|
284
305
|
return;
|
285
306
|
default: {
|
286
307
|
const dep = new PureExpressionDependency(
|
287
|
-
expression.range
|
308
|
+
/** @type {Range} */ (expression.range)
|
288
309
|
);
|
289
|
-
dep.loc =
|
310
|
+
dep.loc =
|
311
|
+
/** @type {DependencyLocation} */
|
312
|
+
(expression.loc);
|
290
313
|
dep.usedByExports = usedByExports;
|
291
314
|
parser.state.module.addDependency(dep);
|
292
315
|
break;
|
@@ -321,9 +344,9 @@ class InnerGraphPlugin {
|
|
321
344
|
return;
|
322
345
|
default: {
|
323
346
|
const dep = new PureExpressionDependency(
|
324
|
-
decl.init.range
|
347
|
+
/** @type {Range} */ (decl.init.range)
|
325
348
|
);
|
326
|
-
dep.loc = decl.loc;
|
349
|
+
dep.loc = /** @type {DependencyLocation} */ (decl.loc);
|
327
350
|
dep.usedByExports = usedByExports;
|
328
351
|
parser.state.module.addDependency(dep);
|
329
352
|
break;
|
@@ -23,6 +23,7 @@ const ConcatenatedModule = require("./ConcatenatedModule");
|
|
23
23
|
/** @typedef {import("../Compilation")} Compilation */
|
24
24
|
/** @typedef {import("../Compiler")} Compiler */
|
25
25
|
/** @typedef {import("../Module")} Module */
|
26
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
26
27
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
27
28
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
28
29
|
|
@@ -49,6 +50,9 @@ const formatBailoutReason = msg => {
|
|
49
50
|
};
|
50
51
|
|
51
52
|
class ModuleConcatenationPlugin {
|
53
|
+
/**
|
54
|
+
* @param {TODO} options options
|
55
|
+
*/
|
52
56
|
constructor(options) {
|
53
57
|
if (typeof options !== "object") options = {};
|
54
58
|
this.options = options;
|
@@ -171,7 +175,7 @@ class ModuleConcatenationPlugin {
|
|
171
175
|
}
|
172
176
|
|
173
177
|
// Must be in strict mode
|
174
|
-
if (!module.buildInfo.strict) {
|
178
|
+
if (!(/** @type {BuildInfo} */ (module.buildInfo).strict)) {
|
175
179
|
setBailoutReason(module, `Module is not in strict mode`);
|
176
180
|
continue;
|
177
181
|
}
|
@@ -242,7 +246,10 @@ class ModuleConcatenationPlugin {
|
|
242
246
|
// this improves performance, because modules already selected as inner are skipped
|
243
247
|
logger.time("sort relevant modules");
|
244
248
|
relevantModules.sort((a, b) => {
|
245
|
-
return
|
249
|
+
return (
|
250
|
+
/** @type {number} */ (moduleGraph.getDepth(a)) -
|
251
|
+
/** @type {number} */ (moduleGraph.getDepth(b))
|
252
|
+
);
|
246
253
|
});
|
247
254
|
logger.timeEnd("sort relevant modules");
|
248
255
|
|
@@ -927,6 +934,9 @@ class ConcatConfiguration {
|
|
927
934
|
return this.modules.size;
|
928
935
|
}
|
929
936
|
|
937
|
+
/**
|
938
|
+
* @param {number} snapshot snapshot
|
939
|
+
*/
|
930
940
|
rollback(snapshot) {
|
931
941
|
const modules = this.modules;
|
932
942
|
for (const m of modules) {
|
@@ -10,6 +10,9 @@
|
|
10
10
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
11
11
|
|
12
12
|
class RuntimeChunkPlugin {
|
13
|
+
/**
|
14
|
+
* @param {{ name?: (entrypoint: { name: string }) => string }} options options
|
15
|
+
*/
|
13
16
|
constructor(options) {
|
14
17
|
this.options = {
|
15
18
|
/**
|
@@ -37,7 +40,9 @@ class RuntimeChunkPlugin {
|
|
37
40
|
(compilation.entries.get(entryName));
|
38
41
|
if (data.options.runtime === undefined && !data.options.dependOn) {
|
39
42
|
// Determine runtime chunk name
|
40
|
-
let name =
|
43
|
+
let name =
|
44
|
+
/** @type {string | ((entrypoint: { name: string }) => string)} */
|
45
|
+
(this.options.name);
|
41
46
|
if (typeof name === "function") {
|
42
47
|
name = name({ name: entryName });
|
43
48
|
}
|
@@ -20,8 +20,11 @@ const formatLocation = require("../formatLocation");
|
|
20
20
|
/** @typedef {import("estree").Statement} Statement */
|
21
21
|
/** @typedef {import("../Compiler")} Compiler */
|
22
22
|
/** @typedef {import("../Dependency")} Dependency */
|
23
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
23
24
|
/** @typedef {import("../Module")} Module */
|
25
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
24
26
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
27
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
25
28
|
|
26
29
|
/**
|
27
30
|
* @typedef {Object} ExportInModule
|
@@ -36,7 +39,9 @@ const formatLocation = require("../formatLocation");
|
|
36
39
|
* @property {Map<Module, Set<string>>} dynamic
|
37
40
|
*/
|
38
41
|
|
39
|
-
/** @
|
42
|
+
/** @typedef {Map<string, RegExp>} CacheItem */
|
43
|
+
|
44
|
+
/** @type {WeakMap<any, CacheItem>} */
|
40
45
|
const globToRegexpCache = new WeakMap();
|
41
46
|
|
42
47
|
/**
|
@@ -96,7 +101,7 @@ class SideEffectsFlagPlugin {
|
|
96
101
|
const hasSideEffects = SideEffectsFlagPlugin.moduleHasSideEffects(
|
97
102
|
resolveData.relativePath,
|
98
103
|
sideEffects,
|
99
|
-
cache
|
104
|
+
/** @type {CacheItem} */ (cache)
|
100
105
|
);
|
101
106
|
module.factoryMeta.sideEffectFree = !hasSideEffects;
|
102
107
|
}
|
@@ -132,7 +137,10 @@ class SideEffectsFlagPlugin {
|
|
132
137
|
switch (statement.type) {
|
133
138
|
case "ExpressionStatement":
|
134
139
|
if (
|
135
|
-
!parser.isPure(
|
140
|
+
!parser.isPure(
|
141
|
+
statement.expression,
|
142
|
+
/** @type {Range} */ (statement.range)[0]
|
143
|
+
)
|
136
144
|
) {
|
137
145
|
sideEffectsStatement = statement;
|
138
146
|
}
|
@@ -140,27 +148,35 @@ class SideEffectsFlagPlugin {
|
|
140
148
|
case "IfStatement":
|
141
149
|
case "WhileStatement":
|
142
150
|
case "DoWhileStatement":
|
143
|
-
if (
|
151
|
+
if (
|
152
|
+
!parser.isPure(
|
153
|
+
statement.test,
|
154
|
+
/** @type {Range} */ (statement.range)[0]
|
155
|
+
)
|
156
|
+
) {
|
144
157
|
sideEffectsStatement = statement;
|
145
158
|
}
|
146
159
|
// statement hook will be called for child statements too
|
147
160
|
break;
|
148
161
|
case "ForStatement":
|
149
162
|
if (
|
150
|
-
!parser.isPure(
|
163
|
+
!parser.isPure(
|
164
|
+
statement.init,
|
165
|
+
/** @type {Range} */ (statement.range)[0]
|
166
|
+
) ||
|
151
167
|
!parser.isPure(
|
152
168
|
statement.test,
|
153
169
|
statement.init
|
154
|
-
? statement.init.range[1]
|
155
|
-
: statement.range[0]
|
170
|
+
? /** @type {Range} */ (statement.init.range)[1]
|
171
|
+
: /** @type {Range} */ (statement.range)[0]
|
156
172
|
) ||
|
157
173
|
!parser.isPure(
|
158
174
|
statement.update,
|
159
175
|
statement.test
|
160
|
-
? statement.test.range[1]
|
176
|
+
? /** @type {Range} */ (statement.test.range)[1]
|
161
177
|
: statement.init
|
162
|
-
? statement.init.range[1]
|
163
|
-
: statement.range[0]
|
178
|
+
? /** @type {Range} */ (statement.init.range)[1]
|
179
|
+
: /** @type {Range} */ (statement.range)[0]
|
164
180
|
)
|
165
181
|
) {
|
166
182
|
sideEffectsStatement = statement;
|
@@ -169,7 +185,10 @@ class SideEffectsFlagPlugin {
|
|
169
185
|
break;
|
170
186
|
case "SwitchStatement":
|
171
187
|
if (
|
172
|
-
!parser.isPure(
|
188
|
+
!parser.isPure(
|
189
|
+
statement.discriminant,
|
190
|
+
/** @type {Range} */ (statement.range)[0]
|
191
|
+
)
|
173
192
|
) {
|
174
193
|
sideEffectsStatement = statement;
|
175
194
|
}
|
@@ -178,14 +197,22 @@ class SideEffectsFlagPlugin {
|
|
178
197
|
case "VariableDeclaration":
|
179
198
|
case "ClassDeclaration":
|
180
199
|
case "FunctionDeclaration":
|
181
|
-
if (
|
200
|
+
if (
|
201
|
+
!parser.isPure(
|
202
|
+
statement,
|
203
|
+
/** @type {Range} */ (statement.range)[0]
|
204
|
+
)
|
205
|
+
) {
|
182
206
|
sideEffectsStatement = statement;
|
183
207
|
}
|
184
208
|
break;
|
185
209
|
case "ExportNamedDeclaration":
|
186
210
|
case "ExportDefaultDeclaration":
|
187
211
|
if (
|
188
|
-
!parser.isPure(
|
212
|
+
!parser.isPure(
|
213
|
+
statement.declaration,
|
214
|
+
/** @type {Range} */ (statement.range)[0]
|
215
|
+
)
|
189
216
|
) {
|
190
217
|
sideEffectsStatement = statement;
|
191
218
|
}
|
@@ -208,7 +235,8 @@ class SideEffectsFlagPlugin {
|
|
208
235
|
);
|
209
236
|
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
210
237
|
if (sideEffectsStatement === undefined) {
|
211
|
-
|
238
|
+
/** @type {BuildMeta} */
|
239
|
+
(parser.state.module.buildMeta).sideEffectFree = true;
|
212
240
|
} else {
|
213
241
|
const { loc, type } = sideEffectsStatement;
|
214
242
|
moduleGraph
|
@@ -216,7 +244,7 @@ class SideEffectsFlagPlugin {
|
|
216
244
|
.push(
|
217
245
|
() =>
|
218
246
|
`Statement (${type}) with side effects in source code at ${formatLocation(
|
219
|
-
loc
|
247
|
+
/** @type {DependencyLocation} */ (loc)
|
220
248
|
)}`
|
221
249
|
);
|
222
250
|
}
|
@@ -246,6 +274,9 @@ class SideEffectsFlagPlugin {
|
|
246
274
|
|
247
275
|
const optimizedModules = new Set();
|
248
276
|
|
277
|
+
/**
|
278
|
+
* @param {Module} module module
|
279
|
+
*/
|
249
280
|
const optimizeIncomingConnections = module => {
|
250
281
|
if (optimizedModules.has(module)) return;
|
251
282
|
optimizedModules.add(module);
|
@@ -160,7 +160,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
160
160
|
* @property {string} name
|
161
161
|
* @property {Record<string, number>} sizes
|
162
162
|
* @property {Set<Chunk>} chunks
|
163
|
-
* @property {Set<Chunk>}
|
163
|
+
* @property {Set<Chunk>} reusableChunks
|
164
164
|
* @property {Set<bigint | Chunk>} chunksKeys
|
165
165
|
*/
|
166
166
|
|
@@ -1177,7 +1177,7 @@ module.exports = class SplitChunksPlugin {
|
|
1177
1177
|
name,
|
1178
1178
|
sizes: {},
|
1179
1179
|
chunks: new Set(),
|
1180
|
-
|
1180
|
+
reusableChunks: new Set(),
|
1181
1181
|
chunksKeys: new Set()
|
1182
1182
|
})
|
1183
1183
|
);
|
@@ -13,6 +13,7 @@ const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
|
|
13
13
|
/** @typedef {import("webpack-sources").Source} Source */
|
14
14
|
/** @typedef {import("../../declarations/WebpackOptions").PerformanceOptions} PerformanceOptions */
|
15
15
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
16
|
+
/** @typedef {import("../Compilation").Asset} Asset */
|
16
17
|
/** @typedef {import("../Compiler")} Compiler */
|
17
18
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
18
19
|
/** @typedef {import("../WebpackError")} WebpackError */
|
@@ -32,6 +33,12 @@ const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
|
|
32
33
|
|
33
34
|
const isOverSizeLimitSet = new WeakSet();
|
34
35
|
|
36
|
+
/**
|
37
|
+
* @param {Asset["name"]} name the name
|
38
|
+
* @param {Asset["source"]} source the source
|
39
|
+
* @param {Asset["info"]} info the info
|
40
|
+
* @returns {boolean} result
|
41
|
+
*/
|
35
42
|
const excludeSourceMap = (name, source, info) => !info.development;
|
36
43
|
|
37
44
|
module.exports = class SizeLimitsPlugin {
|
@@ -104,6 +111,10 @@ module.exports = class SizeLimitsPlugin {
|
|
104
111
|
}
|
105
112
|
}
|
106
113
|
|
114
|
+
/**
|
115
|
+
* @param {Asset["name"]} name the name
|
116
|
+
* @returns {boolean | undefined} result
|
117
|
+
*/
|
107
118
|
const fileFilter = name => {
|
108
119
|
const asset = compilation.getAsset(name);
|
109
120
|
return asset && assetFilter(asset.name, asset.source, asset.info);
|
@@ -9,6 +9,10 @@
|
|
9
9
|
/** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
|
10
10
|
|
11
11
|
class ObjectMatcherRulePlugin {
|
12
|
+
/**
|
13
|
+
* @param {string} ruleProperty the rule property
|
14
|
+
* @param {string=} dataProperty the data property
|
15
|
+
*/
|
12
16
|
constructor(ruleProperty, dataProperty) {
|
13
17
|
this.ruleProperty = ruleProperty;
|
14
18
|
this.dataProperty = dataProperty || ruleProperty;
|
@@ -9,10 +9,11 @@ const RuntimeModule = require("../RuntimeModule");
|
|
9
9
|
const Template = require("../Template");
|
10
10
|
|
11
11
|
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
12
13
|
|
13
14
|
class EnsureChunkRuntimeModule extends RuntimeModule {
|
14
15
|
/**
|
15
|
-
* @param {
|
16
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
16
17
|
*/
|
17
18
|
constructor(runtimeRequirements) {
|
18
19
|
super("ensure chunk");
|
@@ -9,10 +9,11 @@ const Template = require("../Template");
|
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
10
|
|
11
11
|
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
12
13
|
|
13
14
|
class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
|
14
15
|
/**
|
15
|
-
* @param {
|
16
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
16
17
|
*/
|
17
18
|
constructor(runtimeRequirements) {
|
18
19
|
super("trusted types policy");
|
@@ -576,6 +576,7 @@ class FileMiddleware extends SerializerMiddleware {
|
|
576
576
|
/** @type {number | undefined} */
|
577
577
|
let currentBufferUsed;
|
578
578
|
const buf = [];
|
579
|
+
/** @type {import("zlib").Zlib & import("stream").Transform | undefined} */
|
579
580
|
let decompression;
|
580
581
|
if (file.endsWith(".gz")) {
|
581
582
|
decompression = createGunzip({
|
@@ -46,6 +46,8 @@ Technically any value can be used.
|
|
46
46
|
/**
|
47
47
|
* @typedef {Object} ObjectSerializerContext
|
48
48
|
* @property {function(any): void} write
|
49
|
+
* @property {(function(any): void)=} writeLazy
|
50
|
+
* @property {(function(any, object=): (() => Promise<any> | any))=} writeSeparate
|
49
51
|
* @property {function(any): void} setCircularReference
|
50
52
|
*/
|
51
53
|
|
@@ -4,13 +4,27 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/**
|
8
|
+
* @template T, K
|
9
|
+
* @typedef {import("./SerializerMiddleware")<T, K>} SerializerMiddleware
|
10
|
+
*/
|
11
|
+
|
7
12
|
class Serializer {
|
13
|
+
/**
|
14
|
+
* @param {SerializerMiddleware<any, any>[]} middlewares serializer middlewares
|
15
|
+
* @param {TODO=} context context
|
16
|
+
*/
|
8
17
|
constructor(middlewares, context) {
|
9
18
|
this.serializeMiddlewares = middlewares.slice();
|
10
19
|
this.deserializeMiddlewares = middlewares.slice().reverse();
|
11
20
|
this.context = context;
|
12
21
|
}
|
13
22
|
|
23
|
+
/**
|
24
|
+
* @param {any} obj object
|
25
|
+
* @param {TODO} context content
|
26
|
+
* @returns {Promise<any>} result
|
27
|
+
*/
|
14
28
|
serialize(obj, context) {
|
15
29
|
const ctx = { ...context, ...this.context };
|
16
30
|
let current = obj;
|
@@ -28,6 +42,11 @@ class Serializer {
|
|
28
42
|
return current;
|
29
43
|
}
|
30
44
|
|
45
|
+
/**
|
46
|
+
* @param {any} value value
|
47
|
+
* @param {TODO} context context
|
48
|
+
* @returns {Promise<any>} result
|
49
|
+
*/
|
31
50
|
deserialize(value, context) {
|
32
51
|
const ctx = { ...context, ...this.context };
|
33
52
|
/** @type {any} */
|
@@ -25,6 +25,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
|
|
25
25
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
26
26
|
/** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
|
27
27
|
/** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
|
28
|
+
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
28
29
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
29
30
|
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
30
31
|
/** @typedef {import("../WebpackError")} WebpackError */
|
@@ -41,7 +42,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
|
|
41
42
|
* @property {string} shareKey global share key
|
42
43
|
* @property {string} shareScope share scope
|
43
44
|
* @property {SemVerRange | false | undefined} requiredVersion version requirement
|
44
|
-
* @property {string} packageName package name to determine required version automatically
|
45
|
+
* @property {string=} packageName package name to determine required version automatically
|
45
46
|
* @property {boolean} strictVersion don't use shared version even if version isn't valid
|
46
47
|
* @property {boolean} singleton use single global version
|
47
48
|
* @property {boolean} eager include the fallback module in a sync way
|
@@ -147,7 +148,7 @@ class ConsumeSharedModule extends Module {
|
|
147
148
|
}
|
148
149
|
|
149
150
|
/**
|
150
|
-
* @returns {
|
151
|
+
* @returns {SourceTypes} types available (do not mutate)
|
151
152
|
*/
|
152
153
|
getSourceTypes() {
|
153
154
|
return TYPES;
|
@@ -117,7 +117,12 @@ class ConsumeSharedPlugin {
|
|
117
117
|
normalModuleFactory
|
118
118
|
);
|
119
119
|
|
120
|
-
|
120
|
+
/** @type {Map<string, ConsumeOptions>} */
|
121
|
+
let unresolvedConsumes;
|
122
|
+
/** @type {Map<string, ConsumeOptions>} */
|
123
|
+
let resolvedConsumes;
|
124
|
+
/** @type {Map<string, ConsumeOptions>} */
|
125
|
+
let prefixedConsumes;
|
121
126
|
const promise = resolveMatchedConfigs(compilation, this._consumes).then(
|
122
127
|
({ resolved, unresolved, prefixed }) => {
|
123
128
|
resolvedConsumes = resolved;
|
@@ -138,6 +143,9 @@ class ConsumeSharedPlugin {
|
|
138
143
|
* @returns {Promise<ConsumeSharedModule>} create module
|
139
144
|
*/
|
140
145
|
const createConsumeSharedModule = (context, request, config) => {
|
146
|
+
/**
|
147
|
+
* @param {string} details details
|
148
|
+
*/
|
141
149
|
const requiredVersionWarning = details => {
|
142
150
|
const error = new WebpackError(
|
143
151
|
`No required version specified and unable to automatically determine one. ${details}`
|
@@ -293,9 +301,15 @@ class ConsumeSharedPlugin {
|
|
293
301
|
) {
|
294
302
|
return Promise.resolve();
|
295
303
|
}
|
296
|
-
const options = resolvedConsumes.get(
|
304
|
+
const options = resolvedConsumes.get(
|
305
|
+
/** @type {string} */ (resource)
|
306
|
+
);
|
297
307
|
if (options !== undefined) {
|
298
|
-
return createConsumeSharedModule(
|
308
|
+
return createConsumeSharedModule(
|
309
|
+
context,
|
310
|
+
/** @type {string} */ (resource),
|
311
|
+
options
|
312
|
+
);
|
299
313
|
}
|
300
314
|
return Promise.resolve();
|
301
315
|
}
|
@@ -17,14 +17,16 @@ const {
|
|
17
17
|
|
18
18
|
/** @typedef {import("webpack-sources").Source} Source */
|
19
19
|
/** @typedef {import("../Chunk")} Chunk */
|
20
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
20
21
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
21
22
|
/** @typedef {import("../Compilation")} Compilation */
|
22
23
|
/** @typedef {import("../Module")} Module */
|
24
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
23
25
|
/** @typedef {import("./ConsumeSharedModule")} ConsumeSharedModule */
|
24
26
|
|
25
27
|
class ConsumeSharedRuntimeModule extends RuntimeModule {
|
26
28
|
/**
|
27
|
-
* @param {
|
29
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
28
30
|
*/
|
29
31
|
constructor(runtimeRequirements) {
|
30
32
|
super("consumes", RuntimeModule.STAGE_ATTACH);
|
@@ -38,6 +40,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
38
40
|
const compilation = /** @type {Compilation} */ (this.compilation);
|
39
41
|
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
40
42
|
const { runtimeTemplate, codeGenerationResults } = compilation;
|
43
|
+
/** @type {Record<ChunkId, (string | number)[]>} */
|
41
44
|
const chunkToModuleMapping = {};
|
42
45
|
/** @type {Map<string | number, Source>} */
|
43
46
|
const moduleIdToSourceMapping = new Map();
|
@@ -70,7 +73,11 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
70
73
|
"consume-shared"
|
71
74
|
);
|
72
75
|
if (!modules) continue;
|
73
|
-
addModules(
|
76
|
+
addModules(
|
77
|
+
modules,
|
78
|
+
chunk,
|
79
|
+
(chunkToModuleMapping[/** @type {ChunkId} */ (chunk.id)] = [])
|
80
|
+
);
|
74
81
|
}
|
75
82
|
for (const chunk of /** @type {Chunk} */ (
|
76
83
|
this.chunk
|
@@ -21,6 +21,7 @@ const ProvideForSharedDependency = require("./ProvideForSharedDependency");
|
|
21
21
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
22
22
|
/** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
|
23
23
|
/** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
|
24
|
+
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
24
25
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
25
26
|
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
26
27
|
/** @typedef {import("../WebpackError")} WebpackError */
|
@@ -120,7 +121,7 @@ class ProvideSharedModule extends Module {
|
|
120
121
|
}
|
121
122
|
|
122
123
|
/**
|
123
|
-
* @returns {
|
124
|
+
* @returns {SourceTypes} types available (do not mutate)
|
124
125
|
*/
|
125
126
|
getSourceTypes() {
|
126
127
|
return TYPES;
|