webpack 5.99.5 → 5.99.7
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/AutomaticPrefetchPlugin.js +21 -22
- package/lib/BannerPlugin.js +31 -35
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +12 -9
- package/lib/CleanPlugin.js +5 -3
- package/lib/Compilation.js +45 -35
- package/lib/Compiler.js +6 -4
- package/lib/ContextExclusionPlugin.js +4 -2
- package/lib/ContextModule.js +2 -1
- package/lib/ContextReplacementPlugin.js +5 -3
- package/lib/DelegatedPlugin.js +4 -2
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllPlugin.js +5 -3
- package/lib/DllReferencePlugin.js +56 -60
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryOptionPlugin.js +3 -1
- package/lib/EntryPlugin.js +4 -2
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/EvalDevToolModulePlugin.js +9 -7
- package/lib/EvalSourceMapDevToolPlugin.js +137 -138
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FlagDependencyExportsPlugin.js +2 -1
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/IgnorePlugin.js +6 -4
- package/lib/IgnoreWarningsPlugin.js +4 -2
- package/lib/LibManifestPlugin.js +3 -4
- package/lib/LoaderOptionsPlugin.js +4 -2
- package/lib/LoaderTargetPlugin.js +4 -2
- package/lib/Module.js +29 -14
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +15 -10
- package/lib/ModuleInfoHeaderPlugin.js +11 -12
- package/lib/MultiCompiler.js +5 -3
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NormalModule.js +6 -2
- package/lib/NormalModuleReplacementPlugin.js +33 -36
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +5 -3
- package/lib/ProgressPlugin.js +23 -26
- package/lib/RecordIdsPlugin.js +73 -103
- package/lib/RuntimePlugin.js +34 -32
- package/lib/SourceMapDevToolPlugin.js +8 -6
- package/lib/Template.js +1 -1
- package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
- package/lib/WarnNoModeSetPlugin.js +3 -1
- package/lib/WatchIgnorePlugin.js +3 -1
- package/lib/WebpackError.js +11 -3
- package/lib/WebpackOptionsApply.js +22 -5
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/buildChunkGraph.js +7 -2
- package/lib/cache/IdleFileCachePlugin.js +12 -13
- package/lib/cache/MemoryCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
- package/lib/cache/PackFileCacheStrategy.js +13 -21
- package/lib/cache/ResolverCachePlugin.js +22 -22
- package/lib/cli.js +8 -4
- package/lib/config/defaults.js +2 -2
- package/lib/config/normalization.js +9 -3
- package/lib/config/target.js +6 -6
- package/lib/container/ContainerReferencePlugin.js +24 -26
- package/lib/container/ModuleFederationPlugin.js +2 -1
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssModulesPlugin.js +6 -4
- 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/HarmonyDetectionParserPlugin.js +9 -15
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +5 -3
- package/lib/dependencies/LocalModulesHelpers.js +1 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
- package/lib/dependencies/RequireResolveDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/LazyCompilationPlugin.js +17 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
- package/lib/ids/HashedModuleIdsPlugin.js +4 -2
- package/lib/ids/NamedChunkIdsPlugin.js +6 -4
- package/lib/ids/NamedModuleIdsPlugin.js +6 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
- package/lib/index.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/JavascriptParser.js +670 -688
- package/lib/library/EnableLibraryPlugin.js +15 -2
- package/lib/library/ModuleLibraryPlugin.js +66 -43
- package/lib/logging/createConsoleLogger.js +0 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
- package/lib/node/NodeEnvironmentPlugin.js +3 -1
- 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/AggressiveSplittingPlugin.js +224 -232
- package/lib/optimize/ConcatenatedModule.js +12 -15
- package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +15 -16
- package/lib/optimize/MinChunkSizePlugin.js +4 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +4 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
- package/lib/optimize/RuntimeChunkPlugin.js +17 -18
- package/lib/optimize/SplitChunksPlugin.js +9 -6
- package/lib/performance/SizeLimitsPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
- package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
- package/lib/schemes/DataUriPlugin.js +5 -3
- package/lib/schemes/FileUriPlugin.js +5 -3
- package/lib/schemes/HttpUriPlugin.js +32 -39
- package/lib/serialization/AggregateErrorSerializer.js +42 -0
- package/lib/serialization/BinaryMiddleware.js +22 -38
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/FileMiddleware.js +29 -33
- package/lib/serialization/ObjectMiddleware.js +42 -30
- package/lib/serialization/Serializer.js +29 -18
- package/lib/serialization/SerializerMiddleware.js +105 -72
- package/lib/serialization/SingleItemMiddleware.js +4 -5
- package/lib/sharing/ProvideSharedPlugin.js +6 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
- package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
- 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/concatenate.js +4 -2
- 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/WasmFinalizeExportsPlugin.js +55 -57
- 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/web/JsonpChunkLoadingPlugin.js +73 -74
- package/lib/webpack.js +1 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
- package/package.json +4 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +24 -2
- package/types.d.ts +273 -128
package/lib/util/WeakTupleMap.js
CHANGED
@@ -6,15 +6,15 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/**
|
9
|
-
* @template T
|
9
|
+
* @template {EXPECTED_ANY[]} T
|
10
10
|
* @template V
|
11
|
-
* @typedef {Map<EXPECTED_ANY, WeakTupleMap<T
|
11
|
+
* @typedef {Map<EXPECTED_ANY, WeakTupleMap<T, V>>} M
|
12
12
|
*/
|
13
13
|
|
14
14
|
/**
|
15
|
-
* @template T
|
15
|
+
* @template {EXPECTED_ANY[]} T
|
16
16
|
* @template V
|
17
|
-
* @typedef {WeakMap<EXPECTED_OBJECT, WeakTupleMap<T
|
17
|
+
* @typedef {WeakMap<EXPECTED_OBJECT, WeakTupleMap<T, V>>} W
|
18
18
|
*/
|
19
19
|
|
20
20
|
/**
|
@@ -24,7 +24,12 @@
|
|
24
24
|
const isWeakKey = thing => typeof thing === "object" && thing !== null;
|
25
25
|
|
26
26
|
/**
|
27
|
-
* @template {
|
27
|
+
* @template {unknown[]} T
|
28
|
+
* @typedef {T extends readonly (infer ElementType)[] ? ElementType : never} ArrayElement
|
29
|
+
*/
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @template {EXPECTED_ANY[]} K
|
28
33
|
* @template V
|
29
34
|
*/
|
30
35
|
class WeakTupleMap {
|
@@ -38,83 +43,83 @@ class WeakTupleMap {
|
|
38
43
|
this.v = undefined;
|
39
44
|
/**
|
40
45
|
* @private
|
41
|
-
* @type {M<
|
46
|
+
* @type {M<K, V> | undefined}
|
42
47
|
*/
|
43
48
|
this.m = undefined;
|
44
49
|
/**
|
45
50
|
* @private
|
46
|
-
* @type {W<
|
51
|
+
* @type {W<K, V> | undefined}
|
47
52
|
*/
|
48
53
|
this.w = undefined;
|
49
54
|
}
|
50
55
|
|
51
56
|
/**
|
52
|
-
* @param {[...
|
57
|
+
* @param {[...K, V]} args tuple
|
53
58
|
* @returns {void}
|
54
59
|
*/
|
55
60
|
set(...args) {
|
56
|
-
/** @type {WeakTupleMap<
|
61
|
+
/** @type {WeakTupleMap<K, V>} */
|
57
62
|
let node = this;
|
58
63
|
for (let i = 0; i < args.length - 1; i++) {
|
59
|
-
node = node._get(args[i]);
|
64
|
+
node = node._get(/** @type {ArrayElement<K>} */ (args[i]));
|
60
65
|
}
|
61
|
-
node._setValue(args[args.length - 1]);
|
66
|
+
node._setValue(/** @type {V} */ (args[args.length - 1]));
|
62
67
|
}
|
63
68
|
|
64
69
|
/**
|
65
|
-
* @param {
|
70
|
+
* @param {K} args tuple
|
66
71
|
* @returns {boolean} true, if the tuple is in the Set
|
67
72
|
*/
|
68
73
|
has(...args) {
|
69
|
-
/** @type {WeakTupleMap<
|
74
|
+
/** @type {WeakTupleMap<K, V> | undefined} */
|
70
75
|
let node = this;
|
71
76
|
for (let i = 0; i < args.length; i++) {
|
72
|
-
node = node._peek(args[i]);
|
77
|
+
node = node._peek(/** @type {ArrayElement<K>} */ (args[i]));
|
73
78
|
if (node === undefined) return false;
|
74
79
|
}
|
75
80
|
return node._hasValue();
|
76
81
|
}
|
77
82
|
|
78
83
|
/**
|
79
|
-
* @param {
|
84
|
+
* @param {K} args tuple
|
80
85
|
* @returns {V | undefined} the value
|
81
86
|
*/
|
82
87
|
get(...args) {
|
83
|
-
/** @type {WeakTupleMap<
|
88
|
+
/** @type {WeakTupleMap<K, V> | undefined} */
|
84
89
|
let node = this;
|
85
90
|
for (let i = 0; i < args.length; i++) {
|
86
|
-
node = node._peek(args[i]);
|
91
|
+
node = node._peek(/** @type {ArrayElement<K>} */ (args[i]));
|
87
92
|
if (node === undefined) return;
|
88
93
|
}
|
89
94
|
return node._getValue();
|
90
95
|
}
|
91
96
|
|
92
97
|
/**
|
93
|
-
* @param {[...
|
98
|
+
* @param {[...K, (...args: K) => V]} args tuple
|
94
99
|
* @returns {V} the value
|
95
100
|
*/
|
96
101
|
provide(...args) {
|
97
|
-
/** @type {WeakTupleMap<
|
102
|
+
/** @type {WeakTupleMap<K, V>} */
|
98
103
|
let node = this;
|
99
104
|
for (let i = 0; i < args.length - 1; i++) {
|
100
|
-
node = node._get(args[i]);
|
105
|
+
node = node._get(/** @type {ArrayElement<K>} */ (args[i]));
|
101
106
|
}
|
102
107
|
if (node._hasValue()) return /** @type {V} */ (node._getValue());
|
103
|
-
const fn = args[args.length - 1];
|
104
|
-
const newValue = fn(
|
108
|
+
const fn = /** @type {(...args: K) => V} */ (args[args.length - 1]);
|
109
|
+
const newValue = fn(.../** @type {K} */ (args.slice(0, -1)));
|
105
110
|
node._setValue(newValue);
|
106
111
|
return newValue;
|
107
112
|
}
|
108
113
|
|
109
114
|
/**
|
110
|
-
* @param {
|
115
|
+
* @param {K} args tuple
|
111
116
|
* @returns {void}
|
112
117
|
*/
|
113
118
|
delete(...args) {
|
114
|
-
/** @type {WeakTupleMap<
|
119
|
+
/** @type {WeakTupleMap<K, V> | undefined} */
|
115
120
|
let node = this;
|
116
121
|
for (let i = 0; i < args.length; i++) {
|
117
|
-
node = node._peek(args[i]);
|
122
|
+
node = node._peek(/** @type {ArrayElement<K>} */ (args[i]));
|
118
123
|
if (node === undefined) return;
|
119
124
|
}
|
120
125
|
node._deleteValue();
|
@@ -153,59 +158,67 @@ class WeakTupleMap {
|
|
153
158
|
}
|
154
159
|
|
155
160
|
/**
|
156
|
-
* @param {
|
157
|
-
* @returns {WeakTupleMap<
|
161
|
+
* @param {ArrayElement<K>} thing thing
|
162
|
+
* @returns {WeakTupleMap<K, V> | undefined} thing
|
158
163
|
* @private
|
159
164
|
*/
|
160
165
|
_peek(thing) {
|
161
166
|
if (isWeakKey(thing)) {
|
162
167
|
if ((this.f & 4) !== 4) return;
|
163
|
-
return /** @type {
|
168
|
+
return /** @type {WeakMap<ArrayElement<K>, WeakTupleMap<K, V>>} */ (
|
169
|
+
this.w
|
170
|
+
).get(thing);
|
164
171
|
}
|
165
172
|
if ((this.f & 2) !== 2) return;
|
166
|
-
return /** @type {
|
173
|
+
return /** @type {Map<ArrayElement<K>, WeakTupleMap<K, V>>} */ (this.m).get(
|
174
|
+
thing
|
175
|
+
);
|
167
176
|
}
|
168
177
|
|
169
178
|
/**
|
170
179
|
* @private
|
171
|
-
* @param {
|
172
|
-
* @returns {WeakTupleMap<
|
180
|
+
* @param {ArrayElement<K>} thing thing
|
181
|
+
* @returns {WeakTupleMap<K, V>} value
|
173
182
|
*/
|
174
183
|
_get(thing) {
|
175
184
|
if (isWeakKey(thing)) {
|
176
185
|
if ((this.f & 4) !== 4) {
|
186
|
+
/** @type {W<K, V>} */
|
177
187
|
const newMap = new WeakMap();
|
178
188
|
this.f |= 4;
|
189
|
+
/** @type {WeakTupleMap<K, V>} */
|
179
190
|
const newNode = new WeakTupleMap();
|
180
191
|
(this.w = newMap).set(thing, newNode);
|
181
192
|
return newNode;
|
182
193
|
}
|
183
|
-
const entry =
|
184
|
-
/** @type {W<T, V>} */
|
185
|
-
(this.w).get(thing);
|
194
|
+
const entry = /** @type {W<K, V>} */ (this.w).get(thing);
|
186
195
|
if (entry !== undefined) {
|
187
196
|
return entry;
|
188
197
|
}
|
198
|
+
/** @type {WeakTupleMap<K, V>} */
|
189
199
|
const newNode = new WeakTupleMap();
|
190
|
-
/** @type {W<
|
200
|
+
/** @type {W<K, V>} */
|
191
201
|
(this.w).set(thing, newNode);
|
192
202
|
return newNode;
|
193
203
|
}
|
194
204
|
if ((this.f & 2) !== 2) {
|
205
|
+
/** @type {M<K, V>} */
|
195
206
|
const newMap = new Map();
|
196
207
|
this.f |= 2;
|
208
|
+
/** @type {WeakTupleMap<K, V>} */
|
197
209
|
const newNode = new WeakTupleMap();
|
198
210
|
(this.m = newMap).set(thing, newNode);
|
199
211
|
return newNode;
|
200
212
|
}
|
201
213
|
const entry =
|
202
|
-
/** @type {M<
|
214
|
+
/** @type {M<K, V>} */
|
203
215
|
(this.m).get(thing);
|
204
216
|
if (entry !== undefined) {
|
205
217
|
return entry;
|
206
218
|
}
|
219
|
+
/** @type {WeakTupleMap<K, V>} */
|
207
220
|
const newNode = new WeakTupleMap();
|
208
|
-
/** @type {M<
|
221
|
+
/** @type {M<K, V>} */
|
209
222
|
(this.m).set(thing, newNode);
|
210
223
|
return newNode;
|
211
224
|
}
|
package/lib/util/cleverMerge.js
CHANGED
@@ -89,9 +89,9 @@ const cachedSetProperty = (obj, property, value) => {
|
|
89
89
|
|
90
90
|
/**
|
91
91
|
* @typedef {object} ObjectParsedPropertyEntry
|
92
|
-
* @property {
|
92
|
+
* @property {TODO | undefined} base base value
|
93
93
|
* @property {string | undefined} byProperty the name of the selector property
|
94
|
-
* @property {ByValues<
|
94
|
+
* @property {ByValues<TODO>} byValues value depending on selector property, merged with base
|
95
95
|
*/
|
96
96
|
|
97
97
|
/** @typedef {(function(...EXPECTED_ANY): object) & { [DYNAMIC_INFO]: [DynamicFunction, object] }} DynamicFunction */
|
package/lib/util/comparators.js
CHANGED
@@ -361,7 +361,7 @@ module.exports.concatComparators = concatComparators;
|
|
361
361
|
* @typedef {(input: A) => B | undefined | null} Selector
|
362
362
|
*/
|
363
363
|
|
364
|
-
/** @type {TwoKeyWeakMap<Selector<
|
364
|
+
/** @type {TwoKeyWeakMap<Selector<EXPECTED_ANY, EXPECTED_ANY>, Comparator<EXPECTED_ANY>, Comparator<EXPECTED_ANY>>}} */
|
365
365
|
const compareSelectCache = new TwoKeyWeakMap();
|
366
366
|
|
367
367
|
/**
|
package/lib/util/concatenate.js
CHANGED
@@ -198,11 +198,13 @@ const RESERVED_NAMES = new Set(
|
|
198
198
|
.split(",")
|
199
199
|
);
|
200
200
|
|
201
|
+
/** @typedef {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} ScopeInfo */
|
202
|
+
|
201
203
|
/**
|
202
|
-
* @param {Map<string,
|
204
|
+
* @param {Map<string, ScopeInfo>} usedNamesInScopeInfo used names in scope info
|
203
205
|
* @param {string} module module identifier
|
204
206
|
* @param {string} id export id
|
205
|
-
* @returns {
|
207
|
+
* @returns {ScopeInfo} info
|
206
208
|
*/
|
207
209
|
const getUsedNamesInScopeInfo = (usedNamesInScopeInfo, module, id) => {
|
208
210
|
const key = `${module}-${id}`;
|
package/lib/util/createHash.js
CHANGED
@@ -19,7 +19,7 @@ const digestCaches = {};
|
|
19
19
|
class BulkUpdateDecorator extends Hash {
|
20
20
|
/**
|
21
21
|
* @param {Hash | HashFactory} hashOrFactory function to create a hash
|
22
|
-
* @param {string}
|
22
|
+
* @param {string=} hashKey key for caching
|
23
23
|
*/
|
24
24
|
constructor(hashOrFactory, hashKey) {
|
25
25
|
super();
|
package/lib/util/fs.js
CHANGED
@@ -53,7 +53,7 @@ class ClassSerializer {
|
|
53
53
|
* @template {Constructor} T
|
54
54
|
* @param {T} Constructor the constructor
|
55
55
|
* @param {string} request the request which will be required when deserializing
|
56
|
-
* @param {string | null}
|
56
|
+
* @param {string | null=} name the name to make multiple serializer unique when sharing a request
|
57
57
|
*/
|
58
58
|
module.exports = (Constructor, request, name = null) => {
|
59
59
|
register(Constructor, request, name, new ClassSerializer(Constructor));
|
package/lib/util/runtime.js
CHANGED
@@ -431,6 +431,7 @@ class RuntimeSpecMap {
|
|
431
431
|
* @param {RuntimeSpecMap<T, R>=} clone copy form this
|
432
432
|
*/
|
433
433
|
constructor(clone) {
|
434
|
+
/** @type {0 | 1 | 2} */
|
434
435
|
this._mode = clone ? clone._mode : 0; // 0 = empty, 1 = single entry, 2 = map
|
435
436
|
/** @type {RuntimeSpec} */
|
436
437
|
this._singleRuntime = clone ? clone._singleRuntime : undefined;
|
@@ -9,10 +9,14 @@ const memoize = require("./memoize");
|
|
9
9
|
|
10
10
|
/** @typedef {import("../serialization/BinaryMiddleware").MEASURE_END_OPERATION_TYPE} MEASURE_END_OPERATION */
|
11
11
|
/** @typedef {import("../serialization/BinaryMiddleware").MEASURE_START_OPERATION_TYPE} MEASURE_START_OPERATION */
|
12
|
-
/** @typedef {import("../serialization/Serializer")} Serializer */
|
13
12
|
/** @typedef {typeof import("../util/Hash")} Hash */
|
14
13
|
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
15
14
|
|
15
|
+
/**
|
16
|
+
* @template D, S, C
|
17
|
+
* @typedef {import("../serialization/Serializer")<D, S, C>} Serializer
|
18
|
+
*/
|
19
|
+
|
16
20
|
const getBinaryMiddleware = memoize(() =>
|
17
21
|
require("../serialization/BinaryMiddleware")
|
18
22
|
);
|
@@ -53,7 +57,9 @@ const registerSerializers = memoize(() => {
|
|
53
57
|
});
|
54
58
|
});
|
55
59
|
|
56
|
-
/**
|
60
|
+
/**
|
61
|
+
* @type {Serializer<EXPECTED_ANY, EXPECTED_ANY, EXPECTED_ANY>}
|
62
|
+
*/
|
57
63
|
let buffersSerializer;
|
58
64
|
|
59
65
|
// Expose serialization API
|
@@ -78,9 +84,6 @@ module.exports = {
|
|
78
84
|
get MEASURE_END_OPERATION() {
|
79
85
|
return getBinaryMiddleware().MEASURE_END_OPERATION;
|
80
86
|
},
|
81
|
-
/**
|
82
|
-
* @returns {Serializer} buffer serializer
|
83
|
-
*/
|
84
87
|
get buffersSerializer() {
|
85
88
|
if (buffersSerializer !== undefined) return buffersSerializer;
|
86
89
|
registerSerializers();
|
@@ -88,24 +91,27 @@ module.exports = {
|
|
88
91
|
const binaryMiddleware = getBinaryMiddlewareInstance();
|
89
92
|
const SerializerMiddleware = getSerializerMiddleware();
|
90
93
|
const SingleItemMiddleware = getSingleItemMiddleware();
|
91
|
-
return
|
92
|
-
new
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
context.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
94
|
+
return /** @type {Serializer<EXPECTED_ANY, EXPECTED_ANY, EXPECTED_ANY>} */ (
|
95
|
+
buffersSerializer = new Serializer([
|
96
|
+
new SingleItemMiddleware(),
|
97
|
+
new (getObjectMiddleware())(context => {
|
98
|
+
if ("write" in context) {
|
99
|
+
context.writeLazy = value => {
|
100
|
+
context.write(
|
101
|
+
SerializerMiddleware.createLazy(value, binaryMiddleware)
|
102
|
+
);
|
103
|
+
};
|
104
|
+
}
|
105
|
+
}, DEFAULTS.HASH_FUNCTION),
|
106
|
+
binaryMiddleware
|
107
|
+
])
|
108
|
+
);
|
104
109
|
},
|
105
110
|
/**
|
111
|
+
* @template D, S, C
|
106
112
|
* @param {IntermediateFileSystem} fs filesystem
|
107
113
|
* @param {string | Hash} hashFunction hash function to use
|
108
|
-
* @returns {Serializer} file serializer
|
114
|
+
* @returns {Serializer<D, S, C>} file serializer
|
109
115
|
*/
|
110
116
|
createFileSerializer: (fs, hashFunction) => {
|
111
117
|
registerSerializers();
|
@@ -115,28 +121,30 @@ module.exports = {
|
|
115
121
|
const binaryMiddleware = getBinaryMiddlewareInstance();
|
116
122
|
const SerializerMiddleware = getSerializerMiddleware();
|
117
123
|
const SingleItemMiddleware = getSingleItemMiddleware();
|
118
|
-
return
|
119
|
-
new
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
context.
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
124
|
+
return /** @type {Serializer<D, S, C>} */ (
|
125
|
+
new Serializer([
|
126
|
+
new SingleItemMiddleware(),
|
127
|
+
new (getObjectMiddleware())(context => {
|
128
|
+
if ("write" in context) {
|
129
|
+
context.writeLazy = value => {
|
130
|
+
context.write(
|
131
|
+
SerializerMiddleware.createLazy(value, binaryMiddleware)
|
132
|
+
);
|
133
|
+
};
|
134
|
+
context.writeSeparate = (value, options) => {
|
135
|
+
const lazy = SerializerMiddleware.createLazy(
|
136
|
+
value,
|
137
|
+
fileMiddleware,
|
138
|
+
options
|
139
|
+
);
|
140
|
+
context.write(lazy);
|
141
|
+
return lazy;
|
142
|
+
};
|
143
|
+
}
|
144
|
+
}, hashFunction),
|
145
|
+
binaryMiddleware,
|
146
|
+
fileMiddleware
|
147
|
+
])
|
148
|
+
);
|
141
149
|
}
|
142
150
|
};
|
@@ -16,7 +16,7 @@ const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypesConstants");
|
|
16
16
|
|
17
17
|
/**
|
18
18
|
* @typedef {object} AsyncWebAssemblyGeneratorOptions
|
19
|
-
* @property {boolean}
|
19
|
+
* @property {boolean=} mangleImports mangle imports
|
20
20
|
*/
|
21
21
|
|
22
22
|
class AsyncWebAssemblyGenerator extends Generator {
|
@@ -55,7 +55,7 @@ const getAsyncWebAssemblyParser = memoize(() =>
|
|
55
55
|
|
56
56
|
/**
|
57
57
|
* @typedef {object} AsyncWebAssemblyModulesPluginOptions
|
58
|
-
* @property {boolean}
|
58
|
+
* @property {boolean=} mangleImports mangle imports
|
59
59
|
*/
|
60
60
|
|
61
61
|
/** @type {WeakMap<Compilation, CompilationHooks>} */
|
@@ -213,8 +213,8 @@ const generateImportObject = (
|
|
213
213
|
/**
|
214
214
|
* @typedef {object} WasmChunkLoadingRuntimeModuleOptions
|
215
215
|
* @property {(path: string) => string} generateLoadBinaryCode
|
216
|
-
* @property {boolean}
|
217
|
-
* @property {boolean}
|
216
|
+
* @property {boolean=} supportsStreaming
|
217
|
+
* @property {boolean=} mangleImports
|
218
218
|
* @property {ReadOnlyRuntimeRequirements} runtimeRequirements
|
219
219
|
*/
|
220
220
|
|
@@ -13,6 +13,8 @@ const UnsupportedWebAssemblyFeatureError = require("./UnsupportedWebAssemblyFeat
|
|
13
13
|
/** @typedef {import("../Module")} Module */
|
14
14
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
15
15
|
|
16
|
+
const PLUGIN_NAME = "WasmFinalizeExportsPlugin";
|
17
|
+
|
16
18
|
class WasmFinalizeExportsPlugin {
|
17
19
|
/**
|
18
20
|
* Apply the plugin
|
@@ -20,72 +22,68 @@ class WasmFinalizeExportsPlugin {
|
|
20
22
|
* @returns {void}
|
21
23
|
*/
|
22
24
|
apply(compiler) {
|
23
|
-
compiler.hooks.compilation.tap(
|
24
|
-
compilation.hooks.finishModules.tap(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
/** @type {BuildMeta} */
|
32
|
-
(module.buildMeta).jsIncompatibleExports;
|
25
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
26
|
+
compilation.hooks.finishModules.tap(PLUGIN_NAME, modules => {
|
27
|
+
for (const module of modules) {
|
28
|
+
// 1. if a WebAssembly module
|
29
|
+
if (module.type.startsWith("webassembly") === true) {
|
30
|
+
const jsIncompatibleExports =
|
31
|
+
/** @type {BuildMeta} */
|
32
|
+
(module.buildMeta).jsIncompatibleExports;
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
if (jsIncompatibleExports === undefined) {
|
35
|
+
continue;
|
36
|
+
}
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
38
|
+
for (const connection of compilation.moduleGraph.getIncomingConnections(
|
39
|
+
module
|
40
|
+
)) {
|
41
|
+
// 2. is active and referenced by a non-WebAssembly module
|
42
|
+
if (
|
43
|
+
connection.isTargetActive(undefined) &&
|
44
|
+
/** @type {Module} */
|
45
|
+
(connection.originModule).type.startsWith("webassembly") ===
|
46
|
+
false
|
47
|
+
) {
|
48
|
+
const referencedExports =
|
49
|
+
compilation.getDependencyReferencedExports(
|
50
|
+
/** @type {Dependency} */ (connection.dependency),
|
51
|
+
undefined
|
52
|
+
);
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
compilation.errors.push(error);
|
81
|
-
}
|
54
|
+
for (const info of referencedExports) {
|
55
|
+
const names = Array.isArray(info) ? info : info.name;
|
56
|
+
if (names.length === 0) continue;
|
57
|
+
const name = names[0];
|
58
|
+
if (typeof name === "object") continue;
|
59
|
+
// 3. and uses a func with an incompatible JS signature
|
60
|
+
if (
|
61
|
+
Object.prototype.hasOwnProperty.call(
|
62
|
+
jsIncompatibleExports,
|
63
|
+
name
|
64
|
+
)
|
65
|
+
) {
|
66
|
+
// 4. error
|
67
|
+
const error = new UnsupportedWebAssemblyFeatureError(
|
68
|
+
`Export "${name}" with ${jsIncompatibleExports[name]} can only be used for direct wasm to wasm dependencies\n` +
|
69
|
+
`It's used from ${
|
70
|
+
/** @type {Module} */
|
71
|
+
(connection.originModule).readableIdentifier(
|
72
|
+
compilation.requestShortener
|
73
|
+
)
|
74
|
+
} at ${formatLocation(
|
75
|
+
/** @type {Dependency} */ (connection.dependency).loc
|
76
|
+
)}.`
|
77
|
+
);
|
78
|
+
error.module = module;
|
79
|
+
compilation.errors.push(error);
|
82
80
|
}
|
83
81
|
}
|
84
82
|
}
|
85
83
|
}
|
86
84
|
}
|
87
85
|
}
|
88
|
-
);
|
86
|
+
});
|
89
87
|
});
|
90
88
|
}
|
91
89
|
}
|
@@ -407,7 +407,7 @@ const getUsedDependencyMap = (moduleGraph, module, mangle) => {
|
|
407
407
|
|
408
408
|
/**
|
409
409
|
* @typedef {object} WebAssemblyGeneratorOptions
|
410
|
-
* @property {boolean}
|
410
|
+
* @property {boolean=} mangleImports mangle imports
|
411
411
|
*/
|
412
412
|
|
413
413
|
class WebAssemblyGenerator extends Generator {
|
@@ -32,7 +32,7 @@ const PLUGIN_NAME = "WebAssemblyModulesPlugin";
|
|
32
32
|
|
33
33
|
/**
|
34
34
|
* @typedef {object} WebAssemblyModulesPluginOptions
|
35
|
-
* @property {boolean}
|
35
|
+
* @property {boolean=} mangleImports mangle imports
|
36
36
|
*/
|
37
37
|
|
38
38
|
class WebAssemblyModulesPlugin {
|
@@ -14,7 +14,7 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
|
|
14
14
|
|
15
15
|
/**
|
16
16
|
* @typedef {object} FetchCompileWasmPluginOptions
|
17
|
-
* @property {boolean}
|
17
|
+
* @property {boolean=} mangleImports mangle imports
|
18
18
|
*/
|
19
19
|
|
20
20
|
// TODO webpack 6 remove
|
@@ -23,7 +23,7 @@ const PLUGIN_NAME = "FetchCompileWasmPlugin";
|
|
23
23
|
|
24
24
|
class FetchCompileWasmPlugin {
|
25
25
|
/**
|
26
|
-
* @param {FetchCompileWasmPluginOptions}
|
26
|
+
* @param {FetchCompileWasmPluginOptions=} options options
|
27
27
|
*/
|
28
28
|
constructor(options = {}) {
|
29
29
|
this.options = options;
|