webpack 5.106.2 → 5.107.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 +2 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/Cache.js +3 -6
- package/lib/CompatibilityPlugin.js +8 -7
- package/lib/Compilation.js +34 -26
- package/lib/Compiler.js +4 -13
- package/lib/ContextModule.js +2 -2
- package/lib/DefinePlugin.js +2 -2
- package/lib/Dependency.js +22 -1
- package/lib/DependencyTemplate.js +2 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +8 -9
- package/lib/ExternalModule.js +76 -15
- package/lib/ExternalModuleFactoryPlugin.js +5 -0
- package/lib/FileSystemInfo.js +187 -72
- package/lib/Generator.js +3 -3
- package/lib/HotModuleReplacementPlugin.js +26 -8
- package/lib/IgnorePlugin.js +2 -1
- package/lib/Module.js +19 -18
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleSourceTypeConstants.js +31 -1
- package/lib/ModuleTypeConstants.js +12 -3
- package/lib/MultiCompiler.js +2 -2
- package/lib/NodeStuffPlugin.js +1 -1
- package/lib/NormalModule.js +13 -31
- package/lib/NormalModuleFactory.js +10 -2
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +129 -56
- package/lib/RuntimeGlobals.js +5 -5
- package/lib/RuntimeModule.js +9 -7
- package/lib/RuntimePlugin.js +11 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +16 -1
- package/lib/Watching.js +2 -3
- package/lib/WebpackError.js +3 -77
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +13 -1
- package/lib/asset/AssetBytesGenerator.js +6 -2
- package/lib/asset/AssetGenerator.js +22 -8
- package/lib/asset/AssetModulesPlugin.js +3 -1
- package/lib/asset/AssetSourceGenerator.js +6 -2
- package/lib/buildChunkGraph.js +4 -6
- package/lib/cache/PackFileCacheStrategy.js +4 -4
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +197 -10
- package/lib/config/normalization.js +3 -1
- package/lib/css/CssGenerator.js +320 -105
- package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
- package/lib/css/CssLoadingRuntimeModule.js +22 -4
- package/lib/{CssModule.js → css/CssModule.js} +15 -15
- package/lib/css/CssModulesPlugin.js +166 -86
- package/lib/css/CssParser.js +566 -269
- package/lib/css/walkCssTokens.js +148 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -3
- package/lib/dependencies/CommonJsRequireDependency.js +67 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +332 -67
- package/lib/dependencies/CssIcssImportDependency.js +49 -7
- package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
- package/lib/dependencies/CssImportDependency.js +8 -0
- package/lib/dependencies/CssUrlDependency.js +25 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
- package/lib/dependencies/HarmonyImportDependency.js +10 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
- package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
- package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
- package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
- package/lib/dependencies/HtmlScriptSrcDependency.js +318 -0
- package/lib/dependencies/HtmlSourceDependency.js +127 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/ImportPhase.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
- package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
- package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
- package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
- package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
- package/lib/{DllModule.js → dll/DllModule.js} +24 -24
- package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
- package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
- package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
- package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
- package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
- package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
- package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
- package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
- package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
- package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
- package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
- package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
- package/lib/errors/JSONParseError.js +114 -0
- package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
- package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
- package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
- package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
- package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
- package/lib/{ModuleNotFoundError.js → errors/ModuleNotFoundError.js} +2 -2
- package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
- package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
- package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
- package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
- package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
- package/lib/errors/NonErrorEmittedError.js +28 -0
- package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
- package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
- package/lib/errors/WebpackError.js +84 -0
- package/lib/html/HtmlGenerator.js +379 -0
- package/lib/html/HtmlModulesPlugin.js +433 -0
- package/lib/html/HtmlParser.js +1489 -0
- package/lib/html/walkHtmlTokens.js +2733 -0
- package/lib/ids/IdHelpers.js +2 -1
- package/lib/index.js +34 -15
- package/lib/javascript/JavascriptModulesPlugin.js +89 -8
- package/lib/javascript/JavascriptParser.js +197 -16
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/json/JsonParser.js +7 -16
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/EnableLibraryPlugin.js +1 -1
- package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
- package/lib/library/ModuleLibraryPlugin.js +74 -0
- package/lib/node/NodeEnvironmentPlugin.js +4 -2
- package/lib/node/nodeConsole.js +113 -64
- package/lib/optimize/ConcatenatedModule.js +51 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -1
- package/lib/optimize/MinMaxSizeWarning.js +4 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
- package/lib/optimize/RealContentHashPlugin.js +89 -26
- package/lib/optimize/SideEffectsFlagPlugin.js +111 -3
- package/lib/optimize/SplitChunksPlugin.js +1 -1
- package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/NoAsyncChunksWarning.js +5 -3
- package/lib/performance/SizeLimitsPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
- package/lib/rules/UseEffectRulePlugin.js +4 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
- package/lib/schemes/DataUriPlugin.js +13 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +2 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +1 -1
- package/lib/typescript/TypeScriptPlugin.js +210 -0
- package/lib/url/URLParserPlugin.js +2 -2
- package/lib/util/AsyncQueue.js +2 -2
- package/lib/util/Hash.js +2 -2
- package/lib/util/LocConverter.js +53 -0
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +3 -3
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +42 -1
- package/lib/util/createMappings.js +118 -0
- package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
- package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
- package/lib/util/fs.js +8 -8
- package/lib/util/hash/md4.js +1 -1
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +48 -0
- package/lib/util/internalSerializables.js +35 -19
- package/lib/util/magicComment.js +10 -7
- package/lib/util/parseJson.js +2 -73
- package/lib/util/source.js +21 -0
- package/lib/util/topologicalSort.js +69 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
- package/lib/webpack.js +3 -1
- package/package.json +22 -20
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +118 -3
- package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
- package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +22 -0
- package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
- package/types.d.ts +810 -101
- package/lib/CaseSensitiveModulesWarning.js +0 -80
- package/lib/GraphHelpers.js +0 -49
- package/lib/NoModeWarning.js +0 -23
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
- /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
- /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
- /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
package/lib/css/walkCssTokens.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const { makeCacheable } = require("../util/identifier");
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Defines the css token callbacks type used by this module.
|
|
10
12
|
* @typedef {object} CssTokenCallbacks
|
|
@@ -161,6 +163,143 @@ const isIdentStartCodePoint = (cc) =>
|
|
|
161
163
|
cc === CC_LOW_LINE ||
|
|
162
164
|
cc >= 0x80;
|
|
163
165
|
|
|
166
|
+
const REGEX_SINGLE_ESCAPE = /[ -,./:-@[\]^`{-~]/;
|
|
167
|
+
const REGEX_EXCESSIVE_SPACES = /(^|\\+)?(\\[A-F0-9]{1,6}) (?![a-fA-F0-9 ])/g;
|
|
168
|
+
const REGEX_CTRL_WHITESPACE = /[\t\n\f\r\v]/;
|
|
169
|
+
const REGEX_LEADING_HYPHEN_DIGIT = /^-[-\d]/;
|
|
170
|
+
const REGEX_DIGIT = /\d/;
|
|
171
|
+
const CONTAINS_ESCAPE = /\\/;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Returns escaped identifier.
|
|
175
|
+
* @param {string} str string
|
|
176
|
+
* @returns {string} escaped identifier
|
|
177
|
+
*/
|
|
178
|
+
const _escapeIdentifier = (str) => {
|
|
179
|
+
let output = "";
|
|
180
|
+
let counter = 0;
|
|
181
|
+
|
|
182
|
+
while (counter < str.length) {
|
|
183
|
+
const character = str.charAt(counter++);
|
|
184
|
+
|
|
185
|
+
/** @type {string} */
|
|
186
|
+
let value;
|
|
187
|
+
|
|
188
|
+
if (REGEX_CTRL_WHITESPACE.test(character)) {
|
|
189
|
+
const codePoint = character.charCodeAt(0);
|
|
190
|
+
|
|
191
|
+
value = `\\${codePoint.toString(16).toUpperCase()} `;
|
|
192
|
+
} else if (character === "\\" || REGEX_SINGLE_ESCAPE.test(character)) {
|
|
193
|
+
value = `\\${character}`;
|
|
194
|
+
} else {
|
|
195
|
+
value = character;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
output += value;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const firstChar = str.charAt(0);
|
|
202
|
+
|
|
203
|
+
if (REGEX_LEADING_HYPHEN_DIGIT.test(output)) {
|
|
204
|
+
output = `\\-${output.slice(1)}`;
|
|
205
|
+
} else if (REGEX_DIGIT.test(firstChar)) {
|
|
206
|
+
output = `\\3${firstChar} ${output.slice(1)}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Remove spaces after `\HEX` escapes that are not followed by a hex digit,
|
|
210
|
+
// since they’re redundant. Note that this is only possible if the escape
|
|
211
|
+
// sequence isn’t preceded by an odd number of backslashes.
|
|
212
|
+
output = output.replace(REGEX_EXCESSIVE_SPACES, ($0, $1, $2) => {
|
|
213
|
+
if ($1 && $1.length % 2) {
|
|
214
|
+
// It’s not safe to remove the space, so don’t.
|
|
215
|
+
return $0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Strip the space.
|
|
219
|
+
return ($1 || "") + $2;
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
return output;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Returns hex.
|
|
227
|
+
* @param {string} str string
|
|
228
|
+
* @returns {[string, number] | undefined} hex
|
|
229
|
+
*/
|
|
230
|
+
const gobbleHex = (str) => {
|
|
231
|
+
const lower = str.toLowerCase();
|
|
232
|
+
let hex = "";
|
|
233
|
+
let spaceTerminated = false;
|
|
234
|
+
|
|
235
|
+
for (let i = 0; i < 6 && lower[i] !== undefined; i++) {
|
|
236
|
+
const code = lower.charCodeAt(i);
|
|
237
|
+
// check to see if we are dealing with a valid hex char [a-f|0-9]
|
|
238
|
+
const valid = (code >= 97 && code <= 102) || (code >= 48 && code <= 57);
|
|
239
|
+
// https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
|
|
240
|
+
spaceTerminated = code === 32;
|
|
241
|
+
if (!valid) break;
|
|
242
|
+
hex += lower[i];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (hex.length === 0) return undefined;
|
|
246
|
+
|
|
247
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
248
|
+
const isSurrogate = codePoint >= 0xd800 && codePoint <= 0xdfff;
|
|
249
|
+
|
|
250
|
+
// Add special case for
|
|
251
|
+
// "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
|
|
252
|
+
// https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
|
|
253
|
+
if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10ffff) {
|
|
254
|
+
return ["�", hex.length + (spaceTerminated ? 1 : 0)];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return [
|
|
258
|
+
String.fromCodePoint(codePoint),
|
|
259
|
+
hex.length + (spaceTerminated ? 1 : 0)
|
|
260
|
+
];
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Unescape identifier.
|
|
265
|
+
* @param {string} str string
|
|
266
|
+
* @returns {string} unescaped string
|
|
267
|
+
*/
|
|
268
|
+
const _unescapeIdentifier = (str) => {
|
|
269
|
+
const needToProcess = CONTAINS_ESCAPE.test(str);
|
|
270
|
+
if (!needToProcess) return str;
|
|
271
|
+
let ret = "";
|
|
272
|
+
for (let i = 0; i < str.length; i++) {
|
|
273
|
+
if (str[i] === "\\") {
|
|
274
|
+
const gobbled = gobbleHex(str.slice(i + 1, i + 7));
|
|
275
|
+
if (gobbled !== undefined) {
|
|
276
|
+
ret += gobbled[0];
|
|
277
|
+
i += gobbled[1];
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
// Retain a pair of \\ if double escaped `\\\\`
|
|
281
|
+
// https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
|
|
282
|
+
if (str[i + 1] === "\\") {
|
|
283
|
+
ret += "\\";
|
|
284
|
+
i += 1;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
// if \\ is at the end of the string retain it
|
|
288
|
+
// https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
|
|
289
|
+
if (str.length === i + 1) {
|
|
290
|
+
ret += str[i];
|
|
291
|
+
}
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
ret += str[i];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return ret;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const escapeIdentifier = makeCacheable(_escapeIdentifier);
|
|
301
|
+
const unescapeIdentifier = makeCacheable(_unescapeIdentifier);
|
|
302
|
+
|
|
164
303
|
/** @type {CharHandler} */
|
|
165
304
|
const consumeDelimToken = (input, pos, callbacks) => {
|
|
166
305
|
// Return a <delim-token> with its value set to the current input code point.
|
|
@@ -1632,11 +1771,11 @@ const eatImageSetStrings = (input, pos, cbs) => {
|
|
|
1632
1771
|
* @param {string} input input
|
|
1633
1772
|
* @param {number} pos position
|
|
1634
1773
|
* @param {CssTokenCallbacks} cbs callbacks
|
|
1635
|
-
* @returns {[[number, number, number, number] | undefined, [number, number] | undefined, [number, number] | undefined, [number, number] | undefined]} positions of top level tokens
|
|
1774
|
+
* @returns {[[number, number, number, number, boolean?] | undefined, [number, number] | undefined, [number, number] | undefined, [number, number] | undefined]} positions of top level tokens — the URL tuple's optional 5th element is `true` when the URL was given as an identifier (CSS Modules `@value` reference)
|
|
1636
1775
|
*/
|
|
1637
1776
|
const eatImportTokens = (input, pos, cbs) => {
|
|
1638
1777
|
const result =
|
|
1639
|
-
/** @type {[[number, number, number, number] | undefined, [number, number] | undefined, [number, number] | undefined, [number, number] | undefined]} */
|
|
1778
|
+
/** @type {[[number, number, number, number, boolean?] | undefined, [number, number] | undefined, [number, number] | undefined, [number, number] | undefined]} */
|
|
1640
1779
|
(Array.from({ length: 4 }));
|
|
1641
1780
|
|
|
1642
1781
|
/** @type {0 | 1 | 2 | undefined} */
|
|
@@ -1740,6 +1879,11 @@ const eatImportTokens = (input, pos, cbs) => {
|
|
|
1740
1879
|
if (name === "layer") {
|
|
1741
1880
|
result[1] = [start, end];
|
|
1742
1881
|
scope = undefined;
|
|
1882
|
+
} else if (result[0] === undefined) {
|
|
1883
|
+
// Capture as URL identifier (e.g. `@import myValue;` where
|
|
1884
|
+
// `myValue` is a CSS Modules `@value` definition).
|
|
1885
|
+
result[0] = [start, end, start, end, true];
|
|
1886
|
+
scope = undefined;
|
|
1743
1887
|
}
|
|
1744
1888
|
}
|
|
1745
1889
|
|
|
@@ -1868,7 +2012,9 @@ module.exports.eatUntil = eatUntil;
|
|
|
1868
2012
|
module.exports.eatWhiteLine = eatWhiteLine;
|
|
1869
2013
|
module.exports.eatWhitespace = eatWhitespace;
|
|
1870
2014
|
module.exports.eatWhitespaceAndComments = eatWhitespaceAndComments;
|
|
2015
|
+
module.exports.escapeIdentifier = escapeIdentifier;
|
|
1871
2016
|
module.exports.isIdentStartCodePoint = isIdentStartCodePoint;
|
|
1872
2017
|
module.exports.isWhiteSpace = _isWhiteSpace;
|
|
1873
2018
|
module.exports.skipCommentsAndEatIdentSequence =
|
|
1874
2019
|
skipCommentsAndEatIdentSequence;
|
|
2020
|
+
module.exports.unescapeIdentifier = unescapeIdentifier;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
|
-
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
|
9
|
+
const UnsupportedFeatureWarning = require("../errors/UnsupportedFeatureWarning");
|
|
10
10
|
const AMDRequireArrayDependency = require("./AMDRequireArrayDependency");
|
|
11
11
|
const AMDRequireContextDependency = require("./AMDRequireContextDependency");
|
|
12
12
|
const AMDRequireDependenciesBlock = require("./AMDRequireDependenciesBlock");
|
|
@@ -6,11 +6,72 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
|
+
const { propertyAccess } = require("../util/property");
|
|
9
10
|
|
|
10
11
|
/** @typedef {import("../Module")} Module */
|
|
11
12
|
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
13
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
14
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
12
15
|
/** @typedef {"exports" | "module.exports" | "this" | "Object.defineProperty(exports)" | "Object.defineProperty(module.exports)" | "Object.defineProperty(this)"} CommonJSDependencyBaseKeywords */
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* The well-known name of the ESM named export that, when present, is unwrapped
|
|
19
|
+
* by CommonJS `require()` to match Node.js v23+ `require(esm)` semantics:
|
|
20
|
+
* https://nodejs.org/docs/latest/api/modules.html#loading-ecmascript-modules-using-require
|
|
21
|
+
*/
|
|
22
|
+
const ESM_MODULE_EXPORTS_NAME = "module.exports";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Whether `require()` of `importedModule` would trigger Node.js's
|
|
26
|
+
* `require(esm)` `"module.exports"` named-export unwrap. This is the
|
|
27
|
+
* usage-independent eligibility check: it only looks at module type and
|
|
28
|
+
* whether the export is declared, so it can be safely used from
|
|
29
|
+
* `getReferencedExports` before usage info is finalized (otherwise the
|
|
30
|
+
* check would be circular — we'd need `"module.exports"` to already be
|
|
31
|
+
* marked used in order to ask whether to mark it used).
|
|
32
|
+
* @param {Module} importedModule the imported module
|
|
33
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
|
34
|
+
* @returns {boolean} true if `require()` should unwrap `"module.exports"`
|
|
35
|
+
*/
|
|
36
|
+
const isRequireEsmModuleExportsModule = (importedModule, moduleGraph) => {
|
|
37
|
+
if (importedModule.getExportsType(moduleGraph, false) !== "namespace") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const exportsInfo = moduleGraph.getExportsInfo(importedModule);
|
|
41
|
+
const exportInfo = exportsInfo.getReadOnlyExportInfo(ESM_MODULE_EXPORTS_NAME);
|
|
42
|
+
return exportInfo.provided === true;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* When CommonJS `require()` resolves to an ES module that has a named export
|
|
47
|
+
* with the literal string name `"module.exports"`, Node.js returns the value of
|
|
48
|
+
* that export instead of the namespace object. Returns the property-access
|
|
49
|
+
* expression to apply to the require result for that unwrapping, or `null` if
|
|
50
|
+
* the imported module is not eligible (not strictly ESM, or no such export,
|
|
51
|
+
* or the export was tree-shaken away).
|
|
52
|
+
* @param {Module} importedModule the imported module
|
|
53
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
|
54
|
+
* @param {RuntimeSpec} runtime the runtime for which the module is analysed
|
|
55
|
+
* @returns {string | null} property-access expression (e.g. `["module.exports"]`), or `null`
|
|
56
|
+
*/
|
|
57
|
+
const getRequireEsmModuleExportsAccess = (
|
|
58
|
+
importedModule,
|
|
59
|
+
moduleGraph,
|
|
60
|
+
runtime
|
|
61
|
+
) => {
|
|
62
|
+
if (!isRequireEsmModuleExportsModule(importedModule, moduleGraph)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const exportsInfo = moduleGraph.getExportsInfo(importedModule);
|
|
66
|
+
const usedName = exportsInfo.getUsedName([ESM_MODULE_EXPORTS_NAME], runtime);
|
|
67
|
+
if (usedName === false) return null;
|
|
68
|
+
return propertyAccess(/** @type {readonly string[]} */ (usedName));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
module.exports.ESM_MODULE_EXPORTS_NAME = ESM_MODULE_EXPORTS_NAME;
|
|
72
|
+
module.exports.getRequireEsmModuleExportsAccess =
|
|
73
|
+
getRequireEsmModuleExportsAccess;
|
|
74
|
+
|
|
14
75
|
/**
|
|
15
76
|
* Returns type and base.
|
|
16
77
|
* @param {CommonJSDependencyBaseKeywords} depBase commonjs dependency base
|
|
@@ -64,3 +125,5 @@ module.exports.handleDependencyBase = (
|
|
|
64
125
|
|
|
65
126
|
return [type, base];
|
|
66
127
|
};
|
|
128
|
+
module.exports.isRequireEsmModuleExportsModule =
|
|
129
|
+
isRequireEsmModuleExportsModule;
|
|
@@ -11,7 +11,12 @@ const Template = require("../Template");
|
|
|
11
11
|
const { equals } = require("../util/ArrayHelpers");
|
|
12
12
|
const makeSerializable = require("../util/makeSerializable");
|
|
13
13
|
const { propertyAccess } = require("../util/property");
|
|
14
|
-
const {
|
|
14
|
+
const {
|
|
15
|
+
ESM_MODULE_EXPORTS_NAME,
|
|
16
|
+
getRequireEsmModuleExportsAccess,
|
|
17
|
+
handleDependencyBase,
|
|
18
|
+
isRequireEsmModuleExportsModule
|
|
19
|
+
} = require("./CommonJsDependencyHelpers");
|
|
15
20
|
const ModuleDependency = require("./ModuleDependency");
|
|
16
21
|
const processExportInfo = require("./processExportInfo");
|
|
17
22
|
|
|
@@ -107,6 +112,16 @@ class CommonJsExportRequireDependency extends ModuleDependency {
|
|
|
107
112
|
*/
|
|
108
113
|
getReferencedExports(moduleGraph, runtime) {
|
|
109
114
|
const ids = this.getIds(moduleGraph);
|
|
115
|
+
const importedModule = moduleGraph.getModule(this);
|
|
116
|
+
if (
|
|
117
|
+
importedModule &&
|
|
118
|
+
isRequireEsmModuleExportsModule(importedModule, moduleGraph)
|
|
119
|
+
) {
|
|
120
|
+
// `require(esm)` unwraps the "module.exports" named export; any
|
|
121
|
+
// further property access lands on that value (which webpack does
|
|
122
|
+
// not model), so only the "module.exports" export is observable.
|
|
123
|
+
return [[ESM_MODULE_EXPORTS_NAME]];
|
|
124
|
+
}
|
|
110
125
|
const getFullResult = () => {
|
|
111
126
|
if (ids.length === 0) {
|
|
112
127
|
return Dependency.EXPORTS_OBJECT_REFERENCED;
|
|
@@ -159,17 +174,26 @@ class CommonJsExportRequireDependency extends ModuleDependency {
|
|
|
159
174
|
* @returns {ExportsSpec | undefined} export names
|
|
160
175
|
*/
|
|
161
176
|
getExports(moduleGraph) {
|
|
177
|
+
const importedModule = moduleGraph.getModule(this);
|
|
178
|
+
const esmUnwrap =
|
|
179
|
+
importedModule &&
|
|
180
|
+
isRequireEsmModuleExportsModule(importedModule, moduleGraph);
|
|
162
181
|
if (this.names.length === 1) {
|
|
163
182
|
const ids = this.getIds(moduleGraph);
|
|
164
183
|
const name = this.names[0];
|
|
165
184
|
const from = moduleGraph.getConnection(this);
|
|
166
185
|
if (!from) return;
|
|
186
|
+
const exportChain = esmUnwrap
|
|
187
|
+
? [ESM_MODULE_EXPORTS_NAME, ...ids]
|
|
188
|
+
: ids.length === 0
|
|
189
|
+
? null
|
|
190
|
+
: ids;
|
|
167
191
|
return {
|
|
168
192
|
exports: [
|
|
169
193
|
{
|
|
170
194
|
name,
|
|
171
195
|
from,
|
|
172
|
-
export:
|
|
196
|
+
export: exportChain,
|
|
173
197
|
// we can't mangle names that are in an empty object
|
|
174
198
|
// because one could access the prototype property
|
|
175
199
|
// when export isn't set yet
|
|
@@ -195,6 +219,17 @@ class CommonJsExportRequireDependency extends ModuleDependency {
|
|
|
195
219
|
}
|
|
196
220
|
const from = moduleGraph.getConnection(this);
|
|
197
221
|
if (!from) return;
|
|
222
|
+
if (esmUnwrap) {
|
|
223
|
+
// Full re-export `module.exports = require("./esm")` of a module
|
|
224
|
+
// with a `"module.exports"` named export: the wrapping module's
|
|
225
|
+
// `module.exports` becomes the unwrapped value, whose own
|
|
226
|
+
// properties webpack cannot enumerate statically.
|
|
227
|
+
return {
|
|
228
|
+
exports: true,
|
|
229
|
+
canMangle: false,
|
|
230
|
+
dependencies: [from.module]
|
|
231
|
+
};
|
|
232
|
+
}
|
|
198
233
|
const reexportInfo = this.getStarReexports(
|
|
199
234
|
moduleGraph,
|
|
200
235
|
undefined,
|
|
@@ -393,14 +428,23 @@ CommonJsExportRequireDependency.Template = class CommonJsExportRequireDependency
|
|
|
393
428
|
});
|
|
394
429
|
if (importedModule) {
|
|
395
430
|
const ids = dep.getIds(moduleGraph);
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
431
|
+
const esmRequireAccess = getRequireEsmModuleExportsAccess(
|
|
432
|
+
importedModule,
|
|
433
|
+
moduleGraph,
|
|
434
|
+
runtime
|
|
435
|
+
);
|
|
436
|
+
if (esmRequireAccess !== null) {
|
|
437
|
+
requireExpr += `${esmRequireAccess}${propertyAccess(ids)}`;
|
|
438
|
+
} else {
|
|
439
|
+
const usedImported = moduleGraph
|
|
440
|
+
.getExportsInfo(importedModule)
|
|
441
|
+
.getUsedName(ids, runtime);
|
|
442
|
+
if (usedImported) {
|
|
443
|
+
const comment = equals(usedImported, ids)
|
|
444
|
+
? ""
|
|
445
|
+
: `${Template.toNormalComment(propertyAccess(ids))} `;
|
|
446
|
+
requireExpr += `${comment}${propertyAccess(usedImported)}`;
|
|
447
|
+
}
|
|
404
448
|
}
|
|
405
449
|
}
|
|
406
450
|
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
|
-
const formatLocation = require("../formatLocation");
|
|
10
9
|
const { evaluateToString } = require("../javascript/JavascriptParserHelpers");
|
|
10
|
+
const formatLocation = require("../util/formatLocation");
|
|
11
11
|
const { propertyAccess } = require("../util/property");
|
|
12
12
|
const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
|
|
13
13
|
const CommonJsExportsDependency = require("./CommonJsExportsDependency");
|
|
@@ -10,6 +10,11 @@ const { equals } = require("../util/ArrayHelpers");
|
|
|
10
10
|
const { getTrimmedIdsAndRange } = require("../util/chainedImports");
|
|
11
11
|
const makeSerializable = require("../util/makeSerializable");
|
|
12
12
|
const { propertyAccess } = require("../util/property");
|
|
13
|
+
const {
|
|
14
|
+
ESM_MODULE_EXPORTS_NAME,
|
|
15
|
+
getRequireEsmModuleExportsAccess,
|
|
16
|
+
isRequireEsmModuleExportsModule
|
|
17
|
+
} = require("./CommonJsDependencyHelpers");
|
|
13
18
|
const ModuleDependency = require("./ModuleDependency");
|
|
14
19
|
|
|
15
20
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
@@ -55,14 +60,22 @@ class CommonJsFullRequireDependency extends ModuleDependency {
|
|
|
55
60
|
* @returns {ReferencedExports} referenced exports
|
|
56
61
|
*/
|
|
57
62
|
getReferencedExports(moduleGraph, runtime) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const importedModule = moduleGraph.getModule(this);
|
|
64
|
+
if (
|
|
65
|
+
importedModule &&
|
|
66
|
+
isRequireEsmModuleExportsModule(importedModule, moduleGraph)
|
|
67
|
+
) {
|
|
68
|
+
// When `require(esm)` unwraps a `"module.exports"` named export, the
|
|
69
|
+
// user's property access lands on that value (which webpack does not
|
|
70
|
+
// model), so only the "module.exports" export itself is referenced.
|
|
71
|
+
return [[ESM_MODULE_EXPORTS_NAME]];
|
|
72
|
+
}
|
|
73
|
+
if (
|
|
74
|
+
this.call &&
|
|
75
|
+
(!importedModule ||
|
|
76
|
+
importedModule.getExportsType(moduleGraph, false) !== "namespace")
|
|
77
|
+
) {
|
|
78
|
+
return [this.names.slice(0, -1)];
|
|
66
79
|
}
|
|
67
80
|
return [this.names];
|
|
68
81
|
}
|
|
@@ -128,6 +141,10 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
|
|
|
128
141
|
runtimeRequirements
|
|
129
142
|
});
|
|
130
143
|
|
|
144
|
+
const esmRequireAccess = importedModule
|
|
145
|
+
? getRequireEsmModuleExportsAccess(importedModule, moduleGraph, runtime)
|
|
146
|
+
: null;
|
|
147
|
+
|
|
131
148
|
const {
|
|
132
149
|
trimmedRange: [trimmedRangeStart, trimmedRangeEnd],
|
|
133
150
|
trimmedIds
|
|
@@ -139,7 +156,13 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
|
|
|
139
156
|
dep
|
|
140
157
|
);
|
|
141
158
|
|
|
142
|
-
if (
|
|
159
|
+
if (esmRequireAccess !== null) {
|
|
160
|
+
const access = `${esmRequireAccess}${propertyAccess(trimmedIds)}`;
|
|
161
|
+
requireExpr =
|
|
162
|
+
dep.asiSafe === true
|
|
163
|
+
? `(${requireExpr}${access})`
|
|
164
|
+
: `${requireExpr}${access}`;
|
|
165
|
+
} else if (importedModule) {
|
|
143
166
|
const usedImported = moduleGraph
|
|
144
167
|
.getExportsInfo(importedModule)
|
|
145
168
|
.getUsedName(trimmedIds, runtime);
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const CommentCompilationWarning = require("../CommentCompilationWarning");
|
|
9
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
|
-
const
|
|
9
|
+
const CommentCompilationWarning = require("../errors/CommentCompilationWarning");
|
|
10
|
+
const UnsupportedFeatureWarning = require("../errors/UnsupportedFeatureWarning");
|
|
11
11
|
const {
|
|
12
12
|
evaluateToIdentifier,
|
|
13
13
|
evaluateToString,
|
|
@@ -160,7 +160,8 @@ const createRequireCallHandler = (parser, options, getContext) => {
|
|
|
160
160
|
/** @type {string} */ (param.string),
|
|
161
161
|
/** @type {Range} */ (param.range),
|
|
162
162
|
getContext(),
|
|
163
|
-
referencedExports
|
|
163
|
+
referencedExports,
|
|
164
|
+
/** @type {Range} */ (expr.range)
|
|
164
165
|
);
|
|
165
166
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
166
167
|
dep.optional = Boolean(parser.scope.inTry);
|
|
@@ -7,11 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
const Dependency = require("../Dependency");
|
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
|
10
|
+
const {
|
|
11
|
+
ESM_MODULE_EXPORTS_NAME,
|
|
12
|
+
getRequireEsmModuleExportsAccess,
|
|
13
|
+
isRequireEsmModuleExportsModule
|
|
14
|
+
} = require("./CommonJsDependencyHelpers");
|
|
10
15
|
const ModuleDependency = require("./ModuleDependency");
|
|
11
|
-
const ModuleDependencyTemplateAsId = require("./ModuleDependencyTemplateAsId");
|
|
12
16
|
|
|
17
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
13
18
|
/** @typedef {import("../Dependency").RawReferencedExports} RawReferencedExports */
|
|
14
19
|
/** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
|
|
20
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
21
|
+
/** @typedef {import("../Module")} Module */
|
|
15
22
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
16
23
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
17
24
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
@@ -22,15 +29,23 @@ class CommonJsRequireDependency extends ModuleDependency {
|
|
|
22
29
|
/**
|
|
23
30
|
* Creates an instance of CommonJsRequireDependency.
|
|
24
31
|
* @param {string} request request
|
|
25
|
-
* @param {Range=} range location in source code
|
|
32
|
+
* @param {Range=} range location in source code of the string-literal argument (gets replaced by the module id)
|
|
26
33
|
* @param {string=} context request context
|
|
27
34
|
* @param {RawReferencedExports | null=} referencedExports list of referenced exports
|
|
35
|
+
* @param {Range=} valueRange location in source code of the whole `require(...)` call (for `require(esm)` interop)
|
|
28
36
|
*/
|
|
29
|
-
constructor(
|
|
37
|
+
constructor(
|
|
38
|
+
request,
|
|
39
|
+
range,
|
|
40
|
+
context,
|
|
41
|
+
referencedExports = null,
|
|
42
|
+
valueRange = undefined
|
|
43
|
+
) {
|
|
30
44
|
super(request);
|
|
31
45
|
this.range = range;
|
|
32
46
|
this._context = context;
|
|
33
47
|
this.referencedExports = referencedExports;
|
|
48
|
+
this.valueRange = valueRange;
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
get type() {
|
|
@@ -48,6 +63,15 @@ class CommonJsRequireDependency extends ModuleDependency {
|
|
|
48
63
|
* @returns {ReferencedExports} referenced exports
|
|
49
64
|
*/
|
|
50
65
|
getReferencedExports(moduleGraph, runtime) {
|
|
66
|
+
const importedModule = moduleGraph.getModule(this);
|
|
67
|
+
if (
|
|
68
|
+
importedModule &&
|
|
69
|
+
isRequireEsmModuleExportsModule(importedModule, moduleGraph)
|
|
70
|
+
) {
|
|
71
|
+
// `require(esm)` will unwrap the "module.exports" named export; only
|
|
72
|
+
// that export is observable through this `require()` call.
|
|
73
|
+
return [[ESM_MODULE_EXPORTS_NAME]];
|
|
74
|
+
}
|
|
51
75
|
if (!this.referencedExports) return Dependency.EXPORTS_OBJECT_REFERENCED;
|
|
52
76
|
return this.referencedExports.map((name) => ({
|
|
53
77
|
name,
|
|
@@ -62,6 +86,7 @@ class CommonJsRequireDependency extends ModuleDependency {
|
|
|
62
86
|
serialize(context) {
|
|
63
87
|
const { write } = context;
|
|
64
88
|
write(this.referencedExports);
|
|
89
|
+
write(this.valueRange);
|
|
65
90
|
super.serialize(context);
|
|
66
91
|
}
|
|
67
92
|
|
|
@@ -72,11 +97,49 @@ class CommonJsRequireDependency extends ModuleDependency {
|
|
|
72
97
|
deserialize(context) {
|
|
73
98
|
const { read } = context;
|
|
74
99
|
this.referencedExports = read();
|
|
100
|
+
this.valueRange = read();
|
|
75
101
|
super.deserialize(context);
|
|
76
102
|
}
|
|
77
103
|
}
|
|
78
104
|
|
|
79
|
-
CommonJsRequireDependency.Template =
|
|
105
|
+
CommonJsRequireDependency.Template = class CommonJsRequireDependencyTemplate extends (
|
|
106
|
+
ModuleDependency.Template
|
|
107
|
+
) {
|
|
108
|
+
/**
|
|
109
|
+
* Applies the plugin by registering its hooks on the compiler.
|
|
110
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
111
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
112
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
115
|
+
apply(
|
|
116
|
+
dependency,
|
|
117
|
+
source,
|
|
118
|
+
{ runtimeTemplate, moduleGraph, chunkGraph, runtime }
|
|
119
|
+
) {
|
|
120
|
+
const dep = /** @type {CommonJsRequireDependency} */ (dependency);
|
|
121
|
+
if (!dep.range) return;
|
|
122
|
+
const importedModule = /** @type {Module} */ (moduleGraph.getModule(dep));
|
|
123
|
+
const content = runtimeTemplate.moduleId({
|
|
124
|
+
module: importedModule,
|
|
125
|
+
chunkGraph,
|
|
126
|
+
request: dep.request,
|
|
127
|
+
weak: dep.weak
|
|
128
|
+
});
|
|
129
|
+
source.replace(dep.range[0], dep.range[1] - 1, content);
|
|
130
|
+
|
|
131
|
+
if (dep.valueRange && importedModule) {
|
|
132
|
+
const access = getRequireEsmModuleExportsAccess(
|
|
133
|
+
importedModule,
|
|
134
|
+
moduleGraph,
|
|
135
|
+
runtime
|
|
136
|
+
);
|
|
137
|
+
if (access !== null) {
|
|
138
|
+
source.insert(dep.valueRange[1], access);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
80
143
|
|
|
81
144
|
makeSerializable(
|
|
82
145
|
CommonJsRequireDependency,
|
|
@@ -14,7 +14,7 @@ const memoize = require("../util/memoize");
|
|
|
14
14
|
/** @typedef {import("../ContextModule").ContextOptions} ContextOptions */
|
|
15
15
|
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
|
16
16
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
17
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
17
|
+
/** @typedef {import("../errors/WebpackError")} WebpackError */
|
|
18
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
19
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
20
20
|
|
|
@@ -48,7 +48,7 @@ const splitContextFromPrefix = (prefix) => {
|
|
|
48
48
|
/**
|
|
49
49
|
* Defines the get additional dep args type used by this module.
|
|
50
50
|
* @template T
|
|
51
|
-
* @typedef {T extends new (options: ContextDependencyOptions, range: Range, valueRange: Range, ...remains: infer R) =>
|
|
51
|
+
* @typedef {T extends new (options: ContextDependencyOptions, range: Range, valueRange: Range, ...remains: infer R) => ContextDependency ? R : []} GetAdditionalDepArgs
|
|
52
52
|
*/
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { fileURLToPath } = require("url");
|
|
9
|
-
const WebpackError = require("../WebpackError");
|
|
9
|
+
const WebpackError = require("../errors/WebpackError");
|
|
10
10
|
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
|
|
11
11
|
const { VariableInfo } = require("../javascript/JavascriptParser");
|
|
12
12
|
const {
|