webpack 5.99.4 → 5.99.6
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/README.md +1 -1
- package/lib/APIPlugin.js +2 -2
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +12 -9
- package/lib/Compilation.js +36 -27
- package/lib/Compiler.js +4 -3
- package/lib/ContextModule.js +2 -1
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/Module.js +10 -2
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +15 -10
- package/lib/NormalModule.js +1 -1
- package/lib/PrefetchPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +1 -1
- package/lib/Template.js +1 -1
- package/lib/WebpackOptionsApply.js +17 -2
- package/lib/buildChunkGraph.js +7 -2
- package/lib/cache/IdleFileCachePlugin.js +1 -1
- package/lib/cache/MemoryCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +3 -2
- package/lib/cache/PackFileCacheStrategy.js +13 -21
- package/lib/cache/ResolverCachePlugin.js +14 -16
- package/lib/cli.js +3 -3
- package/lib/config/defaults.js +2 -2
- package/lib/config/target.js +6 -6
- package/lib/css/CssParser.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CssIcssImportDependency.js +3 -2
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LocalModulesHelpers.js +1 -1
- package/lib/dependencies/RequireResolveDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +20 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/NamedChunkIdsPlugin.js +2 -2
- package/lib/ids/NamedModuleIdsPlugin.js +2 -2
- package/lib/index.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/JavascriptParser.js +66 -72
- package/lib/library/EnableLibraryPlugin.js +15 -2
- package/lib/library/ModuleLibraryPlugin.js +6 -1
- package/lib/logging/createConsoleLogger.js +0 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
- package/lib/node/NodeTemplatePlugin.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/SplitChunksPlugin.js +2 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
- package/lib/serialization/BinaryMiddleware.js +22 -38
- package/lib/serialization/FileMiddleware.js +29 -33
- package/lib/serialization/ObjectMiddleware.js +29 -30
- package/lib/serialization/Serializer.js +29 -18
- package/lib/serialization/SerializerMiddleware.js +105 -72
- package/lib/serialization/SingleItemMiddleware.js +4 -5
- package/lib/stats/DefaultStatsFactoryPlugin.js +39 -24
- package/lib/stats/DefaultStatsPrinterPlugin.js +267 -80
- package/lib/stats/StatsFactory.js +47 -10
- package/lib/stats/StatsPrinter.js +52 -31
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/TupleQueue.js +9 -7
- package/lib/util/TupleSet.js +37 -18
- package/lib/util/WeakTupleMap.js +50 -37
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/fs.js +1 -1
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/runtime.js +1 -0
- package/lib/util/serialization.js +50 -42
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/web/FetchCompileWasmPlugin.js +2 -2
- package/lib/webpack.js +1 -1
- package/package.json +1 -1
- package/types.d.ts +125 -74
@@ -280,10 +280,13 @@ class VariableInfo {
|
|
280
280
|
/**
|
281
281
|
* @typedef {object} TagInfo
|
282
282
|
* @property {Tag} tag
|
283
|
-
* @property {TagData}
|
283
|
+
* @property {TagData=} data
|
284
284
|
* @property {TagInfo | undefined} next
|
285
285
|
*/
|
286
286
|
|
287
|
+
const SCOPE_INFO_TERMINATED_RETURN = 1;
|
288
|
+
const SCOPE_INFO_TERMINATED_THROW = 2;
|
289
|
+
|
287
290
|
/**
|
288
291
|
* @typedef {object} ScopeInfo
|
289
292
|
* @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
|
@@ -293,8 +296,7 @@ class VariableInfo {
|
|
293
296
|
* @property {boolean} inTry
|
294
297
|
* @property {boolean} isStrict
|
295
298
|
* @property {boolean} isAsmJs
|
296
|
-
* @property {
|
297
|
-
* @property {undefined|"return"|"throw"} terminated
|
299
|
+
* @property {undefined | 1 | 2} terminated
|
298
300
|
*/
|
299
301
|
|
300
302
|
/** @typedef {[number, number]} Range */
|
@@ -310,9 +312,9 @@ class VariableInfo {
|
|
310
312
|
* Helper function for joining two ranges into a single range. This is useful
|
311
313
|
* when working with AST nodes, as it allows you to combine the ranges of child nodes
|
312
314
|
* to create the range of the _parent node_.
|
313
|
-
* @param {
|
314
|
-
* @param {
|
315
|
-
* @returns {
|
315
|
+
* @param {Range} startRange start range to join
|
316
|
+
* @param {Range} endRange end range to join
|
317
|
+
* @returns {Range} joined range
|
316
318
|
* @example
|
317
319
|
* ```js
|
318
320
|
* const startRange = [0, 5];
|
@@ -827,8 +829,8 @@ class JavascriptParser extends Parser {
|
|
827
829
|
if (!right.isCompileTimeValue()) return;
|
828
830
|
|
829
831
|
const result = operandHandler(
|
830
|
-
left.asCompileTimeValue(),
|
831
|
-
right.asCompileTimeValue()
|
832
|
+
/** @type {T} */ (left.asCompileTimeValue()),
|
833
|
+
/** @type {T} */ (right.asCompileTimeValue())
|
832
834
|
);
|
833
835
|
return valueAsExpression(
|
834
836
|
result,
|
@@ -1231,7 +1233,9 @@ class JavascriptParser extends Parser {
|
|
1231
1233
|
const handleConstOperation = operandHandler => {
|
1232
1234
|
const argument = this.evaluateExpression(expr.argument);
|
1233
1235
|
if (!argument.isCompileTimeValue()) return;
|
1234
|
-
const result = operandHandler(
|
1236
|
+
const result = operandHandler(
|
1237
|
+
/** @type {T} */ (argument.asCompileTimeValue())
|
1238
|
+
);
|
1235
1239
|
return valueAsExpression(
|
1236
1240
|
result,
|
1237
1241
|
expr,
|
@@ -2171,7 +2175,7 @@ class JavascriptParser extends Parser {
|
|
2171
2175
|
this.blockPreWalkStatements(body);
|
2172
2176
|
this.prevStatement = prev;
|
2173
2177
|
this.walkStatements(body);
|
2174
|
-
},
|
2178
|
+
}, true);
|
2175
2179
|
}
|
2176
2180
|
|
2177
2181
|
/**
|
@@ -2211,16 +2215,12 @@ class JavascriptParser extends Parser {
|
|
2211
2215
|
|
2212
2216
|
this.scope.terminated =
|
2213
2217
|
consequentTerminated && alternateTerminated
|
2214
|
-
?
|
2218
|
+
? alternateTerminated
|
2215
2219
|
: undefined;
|
2216
|
-
} else {
|
2217
|
-
this.
|
2218
|
-
|
2219
|
-
|
2220
|
-
} else if (statement.alternate) {
|
2221
|
-
this.walkNestedStatement(statement.alternate);
|
2222
|
-
}
|
2223
|
-
});
|
2220
|
+
} else if (result) {
|
2221
|
+
this.walkNestedStatement(statement.consequent);
|
2222
|
+
} else if (statement.alternate) {
|
2223
|
+
this.walkNestedStatement(statement.alternate);
|
2224
2224
|
}
|
2225
2225
|
}
|
2226
2226
|
|
@@ -2240,7 +2240,9 @@ class JavascriptParser extends Parser {
|
|
2240
2240
|
const result = hook.call(statement);
|
2241
2241
|
if (result === true) return;
|
2242
2242
|
}
|
2243
|
-
this.
|
2243
|
+
this.inBlockScope(() => {
|
2244
|
+
this.walkNestedStatement(statement.body);
|
2245
|
+
});
|
2244
2246
|
}
|
2245
2247
|
|
2246
2248
|
/**
|
@@ -2254,8 +2256,10 @@ class JavascriptParser extends Parser {
|
|
2254
2256
|
* @param {WithStatement} statement with statement
|
2255
2257
|
*/
|
2256
2258
|
walkWithStatement(statement) {
|
2257
|
-
this.
|
2258
|
-
|
2259
|
+
this.inBlockScope(() => {
|
2260
|
+
this.walkExpression(statement.object);
|
2261
|
+
this.walkNestedStatement(statement.body);
|
2262
|
+
});
|
2259
2263
|
}
|
2260
2264
|
|
2261
2265
|
/**
|
@@ -2282,7 +2286,9 @@ class JavascriptParser extends Parser {
|
|
2282
2286
|
if (this.scope.topLevelScope === true) return;
|
2283
2287
|
if (this.hooks.terminate.call(statement)) {
|
2284
2288
|
this.scope.terminated =
|
2285
|
-
statement.type === "ReturnStatement"
|
2289
|
+
statement.type === "ReturnStatement"
|
2290
|
+
? SCOPE_INFO_TERMINATED_RETURN
|
2291
|
+
: SCOPE_INFO_TERMINATED_THROW;
|
2286
2292
|
}
|
2287
2293
|
}
|
2288
2294
|
|
@@ -2329,14 +2335,20 @@ class JavascriptParser extends Parser {
|
|
2329
2335
|
const handlerTerminated = this.scope.terminated;
|
2330
2336
|
this.scope.terminated = undefined;
|
2331
2337
|
|
2332
|
-
if (statement.finalizer)
|
2338
|
+
if (statement.finalizer) {
|
2339
|
+
this.walkStatement(statement.finalizer);
|
2340
|
+
}
|
2333
2341
|
|
2334
|
-
|
2335
|
-
|
2342
|
+
const finalizerTerminated = this.scope.terminated;
|
2343
|
+
this.scope.terminated = undefined;
|
2344
|
+
|
2345
|
+
if (finalizerTerminated) {
|
2346
|
+
this.scope.terminated = finalizerTerminated;
|
2347
|
+
} else if (
|
2336
2348
|
tryTerminated &&
|
2337
2349
|
(statement.handler ? handlerTerminated : true)
|
2338
2350
|
) {
|
2339
|
-
this.scope.terminated = tryTerminated;
|
2351
|
+
this.scope.terminated = handlerTerminated || tryTerminated;
|
2340
2352
|
}
|
2341
2353
|
}
|
2342
2354
|
|
@@ -2351,8 +2363,10 @@ class JavascriptParser extends Parser {
|
|
2351
2363
|
* @param {WhileStatement} statement while statement
|
2352
2364
|
*/
|
2353
2365
|
walkWhileStatement(statement) {
|
2354
|
-
this.
|
2355
|
-
|
2366
|
+
this.inBlockScope(() => {
|
2367
|
+
this.walkExpression(statement.test);
|
2368
|
+
this.walkNestedStatement(statement.body);
|
2369
|
+
});
|
2356
2370
|
}
|
2357
2371
|
|
2358
2372
|
/**
|
@@ -2366,8 +2380,10 @@ class JavascriptParser extends Parser {
|
|
2366
2380
|
* @param {DoWhileStatement} statement do while statement
|
2367
2381
|
*/
|
2368
2382
|
walkDoWhileStatement(statement) {
|
2369
|
-
this.
|
2370
|
-
|
2383
|
+
this.inBlockScope(() => {
|
2384
|
+
this.walkNestedStatement(statement.body);
|
2385
|
+
this.walkExpression(statement.test);
|
2386
|
+
});
|
2371
2387
|
}
|
2372
2388
|
|
2373
2389
|
/**
|
@@ -2400,7 +2416,9 @@ class JavascriptParser extends Parser {
|
|
2400
2416
|
if (statement.update) {
|
2401
2417
|
this.walkExpression(statement.update);
|
2402
2418
|
}
|
2419
|
+
|
2403
2420
|
const body = statement.body;
|
2421
|
+
|
2404
2422
|
if (body.type === "BlockStatement") {
|
2405
2423
|
// no need to add additional scope
|
2406
2424
|
const prev = this.prevStatement;
|
@@ -2434,8 +2452,11 @@ class JavascriptParser extends Parser {
|
|
2434
2452
|
} else {
|
2435
2453
|
this.walkPattern(statement.left);
|
2436
2454
|
}
|
2455
|
+
|
2437
2456
|
this.walkExpression(statement.right);
|
2457
|
+
|
2438
2458
|
const body = statement.body;
|
2459
|
+
|
2439
2460
|
if (body.type === "BlockStatement") {
|
2440
2461
|
// no need to add additional scope
|
2441
2462
|
const prev = this.prevStatement;
|
@@ -2472,8 +2493,11 @@ class JavascriptParser extends Parser {
|
|
2472
2493
|
} else {
|
2473
2494
|
this.walkPattern(statement.left);
|
2474
2495
|
}
|
2496
|
+
|
2475
2497
|
this.walkExpression(statement.right);
|
2498
|
+
|
2476
2499
|
const body = statement.body;
|
2500
|
+
|
2477
2501
|
if (body.type === "BlockStatement") {
|
2478
2502
|
// no need to add additional scope
|
2479
2503
|
const prev = this.prevStatement;
|
@@ -3485,21 +3509,16 @@ class JavascriptParser extends Parser {
|
|
3485
3509
|
walkConditionalExpression(expression) {
|
3486
3510
|
const result = this.hooks.expressionConditionalOperator.call(expression);
|
3487
3511
|
if (result === undefined) {
|
3488
|
-
this.
|
3489
|
-
|
3490
|
-
|
3491
|
-
|
3492
|
-
|
3493
|
-
|
3494
|
-
|
3495
|
-
|
3496
|
-
|
3497
|
-
|
3498
|
-
this.walkExpression(expression.consequent);
|
3499
|
-
} else if (expression.alternate) {
|
3500
|
-
this.walkExpression(expression.alternate);
|
3501
|
-
}
|
3502
|
-
});
|
3512
|
+
this.walkExpression(expression.test);
|
3513
|
+
this.walkExpression(expression.consequent);
|
3514
|
+
|
3515
|
+
if (expression.alternate) {
|
3516
|
+
this.walkExpression(expression.alternate);
|
3517
|
+
}
|
3518
|
+
} else if (result) {
|
3519
|
+
this.walkExpression(expression.consequent);
|
3520
|
+
} else if (expression.alternate) {
|
3521
|
+
this.walkExpression(expression.alternate);
|
3503
3522
|
}
|
3504
3523
|
}
|
3505
3524
|
|
@@ -4067,7 +4086,6 @@ class JavascriptParser extends Parser {
|
|
4067
4086
|
inTaggedTemplateTag: false,
|
4068
4087
|
isStrict: oldScope.isStrict,
|
4069
4088
|
isAsmJs: oldScope.isAsmJs,
|
4070
|
-
inExecutedPath: false,
|
4071
4089
|
terminated: undefined,
|
4072
4090
|
definitions: oldScope.definitions.createChild()
|
4073
4091
|
};
|
@@ -4083,23 +4101,6 @@ class JavascriptParser extends Parser {
|
|
4083
4101
|
this.scope = oldScope;
|
4084
4102
|
}
|
4085
4103
|
|
4086
|
-
/**
|
4087
|
-
* @param {boolean} state executed state
|
4088
|
-
* @param {() => void} fn inner function
|
4089
|
-
*/
|
4090
|
-
inExecutedPath(state, fn) {
|
4091
|
-
const oldState = this.scope.inExecutedPath;
|
4092
|
-
const oldTerminated = this.scope.terminated;
|
4093
|
-
this.scope.inExecutedPath = state;
|
4094
|
-
|
4095
|
-
fn();
|
4096
|
-
|
4097
|
-
if (!state) {
|
4098
|
-
this.scope.terminated = oldTerminated;
|
4099
|
-
}
|
4100
|
-
this.scope.inExecutedPath = oldState;
|
4101
|
-
}
|
4102
|
-
|
4103
4104
|
/**
|
4104
4105
|
* @param {boolean} hasThis true, when this is defined
|
4105
4106
|
* @param {Identifier[]} params scope params
|
@@ -4113,7 +4114,6 @@ class JavascriptParser extends Parser {
|
|
4113
4114
|
inTry: false,
|
4114
4115
|
inShorthand: false,
|
4115
4116
|
inTaggedTemplateTag: false,
|
4116
|
-
inExecutedPath: true,
|
4117
4117
|
isStrict: oldScope.isStrict,
|
4118
4118
|
isAsmJs: oldScope.isAsmJs,
|
4119
4119
|
terminated: undefined,
|
@@ -4146,7 +4146,6 @@ class JavascriptParser extends Parser {
|
|
4146
4146
|
inTry: false,
|
4147
4147
|
inShorthand: false,
|
4148
4148
|
inTaggedTemplateTag: false,
|
4149
|
-
inExecutedPath: true,
|
4150
4149
|
isStrict: oldScope.isStrict,
|
4151
4150
|
isAsmJs: oldScope.isAsmJs,
|
4152
4151
|
terminated: undefined,
|
@@ -4178,7 +4177,6 @@ class JavascriptParser extends Parser {
|
|
4178
4177
|
inTry: oldScope.inTry,
|
4179
4178
|
inShorthand: false,
|
4180
4179
|
inTaggedTemplateTag: false,
|
4181
|
-
inExecutedPath,
|
4182
4180
|
isStrict: oldScope.isStrict,
|
4183
4181
|
isAsmJs: oldScope.isAsmJs,
|
4184
4182
|
terminated: oldScope.terminated,
|
@@ -4189,10 +4187,7 @@ class JavascriptParser extends Parser {
|
|
4189
4187
|
|
4190
4188
|
const terminated = this.scope.terminated;
|
4191
4189
|
|
4192
|
-
if (
|
4193
|
-
inExecutedPath &&
|
4194
|
-
((this.scope.inTry && terminated === "throw") || terminated === "return")
|
4195
|
-
) {
|
4190
|
+
if (inExecutedPath && terminated) {
|
4196
4191
|
oldScope.terminated = terminated;
|
4197
4192
|
}
|
4198
4193
|
|
@@ -4512,7 +4507,6 @@ class JavascriptParser extends Parser {
|
|
4512
4507
|
inTry: false,
|
4513
4508
|
inShorthand: false,
|
4514
4509
|
inTaggedTemplateTag: false,
|
4515
|
-
inExecutedPath: false,
|
4516
4510
|
isStrict: false,
|
4517
4511
|
isAsmJs: false,
|
4518
4512
|
terminated: undefined,
|
@@ -12,6 +12,11 @@
|
|
12
12
|
/** @type {WeakMap<Compiler, Set<LibraryType>>} */
|
13
13
|
const enabledTypes = new WeakMap();
|
14
14
|
|
15
|
+
/**
|
16
|
+
* @typedef {object} EnableLibraryPluginOptions
|
17
|
+
* @property {() => void=} additionalApply function that runs when applying the current plugin.
|
18
|
+
*/
|
19
|
+
|
15
20
|
/**
|
16
21
|
* @param {Compiler} compiler the compiler instance
|
17
22
|
* @returns {Set<LibraryType>} enabled types
|
@@ -28,9 +33,13 @@ const getEnabledTypes = compiler => {
|
|
28
33
|
class EnableLibraryPlugin {
|
29
34
|
/**
|
30
35
|
* @param {LibraryType} type library type that should be available
|
36
|
+
* @param {EnableLibraryPluginOptions} options options of EnableLibraryPlugin
|
31
37
|
*/
|
32
|
-
constructor(type) {
|
38
|
+
constructor(type, options = {}) {
|
39
|
+
/** @type {LibraryType} */
|
33
40
|
this.type = type;
|
41
|
+
/** @type {EnableLibraryPluginOptions} */
|
42
|
+
this.options = options;
|
34
43
|
}
|
35
44
|
|
36
45
|
/**
|
@@ -67,13 +76,17 @@ class EnableLibraryPlugin {
|
|
67
76
|
* @returns {void}
|
68
77
|
*/
|
69
78
|
apply(compiler) {
|
70
|
-
const { type } = this;
|
79
|
+
const { type, options } = this;
|
71
80
|
|
72
81
|
// Only enable once
|
73
82
|
const enabled = getEnabledTypes(compiler);
|
74
83
|
if (enabled.has(type)) return;
|
75
84
|
enabled.add(type);
|
76
85
|
|
86
|
+
if (typeof options.additionalApply === "function") {
|
87
|
+
options.additionalApply();
|
88
|
+
}
|
89
|
+
|
77
90
|
if (typeof type === "string") {
|
78
91
|
const enableExportProperty = () => {
|
79
92
|
const ExportPropertyTemplatePlugin = require("./ExportPropertyLibraryPlugin");
|
@@ -187,7 +187,12 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
187
187
|
);
|
188
188
|
}
|
189
189
|
|
190
|
-
if (
|
190
|
+
if (
|
191
|
+
finalName &&
|
192
|
+
(finalName.includes(".") ||
|
193
|
+
finalName.includes("[") ||
|
194
|
+
finalName.includes("("))
|
195
|
+
) {
|
191
196
|
exports.push([exportInfo.name, finalName]);
|
192
197
|
} else {
|
193
198
|
shortHandedExports.push(
|
@@ -13,12 +13,12 @@ const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenc
|
|
13
13
|
|
14
14
|
/**
|
15
15
|
* @typedef {object} CommonJsChunkLoadingPluginOptions
|
16
|
-
* @property {boolean}
|
16
|
+
* @property {boolean=} asyncChunkLoading enable async chunk loading
|
17
17
|
*/
|
18
18
|
|
19
19
|
class CommonJsChunkLoadingPlugin {
|
20
20
|
/**
|
21
|
-
* @param {CommonJsChunkLoadingPluginOptions}
|
21
|
+
* @param {CommonJsChunkLoadingPluginOptions=} options options
|
22
22
|
*/
|
23
23
|
constructor(options = {}) {
|
24
24
|
this._asyncChunkLoading = options.asyncChunkLoading;
|
@@ -12,12 +12,12 @@ const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin
|
|
12
12
|
|
13
13
|
/**
|
14
14
|
* @typedef {object} NodeTemplatePluginOptions
|
15
|
-
* @property {boolean}
|
15
|
+
* @property {boolean=} asyncChunkLoading enable async chunk loading
|
16
16
|
*/
|
17
17
|
|
18
18
|
class NodeTemplatePlugin {
|
19
19
|
/**
|
20
|
-
* @param {NodeTemplatePluginOptions}
|
20
|
+
* @param {NodeTemplatePluginOptions=} options options object
|
21
21
|
*/
|
22
22
|
constructor(options = {}) {
|
23
23
|
this._options = options;
|
@@ -15,14 +15,14 @@ const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRun
|
|
15
15
|
|
16
16
|
/**
|
17
17
|
* @typedef {object} ReadFileCompileAsyncWasmPluginOptions
|
18
|
-
* @property {boolean}
|
18
|
+
* @property {boolean=} import use import?
|
19
19
|
*/
|
20
20
|
|
21
21
|
const PLUGIN_NAME = "ReadFileCompileAsyncWasmPlugin";
|
22
22
|
|
23
23
|
class ReadFileCompileAsyncWasmPlugin {
|
24
24
|
/**
|
25
|
-
* @param {ReadFileCompileAsyncWasmPluginOptions}
|
25
|
+
* @param {ReadFileCompileAsyncWasmPluginOptions=} options options object
|
26
26
|
*/
|
27
27
|
constructor({ import: useImport = false } = {}) {
|
28
28
|
this._import = useImport;
|
@@ -15,8 +15,8 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
|
|
15
15
|
|
16
16
|
/**
|
17
17
|
* @typedef {object} ReadFileCompileWasmPluginOptions
|
18
|
-
* @property {boolean}
|
19
|
-
* @property {boolean}
|
18
|
+
* @property {boolean=} mangleImports mangle imports
|
19
|
+
* @property {boolean=} import use import?
|
20
20
|
*/
|
21
21
|
|
22
22
|
// TODO webpack 6 remove
|
@@ -25,7 +25,7 @@ const PLUGIN_NAME = "ReadFileCompileWasmPlugin";
|
|
25
25
|
|
26
26
|
class ReadFileCompileWasmPlugin {
|
27
27
|
/**
|
28
|
-
* @param {ReadFileCompileWasmPluginOptions}
|
28
|
+
* @param {ReadFileCompileWasmPluginOptions=} options options object
|
29
29
|
*/
|
30
30
|
constructor(options = {}) {
|
31
31
|
this.options = options;
|
@@ -17,7 +17,7 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
|
|
17
17
|
|
18
18
|
class AggressiveMergingPlugin {
|
19
19
|
/**
|
20
|
-
* @param {AggressiveMergingPluginOptions=}
|
20
|
+
* @param {AggressiveMergingPluginOptions=} options options object
|
21
21
|
*/
|
22
22
|
constructor(options) {
|
23
23
|
if (
|
@@ -26,6 +26,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
26
26
|
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
|
27
27
|
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksSizes} OptimizationSplitChunksSizes */
|
28
28
|
/** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
|
29
|
+
/** @typedef {import("../Chunk").ChunkName} ChunkName */
|
29
30
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
30
31
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
31
32
|
/** @typedef {import("../Compiler")} Compiler */
|
@@ -1387,7 +1388,7 @@ module.exports = class SplitChunksPlugin {
|
|
1387
1388
|
const item = /** @type {ChunksInfoItem} */ (bestEntry);
|
1388
1389
|
chunksInfoMap.delete(/** @type {string} */ (bestEntryKey));
|
1389
1390
|
|
1390
|
-
/** @type {
|
1391
|
+
/** @type {ChunkName | undefined} */
|
1391
1392
|
let chunkName = item.name;
|
1392
1393
|
// Variable for the new chunk (lazy created)
|
1393
1394
|
/** @type {Chunk | undefined} */
|
@@ -10,6 +10,7 @@ const Template = require("../Template");
|
|
10
10
|
const { first } = require("../util/SetHelpers");
|
11
11
|
|
12
12
|
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
13
14
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
14
15
|
/** @typedef {import("../Compilation")} Compilation */
|
15
16
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
@@ -156,14 +157,12 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
156
157
|
hashWithLength: length =>
|
157
158
|
`" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
|
158
159
|
chunk: {
|
159
|
-
id: unquotedStringify(/** @type {
|
160
|
+
id: unquotedStringify(/** @type {ChunkId} */ (c.id)),
|
160
161
|
hash: unquotedStringify(/** @type {string} */ (c.renderedHash)),
|
161
162
|
hashWithLength: unquotedStringifyWithLength(
|
162
163
|
/** @type {string} */ (c.renderedHash)
|
163
164
|
),
|
164
|
-
name: unquotedStringify(
|
165
|
-
c.name || /** @type {number | string} */ (c.id)
|
166
|
-
),
|
165
|
+
name: unquotedStringify(c.name || /** @type {ChunkId} */ (c.id)),
|
167
166
|
contentHash: {
|
168
167
|
[contentType]: unquotedStringify(c.contentHash[contentType])
|
169
168
|
},
|
@@ -7,15 +7,9 @@
|
|
7
7
|
const memoize = require("../util/memoize");
|
8
8
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
9
9
|
|
10
|
-
/** @typedef {import("./SerializerMiddleware").Context} Context */
|
11
10
|
/** @typedef {import("./types").BufferSerializableType} BufferSerializableType */
|
12
11
|
/** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
|
13
12
|
|
14
|
-
/**
|
15
|
-
* @template LAZY_RESULT
|
16
|
-
* @typedef {import("./SerializerMiddleware").LazyFunction<LAZY_RESULT>} LazyFunction
|
17
|
-
*/
|
18
|
-
|
19
13
|
/*
|
20
14
|
Format:
|
21
15
|
|
@@ -141,10 +135,18 @@ const identifyBigInt = n => {
|
|
141
135
|
return 2;
|
142
136
|
};
|
143
137
|
|
138
|
+
/** @typedef {PrimitiveSerializableType[]} DeserializedType */
|
139
|
+
/** @typedef {BufferSerializableType[]} SerializedType} */
|
140
|
+
/** @typedef {{ retainedBuffer?: (x: Buffer) => Buffer }} Context} */
|
141
|
+
|
144
142
|
/**
|
145
|
-
* @
|
146
|
-
* @
|
147
|
-
* @
|
143
|
+
* @template LazyInputValue
|
144
|
+
* @template LazyOutputValue
|
145
|
+
* @typedef {import("./SerializerMiddleware").LazyFunction<LazyInputValue, LazyOutputValue, BinaryMiddleware, undefined>} LazyFunction
|
146
|
+
*/
|
147
|
+
|
148
|
+
/**
|
149
|
+
* @extends {SerializerMiddleware<DeserializedType, SerializedType, Context>}
|
148
150
|
*/
|
149
151
|
class BinaryMiddleware extends SerializerMiddleware {
|
150
152
|
/**
|
@@ -157,9 +159,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
157
159
|
}
|
158
160
|
|
159
161
|
/**
|
160
|
-
* @param {LazyFunction<DeserializedType>} fn lazy function
|
162
|
+
* @param {LazyFunction<DeserializedType, SerializedType>} fn lazy function
|
161
163
|
* @param {Context} context serialize function
|
162
|
-
* @returns {LazyFunction<SerializedType>} new lazy
|
164
|
+
* @returns {LazyFunction<SerializedType, DeserializedType>} new lazy
|
163
165
|
*/
|
164
166
|
_serializeLazy(fn, context) {
|
165
167
|
return SerializerMiddleware.serializeLazy(fn, data =>
|
@@ -281,7 +283,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
281
283
|
case "function": {
|
282
284
|
if (!SerializerMiddleware.isLazy(thing))
|
283
285
|
throw new Error(`Unexpected function ${thing}`);
|
284
|
-
/** @type {SerializedType | LazyFunction<SerializedType>} */
|
286
|
+
/** @type {SerializedType | LazyFunction<SerializedType, DeserializedType> | undefined} */
|
285
287
|
let serializedData =
|
286
288
|
SerializerMiddleware.getLazySerializedValue(thing);
|
287
289
|
if (serializedData === undefined) {
|
@@ -294,18 +296,10 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
294
296
|
const data = this._serialize(result, context, allocationScope);
|
295
297
|
leftOverBuffer = allocationScope.leftOverBuffer;
|
296
298
|
allocationScope.leftOverBuffer = null;
|
297
|
-
SerializerMiddleware.setLazySerializedValue(
|
298
|
-
/** @type {LazyFunction<DeserializedType>} */
|
299
|
-
(thing),
|
300
|
-
data
|
301
|
-
);
|
299
|
+
SerializerMiddleware.setLazySerializedValue(thing, data);
|
302
300
|
serializedData = data;
|
303
301
|
} else {
|
304
|
-
serializedData = this._serializeLazy(
|
305
|
-
/** @type {LazyFunction<DeserializedType>} */
|
306
|
-
(thing),
|
307
|
-
context
|
308
|
-
);
|
302
|
+
serializedData = this._serializeLazy(thing, context);
|
309
303
|
flush();
|
310
304
|
buffers.push(serializedData);
|
311
305
|
break;
|
@@ -666,7 +660,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
666
660
|
* @private
|
667
661
|
* @param {SerializedType} content content
|
668
662
|
* @param {Context} context context object
|
669
|
-
* @returns {LazyFunction<DeserializedType>} lazy function
|
663
|
+
* @returns {LazyFunction<DeserializedType, SerializedType>} lazy function
|
670
664
|
*/
|
671
665
|
_createLazyDeserialized(content, context) {
|
672
666
|
return SerializerMiddleware.createLazy(
|
@@ -679,9 +673,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
679
673
|
|
680
674
|
/**
|
681
675
|
* @private
|
682
|
-
* @param {LazyFunction<SerializedType>} fn lazy function
|
676
|
+
* @param {LazyFunction<SerializedType, DeserializedType>} fn lazy function
|
683
677
|
* @param {Context} context context object
|
684
|
-
* @returns {LazyFunction<DeserializedType>} new lazy
|
678
|
+
* @returns {LazyFunction<DeserializedType, SerializedType>} new lazy
|
685
679
|
*/
|
686
680
|
_deserializeLazy(fn, context) {
|
687
681
|
return SerializerMiddleware.deserializeLazy(fn, data =>
|
@@ -701,7 +695,6 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
701
695
|
let currentIsBuffer = Buffer.isBuffer(currentBuffer);
|
702
696
|
let currentPosition = 0;
|
703
697
|
|
704
|
-
/** @type {(x: Buffer) => Buffer} */
|
705
698
|
const retainedBuffer = context.retainedBuffer || (x => x);
|
706
699
|
|
707
700
|
const checkOverflow = () => {
|
@@ -818,17 +811,14 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
818
811
|
return () => {
|
819
812
|
const count = readU32();
|
820
813
|
const lengths = Array.from({ length: count }).map(() => readU32());
|
821
|
-
/** @type {(Buffer | LazyFunction<
|
814
|
+
/** @type {(Buffer | LazyFunction<SerializedType, DeserializedType>)[]} */
|
822
815
|
const content = [];
|
823
816
|
for (let l of lengths) {
|
824
817
|
if (l === 0) {
|
825
818
|
if (typeof currentBuffer !== "function") {
|
826
819
|
throw new Error("Unexpected non-lazy element in stream");
|
827
820
|
}
|
828
|
-
content.push(
|
829
|
-
/** @type {LazyFunction<BufferSerializableType[]>} */
|
830
|
-
(currentBuffer)
|
831
|
-
);
|
821
|
+
content.push(currentBuffer);
|
832
822
|
currentDataItem++;
|
833
823
|
currentBuffer =
|
834
824
|
currentDataItem < data.length ? data[currentDataItem] : null;
|
@@ -1144,13 +1134,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
1144
1134
|
let result = [];
|
1145
1135
|
while (currentBuffer !== null) {
|
1146
1136
|
if (typeof currentBuffer === "function") {
|
1147
|
-
result.push(
|
1148
|
-
this._deserializeLazy(
|
1149
|
-
/** @type {LazyFunction<SerializedType>} */
|
1150
|
-
(currentBuffer),
|
1151
|
-
context
|
1152
|
-
)
|
1153
|
-
);
|
1137
|
+
result.push(this._deserializeLazy(currentBuffer, context));
|
1154
1138
|
currentDataItem++;
|
1155
1139
|
currentBuffer =
|
1156
1140
|
currentDataItem < data.length ? data[currentDataItem] : null;
|