webpack 5.103.0 → 5.104.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.
- 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 +3 -0
- package/lib/Compilation.js +33 -19
- package/lib/Compiler.js +3 -3
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/DefinePlugin.js +34 -3
- package/lib/DelegatedModule.js +7 -4
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +11 -6
- package/lib/ExportsInfo.js +5 -5
- package/lib/ExternalModule.js +8 -7
- package/lib/ExternalModuleFactoryPlugin.js +1 -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 +1 -1
- package/lib/Module.js +24 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +27 -12
- 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/NodeStuffPlugin.js +52 -42
- package/lib/NormalModule.js +6 -4
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimeTemplate.js +5 -1
- package/lib/SizeFormatHelpers.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +6 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +37 -9
- package/lib/asset/AssetBytesGenerator.js +15 -11
- package/lib/asset/AssetGenerator.js +30 -24
- package/lib/asset/AssetSourceGenerator.js +15 -11
- 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 +19 -0
- package/lib/config/defaults.js +128 -43
- package/lib/config/normalization.js +2 -2
- package/lib/config/target.js +5 -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 +26 -24
- package/lib/css/CssLoadingRuntimeModule.js +12 -4
- package/lib/css/CssModulesPlugin.js +29 -74
- package/lib/css/CssParser.js +828 -341
- package/lib/css/walkCssTokens.js +33 -13
- package/lib/dependencies/CachedConstDependency.js +24 -10
- 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 +242 -104
- package/lib/dependencies/CssIcssImportDependency.js +61 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
- package/lib/dependencies/CssImportDependency.js +2 -1
- 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 +2 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -4
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +8 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +57 -0
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +4 -3
- package/lib/ids/IdHelpers.js +16 -7
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +4 -3
- package/lib/javascript/JavascriptModulesPlugin.js +57 -24
- package/lib/javascript/JavascriptParser.js +19 -6
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +2 -1
- 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 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/optimize/ConcatenatedModule.js +47 -32
- 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/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/schemes/HttpUriPlugin.js +97 -10
- 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 +53 -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-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/webpack.js +1 -1
- package/package.json +30 -25
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +59 -82
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/types.d.ts +225 -158
- package/lib/ModuleSourceTypesConstants.js +0 -117
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
- package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
- package/lib/util/jsonParseEvenBetterErrors.js +0 -10
- 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.d.ts +0 -7
- 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/CssIcssSelfLocalIdentifierDependency": () =>
|
|
79
|
-
require("../dependencies/CssIcssSelfLocalIdentifierDependency"),
|
|
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;
|
|
@@ -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,6 +16,7 @@ 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
|
|
|
@@ -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) {
|
|
@@ -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) {
|
|
@@ -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
|
|
package/lib/webpack.js
CHANGED
|
@@ -154,7 +154,7 @@ const webpack = (options, callback) => {
|
|
|
154
154
|
"DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
|
|
155
155
|
)();
|
|
156
156
|
}
|
|
157
|
-
/** @type {MultiCompiler|Compiler} */
|
|
157
|
+
/** @type {MultiCompiler | Compiler} */
|
|
158
158
|
let compiler;
|
|
159
159
|
/** @type {boolean | undefined} */
|
|
160
160
|
let watch = false;
|