webpack 5.86.0 → 5.87.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 -2
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/ChunkGroup.js +1 -0
- package/lib/Compiler.js +3 -1
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +57 -29
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleGraph.js +31 -24
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +2 -1
- package/lib/RuntimeTemplate.js +20 -2
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/config/defaults.js +31 -2
- package/lib/css/CssModulesPlugin.js +5 -2
- package/lib/css/CssParser.js +12 -0
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportParserPlugin.js +25 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +23 -15
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptParser.js +118 -58
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +4 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
- package/lib/runtime/CompatRuntimeModule.js +6 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
- package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
- package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
- package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
- package/lib/runtime/PublicPathRuntimeModule.js +3 -1
- package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
- package/lib/serialization/ObjectMiddleware.js +6 -3
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
- package/lib/sharing/ProvideSharedDependency.js +11 -0
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +11 -4
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +32 -5
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/createHash.js +30 -9
- package/lib/util/deprecation.js +10 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/memoize.js +3 -3
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +14 -1
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyParser.js +6 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -3
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
- package/module.d.ts +1 -0
- package/package.json +4 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +39 -5
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +433 -184
@@ -94,7 +94,8 @@ const subtractSizeFrom = (total, size) => {
|
|
94
94
|
};
|
95
95
|
|
96
96
|
/**
|
97
|
-
* @
|
97
|
+
* @template T
|
98
|
+
* @param {Iterable<Node<T>>} nodes some nodes
|
98
99
|
* @returns {Record<string, number>} total size
|
99
100
|
*/
|
100
101
|
const sumSize = nodes => {
|
@@ -105,6 +106,11 @@ const sumSize = nodes => {
|
|
105
106
|
return sum;
|
106
107
|
};
|
107
108
|
|
109
|
+
/**
|
110
|
+
* @param {Record<string, number>} size size
|
111
|
+
* @param {Record<string, number>} maxSize minimum size
|
112
|
+
* @returns {boolean} true, when size is too big
|
113
|
+
*/
|
108
114
|
const isTooBig = (size, maxSize) => {
|
109
115
|
for (const key of Object.keys(size)) {
|
110
116
|
const s = size[key];
|
@@ -117,6 +123,11 @@ const isTooBig = (size, maxSize) => {
|
|
117
123
|
return false;
|
118
124
|
};
|
119
125
|
|
126
|
+
/**
|
127
|
+
* @param {Record<string, number>} size size
|
128
|
+
* @param {Record<string, number>} minSize minimum size
|
129
|
+
* @returns {boolean} true, when size is too small
|
130
|
+
*/
|
120
131
|
const isTooSmall = (size, minSize) => {
|
121
132
|
for (const key of Object.keys(size)) {
|
122
133
|
const s = size[key];
|
@@ -129,6 +140,11 @@ const isTooSmall = (size, minSize) => {
|
|
129
140
|
return false;
|
130
141
|
};
|
131
142
|
|
143
|
+
/**
|
144
|
+
* @param {Record<string, number>} size size
|
145
|
+
* @param {Record<string, number>} minSize minimum size
|
146
|
+
* @returns {Set<string>} set of types that are too small
|
147
|
+
*/
|
132
148
|
const getTooSmallTypes = (size, minSize) => {
|
133
149
|
const types = new Set();
|
134
150
|
for (const key of Object.keys(size)) {
|
@@ -142,6 +158,12 @@ const getTooSmallTypes = (size, minSize) => {
|
|
142
158
|
return types;
|
143
159
|
};
|
144
160
|
|
161
|
+
/**
|
162
|
+
* @template T
|
163
|
+
* @param {TODO} size size
|
164
|
+
* @param {Set<string>} types types
|
165
|
+
* @returns {number} number of matching size types
|
166
|
+
*/
|
145
167
|
const getNumberOfMatchingSizeTypes = (size, types) => {
|
146
168
|
let i = 0;
|
147
169
|
for (const key of Object.keys(size)) {
|
@@ -150,6 +172,11 @@ const getNumberOfMatchingSizeTypes = (size, types) => {
|
|
150
172
|
return i;
|
151
173
|
};
|
152
174
|
|
175
|
+
/**
|
176
|
+
* @param {Record<string, number>} size size
|
177
|
+
* @param {Set<string>} types types
|
178
|
+
* @returns {number} selective size sum
|
179
|
+
*/
|
153
180
|
const selectiveSizeSum = (size, types) => {
|
154
181
|
let sum = 0;
|
155
182
|
for (const key of Object.keys(size)) {
|
@@ -180,20 +207,20 @@ class Node {
|
|
180
207
|
class Group {
|
181
208
|
/**
|
182
209
|
* @param {Node<T>[]} nodes nodes
|
183
|
-
* @param {number[]} similarities similarities between the nodes (length = nodes.length - 1)
|
210
|
+
* @param {number[] | null} similarities similarities between the nodes (length = nodes.length - 1)
|
184
211
|
* @param {Record<string, number>=} size size of the group
|
185
212
|
*/
|
186
213
|
constructor(nodes, similarities, size) {
|
187
214
|
this.nodes = nodes;
|
188
215
|
this.similarities = similarities;
|
189
216
|
this.size = size || sumSize(nodes);
|
190
|
-
/** @type {string} */
|
217
|
+
/** @type {string | undefined} */
|
191
218
|
this.key = undefined;
|
192
219
|
}
|
193
220
|
|
194
221
|
/**
|
195
|
-
* @param {function(Node): boolean} filter filter function
|
196
|
-
* @returns {Node[]} removed nodes
|
222
|
+
* @param {function(Node<T>): boolean} filter filter function
|
223
|
+
* @returns {Node<T>[] | undefined} removed nodes
|
197
224
|
*/
|
198
225
|
popNodes(filter) {
|
199
226
|
const newNodes = [];
|
@@ -208,7 +235,7 @@ class Group {
|
|
208
235
|
if (newNodes.length > 0) {
|
209
236
|
newSimilarities.push(
|
210
237
|
lastNode === this.nodes[i - 1]
|
211
|
-
? this.similarities[i - 1]
|
238
|
+
? /** @type {number[]} */ (this.similarities)[i - 1]
|
212
239
|
: similarity(lastNode.key, node.key)
|
213
240
|
);
|
214
241
|
}
|
@@ -225,7 +252,8 @@ class Group {
|
|
225
252
|
}
|
226
253
|
|
227
254
|
/**
|
228
|
-
* @
|
255
|
+
* @template T
|
256
|
+
* @param {Iterable<Node<T>>} nodes nodes
|
229
257
|
* @returns {number[]} similarities
|
230
258
|
*/
|
231
259
|
const getSimilarities = nodes => {
|
@@ -297,6 +325,11 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
297
325
|
if (initialNodes.length > 0) {
|
298
326
|
const initialGroup = new Group(initialNodes, getSimilarities(initialNodes));
|
299
327
|
|
328
|
+
/**
|
329
|
+
* @param {Group<T>} group group
|
330
|
+
* @param {Record<string, number>} consideredSize size of the group to consider
|
331
|
+
* @returns {boolean} true, if the group was modified
|
332
|
+
*/
|
300
333
|
const removeProblematicNodes = (group, consideredSize = group.size) => {
|
301
334
|
const problemTypes = getTooSmallTypes(consideredSize, minSize);
|
302
335
|
if (problemTypes.size > 0) {
|
@@ -347,7 +380,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
347
380
|
const queue = [initialGroup];
|
348
381
|
|
349
382
|
while (queue.length) {
|
350
|
-
const group = queue.pop();
|
383
|
+
const group = /** @type {Group<T>} */ (queue.pop());
|
351
384
|
// only groups bigger than maxSize need to be splitted
|
352
385
|
if (!isTooBig(group.size, maxSize)) {
|
353
386
|
result.push(group);
|
@@ -428,7 +461,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
428
461
|
// rightSize ^^^^^^^^^^^^^^^
|
429
462
|
|
430
463
|
while (pos <= right + 1) {
|
431
|
-
const similarity = group.similarities[
|
464
|
+
const similarity = /** @type {number[]} */ (group.similarities)[
|
465
|
+
pos - 1
|
466
|
+
];
|
432
467
|
if (
|
433
468
|
similarity < bestSimilarity &&
|
434
469
|
!isTooSmall(leftSize, minSize) &&
|
@@ -458,7 +493,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
458
493
|
/** @type {number[]} */
|
459
494
|
const rightSimilarities = [];
|
460
495
|
for (let i = right + 2; i < group.nodes.length; i++) {
|
461
|
-
rightSimilarities.push(
|
496
|
+
rightSimilarities.push(
|
497
|
+
/** @type {number[]} */ (group.similarities)[i - 1]
|
498
|
+
);
|
462
499
|
rightNodes.push(group.nodes[i]);
|
463
500
|
}
|
464
501
|
queue.push(new Group(rightNodes, rightSimilarities));
|
@@ -467,7 +504,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
467
504
|
/** @type {number[]} */
|
468
505
|
const leftSimilarities = [];
|
469
506
|
for (let i = 1; i < left; i++) {
|
470
|
-
leftSimilarities.push(
|
507
|
+
leftSimilarities.push(
|
508
|
+
/** @type {number[]} */ (group.similarities)[i - 1]
|
509
|
+
);
|
471
510
|
leftNodes.push(group.nodes[i]);
|
472
511
|
}
|
473
512
|
queue.push(new Group(leftNodes, leftSimilarities));
|
@@ -109,7 +109,9 @@ module.exports = (items, getDependencies) => {
|
|
109
109
|
// Are there still edges unprocessed in the current node?
|
110
110
|
if (topOfStack.openEdges.length > 0) {
|
111
111
|
// Process one dependency
|
112
|
-
const dependency =
|
112
|
+
const dependency =
|
113
|
+
/** @type {Node<T>} */
|
114
|
+
(topOfStack.openEdges.pop());
|
113
115
|
switch (dependency.marker) {
|
114
116
|
case NO_MARKER:
|
115
117
|
// dependency has not be visited yet
|
@@ -169,7 +171,7 @@ module.exports = (items, getDependencies) => {
|
|
169
171
|
// so it's not really a root cycle
|
170
172
|
// remove the cycle from the root cycles
|
171
173
|
// and convert it to a normal node
|
172
|
-
rootCycles.delete(dependency.cycle);
|
174
|
+
rootCycles.delete(/** @type {Cycle<T>} */ (dependency.cycle));
|
173
175
|
dependency.marker = DONE_MARKER;
|
174
176
|
break;
|
175
177
|
// DONE_MARKER: nothing to do, don't recurse into dependencies
|
package/lib/util/memoize.js
CHANGED
@@ -13,18 +13,18 @@
|
|
13
13
|
*/
|
14
14
|
const memoize = fn => {
|
15
15
|
let cache = false;
|
16
|
-
/** @type {T} */
|
16
|
+
/** @type {T | undefined} */
|
17
17
|
let result = undefined;
|
18
18
|
return () => {
|
19
19
|
if (cache) {
|
20
|
-
return result;
|
20
|
+
return /** @type {T} */ (result);
|
21
21
|
} else {
|
22
22
|
result = fn();
|
23
23
|
cache = true;
|
24
24
|
// Allow to clean up memory for fn
|
25
25
|
// and all dependent resources
|
26
26
|
fn = undefined;
|
27
|
-
return result;
|
27
|
+
return /** @type {T} */ (result);
|
28
28
|
}
|
29
29
|
};
|
30
30
|
};
|
@@ -21,6 +21,9 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
|
|
21
21
|
let finished = false;
|
22
22
|
let processScheduled = true;
|
23
23
|
|
24
|
+
/**
|
25
|
+
* @param {T} item item
|
26
|
+
*/
|
24
27
|
const push = item => {
|
25
28
|
queue.push(item);
|
26
29
|
if (!processScheduled && processing < concurrency) {
|
@@ -29,6 +32,9 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
|
|
29
32
|
}
|
30
33
|
};
|
31
34
|
|
35
|
+
/**
|
36
|
+
* @param {E | null | undefined} err error
|
37
|
+
*/
|
32
38
|
const processorCallback = err => {
|
33
39
|
processing--;
|
34
40
|
if (err && !finished) {
|
@@ -46,7 +52,7 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
|
|
46
52
|
if (finished) return;
|
47
53
|
while (processing < concurrency && queue.length > 0) {
|
48
54
|
processing++;
|
49
|
-
const item = queue.pop();
|
55
|
+
const item = /** @type {T} */ (queue.pop());
|
50
56
|
processor(item, push, processorCallback);
|
51
57
|
}
|
52
58
|
processScheduled = false;
|
@@ -26,7 +26,7 @@ const {
|
|
26
26
|
/** @typedef {import("./serialization").ObjectDeserializerContext} ObjectDeserializerContext */
|
27
27
|
/** @typedef {import("./serialization").ObjectSerializerContext} ObjectSerializerContext */
|
28
28
|
|
29
|
-
/** @typedef {ObjectSerializerContext & { writeLazy?: (any) => void }} WebpackObjectSerializerContext */
|
29
|
+
/** @typedef {ObjectSerializerContext & { writeLazy?: (value: any) => void }} WebpackObjectSerializerContext */
|
30
30
|
|
31
31
|
const CURRENT_MODULE = "webpack/lib/util/registerExternalSerializer";
|
32
32
|
|
package/lib/util/runtime.js
CHANGED
@@ -434,7 +434,7 @@ class RuntimeSpecMap {
|
|
434
434
|
|
435
435
|
/**
|
436
436
|
* @param {RuntimeSpec} runtime the runtimes
|
437
|
-
* @returns {T} value
|
437
|
+
* @returns {T | undefined} value
|
438
438
|
*/
|
439
439
|
get(runtime) {
|
440
440
|
switch (this._mode) {
|
@@ -517,6 +517,9 @@ class RuntimeSpecMap {
|
|
517
517
|
}
|
518
518
|
}
|
519
519
|
|
520
|
+
/**
|
521
|
+
* @param {RuntimeSpec} runtime the runtimes
|
522
|
+
*/
|
520
523
|
delete(runtime) {
|
521
524
|
switch (this._mode) {
|
522
525
|
case 0:
|
@@ -593,6 +596,9 @@ class RuntimeSpecMap {
|
|
593
596
|
exports.RuntimeSpecMap = RuntimeSpecMap;
|
594
597
|
|
595
598
|
class RuntimeSpecSet {
|
599
|
+
/**
|
600
|
+
* @param {Iterable<RuntimeSpec>=} iterable iterable
|
601
|
+
*/
|
596
602
|
constructor(iterable) {
|
597
603
|
/** @type {Map<string, RuntimeSpec>} */
|
598
604
|
this._map = new Map();
|
@@ -603,10 +609,17 @@ class RuntimeSpecSet {
|
|
603
609
|
}
|
604
610
|
}
|
605
611
|
|
612
|
+
/**
|
613
|
+
* @param {RuntimeSpec} runtime runtime
|
614
|
+
*/
|
606
615
|
add(runtime) {
|
607
616
|
this._map.set(getRuntimeKey(runtime), runtime);
|
608
617
|
}
|
609
618
|
|
619
|
+
/**
|
620
|
+
* @param {RuntimeSpec} runtime runtime
|
621
|
+
* @returns {boolean} true, when the runtime exists
|
622
|
+
*/
|
610
623
|
has(runtime) {
|
611
624
|
return this._map.has(getRuntimeKey(runtime));
|
612
625
|
}
|
@@ -110,7 +110,7 @@ const smartGrouping = (items, groupConfigs) => {
|
|
110
110
|
/** @type {(T | R)[]} */
|
111
111
|
const results = [];
|
112
112
|
for (;;) {
|
113
|
-
/** @type {Group<T, R>} */
|
113
|
+
/** @type {Group<T, R> | undefined} */
|
114
114
|
let bestGroup = undefined;
|
115
115
|
let bestGroupSize = -1;
|
116
116
|
let bestGroupItems = undefined;
|
package/lib/validateSchema.js
CHANGED
@@ -119,7 +119,9 @@ const validateSchema = (schema, options, validationConfiguration) => {
|
|
119
119
|
)
|
120
120
|
) {
|
121
121
|
return `${formattedError}\nDid you mean ${
|
122
|
-
DID_YOU_MEAN[
|
122
|
+
DID_YOU_MEAN[
|
123
|
+
/** @type {keyof DID_YOU_MEAN} */ (params.additionalProperty)
|
124
|
+
]
|
123
125
|
}?`;
|
124
126
|
}
|
125
127
|
|
@@ -129,7 +131,9 @@ const validateSchema = (schema, options, validationConfiguration) => {
|
|
129
131
|
params.additionalProperty
|
130
132
|
)
|
131
133
|
) {
|
132
|
-
return `${formattedError}\n${
|
134
|
+
return `${formattedError}\n${
|
135
|
+
REMOVED[/** @type {keyof REMOVED} */ (params.additionalProperty)]
|
136
|
+
}?`;
|
133
137
|
}
|
134
138
|
|
135
139
|
if (!error.dataPath) {
|
@@ -9,6 +9,9 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
10
10
|
const Template = require("../Template");
|
11
11
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../Compilation")} Compilation */
|
14
|
+
|
12
15
|
/**
|
13
16
|
* @typedef {Object} AsyncWasmLoadingRuntimeModuleOptions
|
14
17
|
* @property {function(string): string} generateLoadBinaryCode
|
@@ -29,7 +32,8 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
|
|
29
32
|
* @returns {string} runtime code
|
30
33
|
*/
|
31
34
|
generate() {
|
32
|
-
const
|
35
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
36
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
33
37
|
const { outputOptions, runtimeTemplate } = compilation;
|
34
38
|
const fn = RuntimeGlobals.instantiateWasm;
|
35
39
|
const wasmModuleSrcPath = compilation.getPath(
|
@@ -11,6 +11,8 @@ const Parser = require("../Parser");
|
|
11
11
|
const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
|
12
12
|
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
13
13
|
|
14
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
15
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
14
16
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
15
17
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
16
18
|
|
@@ -43,9 +45,11 @@ class WebAssemblyParser extends Parser {
|
|
43
45
|
}
|
44
46
|
|
45
47
|
// flag it as async module
|
46
|
-
state.module.buildInfo
|
47
|
-
|
48
|
-
state.module.buildMeta
|
48
|
+
const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
|
49
|
+
buildInfo.strict = true;
|
50
|
+
const BuildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
|
51
|
+
BuildMeta.exportsType = "namespace";
|
52
|
+
BuildMeta.async = true;
|
49
53
|
|
50
54
|
// parse it
|
51
55
|
const program = decode(source, decoderOpts);
|
@@ -10,6 +10,7 @@ const Template = require("../Template");
|
|
10
10
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
11
11
|
const WebAssemblyUtils = require("./WebAssemblyUtils");
|
12
12
|
|
13
|
+
/** @typedef {import("@webassemblyjs/ast").Signature} Signature */
|
13
14
|
/** @typedef {import("../Chunk")} Chunk */
|
14
15
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
15
16
|
/** @typedef {import("../Compilation")} Compilation */
|
@@ -91,9 +92,11 @@ const generateImportObject = (
|
|
91
92
|
value: `${instanceVar}[${JSON.stringify(usedName)}]`
|
92
93
|
});
|
93
94
|
} else {
|
94
|
-
const params =
|
95
|
-
|
96
|
-
|
95
|
+
const params =
|
96
|
+
/** @type {Signature} */
|
97
|
+
(description.signature).params.map(
|
98
|
+
(param, k) => "p" + k + param.valtype
|
99
|
+
);
|
97
100
|
|
98
101
|
const mod = `${RuntimeGlobals.moduleCache}[${JSON.stringify(
|
99
102
|
chunkGraph.getModuleId(importedModule)
|
@@ -130,6 +133,7 @@ const generateImportObject = (
|
|
130
133
|
"};"
|
131
134
|
];
|
132
135
|
} else {
|
136
|
+
/** @type {Map<string, Array<{ name: string, value: string }>>} */
|
133
137
|
const propertiesByModule = new Map();
|
134
138
|
for (const p of properties) {
|
135
139
|
let list = propertiesByModule.get(p.module);
|
@@ -225,20 +229,23 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
225
229
|
* @returns {string} runtime code
|
226
230
|
*/
|
227
231
|
generate() {
|
228
|
-
const { chunkGraph, compilation, chunk, mangleImports } = this;
|
229
|
-
const { moduleGraph, outputOptions } = compilation;
|
230
232
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
231
233
|
const withHmr = this._runtimeRequirements.has(
|
232
234
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
233
235
|
);
|
236
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
237
|
+
const { moduleGraph, outputOptions } = compilation;
|
238
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
239
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
234
240
|
const wasmModules = getAllWasmModules(moduleGraph, chunkGraph, chunk);
|
241
|
+
const { mangleImports } = this;
|
235
242
|
/** @type {string[]} */
|
236
243
|
const declarations = [];
|
237
244
|
const importObjects = wasmModules.map(module => {
|
238
245
|
return generateImportObject(
|
239
246
|
chunkGraph,
|
240
247
|
module,
|
241
|
-
|
248
|
+
mangleImports,
|
242
249
|
declarations,
|
243
250
|
chunk.runtime
|
244
251
|
);
|
@@ -11,6 +11,7 @@ const UnsupportedWebAssemblyFeatureError = require("./UnsupportedWebAssemblyFeat
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
/** @typedef {import("../Dependency")} Dependency */
|
13
13
|
/** @typedef {import("../Module")} Module */
|
14
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
14
15
|
|
15
16
|
class WasmFinalizeExportsPlugin {
|
16
17
|
/**
|
@@ -27,7 +28,8 @@ class WasmFinalizeExportsPlugin {
|
|
27
28
|
// 1. if a WebAssembly module
|
28
29
|
if (module.type.startsWith("webassembly") === true) {
|
29
30
|
const jsIncompatibleExports =
|
30
|
-
|
31
|
+
/** @type {BuildMeta} */
|
32
|
+
(module.buildMeta).jsIncompatibleExports;
|
31
33
|
|
32
34
|
if (jsIncompatibleExports === undefined) {
|
33
35
|
continue;
|
@@ -174,6 +174,7 @@ const createDefaultInitForGlobal = globalType => {
|
|
174
174
|
*/
|
175
175
|
const rewriteImportedGlobals = state => bin => {
|
176
176
|
const additionalInitCode = state.additionalInitCode;
|
177
|
+
/** @type {Array<t.Global>} */
|
177
178
|
const newGlobals = [];
|
178
179
|
|
179
180
|
bin = editWithAST(state.ast, bin, {
|
@@ -14,6 +14,8 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
|
|
14
14
|
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
15
15
|
|
16
16
|
/** @typedef {import("../Module")} Module */
|
17
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
18
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
17
19
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
18
20
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
19
21
|
|
@@ -81,8 +83,10 @@ class WebAssemblyParser extends Parser {
|
|
81
83
|
}
|
82
84
|
|
83
85
|
// flag it as ESM
|
84
|
-
|
85
|
-
state.module.
|
86
|
+
/** @type {BuildInfo} */
|
87
|
+
(state.module.buildInfo).strict = true;
|
88
|
+
/** @type {BuildMeta} */
|
89
|
+
(state.module.buildMeta).exportsType = "namespace";
|
86
90
|
|
87
91
|
// parse it
|
88
92
|
const program = decode(source, decoderOpts);
|
@@ -14,6 +14,7 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
|
14
14
|
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
15
15
|
|
16
16
|
/** @typedef {import("../Chunk")} Chunk */
|
17
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
18
|
|
18
19
|
/**
|
19
20
|
* @typedef {Object} JsonpCompilationPluginHooks
|
@@ -72,7 +73,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
72
73
|
* @returns {string} runtime code
|
73
74
|
*/
|
74
75
|
generate() {
|
75
|
-
const
|
76
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
76
77
|
const {
|
77
78
|
runtimeTemplate,
|
78
79
|
outputOptions: {
|
@@ -108,9 +109,14 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
108
109
|
const withPreload = this._runtimeRequirements.has(
|
109
110
|
RuntimeGlobals.preloadChunkHandlers
|
110
111
|
);
|
112
|
+
const withFetchPriority = this._runtimeRequirements.has(
|
113
|
+
RuntimeGlobals.hasFetchPriority
|
114
|
+
);
|
111
115
|
const chunkLoadingGlobalExpr = `${globalObject}[${JSON.stringify(
|
112
116
|
chunkLoadingGlobal
|
113
117
|
)}]`;
|
118
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
119
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
114
120
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
115
121
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
116
122
|
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
@@ -138,7 +144,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
138
144
|
withLoading
|
139
145
|
? Template.asString([
|
140
146
|
`${fn}.j = ${runtimeTemplate.basicFunction(
|
141
|
-
|
147
|
+
`chunkId, promises${withFetchPriority ? ", fetchPriority" : ""}`,
|
142
148
|
hasJsMatcher !== false
|
143
149
|
? Template.indent([
|
144
150
|
"// JSONP chunk loading for javascript",
|
@@ -190,7 +196,11 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
190
196
|
"}"
|
191
197
|
]
|
192
198
|
)};`,
|
193
|
-
`${
|
199
|
+
`${
|
200
|
+
RuntimeGlobals.loadScript
|
201
|
+
}(url, loadingEnded, "chunk-" + chunkId, chunkId${
|
202
|
+
withFetchPriority ? ", fetchPriority" : ""
|
203
|
+
});`
|
194
204
|
]),
|
195
205
|
hasJsMatcher === true
|
196
206
|
? "}"
|
package/lib/webpack.js
CHANGED
@@ -61,7 +61,10 @@ const createMultiCompiler = (childOptions, options) => {
|
|
61
61
|
const createCompiler = rawOptions => {
|
62
62
|
const options = getNormalizedWebpackOptions(rawOptions);
|
63
63
|
applyWebpackOptionsBaseDefaults(options);
|
64
|
-
const compiler = new Compiler(
|
64
|
+
const compiler = new Compiler(
|
65
|
+
/** @type {string} */ (options.context),
|
66
|
+
options
|
67
|
+
);
|
65
68
|
new NodeEnvironmentPlugin({
|
66
69
|
infrastructureLogging: options.infrastructureLogging
|
67
70
|
}).apply(compiler);
|
@@ -69,7 +72,7 @@ const createCompiler = rawOptions => {
|
|
69
72
|
for (const plugin of options.plugins) {
|
70
73
|
if (typeof plugin === "function") {
|
71
74
|
plugin.call(compiler, compiler);
|
72
|
-
} else {
|
75
|
+
} else if (plugin) {
|
73
76
|
plugin.apply(compiler);
|
74
77
|
}
|
75
78
|
}
|
@@ -96,6 +99,11 @@ const createCompiler = rawOptions => {
|
|
96
99
|
* @returns {MultiCompiler} the multi compiler object
|
97
100
|
*/
|
98
101
|
|
102
|
+
/**
|
103
|
+
* @template T
|
104
|
+
* @param {Array<T> | T} options options
|
105
|
+
* @returns {Array<T>} array of options
|
106
|
+
*/
|
99
107
|
const asArray = options =>
|
100
108
|
Array.isArray(options) ? Array.from(options) : [options];
|
101
109
|
|
@@ -117,6 +125,7 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
|
|
117
125
|
}
|
118
126
|
/** @type {MultiCompiler|Compiler} */
|
119
127
|
let compiler;
|
128
|
+
/** @type {boolean | undefined} */
|
120
129
|
let watch = false;
|
121
130
|
/** @type {WatchOptions|WatchOptions[]} */
|
122
131
|
let watchOptions;
|
@@ -16,6 +16,8 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
16
16
|
const { getUndoPath } = require("../util/identifier");
|
17
17
|
|
18
18
|
/** @typedef {import("../Chunk")} Chunk */
|
19
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
20
|
+
/** @typedef {import("../Compilation")} Compilation */
|
19
21
|
|
20
22
|
class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
21
23
|
/**
|
@@ -38,8 +40,9 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
38
40
|
if (options && options.baseUri) {
|
39
41
|
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
40
42
|
}
|
41
|
-
const
|
42
|
-
|
43
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
44
|
+
const outputName = compilation.getPath(
|
45
|
+
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
43
46
|
{
|
44
47
|
chunk,
|
45
48
|
contentHashType: "javascript"
|
@@ -47,7 +50,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
47
50
|
);
|
48
51
|
const rootOutputDir = getUndoPath(
|
49
52
|
outputName,
|
50
|
-
/** @type {string} */ (
|
53
|
+
/** @type {string} */ (compilation.outputOptions.path),
|
51
54
|
false
|
52
55
|
);
|
53
56
|
return `${RuntimeGlobals.baseURI} = self.location + ${JSON.stringify(
|
@@ -59,16 +62,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
59
62
|
* @returns {string} runtime code
|
60
63
|
*/
|
61
64
|
generate() {
|
62
|
-
const {
|
63
|
-
chunk,
|
64
|
-
chunkGraph,
|
65
|
-
compilation: {
|
66
|
-
runtimeTemplate,
|
67
|
-
outputOptions: { chunkLoadingGlobal, hotUpdateGlobal }
|
68
|
-
},
|
69
|
-
_withCreateScriptUrl: withCreateScriptUrl
|
70
|
-
} = this;
|
71
|
-
const globalObject = runtimeTemplate.globalObject;
|
65
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
72
66
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
73
67
|
const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
|
74
68
|
const withLoading = this.runtimeRequirements.has(
|
@@ -80,9 +74,12 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
80
74
|
const withHmrManifest = this.runtimeRequirements.has(
|
81
75
|
RuntimeGlobals.hmrDownloadManifest
|
82
76
|
);
|
77
|
+
const globalObject = compilation.runtimeTemplate.globalObject;
|
83
78
|
const chunkLoadingGlobalExpr = `${globalObject}[${JSON.stringify(
|
84
|
-
chunkLoadingGlobal
|
79
|
+
compilation.outputOptions.chunkLoadingGlobal
|
85
80
|
)}]`;
|
81
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
82
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
86
83
|
const hasJsMatcher = compileBooleanMatcher(
|
87
84
|
chunkGraph.getChunkConditionMap(chunk, chunkHasJs)
|
88
85
|
);
|
@@ -91,6 +88,8 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
91
88
|
const stateExpression = withHmr
|
92
89
|
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_importScripts`
|
93
90
|
: undefined;
|
91
|
+
const runtimeTemplate = compilation.runtimeTemplate;
|
92
|
+
const { _withCreateScriptUrl: withCreateScriptUrl } = this;
|
94
93
|
|
95
94
|
return Template.asString([
|
96
95
|
withBaseURI ? this._generateBaseUri(chunk) : "// no baseURI",
|
@@ -169,7 +168,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
169
168
|
Template.indent([
|
170
169
|
"var success = false;",
|
171
170
|
`${globalObject}[${JSON.stringify(
|
172
|
-
hotUpdateGlobal
|
171
|
+
compilation.outputOptions.hotUpdateGlobal
|
173
172
|
)}] = ${runtimeTemplate.basicFunction("_, moreModules, runtime", [
|
174
173
|
"for(var moduleId in moreModules) {",
|
175
174
|
Template.indent([
|
package/module.d.ts
CHANGED
@@ -174,6 +174,7 @@ interface ImportMeta {
|
|
174
174
|
exclude?: RegExp;
|
175
175
|
preload?: boolean | number;
|
176
176
|
prefetch?: boolean | number;
|
177
|
+
fetchPriority?: "low" | "high" | "auto";
|
177
178
|
chunkName?: string;
|
178
179
|
exports?: string | string[][];
|
179
180
|
mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once";
|