webpack 5.102.1 → 5.104.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.
- package/README.md +121 -134
- package/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +28 -2
- package/lib/Compilation.js +58 -21
- package/lib/Compiler.js +3 -3
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +45 -14
- package/lib/DelegatedModule.js +7 -4
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +462 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +28 -35
- package/lib/ExternalModuleFactoryPlugin.js +11 -9
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +27 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +29 -13
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +424 -116
- package/lib/NormalModule.js +23 -20
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +120 -57
- package/lib/SourceMapDevToolPlugin.js +26 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +67 -15
- package/lib/asset/AssetBytesGenerator.js +16 -12
- package/lib/asset/AssetGenerator.js +31 -26
- package/lib/asset/AssetSourceGenerator.js +16 -12
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +24 -0
- package/lib/config/defaults.js +226 -61
- package/lib/config/normalization.js +4 -3
- package/lib/config/target.js +11 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +304 -76
- package/lib/css/CssLoadingRuntimeModule.js +14 -4
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +72 -67
- package/lib/css/CssParser.js +1726 -732
- package/lib/css/walkCssTokens.js +128 -11
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +389 -12
- package/lib/dependencies/CssIcssImportDependency.js +114 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
- package/lib/dependencies/CssImportDependency.js +17 -6
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -9
- package/lib/dependencies/ImportParserPlugin.js +21 -23
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +5 -3
- package/lib/ids/IdHelpers.js +20 -8
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +105 -104
- package/lib/javascript/JavascriptModulesPlugin.js +80 -37
- package/lib/javascript/JavascriptParser.js +161 -44
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -23
- package/lib/library/SystemLibraryPlugin.js +8 -1
- package/lib/library/UmdLibraryPlugin.js +2 -2
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +208 -167
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/schemes/HttpUriPlugin.js +78 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +54 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +34 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +160 -101
- package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +771 -436
- package/lib/ModuleSourceTypesConstants.js +0 -123
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
/** @typedef {import("../Hash")} Hash */
|
|
9
|
+
/** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
|
|
10
|
+
|
|
11
|
+
/** @typedef {"26" | "32" | "36" | "49" | "52" | "58" | "62"} Base */
|
|
12
|
+
|
|
13
|
+
/* cSpell:disable */
|
|
14
|
+
|
|
15
|
+
/** @type {Record<Base, string>} */
|
|
16
|
+
const ENCODE_TABLE = Object.freeze({
|
|
17
|
+
26: "abcdefghijklmnopqrstuvwxyz",
|
|
18
|
+
32: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
19
|
+
36: "0123456789abcdefghijklmnopqrstuvwxyz",
|
|
20
|
+
49: "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",
|
|
21
|
+
52: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
22
|
+
58: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
|
|
23
|
+
62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/* cSpell:enable */
|
|
27
|
+
|
|
28
|
+
const ZERO = BigInt("0");
|
|
29
|
+
const EIGHT = BigInt("8");
|
|
30
|
+
const FF = BigInt("0xff");
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* It encodes octet arrays by doing long divisions on all significant digits in the array, creating a representation of that number in the new base.
|
|
34
|
+
* Then for every leading zero in the input (not significant as a number) it will encode as a single leader character.
|
|
35
|
+
* This is the first in the alphabet and will decode as 8 bits. The other characters depend upon the base.
|
|
36
|
+
* For example, a base58 alphabet packs roughly 5.858 bits per character.
|
|
37
|
+
* This means the encoded string 000f (using a base16, 0-f alphabet) will actually decode to 4 bytes unlike a canonical hex encoding which uniformly packs 4 bits into each character.
|
|
38
|
+
* While unusual, this does mean that no padding is required, and it works for bases like 43.
|
|
39
|
+
* @param {Buffer} buffer buffer
|
|
40
|
+
* @param {Base} base base
|
|
41
|
+
* @returns {string} encoded buffer
|
|
42
|
+
*/
|
|
43
|
+
const encode = (buffer, base) => {
|
|
44
|
+
if (buffer.length === 0) return "";
|
|
45
|
+
const bigIntBase = BigInt(ENCODE_TABLE[base].length);
|
|
46
|
+
// Convert buffer to BigInt efficiently using bitwise operations
|
|
47
|
+
let value = ZERO;
|
|
48
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
49
|
+
value = (value << EIGHT) | BigInt(buffer[i]);
|
|
50
|
+
}
|
|
51
|
+
// Convert to baseX string efficiently using array
|
|
52
|
+
const digits = [];
|
|
53
|
+
if (value === ZERO) return ENCODE_TABLE[base][0];
|
|
54
|
+
while (value > ZERO) {
|
|
55
|
+
const remainder = Number(value % bigIntBase);
|
|
56
|
+
digits.push(ENCODE_TABLE[base][remainder]);
|
|
57
|
+
value /= bigIntBase;
|
|
58
|
+
}
|
|
59
|
+
return digits.reverse().join("");
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {string} data string
|
|
64
|
+
* @param {Base} base base
|
|
65
|
+
* @returns {Buffer} buffer
|
|
66
|
+
*/
|
|
67
|
+
const decode = (data, base) => {
|
|
68
|
+
if (data.length === 0) return Buffer.from("");
|
|
69
|
+
const bigIntBase = BigInt(ENCODE_TABLE[base].length);
|
|
70
|
+
// Convert the baseX string to a BigInt value
|
|
71
|
+
let value = ZERO;
|
|
72
|
+
for (let i = 0; i < data.length; i++) {
|
|
73
|
+
const digit = ENCODE_TABLE[base].indexOf(data[i]);
|
|
74
|
+
if (digit === -1) {
|
|
75
|
+
throw new Error(`Invalid character at position ${i}: ${data[i]}`);
|
|
76
|
+
}
|
|
77
|
+
value = value * bigIntBase + BigInt(digit);
|
|
78
|
+
}
|
|
79
|
+
// If value is 0, return a single-byte buffer with value 0
|
|
80
|
+
if (value === ZERO) {
|
|
81
|
+
return Buffer.alloc(1);
|
|
82
|
+
}
|
|
83
|
+
// Determine buffer size efficiently by counting bytes
|
|
84
|
+
let temp = value;
|
|
85
|
+
let byteLength = 0;
|
|
86
|
+
while (temp > ZERO) {
|
|
87
|
+
temp >>= EIGHT;
|
|
88
|
+
byteLength++;
|
|
89
|
+
}
|
|
90
|
+
// Create buffer and fill it from right to left
|
|
91
|
+
const buffer = Buffer.alloc(byteLength);
|
|
92
|
+
for (let i = byteLength - 1; i >= 0; i--) {
|
|
93
|
+
buffer[i] = Number(value & FF);
|
|
94
|
+
value >>= EIGHT;
|
|
95
|
+
}
|
|
96
|
+
return buffer;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Compatibility with the old hash libraries, they can return different structures, so let's stringify them firstly
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {string | { toString: (radix: number) => string }} value value
|
|
103
|
+
* @param {string} encoding encoding
|
|
104
|
+
* @returns {string} string
|
|
105
|
+
*/
|
|
106
|
+
const toString = (value, encoding) =>
|
|
107
|
+
typeof value === "string"
|
|
108
|
+
? value
|
|
109
|
+
: Buffer.from(value.toString(16), "hex").toString(
|
|
110
|
+
/** @type {NodeJS.BufferEncoding} */
|
|
111
|
+
(encoding)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {Buffer | { toString: (radix: number) => string }} value value
|
|
116
|
+
* @returns {Buffer} buffer
|
|
117
|
+
*/
|
|
118
|
+
const toBuffer = (value) =>
|
|
119
|
+
Buffer.isBuffer(value) ? value : Buffer.from(value.toString(16), "hex");
|
|
120
|
+
|
|
121
|
+
let isBase64URLSupported = false;
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
isBase64URLSupported = Boolean(Buffer.from("", "base64url"));
|
|
125
|
+
} catch (_err) {
|
|
126
|
+
// Nothing
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {Hash} hash hash
|
|
131
|
+
* @param {string | Buffer} data data
|
|
132
|
+
* @param {Encoding=} encoding encoding of the return value
|
|
133
|
+
* @returns {void}
|
|
134
|
+
*/
|
|
135
|
+
const update = (hash, data, encoding) => {
|
|
136
|
+
if (encoding === "base64url" && !isBase64URLSupported) {
|
|
137
|
+
const base64String = /** @type {string} */ (data)
|
|
138
|
+
.replace(/-/g, "+")
|
|
139
|
+
.replace(/_/g, "/");
|
|
140
|
+
const buf = Buffer.from(base64String, "base64");
|
|
141
|
+
hash.update(buf);
|
|
142
|
+
return;
|
|
143
|
+
} else if (
|
|
144
|
+
typeof data === "string" &&
|
|
145
|
+
encoding &&
|
|
146
|
+
typeof ENCODE_TABLE[/** @type {Base} */ (encoding.slice(4))] !== "undefined"
|
|
147
|
+
) {
|
|
148
|
+
const buf = decode(data, /** @type {Base} */ (encoding.slice(4)));
|
|
149
|
+
hash.update(buf);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (encoding) {
|
|
154
|
+
hash.update(/** @type {string} */ (data), encoding);
|
|
155
|
+
} else {
|
|
156
|
+
hash.update(data);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @overload
|
|
162
|
+
* @param {Hash} hash hash
|
|
163
|
+
* @returns {Buffer} digest
|
|
164
|
+
*/
|
|
165
|
+
/**
|
|
166
|
+
* @overload
|
|
167
|
+
* @param {Hash} hash hash
|
|
168
|
+
* @param {undefined} encoding encoding of the return value
|
|
169
|
+
* @param {boolean=} isSafe true when we await right types from digest(), otherwise false
|
|
170
|
+
* @returns {Buffer} digest
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* @overload
|
|
174
|
+
* @param {Hash} hash hash
|
|
175
|
+
* @param {Encoding} encoding encoding of the return value
|
|
176
|
+
* @param {boolean=} isSafe true when we await right types from digest(), otherwise false
|
|
177
|
+
* @returns {string} digest
|
|
178
|
+
*/
|
|
179
|
+
/**
|
|
180
|
+
* @param {Hash} hash hash
|
|
181
|
+
* @param {Encoding=} encoding encoding of the return value
|
|
182
|
+
* @param {boolean=} isSafe true when we await right types from digest(), otherwise false
|
|
183
|
+
* @returns {string | Buffer} digest
|
|
184
|
+
*/
|
|
185
|
+
const digest = (hash, encoding, isSafe) => {
|
|
186
|
+
if (typeof encoding === "undefined") {
|
|
187
|
+
return isSafe ? hash.digest() : toBuffer(hash.digest());
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (encoding === "base64url" && !isBase64URLSupported) {
|
|
191
|
+
const digest = isSafe
|
|
192
|
+
? hash.digest("base64")
|
|
193
|
+
: toString(hash.digest("base64"), "base64");
|
|
194
|
+
|
|
195
|
+
return digest.replace(/\+/g, "-").replace(/\//g, "_").replace(/[=]+$/, "");
|
|
196
|
+
} else if (
|
|
197
|
+
typeof ENCODE_TABLE[/** @type {Base} */ (encoding.slice(4))] !== "undefined"
|
|
198
|
+
) {
|
|
199
|
+
const buf = isSafe ? hash.digest() : toBuffer(hash.digest());
|
|
200
|
+
|
|
201
|
+
return encode(
|
|
202
|
+
buf,
|
|
203
|
+
/** @type {Base} */
|
|
204
|
+
(encoding.slice(4))
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return isSafe
|
|
209
|
+
? hash.digest(encoding)
|
|
210
|
+
: toString(hash.digest(encoding), encoding);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
module.exports.decode = decode;
|
|
214
|
+
module.exports.digest = digest;
|
|
215
|
+
module.exports.encode = encode;
|
|
216
|
+
module.exports.update = update;
|
package/lib/util/identifier.js
CHANGED
|
@@ -321,6 +321,7 @@ const absolutify = makeCacheableWithContext(_absolutify);
|
|
|
321
321
|
const PATH_QUERY_FRAGMENT_REGEXP =
|
|
322
322
|
/^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
|
|
323
323
|
const PATH_QUERY_REGEXP = /^((?:\0.|[^?\0])*)(\?.*)?$/;
|
|
324
|
+
const ZERO_ESCAPE_REGEXP = /\0(.)/g;
|
|
324
325
|
|
|
325
326
|
/** @typedef {{ resource: string, path: string, query: string, fragment: string }} ParsedResource */
|
|
326
327
|
/** @typedef {{ resource: string, path: string, query: string }} ParsedResourceWithoutFragment */
|
|
@@ -330,15 +331,56 @@ const PATH_QUERY_REGEXP = /^((?:\0.|[^?\0])*)(\?.*)?$/;
|
|
|
330
331
|
* @returns {ParsedResource} parsed parts
|
|
331
332
|
*/
|
|
332
333
|
const _parseResource = (str) => {
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
334
|
+
const firstEscape = str.indexOf("\0");
|
|
335
|
+
|
|
336
|
+
// Handle `\0`
|
|
337
|
+
if (firstEscape !== -1) {
|
|
338
|
+
const match =
|
|
339
|
+
/** @type {[string, string, string | undefined, string | undefined]} */
|
|
340
|
+
(/** @type {unknown} */ (PATH_QUERY_FRAGMENT_REGEXP.exec(str)));
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
resource: str,
|
|
344
|
+
path: match[1].replace(ZERO_ESCAPE_REGEXP, "$1"),
|
|
345
|
+
query: match[2] ? match[2].replace(ZERO_ESCAPE_REGEXP, "$1") : "",
|
|
346
|
+
fragment: match[3] || ""
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** @type {ParsedResource} */
|
|
351
|
+
const result = { resource: str, path: "", query: "", fragment: "" };
|
|
352
|
+
const queryStart = str.indexOf("?");
|
|
353
|
+
const fragmentStart = str.indexOf("#");
|
|
354
|
+
|
|
355
|
+
if (fragmentStart < 0) {
|
|
356
|
+
if (queryStart < 0) {
|
|
357
|
+
result.path = result.resource;
|
|
358
|
+
|
|
359
|
+
// No fragment, no query
|
|
360
|
+
return result;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
result.path = str.slice(0, queryStart);
|
|
364
|
+
result.query = str.slice(queryStart);
|
|
365
|
+
|
|
366
|
+
// Query, no fragment
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (queryStart < 0 || fragmentStart < queryStart) {
|
|
371
|
+
result.path = str.slice(0, fragmentStart);
|
|
372
|
+
result.fragment = str.slice(fragmentStart);
|
|
373
|
+
|
|
374
|
+
// Fragment, no query
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
result.path = str.slice(0, queryStart);
|
|
379
|
+
result.query = str.slice(queryStart, fragmentStart);
|
|
380
|
+
result.fragment = str.slice(fragmentStart);
|
|
381
|
+
|
|
382
|
+
// Query and fragment
|
|
383
|
+
return result;
|
|
342
384
|
};
|
|
343
385
|
|
|
344
386
|
/**
|
|
@@ -347,14 +389,37 @@ const _parseResource = (str) => {
|
|
|
347
389
|
* @returns {ParsedResourceWithoutFragment} parsed parts
|
|
348
390
|
*/
|
|
349
391
|
const _parseResourceWithoutFragment = (str) => {
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
392
|
+
const firstEscape = str.indexOf("\0");
|
|
393
|
+
|
|
394
|
+
// Handle `\0`
|
|
395
|
+
if (firstEscape !== -1) {
|
|
396
|
+
const match =
|
|
397
|
+
/** @type {[string, string, string | undefined]} */
|
|
398
|
+
(/** @type {unknown} */ (PATH_QUERY_REGEXP.exec(str)));
|
|
399
|
+
|
|
400
|
+
return {
|
|
401
|
+
resource: str,
|
|
402
|
+
path: match[1].replace(ZERO_ESCAPE_REGEXP, "$1"),
|
|
403
|
+
query: match[2] ? match[2].replace(ZERO_ESCAPE_REGEXP, "$1") : ""
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** @type {ParsedResourceWithoutFragment} */
|
|
408
|
+
const result = { resource: str, path: "", query: "" };
|
|
409
|
+
const queryStart = str.indexOf("?");
|
|
410
|
+
|
|
411
|
+
if (queryStart < 0) {
|
|
412
|
+
result.path = result.resource;
|
|
413
|
+
|
|
414
|
+
// No query
|
|
415
|
+
return result;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
result.path = str.slice(0, queryStart);
|
|
419
|
+
result.query = str.slice(queryStart);
|
|
420
|
+
|
|
421
|
+
// Query
|
|
422
|
+
return result;
|
|
358
423
|
};
|
|
359
424
|
|
|
360
425
|
/**
|
|
@@ -73,16 +73,12 @@ module.exports = {
|
|
|
73
73
|
require("../dependencies/CriticalDependencyWarning"),
|
|
74
74
|
"dependencies/CssImportDependency": () =>
|
|
75
75
|
require("../dependencies/CssImportDependency"),
|
|
76
|
-
"dependencies/
|
|
77
|
-
require("../dependencies/
|
|
78
|
-
"dependencies/CssSelfLocalIdentifierDependency": () =>
|
|
79
|
-
require("../dependencies/CssSelfLocalIdentifierDependency"),
|
|
76
|
+
"dependencies/CssUrlDependency": () =>
|
|
77
|
+
require("../dependencies/CssUrlDependency"),
|
|
80
78
|
"dependencies/CssIcssImportDependency": () =>
|
|
81
79
|
require("../dependencies/CssIcssImportDependency"),
|
|
82
80
|
"dependencies/CssIcssExportDependency": () =>
|
|
83
81
|
require("../dependencies/CssIcssExportDependency"),
|
|
84
|
-
"dependencies/CssUrlDependency": () =>
|
|
85
|
-
require("../dependencies/CssUrlDependency"),
|
|
86
82
|
"dependencies/CssIcssSymbolDependency": () =>
|
|
87
83
|
require("../dependencies/CssIcssSymbolDependency"),
|
|
88
84
|
"dependencies/DelegatedSourceDependency": () =>
|
package/lib/util/runtime.js
CHANGED
|
@@ -71,7 +71,7 @@ const forEachRuntime = (runtime, fn, deterministicOrder = false) => {
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* @template T
|
|
74
|
-
* @param {
|
|
74
|
+
* @param {Exclude<RuntimeSpec, undefined | string>} set set
|
|
75
75
|
* @returns {string} runtime key
|
|
76
76
|
*/
|
|
77
77
|
const getRuntimesKey = (set) => {
|
|
@@ -102,7 +102,7 @@ const keyToRuntime = (key) => {
|
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* @template T
|
|
105
|
-
* @param {
|
|
105
|
+
* @param {Exclude<RuntimeSpec, undefined | string>} set set
|
|
106
106
|
* @returns {string} runtime string
|
|
107
107
|
*/
|
|
108
108
|
const getRuntimesString = (set) => {
|
|
@@ -163,7 +163,7 @@ const runtimeEqual = (a, b) => {
|
|
|
163
163
|
/**
|
|
164
164
|
* @param {RuntimeSpec} a first
|
|
165
165
|
* @param {RuntimeSpec} b second
|
|
166
|
-
* @returns {-1|0|1} compare
|
|
166
|
+
* @returns {-1 | 0 | 1} compare
|
|
167
167
|
*/
|
|
168
168
|
const compareRuntime = (a, b) => {
|
|
169
169
|
if (a === b) {
|
package/lib/util/source.js
CHANGED
|
@@ -17,9 +17,9 @@ const equalityCache = new WeakMap();
|
|
|
17
17
|
*/
|
|
18
18
|
const _isSourceEqual = (a, b) => {
|
|
19
19
|
// prefer .buffer(), it's called anyway during emit
|
|
20
|
-
/** @type {Buffer|string} */
|
|
20
|
+
/** @type {Buffer | string} */
|
|
21
21
|
let aSource = typeof a.buffer === "function" ? a.buffer() : a.source();
|
|
22
|
-
/** @type {Buffer|string} */
|
|
22
|
+
/** @type {Buffer | string} */
|
|
23
23
|
let bSource = typeof b.buffer === "function" ? b.buffer() : b.source();
|
|
24
24
|
if (aSource === bSource) return true;
|
|
25
25
|
if (typeof aSource === "string" && typeof bSource === "string") return false;
|
|
@@ -77,7 +77,6 @@ class EnableWasmLoadingPlugin {
|
|
|
77
77
|
switch (type) {
|
|
78
78
|
case "fetch": {
|
|
79
79
|
if (compiler.options.experiments.syncWebAssembly) {
|
|
80
|
-
// TODO webpack 6 remove FetchCompileWasmPlugin
|
|
81
80
|
const FetchCompileWasmPlugin = require("../web/FetchCompileWasmPlugin");
|
|
82
81
|
|
|
83
82
|
new FetchCompileWasmPlugin({
|
|
@@ -95,7 +94,6 @@ class EnableWasmLoadingPlugin {
|
|
|
95
94
|
}
|
|
96
95
|
case "async-node": {
|
|
97
96
|
if (compiler.options.experiments.syncWebAssembly) {
|
|
98
|
-
// TODO webpack 6 remove ReadFileCompileWasmPlugin
|
|
99
97
|
const ReadFileCompileWasmPlugin = require("../node/ReadFileCompileWasmPlugin");
|
|
100
98
|
|
|
101
99
|
new ReadFileCompileWasmPlugin({
|
|
@@ -119,9 +117,17 @@ class EnableWasmLoadingPlugin {
|
|
|
119
117
|
break;
|
|
120
118
|
}
|
|
121
119
|
case "universal": {
|
|
122
|
-
|
|
120
|
+
if (compiler.options.experiments.syncWebAssembly) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
"Universal wasm loading type is only supported by asynchronous web assembly."
|
|
123
|
+
);
|
|
124
|
+
}
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
if (compiler.options.experiments.asyncWebAssembly) {
|
|
127
|
+
const UniversalCompileAsyncWasmPlugin = require("../wasm-async/UniversalCompileAsyncWasmPlugin");
|
|
128
|
+
|
|
129
|
+
new UniversalCompileAsyncWasmPlugin().apply(compiler);
|
|
130
|
+
}
|
|
125
131
|
break;
|
|
126
132
|
}
|
|
127
133
|
default:
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
const { RawSource } = require("webpack-sources");
|
|
9
9
|
const Generator = require("../Generator");
|
|
10
|
-
const { WEBASSEMBLY_TYPES } = require("../
|
|
10
|
+
const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypeConstants");
|
|
11
11
|
|
|
12
12
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
13
13
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
14
|
+
/** @typedef {import("../Module").SourceType} SourceType */
|
|
14
15
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
15
16
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
16
17
|
|
|
@@ -38,7 +39,7 @@ class AsyncWebAssemblyGenerator extends Generator {
|
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* @param {NormalModule} module the module
|
|
41
|
-
* @param {
|
|
42
|
+
* @param {SourceType=} type source type
|
|
42
43
|
* @returns {number} estimate size of the module
|
|
43
44
|
*/
|
|
44
45
|
getSize(module, type) {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const { RawSource } = require("webpack-sources");
|
|
9
9
|
const Generator = require("../Generator");
|
|
10
10
|
const InitFragment = require("../InitFragment");
|
|
11
|
-
const { WEBASSEMBLY_TYPES } = require("../
|
|
11
|
+
const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypeConstants");
|
|
12
12
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
13
13
|
const Template = require("../Template");
|
|
14
14
|
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
|
@@ -16,11 +16,12 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
|
|
|
16
16
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
17
17
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
18
18
|
/** @typedef {import("../Module")} Module */
|
|
19
|
+
/** @typedef {import("../Module").SourceType} SourceType */
|
|
19
20
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
20
21
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
* @typedef {{ request: string, importVar: string }} ImportObjRequestItem
|
|
24
|
+
* @typedef {{ request: string, importVar: string, dependency: WebAssemblyImportDependency }} ImportObjRequestItem
|
|
24
25
|
*/
|
|
25
26
|
|
|
26
27
|
class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
@@ -34,7 +35,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* @param {NormalModule} module the module
|
|
37
|
-
* @param {
|
|
38
|
+
* @param {SourceType=} type source type
|
|
38
39
|
* @returns {number} estimate size of the module
|
|
39
40
|
*/
|
|
40
41
|
getSize(module, type) {
|
|
@@ -70,7 +71,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
70
71
|
if (!depModules.has(module)) {
|
|
71
72
|
depModules.set(module, {
|
|
72
73
|
request: dep.request,
|
|
73
|
-
importVar: `WEBPACK_IMPORTED_MODULE_${depModules.size}
|
|
74
|
+
importVar: `WEBPACK_IMPORTED_MODULE_${depModules.size}`,
|
|
75
|
+
dependency: dep
|
|
74
76
|
});
|
|
75
77
|
}
|
|
76
78
|
let list = wasmDepsByRequest.get(dep.request);
|
|
@@ -87,7 +89,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
87
89
|
|
|
88
90
|
const importStatements = Array.from(
|
|
89
91
|
depModules,
|
|
90
|
-
([importedModule, { request, importVar }]) => {
|
|
92
|
+
([importedModule, { request, importVar, dependency }]) => {
|
|
91
93
|
if (moduleGraph.isAsync(importedModule)) {
|
|
92
94
|
promises.push(importVar);
|
|
93
95
|
}
|
|
@@ -99,7 +101,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
99
101
|
request,
|
|
100
102
|
originModule: module,
|
|
101
103
|
importVar,
|
|
102
|
-
runtimeRequirements
|
|
104
|
+
runtimeRequirements,
|
|
105
|
+
dependency
|
|
103
106
|
});
|
|
104
107
|
}
|
|
105
108
|
);
|
|
@@ -132,7 +135,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
|
132
135
|
importVar,
|
|
133
136
|
initFragments,
|
|
134
137
|
runtime,
|
|
135
|
-
runtimeRequirements
|
|
138
|
+
runtimeRequirements,
|
|
139
|
+
dependency: dep
|
|
136
140
|
})}`;
|
|
137
141
|
});
|
|
138
142
|
return Template.asString([
|
|
@@ -11,13 +11,14 @@ const { addWithAST, editWithAST } = require("@webassemblyjs/wasm-edit");
|
|
|
11
11
|
const { decode } = require("@webassemblyjs/wasm-parser");
|
|
12
12
|
const { RawSource } = require("webpack-sources");
|
|
13
13
|
const Generator = require("../Generator");
|
|
14
|
-
const { WEBASSEMBLY_TYPES } = require("../
|
|
14
|
+
const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypeConstants");
|
|
15
15
|
const WebAssemblyExportImportedDependency = require("../dependencies/WebAssemblyExportImportedDependency");
|
|
16
16
|
const WebAssemblyUtils = require("./WebAssemblyUtils");
|
|
17
17
|
|
|
18
18
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
19
19
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
20
20
|
/** @typedef {import("../Module")} Module */
|
|
21
|
+
/** @typedef {import("../Module").SourceType} SourceType */
|
|
21
22
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
22
23
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
23
24
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
@@ -270,11 +271,13 @@ const rewriteExportNames =
|
|
|
270
271
|
}
|
|
271
272
|
});
|
|
272
273
|
|
|
274
|
+
/** @typedef {Map<string, UsedWasmDependency>} Mapping */
|
|
275
|
+
|
|
273
276
|
/**
|
|
274
277
|
* Mangle import names and modules
|
|
275
278
|
* @param {object} state state
|
|
276
279
|
* @param {AST} state.ast Module's ast
|
|
277
|
-
* @param {
|
|
280
|
+
* @param {Mapping} state.usedDependencyMap mappings to mangle names
|
|
278
281
|
* @returns {ArrayBufferTransform} transform
|
|
279
282
|
*/
|
|
280
283
|
const rewriteImports =
|
|
@@ -383,11 +386,11 @@ const addInitFunction =
|
|
|
383
386
|
* Extract mangle mappings from module
|
|
384
387
|
* @param {ModuleGraph} moduleGraph module graph
|
|
385
388
|
* @param {Module} module current module
|
|
386
|
-
* @param {boolean
|
|
387
|
-
* @returns {
|
|
389
|
+
* @param {boolean=} mangle mangle imports
|
|
390
|
+
* @returns {Mapping} mappings to mangled names
|
|
388
391
|
*/
|
|
389
392
|
const getUsedDependencyMap = (moduleGraph, module, mangle) => {
|
|
390
|
-
/** @type {
|
|
393
|
+
/** @type {Mapping} */
|
|
391
394
|
const map = new Map();
|
|
392
395
|
for (const usedDep of WebAssemblyUtils.getUsedDependencies(
|
|
393
396
|
moduleGraph,
|
|
@@ -426,7 +429,7 @@ class WebAssemblyGenerator extends Generator {
|
|
|
426
429
|
|
|
427
430
|
/**
|
|
428
431
|
* @param {NormalModule} module the module
|
|
429
|
-
* @param {
|
|
432
|
+
* @param {SourceType=} type source type
|
|
430
433
|
* @returns {number} estimate size of the module
|
|
431
434
|
*/
|
|
432
435
|
getSize(module, type) {
|
|
@@ -9,7 +9,7 @@ const { RawSource } = require("webpack-sources");
|
|
|
9
9
|
const { UsageState } = require("../ExportsInfo");
|
|
10
10
|
const Generator = require("../Generator");
|
|
11
11
|
const InitFragment = require("../InitFragment");
|
|
12
|
-
const { WEBASSEMBLY_TYPES } = require("../
|
|
12
|
+
const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypeConstants");
|
|
13
13
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
14
14
|
const Template = require("../Template");
|
|
15
15
|
const ModuleDependency = require("../dependencies/ModuleDependency");
|
|
@@ -19,6 +19,7 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
|
|
|
19
19
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
20
20
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
21
21
|
/** @typedef {import("../Module")} Module */
|
|
22
|
+
/** @typedef {import("../Module").SourceType} SourceType */
|
|
22
23
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
23
24
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
24
25
|
|
|
@@ -33,7 +34,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* @param {NormalModule} module the module
|
|
36
|
-
* @param {
|
|
37
|
+
* @param {SourceType=} type source type
|
|
37
38
|
* @returns {number} estimate size of the module
|
|
38
39
|
*/
|
|
39
40
|
getSize(module, type) {
|
|
@@ -71,6 +72,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
71
72
|
importedModules.set(
|
|
72
73
|
moduleGraph.getModule(dep),
|
|
73
74
|
(importData = {
|
|
75
|
+
dependency: moduleDep,
|
|
74
76
|
importVar: `m${index}`,
|
|
75
77
|
index,
|
|
76
78
|
request: (moduleDep && moduleDep.userRequest) || undefined,
|
|
@@ -106,7 +108,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
106
108
|
defaultInterop: true,
|
|
107
109
|
initFragments,
|
|
108
110
|
runtime,
|
|
109
|
-
runtimeRequirements
|
|
111
|
+
runtimeRequirements,
|
|
112
|
+
dependency: dep
|
|
110
113
|
})
|
|
111
114
|
);
|
|
112
115
|
}
|
|
@@ -138,7 +141,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
138
141
|
defaultInterop: true,
|
|
139
142
|
initFragments,
|
|
140
143
|
runtime,
|
|
141
|
-
runtimeRequirements
|
|
144
|
+
runtimeRequirements,
|
|
145
|
+
dependency: dep
|
|
142
146
|
})};`,
|
|
143
147
|
`if(WebAssembly.Global) ${exportProp} = ` +
|
|
144
148
|
`new WebAssembly.Global({ value: ${JSON.stringify(
|
|
@@ -154,7 +158,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
154
158
|
const importsCode = Template.asString(
|
|
155
159
|
Array.from(
|
|
156
160
|
importedModules,
|
|
157
|
-
([module, { importVar, request, reexports }]) => {
|
|
161
|
+
([module, { importVar, request, reexports, dependency }]) => {
|
|
158
162
|
const importStatement = runtimeTemplate.importStatement({
|
|
159
163
|
module,
|
|
160
164
|
moduleGraph,
|
|
@@ -162,7 +166,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
|
|
|
162
166
|
request,
|
|
163
167
|
importVar,
|
|
164
168
|
originModule: module,
|
|
165
|
-
runtimeRequirements
|
|
169
|
+
runtimeRequirements,
|
|
170
|
+
dependency
|
|
166
171
|
});
|
|
167
172
|
return importStatement[0] + importStatement[1] + reexports.join("\n");
|
|
168
173
|
}
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const Generator = require("../Generator");
|
|
9
|
+
const {
|
|
10
|
+
JAVASCRIPT_TYPE,
|
|
11
|
+
WEBASSEMBLY_TYPE
|
|
12
|
+
} = require("../ModuleSourceTypeConstants");
|
|
9
13
|
const { WEBASSEMBLY_MODULE_TYPE_SYNC } = require("../ModuleTypeConstants");
|
|
10
14
|
const WebAssemblyExportImportedDependency = require("../dependencies/WebAssemblyExportImportedDependency");
|
|
11
15
|
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
|
@@ -74,8 +78,8 @@ class WebAssemblyModulesPlugin {
|
|
|
74
78
|
const WebAssemblyGenerator = getWebAssemblyGenerator();
|
|
75
79
|
|
|
76
80
|
return Generator.byType({
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
[JAVASCRIPT_TYPE]: new WebAssemblyJavascriptGenerator(),
|
|
82
|
+
[WEBASSEMBLY_TYPE]: new WebAssemblyGenerator(this.options)
|
|
79
83
|
});
|
|
80
84
|
});
|
|
81
85
|
|
|
@@ -17,8 +17,6 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
|
|
|
17
17
|
* @property {boolean=} mangleImports mangle imports
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
// TODO webpack 6 remove
|
|
21
|
-
|
|
22
20
|
const PLUGIN_NAME = "FetchCompileWasmPlugin";
|
|
23
21
|
|
|
24
22
|
class FetchCompileWasmPlugin {
|