webpack 5.89.0 → 5.90.1
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 +3 -0
- package/bin/webpack.js +1 -3
- package/hot/log.js +0 -2
- package/lib/APIPlugin.js +17 -13
- package/lib/ChunkGraph.js +1 -1
- package/lib/CleanPlugin.js +12 -12
- package/lib/Compilation.js +26 -17
- package/lib/Compiler.js +13 -0
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +3 -3
- package/lib/ContextModule.js +4 -4
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DefinePlugin.js +47 -26
- package/lib/DependencyTemplate.js +3 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EvalDevToolModulePlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +2 -2
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +47 -12
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +20 -3
- package/lib/FlagDependencyExportsPlugin.js +1 -1
- package/lib/Generator.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/InitFragment.js +7 -7
- package/lib/LibManifestPlugin.js +4 -1
- package/lib/Module.js +2 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleInfoHeaderPlugin.js +1 -1
- package/lib/MultiStats.js +2 -2
- package/lib/NodeStuffPlugin.js +48 -0
- package/lib/NormalModule.js +13 -11
- package/lib/NormalModuleFactory.js +7 -7
- package/lib/RuntimeTemplate.js +15 -11
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/Stats.js +4 -0
- package/lib/WebpackOptionsApply.js +4 -3
- package/lib/asset/AssetModulesPlugin.js +2 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +53 -0
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +12 -5
- package/lib/cache/PackFileCacheStrategy.js +3 -3
- package/lib/cache/ResolverCachePlugin.js +2 -2
- package/lib/config/browserslistTargetHandler.js +35 -14
- package/lib/config/defaults.js +88 -52
- package/lib/config/normalization.js +17 -18
- package/lib/config/target.js +5 -0
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/css/CssExportsGenerator.js +14 -1
- package/lib/css/CssGenerator.js +14 -1
- package/lib/css/CssLoadingRuntimeModule.js +23 -23
- package/lib/css/CssModulesPlugin.js +68 -32
- package/lib/css/CssParser.js +8 -3
- package/lib/debug/ProfilingPlugin.js +2 -2
- package/lib/dependencies/AMDDefineDependency.js +4 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +126 -34
- package/lib/dependencies/AMDPlugin.js +11 -4
- package/lib/dependencies/AMDRequireArrayDependency.js +13 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +159 -43
- package/lib/dependencies/AMDRequireDependency.js +2 -2
- package/lib/dependencies/AMDRequireItemDependency.js +1 -1
- package/lib/dependencies/CachedConstDependency.js +8 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +107 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +131 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
- package/lib/dependencies/HarmonyExportInitFragment.js +6 -6
- package/lib/dependencies/HarmonyImportDependency.js +4 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
- package/lib/dependencies/ImportDependency.js +26 -6
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +2 -1
- package/lib/dependencies/LocalModuleDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +12 -4
- package/lib/dependencies/RequireIncludeDependency.js +1 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +10 -3
- package/lib/dependencies/getFunctionExpression.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
- package/lib/hmr/lazyCompilationBackend.js +4 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/index.js +4 -0
- package/lib/javascript/JavascriptGenerator.js +16 -1
- package/lib/javascript/JavascriptModulesPlugin.js +33 -33
- package/lib/javascript/JavascriptParser.js +220 -74
- package/lib/json/JsonGenerator.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +5 -1
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +39 -39
- package/lib/logging/createConsoleLogger.js +1 -19
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/nodeConsole.js +1 -5
- package/lib/optimize/ConcatenatedModule.js +7 -7
- package/lib/optimize/InnerGraphPlugin.js +9 -1
- package/lib/optimize/MangleExportsPlugin.js +5 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
- package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -16
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/FileMiddleware.js +4 -4
- package/lib/serialization/ObjectMiddleware.js +4 -4
- package/lib/sharing/ConsumeSharedPlugin.js +5 -5
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +2 -2
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +24 -28
- package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
- package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
- package/lib/util/chainedImports.js +7 -6
- package/lib/util/cleverMerge.js +4 -4
- package/lib/util/comparators.js +59 -23
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +2 -2
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/numberHash.js +64 -52
- package/lib/util/runtime.js +18 -1
- package/lib/util/semver.js +19 -24
- package/lib/util/smartGrouping.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +53 -28
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
- package/package.json +25 -80
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +140 -32
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +273 -94
@@ -45,6 +45,10 @@ module.exports = {
|
|
45
45
|
require("../dependencies/AMDRequireItemDependency"),
|
46
46
|
"dependencies/CachedConstDependency": () =>
|
47
47
|
require("../dependencies/CachedConstDependency"),
|
48
|
+
"dependencies/ExternalModuleDependency": () =>
|
49
|
+
require("../dependencies/ExternalModuleDependency"),
|
50
|
+
"dependencies/ExternalModuleInitFragment": () =>
|
51
|
+
require("../dependencies/ExternalModuleInitFragment"),
|
48
52
|
"dependencies/CreateScriptUrlDependency": () =>
|
49
53
|
require("../dependencies/CreateScriptUrlDependency"),
|
50
54
|
"dependencies/CommonJsRequireContextDependency": () =>
|
@@ -206,6 +210,8 @@ module.exports = {
|
|
206
210
|
"util/LazySet": () => require("../util/LazySet"),
|
207
211
|
UnhandledSchemeError: () => require("../UnhandledSchemeError"),
|
208
212
|
NodeStuffInWebError: () => require("../NodeStuffInWebError"),
|
213
|
+
EnvironmentNotSupportAsyncWarning: () =>
|
214
|
+
require("../EnvironmentNotSupportAsyncWarning"),
|
209
215
|
WebpackError: () => require("../WebpackError"),
|
210
216
|
|
211
217
|
"util/registerExternalSerializer": () => {
|
package/lib/util/numberHash.js
CHANGED
@@ -6,36 +6,80 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/**
|
9
|
-
*
|
9
|
+
* Threshold for switching from 32-bit to 64-bit hashing. This is selected to ensure that the bias towards lower modulo results when using 32-bit hashing is <0.5%.
|
10
10
|
* @type {number}
|
11
11
|
*/
|
12
|
-
const
|
12
|
+
const FNV_64_THRESHOLD = 1 << 24;
|
13
13
|
|
14
14
|
/**
|
15
|
-
* The
|
16
|
-
* in the algorithm to ensure that intermediate hash values do not exceed the
|
17
|
-
* 32-bit integer limit.
|
15
|
+
* The FNV-1a offset basis for 32-bit hash values.
|
18
16
|
* @type {number}
|
19
17
|
*/
|
20
|
-
const
|
21
|
-
|
18
|
+
const FNV_OFFSET_32 = 2166136261;
|
22
19
|
/**
|
23
|
-
* The
|
20
|
+
* The FNV-1a prime for 32-bit hash values.
|
24
21
|
* @type {number}
|
25
22
|
*/
|
26
|
-
const
|
23
|
+
const FNV_PRIME_32 = 16777619;
|
24
|
+
/**
|
25
|
+
* The mask for a positive 32-bit signed integer.
|
26
|
+
* @type {number}
|
27
|
+
*/
|
28
|
+
const MASK_31 = 0x7fffffff;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* The FNV-1a offset basis for 64-bit hash values.
|
32
|
+
* @type {bigint}
|
33
|
+
*/
|
34
|
+
const FNV_OFFSET_64 = BigInt("0xCBF29CE484222325");
|
35
|
+
/**
|
36
|
+
* The FNV-1a prime for 64-bit hash values.
|
37
|
+
* @type {bigint}
|
38
|
+
*/
|
39
|
+
const FNV_PRIME_64 = BigInt("0x100000001B3");
|
27
40
|
|
28
41
|
/**
|
29
|
-
*
|
30
|
-
*
|
42
|
+
* Computes a 32-bit FNV-1a hash value for the given string.
|
43
|
+
* See https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
44
|
+
* @param {string} str The input string to hash
|
45
|
+
* @returns {number} - The computed hash value.
|
31
46
|
*/
|
32
|
-
|
47
|
+
function fnv1a32(str) {
|
48
|
+
let hash = FNV_OFFSET_32;
|
49
|
+
for (let i = 0, len = str.length; i < len; i++) {
|
50
|
+
let code = str.charCodeAt(i);
|
51
|
+
if (code > 0xff) {
|
52
|
+
hash ^= code & 0xff;
|
53
|
+
hash = (hash * FNV_PRIME_32) | 0;
|
54
|
+
code >>= 8;
|
55
|
+
}
|
56
|
+
hash ^= code;
|
57
|
+
hash = (hash * FNV_PRIME_32) | 0;
|
58
|
+
}
|
59
|
+
// Force the result to be positive
|
60
|
+
return hash & MASK_31;
|
61
|
+
}
|
33
62
|
|
34
63
|
/**
|
35
|
-
*
|
36
|
-
*
|
64
|
+
* Computes a 64-bit FNV-1a hash value for the given string.
|
65
|
+
* See https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
66
|
+
* @param {string} str The input string to hash
|
67
|
+
* @returns {bigint} - The computed hash value.
|
37
68
|
*/
|
38
|
-
|
69
|
+
function fnv1a64(str) {
|
70
|
+
let hash = FNV_OFFSET_64;
|
71
|
+
for (let i = 0, len = str.length; i < len; i++) {
|
72
|
+
let code = str.charCodeAt(i);
|
73
|
+
if (code > 0xff) {
|
74
|
+
hash ^= BigInt(code & 0xff);
|
75
|
+
hash = BigInt.asUintN(64, hash * FNV_PRIME_64);
|
76
|
+
code >>= 8;
|
77
|
+
}
|
78
|
+
hash ^= BigInt(code);
|
79
|
+
hash = BigInt.asUintN(64, hash * FNV_PRIME_64);
|
80
|
+
}
|
81
|
+
return hash;
|
82
|
+
}
|
39
83
|
|
40
84
|
/**
|
41
85
|
* Computes a hash value for the given string and range. This hashing algorithm is a modified
|
@@ -53,47 +97,15 @@ const primes = [3, 7, 17, 19];
|
|
53
97
|
*
|
54
98
|
* ```js
|
55
99
|
* const numberHash = require("webpack/lib/util/numberHash");
|
56
|
-
* numberHash("hello", 1000); //
|
57
|
-
* numberHash("hello world"); //
|
100
|
+
* numberHash("hello", 1000); // 73
|
101
|
+
* numberHash("hello world"); // 72
|
58
102
|
* ```
|
59
103
|
*
|
60
104
|
*/
|
61
105
|
module.exports = (str, range) => {
|
62
|
-
|
63
|
-
|
64
|
-
* to store intermediate hash values.
|
65
|
-
*/
|
66
|
-
arr.fill(0);
|
67
|
-
// For each character in the string
|
68
|
-
for (let i = 0; i < str.length; i++) {
|
69
|
-
// Get the character code.
|
70
|
-
const c = str.charCodeAt(i);
|
71
|
-
|
72
|
-
// For each 32-bit integer used to store the hash value
|
73
|
-
// add the character code to the current hash value and multiply by the prime number and
|
74
|
-
// add the previous 32-bit integer.
|
75
|
-
arr[0] = (arr[0] + c * primes[0] + arr[3]) & SAFE_PART;
|
76
|
-
arr[1] = (arr[1] + c * primes[1] + arr[0]) & SAFE_PART;
|
77
|
-
arr[2] = (arr[2] + c * primes[2] + arr[1]) & SAFE_PART;
|
78
|
-
arr[3] = (arr[3] + c * primes[3] + arr[2]) & SAFE_PART;
|
79
|
-
|
80
|
-
// For each 32-bit integer used to store the hash value
|
81
|
-
// XOR the current hash value with the value of the next 32-bit integer.
|
82
|
-
arr[0] = arr[0] ^ (arr[arr[0] % COUNT] >> 1);
|
83
|
-
arr[1] = arr[1] ^ (arr[arr[1] % COUNT] >> 1);
|
84
|
-
arr[2] = arr[2] ^ (arr[arr[2] % COUNT] >> 1);
|
85
|
-
arr[3] = arr[3] ^ (arr[arr[3] % COUNT] >> 1);
|
86
|
-
}
|
87
|
-
|
88
|
-
if (range <= SAFE_PART) {
|
89
|
-
return (arr[0] + arr[1] + arr[2] + arr[3]) % range;
|
106
|
+
if (range < FNV_64_THRESHOLD) {
|
107
|
+
return fnv1a32(str) % range;
|
90
108
|
} else {
|
91
|
-
|
92
|
-
const rangeExt = Math.floor(range / SAFE_LIMIT);
|
93
|
-
|
94
|
-
const sum1 = (arr[0] + arr[2]) & SAFE_PART;
|
95
|
-
const sum2 = (arr[0] + arr[2]) % rangeExt;
|
96
|
-
|
97
|
-
return (sum2 * SAFE_LIMIT + sum1) % range;
|
109
|
+
return Number(fnv1a64(str) % BigInt(range));
|
98
110
|
}
|
99
111
|
};
|
package/lib/util/runtime.js
CHANGED
@@ -57,7 +57,7 @@ exports.getEntryRuntime = (compilation, name, options) => {
|
|
57
57
|
* @param {boolean} deterministicOrder enforce a deterministic order
|
58
58
|
* @returns {void}
|
59
59
|
*/
|
60
|
-
|
60
|
+
const forEachRuntime = (runtime, fn, deterministicOrder = false) => {
|
61
61
|
if (runtime === undefined) {
|
62
62
|
fn(undefined);
|
63
63
|
} else if (typeof runtime === "string") {
|
@@ -69,6 +69,7 @@ exports.forEachRuntime = (runtime, fn, deterministicOrder = false) => {
|
|
69
69
|
}
|
70
70
|
}
|
71
71
|
};
|
72
|
+
exports.forEachRuntime = forEachRuntime;
|
72
73
|
|
73
74
|
/**
|
74
75
|
* @template T
|
@@ -228,6 +229,22 @@ const mergeRuntime = (a, b) => {
|
|
228
229
|
};
|
229
230
|
exports.mergeRuntime = mergeRuntime;
|
230
231
|
|
232
|
+
/**
|
233
|
+
* @param {RuntimeSpec[]} runtimes first
|
234
|
+
* @param {RuntimeSpec} runtime second
|
235
|
+
* @returns {RuntimeSpec} merged
|
236
|
+
*/
|
237
|
+
exports.deepMergeRuntime = (runtimes, runtime) => {
|
238
|
+
if (!Array.isArray(runtimes)) {
|
239
|
+
return runtime;
|
240
|
+
}
|
241
|
+
let merged = runtime;
|
242
|
+
for (const r of runtimes) {
|
243
|
+
merged = mergeRuntime(runtime, r);
|
244
|
+
}
|
245
|
+
return merged;
|
246
|
+
};
|
247
|
+
|
231
248
|
/**
|
232
249
|
* @param {RuntimeCondition} a first
|
233
250
|
* @param {RuntimeCondition} b second
|
package/lib/util/semver.js
CHANGED
@@ -232,16 +232,15 @@ const rangeToString = range => {
|
|
232
232
|
fixCount == 0
|
233
233
|
? ">="
|
234
234
|
: fixCount == -1
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
235
|
+
? "<"
|
236
|
+
: fixCount == 1
|
237
|
+
? "^"
|
238
|
+
: fixCount == 2
|
239
|
+
? "~"
|
240
|
+
: fixCount > 0
|
241
|
+
? "="
|
242
|
+
: "!=";
|
243
243
|
var needDot = 1;
|
244
|
-
// eslint-disable-next-line no-redeclare
|
245
244
|
for (var i = 1; i < range.length; i++) {
|
246
245
|
var item = range[i];
|
247
246
|
var t = (typeof item)[0];
|
@@ -249,9 +248,9 @@ const rangeToString = range => {
|
|
249
248
|
str +=
|
250
249
|
t == "u"
|
251
250
|
? // undefined: prerelease marker, add an "-"
|
252
|
-
|
251
|
+
"-"
|
253
252
|
: // number or string: add the item, set flag to add an "." between two of them
|
254
|
-
|
253
|
+
(needDot > 0 ? "." : "") + ((needDot = 2), item);
|
255
254
|
}
|
256
255
|
return str;
|
257
256
|
} else {
|
@@ -264,10 +263,10 @@ const rangeToString = range => {
|
|
264
263
|
item === 0
|
265
264
|
? "not(" + pop() + ")"
|
266
265
|
: item === 1
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
266
|
+
? "(" + pop() + " || " + pop() + ")"
|
267
|
+
: item === 2
|
268
|
+
? stack.pop() + " " + stack.pop()
|
269
|
+
: rangeToString(item)
|
271
270
|
);
|
272
271
|
}
|
273
272
|
return pop();
|
@@ -416,10 +415,10 @@ const satisfy = (range, version) => {
|
|
416
415
|
item == 1
|
417
416
|
? p() | p()
|
418
417
|
: item == 2
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
418
|
+
? p() & p()
|
419
|
+
: item
|
420
|
+
? satisfy(item, version)
|
421
|
+
: !p()
|
423
422
|
);
|
424
423
|
}
|
425
424
|
return !!p();
|
@@ -452,11 +451,7 @@ exports.stringifyHoley = json => {
|
|
452
451
|
exports.parseVersionRuntimeCode = runtimeTemplate =>
|
453
452
|
`var parseVersion = ${runtimeTemplate.basicFunction("str", [
|
454
453
|
"// see webpack/lib/util/semver.js for original code",
|
455
|
-
`var p=${
|
456
|
-
runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)"
|
457
|
-
}{return p.split(".").map((${
|
458
|
-
runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)"
|
459
|
-
}{return+p==p?+p:p}))},n=/^([^-+]+)?(?:-([^+]+))?(?:\\+(.+))?$/.exec(str),r=n[1]?p(n[1]):[];return n[2]&&(r.length++,r.push.apply(r,p(n[2]))),n[3]&&(r.push([]),r.push.apply(r,p(n[3]))),r;`
|
454
|
+
`var p=${runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)"}{return p.split(".").map((${runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)"}{return+p==p?+p:p}))},n=/^([^-+]+)?(?:-([^+]+))?(?:\\+(.+))?$/.exec(str),r=n[1]?p(n[1]):[];return n[2]&&(r.length++,r.push.apply(r,p(n[2]))),n[3]&&(r.push([]),r.push.apply(r,p(n[3]))),r;`
|
460
455
|
])}`;
|
461
456
|
//#endregion
|
462
457
|
|
@@ -52,38 +52,63 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
|
|
52
52
|
runtime: chunk.runtime
|
53
53
|
}
|
54
54
|
);
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
|
56
|
+
const loader = this.generateLoadBinaryCode(wasmModuleSrcPath);
|
57
|
+
const fallback = [
|
58
|
+
`.then(${runtimeTemplate.returningFunction("x.arrayBuffer()", "x")})`,
|
59
|
+
`.then(${runtimeTemplate.returningFunction(
|
60
|
+
"WebAssembly.instantiate(bytes, importsObj)",
|
61
|
+
"bytes"
|
62
|
+
)})`,
|
63
|
+
`.then(${runtimeTemplate.returningFunction(
|
64
|
+
"Object.assign(exports, res.instance.exports)",
|
65
|
+
"res"
|
66
|
+
)})`
|
67
|
+
];
|
68
|
+
const getStreaming = () => {
|
69
|
+
const concat = (/** @type {string[]} */ ...text) => text.join("");
|
70
|
+
return [
|
71
|
+
`var req = ${loader};`,
|
72
|
+
`var fallback = ${runtimeTemplate.returningFunction(Template.asString(["req", Template.indent(fallback)]))};`,
|
73
|
+
concat(
|
74
|
+
"return req.then(",
|
75
|
+
runtimeTemplate.basicFunction("res", [
|
76
|
+
`if (typeof WebAssembly.instantiateStreaming === "function") {`,
|
77
|
+
Template.indent([
|
78
|
+
"return WebAssembly.instantiateStreaming(res, importsObj)",
|
62
79
|
Template.indent([
|
63
|
-
"
|
80
|
+
".then(",
|
64
81
|
Template.indent([
|
65
|
-
|
82
|
+
runtimeTemplate.returningFunction(
|
66
83
|
"Object.assign(exports, res.instance.exports)",
|
67
84
|
"res"
|
68
|
-
)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
"
|
83
|
-
"
|
84
|
-
)
|
85
|
-
|
86
|
-
|
85
|
+
) + ",",
|
86
|
+
runtimeTemplate.basicFunction("e", [
|
87
|
+
`if(res.headers.get("Content-Type") !== "application/wasm") {`,
|
88
|
+
Template.indent([
|
89
|
+
'console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n", e);',
|
90
|
+
"return fallback();"
|
91
|
+
]),
|
92
|
+
"}",
|
93
|
+
"throw e;"
|
94
|
+
])
|
95
|
+
]),
|
96
|
+
");"
|
97
|
+
])
|
98
|
+
]),
|
99
|
+
"}",
|
100
|
+
"return fallback();"
|
101
|
+
]),
|
102
|
+
");"
|
103
|
+
)
|
104
|
+
];
|
105
|
+
};
|
106
|
+
|
107
|
+
return `${fn} = ${runtimeTemplate.basicFunction(
|
108
|
+
"exports, wasmModuleId, wasmModuleHash, importsObj",
|
109
|
+
this.supportsStreaming
|
110
|
+
? getStreaming()
|
111
|
+
: [`return ${loader}`, Template.indent(fallback) + ";"]
|
87
112
|
)};`;
|
88
113
|
}
|
89
114
|
}
|
@@ -156,7 +156,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
156
156
|
"{",
|
157
157
|
Template.indent(importObjRequestItems.join(",\n")),
|
158
158
|
"}"
|
159
|
-
|
159
|
+
])
|
160
160
|
: undefined;
|
161
161
|
|
162
162
|
const instantiateCall =
|
@@ -194,7 +194,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
194
194
|
"} catch(e) { __webpack_async_result__(e); }"
|
195
195
|
]
|
196
196
|
)}, 1);`
|
197
|
-
|
197
|
+
])
|
198
198
|
: `${importsCode}${importsCompatCode}module.exports = ${instantiateCall};`
|
199
199
|
);
|
200
200
|
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const t = require("@webassemblyjs/ast");
|
9
9
|
const { decode } = require("@webassemblyjs/wasm-parser");
|
10
|
+
const EnvironmentNotSupportAsyncWarning = require("../EnvironmentNotSupportAsyncWarning");
|
10
11
|
const Parser = require("../Parser");
|
11
12
|
const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
|
12
13
|
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
@@ -50,6 +51,11 @@ class WebAssemblyParser extends Parser {
|
|
50
51
|
const BuildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
|
51
52
|
BuildMeta.exportsType = "namespace";
|
52
53
|
BuildMeta.async = true;
|
54
|
+
EnvironmentNotSupportAsyncWarning.check(
|
55
|
+
state.module,
|
56
|
+
state.compilation.runtimeTemplate,
|
57
|
+
"asyncWebAssembly"
|
58
|
+
);
|
53
59
|
|
54
60
|
// parse it
|
55
61
|
const program = decode(source, decoderOpts);
|
@@ -354,7 +354,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
354
354
|
"importObject"
|
355
355
|
)});`
|
356
356
|
])
|
357
|
-
|
357
|
+
])
|
358
358
|
: Template.asString([
|
359
359
|
"if(importObject && typeof importObject.then === 'function') {",
|
360
360
|
Template.indent([
|
@@ -372,7 +372,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|
372
372
|
]),
|
373
373
|
"});"
|
374
374
|
])
|
375
|
-
|
375
|
+
]),
|
376
376
|
"} else {",
|
377
377
|
Template.indent([
|
378
378
|
"var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });",
|
@@ -200,8 +200,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
200
200
|
copyAllExports
|
201
201
|
? `${module.moduleArgument}.exports = wasmExports;`
|
202
202
|
: "for(var name in wasmExports) " +
|
203
|
-
|
204
|
-
|
203
|
+
`if(name) ` +
|
204
|
+
`${module.exportsArgument}[name] = wasmExports[name];`,
|
205
205
|
"// exec imports from WebAssembly module (for esm order)",
|
206
206
|
importsCode,
|
207
207
|
"",
|
@@ -209,16 +209,16 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
209
209
|
"}"
|
210
210
|
]),
|
211
211
|
"}"
|
212
|
-
|
212
|
+
])
|
213
213
|
: Template.indent(["installedChunks[chunkId] = 0;"])
|
214
214
|
)};`
|
215
|
-
|
215
|
+
])
|
216
216
|
: "// no chunk on demand loading",
|
217
217
|
"",
|
218
218
|
withPrefetch && hasJsMatcher !== false
|
219
219
|
? `${
|
220
220
|
RuntimeGlobals.prefetchChunkHandlers
|
221
|
-
|
221
|
+
}.j = ${runtimeTemplate.basicFunction("chunkId", [
|
222
222
|
`if((!${
|
223
223
|
RuntimeGlobals.hasOwnProperty
|
224
224
|
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
@@ -232,7 +232,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
232
232
|
crossOriginLoading
|
233
233
|
? `link.crossOrigin = ${JSON.stringify(
|
234
234
|
crossOriginLoading
|
235
|
-
|
235
|
+
)};`
|
236
236
|
: "",
|
237
237
|
`if (${RuntimeGlobals.scriptNonce}) {`,
|
238
238
|
Template.indent(
|
@@ -248,13 +248,13 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
248
248
|
"document.head.appendChild(link);"
|
249
249
|
]),
|
250
250
|
"}"
|
251
|
-
|
251
|
+
])};`
|
252
252
|
: "// no prefetching",
|
253
253
|
"",
|
254
254
|
withPreload && hasJsMatcher !== false
|
255
255
|
? `${
|
256
256
|
RuntimeGlobals.preloadChunkHandlers
|
257
|
-
|
257
|
+
}.j = ${runtimeTemplate.basicFunction("chunkId", [
|
258
258
|
`if((!${
|
259
259
|
RuntimeGlobals.hasOwnProperty
|
260
260
|
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
@@ -290,7 +290,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
290
290
|
)};`
|
291
291
|
),
|
292
292
|
"}"
|
293
|
-
|
293
|
+
])
|
294
294
|
: ""
|
295
295
|
]),
|
296
296
|
chunk
|
@@ -298,7 +298,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
298
298
|
"document.head.appendChild(link);"
|
299
299
|
]),
|
300
300
|
"}"
|
301
|
-
|
301
|
+
])};`
|
302
302
|
: "// no preloaded",
|
303
303
|
"",
|
304
304
|
withHmr
|
@@ -383,7 +383,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
383
383
|
/\$hmrInvalidateModuleHandlers\$/g,
|
384
384
|
RuntimeGlobals.hmrInvalidateModuleHandlers
|
385
385
|
)
|
386
|
-
|
386
|
+
])
|
387
387
|
: "// no HMR",
|
388
388
|
"",
|
389
389
|
withHmrManifest
|
@@ -400,16 +400,16 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
400
400
|
"return response.json();"
|
401
401
|
])});`
|
402
402
|
])};`
|
403
|
-
|
403
|
+
])
|
404
404
|
: "// no HMR manifest",
|
405
405
|
"",
|
406
406
|
withOnChunkLoad
|
407
407
|
? `${
|
408
408
|
RuntimeGlobals.onChunksLoaded
|
409
|
-
|
409
|
+
}.j = ${runtimeTemplate.returningFunction(
|
410
410
|
"installedChunks[chunkId] === 0",
|
411
411
|
"chunkId"
|
412
|
-
|
412
|
+
)};`
|
413
413
|
: "// no on chunks loaded",
|
414
414
|
"",
|
415
415
|
withCallback || withLoading
|
@@ -461,7 +461,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
461
461
|
`var chunkLoadingGlobal = ${chunkLoadingGlobalExpr} = ${chunkLoadingGlobalExpr} || [];`,
|
462
462
|
"chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));",
|
463
463
|
"chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));"
|
464
|
-
|
464
|
+
])
|
465
465
|
: "// no jsonp function"
|
466
466
|
]);
|
467
467
|
}
|
@@ -128,7 +128,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
128
128
|
Template.indent("installedChunks[chunkIds.pop()] = 1;"),
|
129
129
|
"parentChunkLoadingFunction(data);"
|
130
130
|
])};`
|
131
|
-
|
131
|
+
])
|
132
132
|
: "// no chunk install function needed",
|
133
133
|
withLoading
|
134
134
|
? Template.asString([
|
@@ -152,14 +152,14 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
152
152
|
"}"
|
153
153
|
]),
|
154
154
|
"}"
|
155
|
-
|
155
|
+
]
|
156
156
|
: "installedChunks[chunkId] = 1;"
|
157
157
|
)};`,
|
158
158
|
"",
|
159
159
|
`var chunkLoadingGlobal = ${chunkLoadingGlobalExpr} = ${chunkLoadingGlobalExpr} || [];`,
|
160
160
|
"var parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);",
|
161
161
|
"chunkLoadingGlobal.push = installChunk;"
|
162
|
-
|
162
|
+
])
|
163
163
|
: "// no chunk loading",
|
164
164
|
"",
|
165
165
|
withHmr
|
@@ -196,7 +196,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
196
196
|
Template.getFunctionContent(
|
197
197
|
require("../hmr/JavascriptHotModuleReplacement.runtime.js")
|
198
198
|
)
|
199
|
-
.replace(/\$key\$/g, "
|
199
|
+
.replace(/\$key\$/g, "importScripts")
|
200
200
|
.replace(/\$installedChunks\$/g, "installedChunks")
|
201
201
|
.replace(/\$loadUpdateChunk\$/g, "loadUpdateChunk")
|
202
202
|
.replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache)
|
@@ -215,7 +215,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
215
215
|
/\$hmrInvalidateModuleHandlers\$/g,
|
216
216
|
RuntimeGlobals.hmrInvalidateModuleHandlers
|
217
217
|
)
|
218
|
-
|
218
|
+
])
|
219
219
|
: "// no HMR",
|
220
220
|
"",
|
221
221
|
withHmrManifest
|
@@ -232,7 +232,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
232
232
|
"return response.json();"
|
233
233
|
])});`
|
234
234
|
])};`
|
235
|
-
|
235
|
+
])
|
236
236
|
: "// no HMR manifest"
|
237
237
|
]);
|
238
238
|
}
|