webpack 5.84.0 → 5.85.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/lib/AsyncDependenciesBlock.js +2 -2
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +4 -0
- package/lib/CacheFacade.js +4 -0
- package/lib/ChunkGroup.js +5 -1
- package/lib/CleanPlugin.js +30 -7
- package/lib/CompatibilityPlugin.js +1 -1
- package/lib/Compilation.js +1 -1
- package/lib/Compiler.js +1 -1
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DllModuleFactory.js +1 -1
- package/lib/HookWebpackError.js +1 -1
- package/lib/IgnoreErrorModuleFactory.js +1 -1
- package/lib/Module.js +21 -9
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleTypeConstants.js +2 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +4 -2
- package/lib/NullFactory.js +1 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/RuntimeModule.js +5 -5
- package/lib/RuntimePlugin.js +4 -0
- package/lib/RuntimeTemplate.js +2 -2
- package/lib/SelfModuleFactory.js +1 -1
- package/lib/Template.js +1 -1
- package/lib/UseStrictPlugin.js +4 -0
- package/lib/WarnDeprecatedOptionPlugin.js +7 -0
- package/lib/WatchIgnorePlugin.js +4 -0
- package/lib/WebpackOptionsApply.js +2 -1
- package/lib/asset/AssetGenerator.js +7 -2
- package/lib/asset/AssetModulesPlugin.js +7 -1
- package/lib/asset/AssetParser.js +4 -1
- package/lib/asset/RawDataUrlModule.js +5 -3
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +7 -1
- package/lib/config/defaults.js +38 -10
- package/lib/config/normalization.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/FallbackDependency.js +7 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +4 -0
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/RemoteModule.js +4 -0
- package/lib/container/RemoteRuntimeModule.js +1 -0
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/dependencies/CommonJsPlugin.js +14 -12
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -1
- package/lib/dependencies/HarmonyExports.js +3 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +18 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +75 -6
- package/lib/dependencies/WorkerPlugin.js +25 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +13 -5
- package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -1
- package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
- package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
- package/lib/ids/HashedModuleIdsPlugin.js +8 -1
- package/lib/ids/IdHelpers.js +6 -0
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +14 -3
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +11 -1
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
- package/lib/javascript/JavascriptModulesPlugin.js +24 -19
- package/lib/javascript/JavascriptParser.js +50 -16
- package/lib/javascript/StartupHelpers.js +1 -1
- package/lib/json/JsonGenerator.js +7 -5
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +4 -0
- package/lib/library/AssignLibraryPlugin.js +6 -4
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +6 -3
- package/lib/library/SystemLibraryPlugin.js +1 -0
- package/lib/library/UmdLibraryPlugin.js +4 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
- package/lib/runtime/BaseUriRuntimeModule.js +5 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +5 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -0
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
- package/lib/wasm-sync/WebAssemblyParser.js +9 -2
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
- package/lib/web/FetchCompileWasmPlugin.js +19 -2
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/types.d.ts +186 -141
@@ -91,7 +91,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
91
91
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
92
92
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
93
93
|
/** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
|
94
|
-
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[] }} GetInfoResult */
|
94
|
+
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[] }} GetInfoResult */
|
95
95
|
|
96
96
|
const EMPTY_ARRAY = [];
|
97
97
|
const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
|
@@ -350,9 +350,15 @@ class JavascriptParser extends Parser {
|
|
350
350
|
/** @type {HookMap<SyncBailHook<[BaseCallExpression], boolean | void>>} */
|
351
351
|
call: new HookMap(() => new SyncBailHook(["expression"])),
|
352
352
|
/** Something like "a.b()" */
|
353
|
-
/** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[]], boolean | void>>} */
|
353
|
+
/** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], number[]], boolean | void>>} */
|
354
354
|
callMemberChain: new HookMap(
|
355
|
-
() =>
|
355
|
+
() =>
|
356
|
+
new SyncBailHook([
|
357
|
+
"expression",
|
358
|
+
"members",
|
359
|
+
"membersOptionals",
|
360
|
+
"memberRangeStarts"
|
361
|
+
])
|
356
362
|
),
|
357
363
|
/** Something like "a.b().c.d" */
|
358
364
|
/** @type {HookMap<SyncBailHook<[Expression, string[], CallExpression, string[]], boolean | void>>} */
|
@@ -384,9 +390,15 @@ class JavascriptParser extends Parser {
|
|
384
390
|
binaryExpression: new SyncBailHook(["binaryExpression"]),
|
385
391
|
/** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
|
386
392
|
expression: new HookMap(() => new SyncBailHook(["expression"])),
|
387
|
-
/** @type {HookMap<SyncBailHook<[Expression, string[], boolean[]], boolean | void>>} */
|
393
|
+
/** @type {HookMap<SyncBailHook<[Expression, string[], boolean[], number[]], boolean | void>>} */
|
388
394
|
expressionMemberChain: new HookMap(
|
389
|
-
() =>
|
395
|
+
() =>
|
396
|
+
new SyncBailHook([
|
397
|
+
"expression",
|
398
|
+
"members",
|
399
|
+
"membersOptionals",
|
400
|
+
"memberRangeStarts"
|
401
|
+
])
|
390
402
|
),
|
391
403
|
/** @type {HookMap<SyncBailHook<[Expression, string[]], boolean | void>>} */
|
392
404
|
unhandledExpressionMemberChain: new HookMap(
|
@@ -1150,7 +1162,8 @@ class JavascriptParser extends Parser {
|
|
1150
1162
|
info.name,
|
1151
1163
|
info.rootInfo,
|
1152
1164
|
info.getMembers,
|
1153
|
-
info.getMembersOptionals
|
1165
|
+
info.getMembersOptionals,
|
1166
|
+
info.getMemberRangeStarts
|
1154
1167
|
)
|
1155
1168
|
.setRange(expr.range);
|
1156
1169
|
}
|
@@ -1170,7 +1183,8 @@ class JavascriptParser extends Parser {
|
|
1170
1183
|
name: info,
|
1171
1184
|
rootInfo: info,
|
1172
1185
|
getMembers: () => [],
|
1173
|
-
getMembersOptionals: () => []
|
1186
|
+
getMembersOptionals: () => [],
|
1187
|
+
getMemberRangeStarts: () => []
|
1174
1188
|
};
|
1175
1189
|
}
|
1176
1190
|
});
|
@@ -1184,7 +1198,8 @@ class JavascriptParser extends Parser {
|
|
1184
1198
|
name: info,
|
1185
1199
|
rootInfo: info,
|
1186
1200
|
getMembers: () => [],
|
1187
|
-
getMembersOptionals: () => []
|
1201
|
+
getMembersOptionals: () => [],
|
1202
|
+
getMemberRangeStarts: () => []
|
1188
1203
|
};
|
1189
1204
|
}
|
1190
1205
|
});
|
@@ -3248,7 +3263,8 @@ class JavascriptParser extends Parser {
|
|
3248
3263
|
callee.getMembers(),
|
3249
3264
|
callee.getMembersOptionals
|
3250
3265
|
? callee.getMembersOptionals()
|
3251
|
-
: callee.getMembers().map(() => false)
|
3266
|
+
: callee.getMembers().map(() => false),
|
3267
|
+
callee.getMemberRangeStarts ? callee.getMemberRangeStarts() : []
|
3252
3268
|
);
|
3253
3269
|
if (result1 === true) return;
|
3254
3270
|
const result2 = this.callHooksForInfo(
|
@@ -3292,12 +3308,14 @@ class JavascriptParser extends Parser {
|
|
3292
3308
|
if (result1 === true) return;
|
3293
3309
|
const members = exprInfo.getMembers();
|
3294
3310
|
const membersOptionals = exprInfo.getMembersOptionals();
|
3311
|
+
const memberRangeStarts = exprInfo.getMemberRangeStarts();
|
3295
3312
|
const result2 = this.callHooksForInfo(
|
3296
3313
|
this.hooks.expressionMemberChain,
|
3297
3314
|
exprInfo.rootInfo,
|
3298
3315
|
expression,
|
3299
3316
|
members,
|
3300
|
-
membersOptionals
|
3317
|
+
membersOptionals,
|
3318
|
+
memberRangeStarts
|
3301
3319
|
);
|
3302
3320
|
if (result2 === true) return;
|
3303
3321
|
this.walkMemberExpressionWithExpressionName(
|
@@ -3956,6 +3974,7 @@ class JavascriptParser extends Parser {
|
|
3956
3974
|
.call(expr, commentsStartPos);
|
3957
3975
|
if (typeof result === "boolean") return result;
|
3958
3976
|
switch (expr.type) {
|
3977
|
+
// TODO handle more cases
|
3959
3978
|
case "ClassDeclaration":
|
3960
3979
|
case "ClassExpression": {
|
3961
3980
|
if (expr.body.type !== "ClassBody") return false;
|
@@ -3996,7 +4015,10 @@ class JavascriptParser extends Parser {
|
|
3996
4015
|
case "FunctionDeclaration":
|
3997
4016
|
case "FunctionExpression":
|
3998
4017
|
case "ArrowFunctionExpression":
|
4018
|
+
case "ThisExpression":
|
3999
4019
|
case "Literal":
|
4020
|
+
case "TemplateLiteral":
|
4021
|
+
case "Identifier":
|
4000
4022
|
case "PrivateIdentifier":
|
4001
4023
|
return true;
|
4002
4024
|
|
@@ -4012,6 +4034,12 @@ class JavascriptParser extends Parser {
|
|
4012
4034
|
this.isPure(expr.alternate, expr.consequent.range[1])
|
4013
4035
|
);
|
4014
4036
|
|
4037
|
+
case "LogicalExpression":
|
4038
|
+
return (
|
4039
|
+
this.isPure(expr.left, commentsStartPos) &&
|
4040
|
+
this.isPure(expr.right, expr.left.range[1])
|
4041
|
+
);
|
4042
|
+
|
4015
4043
|
case "SequenceExpression":
|
4016
4044
|
return expr.expressions.every(expr => {
|
4017
4045
|
const pureFlag = this.isPure(expr, commentsStartPos);
|
@@ -4243,20 +4271,23 @@ class JavascriptParser extends Parser {
|
|
4243
4271
|
|
4244
4272
|
/**
|
4245
4273
|
* @param {MemberExpression} expression a member expression
|
4246
|
-
* @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[] }} member names (reverse order) and remaining object
|
4274
|
+
* @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[], memberRangeStarts: number[] }} member names (reverse order) and remaining object
|
4247
4275
|
*/
|
4248
4276
|
extractMemberExpressionChain(expression) {
|
4249
4277
|
/** @type {AnyNode} */
|
4250
4278
|
let expr = expression;
|
4251
4279
|
const members = [];
|
4252
4280
|
const membersOptionals = [];
|
4281
|
+
const memberRangeStarts = [];
|
4253
4282
|
while (expr.type === "MemberExpression") {
|
4254
4283
|
if (expr.computed) {
|
4255
4284
|
if (expr.property.type !== "Literal") break;
|
4256
4285
|
members.push(`${expr.property.value}`);
|
4286
|
+
memberRangeStarts.push(expr.object.range[1]);
|
4257
4287
|
} else {
|
4258
4288
|
if (expr.property.type !== "Identifier") break;
|
4259
4289
|
members.push(expr.property.name);
|
4290
|
+
memberRangeStarts.push(expr.object.range[1]);
|
4260
4291
|
}
|
4261
4292
|
membersOptionals.push(expr.optional);
|
4262
4293
|
expr = expr.object;
|
@@ -4265,6 +4296,7 @@ class JavascriptParser extends Parser {
|
|
4265
4296
|
return {
|
4266
4297
|
members,
|
4267
4298
|
membersOptionals,
|
4299
|
+
memberRangeStarts,
|
4268
4300
|
object: expr
|
4269
4301
|
};
|
4270
4302
|
}
|
@@ -4287,8 +4319,8 @@ class JavascriptParser extends Parser {
|
|
4287
4319
|
return { info, name };
|
4288
4320
|
}
|
4289
4321
|
|
4290
|
-
/** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} CallExpressionInfo */
|
4291
|
-
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} ExpressionExpressionInfo */
|
4322
|
+
/** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[]}} CallExpressionInfo */
|
4323
|
+
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[]}} ExpressionExpressionInfo */
|
4292
4324
|
|
4293
4325
|
/**
|
4294
4326
|
* @param {MemberExpression} expression a member expression
|
@@ -4296,7 +4328,7 @@ class JavascriptParser extends Parser {
|
|
4296
4328
|
* @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
|
4297
4329
|
*/
|
4298
4330
|
getMemberExpressionInfo(expression, allowedTypes) {
|
4299
|
-
const { object, members, membersOptionals } =
|
4331
|
+
const { object, members, membersOptionals, memberRangeStarts } =
|
4300
4332
|
this.extractMemberExpressionChain(expression);
|
4301
4333
|
switch (object.type) {
|
4302
4334
|
case "CallExpression": {
|
@@ -4322,7 +4354,8 @@ class JavascriptParser extends Parser {
|
|
4322
4354
|
getCalleeMembers: memoize(() => rootMembers.reverse()),
|
4323
4355
|
name: objectAndMembersToName(`${calleeName}()`, members),
|
4324
4356
|
getMembers: memoize(() => members.reverse()),
|
4325
|
-
getMembersOptionals: memoize(() => membersOptionals.reverse())
|
4357
|
+
getMembersOptionals: memoize(() => membersOptionals.reverse()),
|
4358
|
+
getMemberRangeStarts: memoize(() => memberRangeStarts.reverse())
|
4326
4359
|
};
|
4327
4360
|
}
|
4328
4361
|
case "Identifier":
|
@@ -4341,7 +4374,8 @@ class JavascriptParser extends Parser {
|
|
4341
4374
|
name: objectAndMembersToName(resolvedRoot, members),
|
4342
4375
|
rootInfo,
|
4343
4376
|
getMembers: memoize(() => members.reverse()),
|
4344
|
-
getMembersOptionals: memoize(() => membersOptionals.reverse())
|
4377
|
+
getMembersOptionals: memoize(() => membersOptionals.reverse()),
|
4378
|
+
getMemberRangeStarts: memoize(() => memberRangeStarts.reverse())
|
4345
4379
|
};
|
4346
4380
|
}
|
4347
4381
|
}
|
@@ -19,7 +19,7 @@ const { getAllChunks } = require("./ChunkHelpers");
|
|
19
19
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
20
20
|
/** @typedef {(string|number)[]} EntryItem */
|
21
21
|
|
22
|
-
const EXPORT_PREFIX =
|
22
|
+
const EXPORT_PREFIX = `var ${RuntimeGlobals.exports} = `;
|
23
23
|
|
24
24
|
/**
|
25
25
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
@@ -45,13 +45,14 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
|
|
45
45
|
if (exportsInfo.otherExportsInfo.getUsed(runtime) !== UsageState.Unused)
|
46
46
|
return data;
|
47
47
|
const isArray = Array.isArray(data);
|
48
|
+
/** @type {RawJsonData} */
|
48
49
|
const reducedData = isArray ? [] : {};
|
49
50
|
for (const key of Object.keys(data)) {
|
50
51
|
const exportInfo = exportsInfo.getReadOnlyExportInfo(key);
|
51
52
|
const used = exportInfo.getUsed(runtime);
|
52
53
|
if (used === UsageState.Unused) continue;
|
53
54
|
|
54
|
-
/** @type {
|
55
|
+
/** @type {RawJsonData} */
|
55
56
|
let value;
|
56
57
|
if (used === UsageState.OnlyPropertiesUsed && exportInfo.exportsInfo) {
|
57
58
|
value = createObjectForExportsInfo(
|
@@ -62,8 +63,9 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
|
|
62
63
|
} else {
|
63
64
|
value = data[key];
|
64
65
|
}
|
65
|
-
|
66
|
-
|
66
|
+
|
67
|
+
const name = /** @type {string} */ (exportInfo.getUsedName(key, runtime));
|
68
|
+
/** @type {Record<string, RawJsonData>} */ (reducedData)[name] = value;
|
67
69
|
}
|
68
70
|
if (isArray) {
|
69
71
|
let arrayLengthWhenUsed =
|
@@ -130,7 +132,7 @@ class JsonGenerator extends Generator {
|
|
130
132
|
module.buildInfo.jsonData &&
|
131
133
|
module.buildInfo.jsonData.get();
|
132
134
|
if (!data) return 0;
|
133
|
-
return stringifySafe(data).length + 10;
|
135
|
+
return /** @type {string} */ (stringifySafe(data)).length + 10;
|
134
136
|
}
|
135
137
|
|
136
138
|
/**
|
@@ -178,7 +180,7 @@ class JsonGenerator extends Generator {
|
|
178
180
|
? createObjectForExportsInfo(data, exportsInfo, runtime)
|
179
181
|
: data;
|
180
182
|
// Use JSON because JSON.parse() is much faster than JavaScript evaluation
|
181
|
-
const jsonStr = stringifySafe(finalJson);
|
183
|
+
const jsonStr = /** @type {string} */ (stringifySafe(finalJson));
|
182
184
|
const jsonExpr =
|
183
185
|
jsonStr.length > 20 && typeof finalJson === "object"
|
184
186
|
? `JSON.parse('${jsonStr.replace(/[\\']/g, "\\$&")}')`
|
package/lib/json/JsonParser.js
CHANGED
@@ -34,7 +34,7 @@ class JsonParser extends Parser {
|
|
34
34
|
source = source.toString("utf-8");
|
35
35
|
}
|
36
36
|
|
37
|
-
/** @type {JsonModulesPluginParserOptions["parse"]} */
|
37
|
+
/** @type {NonNullable<JsonModulesPluginParserOptions["parse"]>} */
|
38
38
|
const parseFn =
|
39
39
|
typeof this.options.parse === "function" ? this.options.parse : parseJson;
|
40
40
|
/** @type {Buffer | RawJsonData} */
|
@@ -87,6 +87,10 @@ class AbstractLibraryPlugin {
|
|
87
87
|
}
|
88
88
|
);
|
89
89
|
|
90
|
+
/**
|
91
|
+
* @param {Chunk} chunk chunk
|
92
|
+
* @returns {TODO} options for the chunk
|
93
|
+
*/
|
90
94
|
const getOptionsForChunk = chunk => {
|
91
95
|
if (compilation.chunkGraph.getNumberOfEntryModules(chunk) === 0)
|
92
96
|
return false;
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
9
9
|
const { UsageState } = require("../ExportsInfo");
|
10
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
10
11
|
const Template = require("../Template");
|
11
12
|
const propertyAccess = require("../util/propertyAccess");
|
12
13
|
const { getEntryRuntime } = require("../util/runtime");
|
@@ -296,7 +297,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
296
297
|
if (!exportInfo.provided) continue;
|
297
298
|
const nameAccess = propertyAccess([exportInfo.name]);
|
298
299
|
result.add(
|
299
|
-
`${exportTarget}${nameAccess} =
|
300
|
+
`${exportTarget}${nameAccess} = ${RuntimeGlobals.exports}${exportAccess}${nameAccess};\n`
|
300
301
|
);
|
301
302
|
}
|
302
303
|
result.add(
|
@@ -310,10 +311,11 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
310
311
|
true
|
311
312
|
)};\n`
|
312
313
|
);
|
313
|
-
|
314
|
+
/** @type {String} */
|
315
|
+
let exports = RuntimeGlobals.exports;
|
314
316
|
if (exportAccess) {
|
315
317
|
result.add(
|
316
|
-
`var __webpack_exports_export__ =
|
318
|
+
`var __webpack_exports_export__ = ${RuntimeGlobals.exports}${exportAccess};\n`
|
317
319
|
);
|
318
320
|
exports = "__webpack_exports_export__";
|
319
321
|
}
|
@@ -329,7 +331,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
329
331
|
fullNameResolved,
|
330
332
|
this._getPrefix(compilation).length,
|
331
333
|
false
|
332
|
-
)} =
|
334
|
+
)} = ${RuntimeGlobals.exports}${exportAccess};\n`
|
333
335
|
);
|
334
336
|
}
|
335
337
|
return result;
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
9
9
|
const { UsageState } = require("../ExportsInfo");
|
10
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
10
11
|
const propertyAccess = require("../util/propertyAccess");
|
11
12
|
const { getEntryRuntime } = require("../util/runtime");
|
12
13
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
@@ -103,7 +104,9 @@ class ExportPropertyLibraryPlugin extends AbstractLibraryPlugin {
|
|
103
104
|
*/
|
104
105
|
renderStartup(source, module, renderContext, { options }) {
|
105
106
|
if (!options.export) return source;
|
106
|
-
const postfix =
|
107
|
+
const postfix = `${RuntimeGlobals.exports} = ${
|
108
|
+
RuntimeGlobals.exports
|
109
|
+
}${propertyAccess(
|
107
110
|
Array.isArray(options.export) ? options.export : [options.export]
|
108
111
|
)};\n`;
|
109
112
|
return new ConcatSource(source, postfix);
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
9
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
10
|
const Template = require("../Template");
|
10
11
|
const propertyAccess = require("../util/propertyAccess");
|
11
12
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
@@ -80,15 +81,17 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
80
81
|
const exports = [];
|
81
82
|
const isAsync = moduleGraph.isAsync(module);
|
82
83
|
if (isAsync) {
|
83
|
-
result.add(
|
84
|
+
result.add(
|
85
|
+
`${RuntimeGlobals.exports} = await ${RuntimeGlobals.exports};\n`
|
86
|
+
);
|
84
87
|
}
|
85
88
|
for (const exportInfo of exportsInfo.orderedExports) {
|
86
89
|
if (!exportInfo.provided) continue;
|
87
|
-
const varName =
|
90
|
+
const varName = `${RuntimeGlobals.exports}${Template.toIdentifier(
|
88
91
|
exportInfo.name
|
89
92
|
)}`;
|
90
93
|
result.add(
|
91
|
-
`var ${varName} =
|
94
|
+
`var ${varName} = ${RuntimeGlobals.exports}${propertyAccess([
|
92
95
|
/** @type {string} */
|
93
96
|
(exportInfo.getUsedName(exportInfo.name, chunk.runtime))
|
94
97
|
])};\n`
|
@@ -106,6 +106,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
106
106
|
.join("\n");
|
107
107
|
|
108
108
|
// Define __esModule flag on all internal variables and helpers
|
109
|
+
/** @type {string[]} */
|
109
110
|
const externalVarInitialization = [];
|
110
111
|
|
111
112
|
// The system.register format requires an array of setter functions for externals.
|
@@ -208,6 +208,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
208
208
|
);
|
209
209
|
};
|
210
210
|
|
211
|
+
/**
|
212
|
+
* @param {ExternalModule[]} modules external modules
|
213
|
+
* @returns {string} arguments
|
214
|
+
*/
|
211
215
|
const externalsArguments = modules => {
|
212
216
|
return modules
|
213
217
|
.map(
|
@@ -8,11 +8,18 @@
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
9
|
const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
|
10
10
|
|
11
|
+
/** @typedef {import("../Chunk")} Chunk */
|
11
12
|
/** @typedef {import("../Compiler")} Compiler */
|
12
13
|
|
14
|
+
/** @typedef {Object} CommonJsChunkLoadingPluginOptions
|
15
|
+
* @property {boolean} [asyncChunkLoading] enable async chunk loading
|
16
|
+
*/
|
17
|
+
|
13
18
|
class CommonJsChunkLoadingPlugin {
|
14
|
-
|
15
|
-
|
19
|
+
/**
|
20
|
+
* @param {CommonJsChunkLoadingPluginOptions} [options] options
|
21
|
+
*/
|
22
|
+
constructor(options = {}) {
|
16
23
|
this._asyncChunkLoading = options.asyncChunkLoading;
|
17
24
|
}
|
18
25
|
|
@@ -36,6 +43,10 @@ class CommonJsChunkLoadingPlugin {
|
|
36
43
|
"CommonJsChunkLoadingPlugin",
|
37
44
|
compilation => {
|
38
45
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
46
|
+
/**
|
47
|
+
* @param {Chunk} chunk chunk
|
48
|
+
* @returns {boolean} true, if wasm loading is enabled for the chunk
|
49
|
+
*/
|
39
50
|
const isEnabledForChunk = chunk => {
|
40
51
|
const options = chunk.getEntryOptions();
|
41
52
|
const chunkLoading =
|
@@ -45,6 +56,10 @@ class CommonJsChunkLoadingPlugin {
|
|
45
56
|
return chunkLoading === chunkLoadingValue;
|
46
57
|
};
|
47
58
|
const onceForChunkSet = new WeakSet();
|
59
|
+
/**
|
60
|
+
* @param {Chunk} chunk chunk
|
61
|
+
* @param {Set<string>} set runtime requirements
|
62
|
+
*/
|
48
63
|
const handler = (chunk, set) => {
|
49
64
|
if (onceForChunkSet.has(chunk)) return;
|
50
65
|
onceForChunkSet.add(chunk);
|
@@ -10,9 +10,17 @@ const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin
|
|
10
10
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
|
13
|
+
/**
|
14
|
+
* @typedef {Object} NodeTemplatePluginOptions
|
15
|
+
* @property {boolean} [asyncChunkLoading] enable async chunk loading
|
16
|
+
*/
|
17
|
+
|
13
18
|
class NodeTemplatePlugin {
|
14
|
-
|
15
|
-
|
19
|
+
/**
|
20
|
+
* @param {NodeTemplatePluginOptions} [options] options object
|
21
|
+
*/
|
22
|
+
constructor(options = {}) {
|
23
|
+
this._options = options;
|
16
24
|
}
|
17
25
|
|
18
26
|
/**
|
@@ -29,7 +29,7 @@ class NodeWatchFileSystem {
|
|
29
29
|
* @param {Iterable<string>} missing watched exitance entries
|
30
30
|
* @param {number} startTime timestamp of start time
|
31
31
|
* @param {WatchOptions} options options object
|
32
|
-
* @param {function(Error=, Map<string, FileSystemInfoEntry>, Map<string, FileSystemInfoEntry>, Set<string>, Set<string>): void} callback aggregated callback
|
32
|
+
* @param {function((Error | null)=, Map<string, FileSystemInfoEntry>, Map<string, FileSystemInfoEntry>, Set<string>, Set<string>): void} callback aggregated callback
|
33
33
|
* @param {function(string, number): void} callbackUndelayed callback when the first change was detected
|
34
34
|
* @returns {Watcher} a watcher
|
35
35
|
*/
|
@@ -18,6 +18,9 @@ const { getUndoPath } = require("../util/identifier");
|
|
18
18
|
/** @typedef {import("../Chunk")} Chunk */
|
19
19
|
|
20
20
|
class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
21
|
+
/**
|
22
|
+
* @param {ReadonlySet<string>} runtimeRequirements runtime requirements
|
23
|
+
*/
|
21
24
|
constructor(runtimeRequirements) {
|
22
25
|
super("readFile chunk loading", RuntimeModule.STAGE_ATTACH);
|
23
26
|
this.runtimeRequirements = runtimeRequirements;
|
@@ -78,7 +81,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
78
81
|
);
|
79
82
|
const rootOutputDir = getUndoPath(
|
80
83
|
outputName,
|
81
|
-
this.compilation.outputOptions.path,
|
84
|
+
/** @type {string} */ (this.compilation.outputOptions.path),
|
82
85
|
false
|
83
86
|
);
|
84
87
|
|
@@ -10,6 +10,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
10
|
const Template = require("../Template");
|
11
11
|
const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
|
12
12
|
|
13
|
+
/** @typedef {import("../Chunk")} Chunk */
|
13
14
|
/** @typedef {import("../Compiler")} Compiler */
|
14
15
|
|
15
16
|
class ReadFileCompileAsyncWasmPlugin {
|
@@ -27,6 +28,10 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
27
28
|
"ReadFileCompileAsyncWasmPlugin",
|
28
29
|
compilation => {
|
29
30
|
const globalWasmLoading = compilation.outputOptions.wasmLoading;
|
31
|
+
/**
|
32
|
+
* @param {Chunk} chunk chunk
|
33
|
+
* @returns {boolean} true, if wasm loading is enabled for the chunk
|
34
|
+
*/
|
30
35
|
const isEnabledForChunk = chunk => {
|
31
36
|
const options = chunk.getEntryOptions();
|
32
37
|
const wasmLoading =
|
@@ -35,6 +40,9 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
35
40
|
: globalWasmLoading;
|
36
41
|
return wasmLoading === this._type;
|
37
42
|
};
|
43
|
+
/**
|
44
|
+
* @type {(path: string) => string}
|
45
|
+
*/
|
38
46
|
const generateLoadBinaryCode = this._import
|
39
47
|
? path =>
|
40
48
|
Template.asString([
|
@@ -10,13 +10,22 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
10
|
const Template = require("../Template");
|
11
11
|
const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRuntimeModule");
|
12
12
|
|
13
|
+
/** @typedef {import("../Chunk")} Chunk */
|
13
14
|
/** @typedef {import("../Compiler")} Compiler */
|
14
15
|
|
16
|
+
/**
|
17
|
+
* @typedef {Object} ReadFileCompileWasmPluginOptions
|
18
|
+
* @property {boolean} [mangleImports] mangle imports
|
19
|
+
*/
|
20
|
+
|
15
21
|
// TODO webpack 6 remove
|
16
22
|
|
17
23
|
class ReadFileCompileWasmPlugin {
|
18
|
-
|
19
|
-
|
24
|
+
/**
|
25
|
+
* @param {ReadFileCompileWasmPluginOptions} [options] options object
|
26
|
+
*/
|
27
|
+
constructor(options = {}) {
|
28
|
+
this.options = options;
|
20
29
|
}
|
21
30
|
|
22
31
|
/**
|
@@ -29,6 +38,10 @@ class ReadFileCompileWasmPlugin {
|
|
29
38
|
"ReadFileCompileWasmPlugin",
|
30
39
|
compilation => {
|
31
40
|
const globalWasmLoading = compilation.outputOptions.wasmLoading;
|
41
|
+
/**
|
42
|
+
* @param {Chunk} chunk chunk
|
43
|
+
* @returns {boolean} true, when wasm loading is enabled for the chunk
|
44
|
+
*/
|
32
45
|
const isEnabledForChunk = chunk => {
|
33
46
|
const options = chunk.getEntryOptions();
|
34
47
|
const wasmLoading =
|
@@ -37,6 +50,10 @@ class ReadFileCompileWasmPlugin {
|
|
37
50
|
: globalWasmLoading;
|
38
51
|
return wasmLoading === "async-node";
|
39
52
|
};
|
53
|
+
/**
|
54
|
+
* @param {string} path path to wasm file
|
55
|
+
* @returns {string} generated code to load the wasm file
|
56
|
+
*/
|
40
57
|
const generateLoadBinaryCode = path =>
|
41
58
|
Template.asString([
|
42
59
|
"new Promise(function (resolve, reject) {",
|
@@ -18,6 +18,9 @@ const { getUndoPath } = require("../util/identifier");
|
|
18
18
|
/** @typedef {import("../Chunk")} Chunk */
|
19
19
|
|
20
20
|
class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
21
|
+
/**
|
22
|
+
* @param {ReadonlySet<string>} runtimeRequirements runtime requirements
|
23
|
+
*/
|
21
24
|
constructor(runtimeRequirements) {
|
22
25
|
super("require chunk loading", RuntimeModule.STAGE_ATTACH);
|
23
26
|
this.runtimeRequirements = runtimeRequirements;
|
@@ -78,7 +81,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
78
81
|
);
|
79
82
|
const rootOutputDir = getUndoPath(
|
80
83
|
outputName,
|
81
|
-
this.compilation.outputOptions.path,
|
84
|
+
/** @type {string} */ (this.compilation.outputOptions.path),
|
82
85
|
true
|
83
86
|
);
|
84
87
|
|
@@ -21,7 +21,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
21
21
|
const fn = RuntimeGlobals.asyncModule;
|
22
22
|
return Template.asString([
|
23
23
|
'var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";',
|
24
|
-
|
24
|
+
`var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
|
25
25
|
'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
|
26
26
|
`var resolveQueue = ${runtimeTemplate.basicFunction("queue", [
|
27
27
|
"if(queue && !queue.d) {",
|
@@ -31,7 +31,11 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
31
31
|
contentHashType: "javascript"
|
32
32
|
}
|
33
33
|
);
|
34
|
-
const undoPath = getUndoPath(
|
34
|
+
const undoPath = getUndoPath(
|
35
|
+
chunkName,
|
36
|
+
/** @type {string} */ (path),
|
37
|
+
false
|
38
|
+
);
|
35
39
|
|
36
40
|
return Template.asString([
|
37
41
|
"var scriptUrl;",
|
@@ -8,6 +8,8 @@
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
10
10
|
|
11
|
+
/** @typedef {import("../../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
|
12
|
+
|
11
13
|
class BaseUriRuntimeModule extends RuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("base uri", RuntimeModule.STAGE_ATTACH);
|
@@ -19,7 +21,9 @@ class BaseUriRuntimeModule extends RuntimeModule {
|
|
19
21
|
generate() {
|
20
22
|
const { chunk } = this;
|
21
23
|
|
22
|
-
const options =
|
24
|
+
const options =
|
25
|
+
/** @type {EntryDescriptionNormalized} */
|
26
|
+
(chunk.getEntryOptions());
|
23
27
|
return `${RuntimeGlobals.baseURI} = ${
|
24
28
|
options.baseUri === undefined
|
25
29
|
? "undefined"
|
@@ -9,6 +9,9 @@ const RuntimeModule = require("../RuntimeModule");
|
|
9
9
|
const Template = require("../Template");
|
10
10
|
|
11
11
|
class EnsureChunkRuntimeModule extends RuntimeModule {
|
12
|
+
/**
|
13
|
+
* @param {ReadonlySet<string>} runtimeRequirements runtime requirements
|
14
|
+
*/
|
12
15
|
constructor(runtimeRequirements) {
|
13
16
|
super("ensure chunk");
|
14
17
|
this.runtimeRequirements = runtimeRequirements;
|