webpack 5.36.2 → 5.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -8
- package/bin/webpack.js +0 -0
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +10 -5
- package/lib/Compilation.js +45 -57
- package/lib/Compiler.js +9 -6
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ContextModule.js +3 -3
- package/lib/ContextReplacementPlugin.js +4 -3
- package/lib/DefinePlugin.js +16 -12
- package/lib/EntryPlugin.js +4 -4
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/ExportsInfo.js +20 -13
- package/lib/FileSystemInfo.js +25 -31
- package/lib/FlagDependencyExportsPlugin.js +8 -7
- package/lib/FlagDependencyUsagePlugin.js +2 -4
- package/lib/HotModuleReplacementPlugin.js +27 -32
- package/lib/JavascriptMetaInfoPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -3
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraphConnection.js +6 -2
- package/lib/ModuleInfoHeaderPlugin.js +2 -3
- package/lib/MultiCompiler.js +31 -27
- package/lib/NormalModule.js +42 -8
- package/lib/NormalModuleFactory.js +2 -0
- package/lib/RecordIdsPlugin.js +5 -4
- package/lib/ResolverFactory.js +10 -7
- package/lib/RuntimeGlobals.js +7 -0
- package/lib/RuntimePlugin.js +19 -1
- package/lib/SourceMapDevToolPlugin.js +14 -15
- package/lib/Template.js +4 -2
- package/lib/Watching.js +91 -47
- package/lib/asset/AssetGenerator.js +46 -29
- package/lib/asset/AssetModulesPlugin.js +1 -1
- package/lib/buildChunkGraph.js +21 -21
- package/lib/cache/PackFileCacheStrategy.js +12 -9
- package/lib/config/defaults.js +31 -10
- package/lib/config/normalization.js +16 -7
- package/lib/config/target.js +7 -2
- package/lib/debug/ProfilingPlugin.js +4 -3
- package/lib/dependencies/AMDRequireDependency.js +3 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
- package/lib/dependencies/CommonJsPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +10 -8
- package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
- package/lib/dependencies/ImportDependency.js +3 -3
- package/lib/dependencies/ImportParserPlugin.js +2 -4
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
- package/lib/dependencies/RequireEnsureDependency.js +3 -3
- package/lib/dependencies/WorkerDependency.js +6 -6
- package/lib/dependencies/WorkerPlugin.js +32 -20
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/ids/HashedModuleIdsPlugin.js +3 -3
- package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
- package/lib/index.js +5 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
- package/lib/javascript/JavascriptGenerator.js +3 -1
- package/lib/javascript/JavascriptModulesPlugin.js +15 -23
- package/lib/javascript/JavascriptParser.js +10 -8
- package/lib/library/AssignLibraryPlugin.js +4 -2
- package/lib/node/NodeEnvironmentPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +19 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
- package/lib/optimize/ConcatenatedModule.js +31 -27
- package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
- package/lib/optimize/InnerGraph.js +9 -11
- package/lib/optimize/InnerGraphPlugin.js +3 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
- package/lib/optimize/RealContentHashPlugin.js +14 -16
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
- package/lib/optimize/SplitChunksPlugin.js +13 -15
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
- package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
- package/lib/schemes/DataUriPlugin.js +21 -2
- package/lib/serialization/BinaryMiddleware.js +5 -3
- package/lib/serialization/FileMiddleware.js +3 -1
- package/lib/serialization/ObjectMiddleware.js +11 -7
- package/lib/stats/DefaultStatsFactoryPlugin.js +7 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
- package/lib/stats/StatsFactory.js +2 -1
- package/lib/stats/StatsPrinter.js +3 -3
- package/lib/util/LazyBucketSortedSet.js +3 -3
- package/lib/util/cleverMerge.js +3 -1
- package/lib/util/comparators.js +13 -13
- package/lib/util/createHash.js +5 -4
- package/lib/util/fs.js +8 -8
- package/lib/util/identifier.js +2 -1
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/serialization.js +108 -59
- package/lib/validateSchema.js +5 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +6 -5
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
- package/lib/webpack.js +11 -7
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
- package/package.json +10 -7
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +107 -60
- package/types.d.ts +480 -285
- package/lib/util/DataURI.js +0 -32
@@ -228,10 +228,11 @@ class JavascriptModulesPlugin {
|
|
228
228
|
chunk instanceof HotUpdateChunk ? chunk : null;
|
229
229
|
|
230
230
|
let render;
|
231
|
-
const filenameTemplate =
|
232
|
-
|
233
|
-
|
234
|
-
|
231
|
+
const filenameTemplate =
|
232
|
+
JavascriptModulesPlugin.getChunkFilenameTemplate(
|
233
|
+
chunk,
|
234
|
+
outputOptions
|
235
|
+
);
|
235
236
|
if (hotUpdateChunk) {
|
236
237
|
render = () =>
|
237
238
|
this.renderChunk(
|
@@ -394,9 +395,8 @@ class JavascriptModulesPlugin {
|
|
394
395
|
compilation.hooks.executeModule.tap(
|
395
396
|
"JavascriptModulesPlugin",
|
396
397
|
(options, context) => {
|
397
|
-
const source =
|
398
|
-
"javascript"
|
399
|
-
);
|
398
|
+
const source =
|
399
|
+
options.codeGenerationResult.sources.get("javascript");
|
400
400
|
if (source === undefined) return;
|
401
401
|
const { module, moduleObject } = options;
|
402
402
|
const code = source.source();
|
@@ -468,12 +468,8 @@ class JavascriptModulesPlugin {
|
|
468
468
|
* @returns {Source} the newly generated source from rendering
|
469
469
|
*/
|
470
470
|
renderModule(module, renderContext, hooks, factory) {
|
471
|
-
const {
|
472
|
-
|
473
|
-
chunkGraph,
|
474
|
-
runtimeTemplate,
|
475
|
-
codeGenerationResults
|
476
|
-
} = renderContext;
|
471
|
+
const { chunk, chunkGraph, runtimeTemplate, codeGenerationResults } =
|
472
|
+
renderContext;
|
477
473
|
try {
|
478
474
|
const moduleSource = codeGenerationResults.getSource(
|
479
475
|
module,
|
@@ -699,9 +695,8 @@ class JavascriptModulesPlugin {
|
|
699
695
|
);
|
700
696
|
}
|
701
697
|
|
702
|
-
const runtimeModules =
|
703
|
-
chunk
|
704
|
-
);
|
698
|
+
const runtimeModules =
|
699
|
+
renderContext.chunkGraph.getChunkRuntimeModulesInOrder(chunk);
|
705
700
|
|
706
701
|
if (runtimeModules.length > 0) {
|
707
702
|
source.add(
|
@@ -985,9 +980,8 @@ class JavascriptModulesPlugin {
|
|
985
980
|
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
986
981
|
/** @type {string[]} */
|
987
982
|
const buf2 = [];
|
988
|
-
const runtimeRequirements =
|
989
|
-
chunk
|
990
|
-
);
|
983
|
+
const runtimeRequirements =
|
984
|
+
chunkGraph.getTreeRuntimeRequirements(chunk);
|
991
985
|
buf2.push("// Load entry module and return exports");
|
992
986
|
let i = chunkGraph.getNumberOfEntryModules(chunk);
|
993
987
|
for (const [
|
@@ -1044,10 +1038,8 @@ class JavascriptModulesPlugin {
|
|
1044
1038
|
}
|
1045
1039
|
i--;
|
1046
1040
|
const moduleId = chunkGraph.getModuleId(entryModule);
|
1047
|
-
const entryRuntimeRequirements =
|
1048
|
-
entryModule,
|
1049
|
-
chunk.runtime
|
1050
|
-
);
|
1041
|
+
const entryRuntimeRequirements =
|
1042
|
+
chunkGraph.getModuleRuntimeRequirements(entryModule, chunk.runtime);
|
1051
1043
|
let moduleIdExpr = JSON.stringify(moduleId);
|
1052
1044
|
if (runtimeRequirements.has(RuntimeGlobals.entryModuleId)) {
|
1053
1045
|
moduleIdExpr = `${RuntimeGlobals.entryModuleId} = ${moduleIdExpr}`;
|
@@ -3336,8 +3336,10 @@ class JavascriptParser extends Parser {
|
|
3336
3336
|
if (expr.superClass && !this.isPure(expr.superClass, expr.range[0])) {
|
3337
3337
|
return false;
|
3338
3338
|
}
|
3339
|
-
const items =
|
3340
|
-
|
3339
|
+
const items =
|
3340
|
+
/** @type {(MethodDefinitionNode | PropertyDefinitionNode)[]} */ (
|
3341
|
+
expr.body.body
|
3342
|
+
);
|
3341
3343
|
return items.every(
|
3342
3344
|
item =>
|
3343
3345
|
(!item.computed ||
|
@@ -3623,10 +3625,8 @@ class JavascriptParser extends Parser {
|
|
3623
3625
|
let callee = object.callee;
|
3624
3626
|
let rootMembers = EMPTY_ARRAY;
|
3625
3627
|
if (callee.type === "MemberExpression") {
|
3626
|
-
({
|
3627
|
-
|
3628
|
-
members: rootMembers
|
3629
|
-
} = this.extractMemberExpressionChain(callee));
|
3628
|
+
({ object: callee, members: rootMembers } =
|
3629
|
+
this.extractMemberExpressionChain(callee));
|
3630
3630
|
}
|
3631
3631
|
const rootName = getRootName(callee);
|
3632
3632
|
if (!rootName) return undefined;
|
@@ -3729,5 +3729,7 @@ class JavascriptParser extends Parser {
|
|
3729
3729
|
|
3730
3730
|
module.exports = JavascriptParser;
|
3731
3731
|
module.exports.ALLOWED_MEMBER_TYPES_ALL = ALLOWED_MEMBER_TYPES_ALL;
|
3732
|
-
module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
|
3733
|
-
|
3732
|
+
module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
|
3733
|
+
ALLOWED_MEMBER_TYPES_EXPRESSION;
|
3734
|
+
module.exports.ALLOWED_MEMBER_TYPES_CALL_EXPRESSION =
|
3735
|
+
ALLOWED_MEMBER_TYPES_CALL_EXPRESSION;
|
@@ -24,8 +24,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
24
24
|
/** @typedef {import("../util/Hash")} Hash */
|
25
25
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
26
26
|
|
27
|
-
const KEYWORD_REGEX =
|
28
|
-
const
|
27
|
+
const KEYWORD_REGEX =
|
28
|
+
/^(await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/;
|
29
|
+
const IDENTIFIER_REGEX =
|
30
|
+
/^[\p{L}\p{Nl}$_][\p{L}\p{Nl}$\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*$/iu;
|
29
31
|
|
30
32
|
/**
|
31
33
|
* Validates the library name by checking for keywords and valid characters
|
@@ -70,11 +70,12 @@ class NodeWatchFileSystem {
|
|
70
70
|
}
|
71
71
|
this.watcher.once("aggregated", (changes, removals) => {
|
72
72
|
if (this.inputFileSystem && this.inputFileSystem.purge) {
|
73
|
+
const fs = this.inputFileSystem;
|
73
74
|
for (const item of changes) {
|
74
|
-
|
75
|
+
fs.purge(item);
|
75
76
|
}
|
76
77
|
for (const item of removals) {
|
77
|
-
|
78
|
+
fs.purge(item);
|
78
79
|
}
|
79
80
|
}
|
80
81
|
const times = this.watcher.getTimeInfoEntries();
|
@@ -99,10 +100,24 @@ class NodeWatchFileSystem {
|
|
99
100
|
}
|
100
101
|
},
|
101
102
|
getAggregatedRemovals: () => {
|
102
|
-
|
103
|
+
const items = this.watcher && this.watcher.aggregatedRemovals;
|
104
|
+
if (items && this.inputFileSystem && this.inputFileSystem.purge) {
|
105
|
+
const fs = this.inputFileSystem;
|
106
|
+
for (const item of items) {
|
107
|
+
fs.purge(item);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return items;
|
103
111
|
},
|
104
112
|
getAggregatedChanges: () => {
|
105
|
-
|
113
|
+
const items = this.watcher && this.watcher.aggregatedChanges;
|
114
|
+
if (items && this.inputFileSystem && this.inputFileSystem.purge) {
|
115
|
+
const fs = this.inputFileSystem;
|
116
|
+
for (const item of items) {
|
117
|
+
fs.purge(item);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return items;
|
106
121
|
},
|
107
122
|
getFileTimeInfoEntries: () => {
|
108
123
|
if (this.watcher) {
|
@@ -109,10 +109,11 @@ class AggressiveSplittingPlugin {
|
|
109
109
|
// Precompute stuff
|
110
110
|
const nameToModuleMap = new Map();
|
111
111
|
const moduleToNameMap = new Map();
|
112
|
-
const makePathsRelative =
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
const makePathsRelative =
|
113
|
+
identifierUtils.makePathsRelative.bindContextCache(
|
114
|
+
compiler.context,
|
115
|
+
compiler.root
|
116
|
+
);
|
116
117
|
for (const m of compilation.modules) {
|
117
118
|
const name = makePathsRelative(m.identifier());
|
118
119
|
nameToModuleMap.set(name, m);
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const eslintScope = require("eslint-scope");
|
9
|
+
const Referencer = require("eslint-scope/lib/referencer");
|
9
10
|
const {
|
10
11
|
CachedSource,
|
11
12
|
ConcatSource,
|
@@ -58,6 +59,14 @@ const {
|
|
58
59
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
59
60
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
60
61
|
|
62
|
+
// fix eslint-scope to support class properties correctly
|
63
|
+
// cspell:word Referencer
|
64
|
+
const ReferencerClass = Referencer;
|
65
|
+
if (!ReferencerClass.prototype.PropertyDefinition) {
|
66
|
+
ReferencerClass.prototype.PropertyDefinition =
|
67
|
+
ReferencerClass.prototype.Property;
|
68
|
+
}
|
69
|
+
|
61
70
|
/**
|
62
71
|
* @typedef {Object} ReexportInfo
|
63
72
|
* @property {Module} module
|
@@ -381,10 +390,9 @@ const getFinalBinding = (
|
|
381
390
|
}
|
382
391
|
const directExport = info.exportMap && info.exportMap.get(exportId);
|
383
392
|
if (directExport) {
|
384
|
-
const usedName = /** @type {string[]} */ (
|
385
|
-
exportName,
|
386
|
-
|
387
|
-
));
|
393
|
+
const usedName = /** @type {string[]} */ (
|
394
|
+
exportsInfo.getUsedName(exportName, runtime)
|
395
|
+
);
|
388
396
|
if (!usedName) {
|
389
397
|
return {
|
390
398
|
info,
|
@@ -443,10 +451,9 @@ const getFinalBinding = (
|
|
443
451
|
);
|
444
452
|
}
|
445
453
|
if (info.namespaceExportSymbol) {
|
446
|
-
const usedName = /** @type {string[]} */ (
|
447
|
-
exportName,
|
448
|
-
|
449
|
-
));
|
454
|
+
const usedName = /** @type {string[]} */ (
|
455
|
+
exportsInfo.getUsedName(exportName, runtime)
|
456
|
+
);
|
450
457
|
return {
|
451
458
|
info,
|
452
459
|
rawName: info.namespaceObjectName,
|
@@ -462,10 +469,9 @@ const getFinalBinding = (
|
|
462
469
|
}
|
463
470
|
|
464
471
|
case "external": {
|
465
|
-
const used = /** @type {string[]} */ (
|
466
|
-
exportName,
|
467
|
-
|
468
|
-
));
|
472
|
+
const used = /** @type {string[]} */ (
|
473
|
+
exportsInfo.getUsedName(exportName, runtime)
|
474
|
+
);
|
469
475
|
if (!used) {
|
470
476
|
return {
|
471
477
|
info,
|
@@ -883,8 +889,9 @@ class ConcatenatedModule extends Module {
|
|
883
889
|
})
|
884
890
|
.map(connection => ({
|
885
891
|
connection,
|
886
|
-
sourceOrder: /** @type {HarmonyImportDependency} */ (
|
887
|
-
.
|
892
|
+
sourceOrder: /** @type {HarmonyImportDependency} */ (
|
893
|
+
connection.dependency
|
894
|
+
).sourceOrder
|
888
895
|
}));
|
889
896
|
references.sort(
|
890
897
|
concatComparators(bySourceOrder, keepOriginalOrder(references))
|
@@ -1162,13 +1169,11 @@ class ConcatenatedModule extends Module {
|
|
1162
1169
|
true
|
1163
1170
|
);
|
1164
1171
|
if (!binding.ids) continue;
|
1165
|
-
const {
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
"name" in binding ? binding.name : ""
|
1171
|
-
);
|
1172
|
+
const { usedNames, alreadyCheckedScopes } =
|
1173
|
+
getUsedNamesInScopeInfo(
|
1174
|
+
binding.info.module.identifier(),
|
1175
|
+
"name" in binding ? binding.name : ""
|
1176
|
+
);
|
1172
1177
|
for (const expr of getSuperClassExpressions(reference.from)) {
|
1173
1178
|
if (
|
1174
1179
|
expr.range[0] <= reference.identifier.range[0] &&
|
@@ -1361,9 +1366,9 @@ class ConcatenatedModule extends Module {
|
|
1361
1366
|
/** @type {Set<string>} */
|
1362
1367
|
const unusedExports = new Set();
|
1363
1368
|
|
1364
|
-
const rootInfo = /** @type {ConcatenatedModuleInfo} */ (
|
1365
|
-
this.rootModule
|
1366
|
-
)
|
1369
|
+
const rootInfo = /** @type {ConcatenatedModuleInfo} */ (
|
1370
|
+
moduleToInfoMap.get(this.rootModule)
|
1371
|
+
);
|
1367
1372
|
const strictHarmonyModule = rootInfo.module.buildMeta.strictHarmonyModule;
|
1368
1373
|
const exportsInfo = moduleGraph.getExportsInfo(rootInfo.module);
|
1369
1374
|
for (const exportInfo of exportsInfo.orderedExports) {
|
@@ -1531,9 +1536,8 @@ ${defineGetters}`
|
|
1531
1536
|
)}\n`
|
1532
1537
|
);
|
1533
1538
|
runtimeRequirements.add(RuntimeGlobals.require);
|
1534
|
-
const {
|
1535
|
-
|
1536
|
-
} = /** @type {ExternalModuleInfo | ReferenceToModuleInfo} */ (rawInfo);
|
1539
|
+
const { runtimeCondition } =
|
1540
|
+
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */ (rawInfo);
|
1537
1541
|
const condition = runtimeTemplate.runtimeConditionExpression({
|
1538
1542
|
chunkGraph,
|
1539
1543
|
runtimeCondition,
|
@@ -68,9 +68,8 @@ class FlagIncludedChunksPlugin {
|
|
68
68
|
|
69
69
|
for (const chunkA of chunks) {
|
70
70
|
const chunkAHash = chunkModulesHash.get(chunkA);
|
71
|
-
const chunkAModulesCount =
|
72
|
-
chunkA
|
73
|
-
);
|
71
|
+
const chunkAModulesCount =
|
72
|
+
chunkGraph.getNumberOfChunkModules(chunkA);
|
74
73
|
if (chunkAModulesCount === 0) continue;
|
75
74
|
let bestModule = undefined;
|
76
75
|
for (const module of chunkGraph.getChunkModulesIterable(chunkA)) {
|
@@ -88,9 +87,8 @@ class FlagIncludedChunksPlugin {
|
|
88
87
|
// skip if we find ourselves
|
89
88
|
if (chunkA === chunkB) continue;
|
90
89
|
|
91
|
-
const chunkBModulesCount =
|
92
|
-
chunkB
|
93
|
-
);
|
90
|
+
const chunkBModulesCount =
|
91
|
+
chunkGraph.getNumberOfChunkModules(chunkB);
|
94
92
|
|
95
93
|
// ids for empty chunks are not included
|
96
94
|
if (chunkBModulesCount === 0) continue;
|
@@ -103,10 +103,9 @@ exports.addUsage = (state, symbol, usage) => {
|
|
103
103
|
*/
|
104
104
|
exports.addVariableUsage = (parser, name, usage) => {
|
105
105
|
const symbol =
|
106
|
-
/** @type {TopLevelSymbol} */ (
|
107
|
-
name,
|
108
|
-
|
109
|
-
)) || exports.tagTopLevelSymbol(parser, name);
|
106
|
+
/** @type {TopLevelSymbol} */ (
|
107
|
+
parser.getTagData(name, topLevelSymbolTag)
|
108
|
+
) || exports.tagTopLevelSymbol(parser, name);
|
110
109
|
if (symbol) {
|
111
110
|
exports.addUsage(parser.state, symbol, usage);
|
112
111
|
}
|
@@ -179,9 +178,9 @@ exports.inferDependencyUsage = state => {
|
|
179
178
|
|
180
179
|
/** @type {Map<Dependency, true | Set<string>>} */
|
181
180
|
for (const [symbol, callbacks] of usageCallbackMap) {
|
182
|
-
const usage = /** @type {true | Set<string> | undefined} */ (
|
183
|
-
symbol
|
184
|
-
)
|
181
|
+
const usage = /** @type {true | Set<string> | undefined} */ (
|
182
|
+
innerGraph.get(symbol)
|
183
|
+
);
|
185
184
|
for (const callback of callbacks) {
|
186
185
|
callback(usage === undefined ? false : usage);
|
187
186
|
}
|
@@ -249,10 +248,9 @@ exports.tagTopLevelSymbol = (parser, name) => {
|
|
249
248
|
|
250
249
|
parser.defineVariable(name);
|
251
250
|
|
252
|
-
const existingTag = /** @type {TopLevelSymbol} */ (
|
253
|
-
name,
|
254
|
-
|
255
|
-
));
|
251
|
+
const existingTag = /** @type {TopLevelSymbol} */ (
|
252
|
+
parser.getTagData(name, topLevelSymbolTag)
|
253
|
+
);
|
256
254
|
if (existingTag) {
|
257
255
|
return existingTag;
|
258
256
|
}
|
@@ -300,7 +300,9 @@ class InnerGraphPlugin {
|
|
300
300
|
parser.hooks.expression
|
301
301
|
.for(topLevelSymbolTag)
|
302
302
|
.tap("InnerGraphPlugin", () => {
|
303
|
-
const topLevelSymbol = /** @type {TopLevelSymbol} */ (
|
303
|
+
const topLevelSymbol = /** @type {TopLevelSymbol} */ (
|
304
|
+
parser.currentTagData
|
305
|
+
);
|
304
306
|
const currentTopLevelSymbol = InnerGraph.getTopLevelSymbol(
|
305
307
|
parser.state
|
306
308
|
);
|
@@ -316,9 +316,8 @@ class ModuleConcatenationPlugin {
|
|
316
316
|
}
|
317
317
|
} else {
|
318
318
|
statsEmptyConfigurations++;
|
319
|
-
const optimizationBailouts =
|
320
|
-
currentRoot
|
321
|
-
);
|
319
|
+
const optimizationBailouts =
|
320
|
+
moduleGraph.getOptimizationBailout(currentRoot);
|
322
321
|
for (const warning of currentConfiguration.getWarningsSorted()) {
|
323
322
|
optimizationBailouts.push(
|
324
323
|
formatBailoutWarning(warning[0], warning[1])
|
@@ -574,20 +573,18 @@ class ModuleConcatenationPlugin {
|
|
574
573
|
|
575
574
|
const moduleGraph = compilation.moduleGraph;
|
576
575
|
|
577
|
-
const incomingConnections =
|
578
|
-
module
|
579
|
-
);
|
576
|
+
const incomingConnections =
|
577
|
+
moduleGraph.getIncomingConnectionsByOriginModule(module);
|
580
578
|
|
581
579
|
const incomingConnectionsFromNonModules =
|
582
580
|
incomingConnections.get(null) || incomingConnections.get(undefined);
|
583
581
|
if (incomingConnectionsFromNonModules) {
|
584
|
-
const activeNonModulesConnections =
|
585
|
-
connection => {
|
582
|
+
const activeNonModulesConnections =
|
583
|
+
incomingConnectionsFromNonModules.filter(connection => {
|
586
584
|
// We are not interested in inactive connections
|
587
585
|
// or connections without dependency
|
588
586
|
return connection.isActive(runtime) || connection.dependency;
|
589
|
-
}
|
590
|
-
);
|
587
|
+
});
|
591
588
|
if (activeNonModulesConnections.length > 0) {
|
592
589
|
const problem = requestShortener => {
|
593
590
|
const importingExplanations = new Set(
|
@@ -194,24 +194,22 @@ class RealContentHashPlugin {
|
|
194
194
|
cacheAnalyse.getLazyHashedEtag(source),
|
195
195
|
Array.from(hashes).join("|")
|
196
196
|
);
|
197
|
-
[
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
197
|
+
[asset.referencedHashes, asset.ownHashes] =
|
198
|
+
await cacheAnalyse.providePromise(name, etag, () => {
|
199
|
+
const referencedHashes = new Set();
|
200
|
+
let ownHashes = new Set();
|
201
|
+
const inContent = content.match(hashRegExp);
|
202
|
+
if (inContent) {
|
203
|
+
for (const hash of inContent) {
|
204
|
+
if (hashes.has(hash)) {
|
205
|
+
ownHashes.add(hash);
|
206
|
+
continue;
|
207
|
+
}
|
208
|
+
referencedHashes.add(hash);
|
209
209
|
}
|
210
|
-
referencedHashes.add(hash);
|
211
210
|
}
|
212
|
-
|
213
|
-
|
214
|
-
});
|
211
|
+
return [referencedHashes, ownHashes];
|
212
|
+
});
|
215
213
|
})
|
216
214
|
);
|
217
215
|
const getDependencies = hash => {
|
@@ -86,11 +86,12 @@ class SideEffectsFlagPlugin {
|
|
86
86
|
if (module.factoryMeta === undefined) {
|
87
87
|
module.factoryMeta = {};
|
88
88
|
}
|
89
|
-
const hasSideEffects =
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
const hasSideEffects =
|
90
|
+
SideEffectsFlagPlugin.moduleHasSideEffects(
|
91
|
+
resolveData.relativePath,
|
92
|
+
sideEffects,
|
93
|
+
cache
|
94
|
+
);
|
94
95
|
module.factoryMeta.sideEffectFree = !hasSideEffects;
|
95
96
|
}
|
96
97
|
}
|
@@ -162,7 +162,10 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
162
162
|
|
163
163
|
const defaultGetName = /** @type {GetName} */ (() => {});
|
164
164
|
|
165
|
-
const deterministicGroupingForModules =
|
165
|
+
const deterministicGroupingForModules =
|
166
|
+
/** @type {function(DeterministicGroupingOptionsForModule): DeterministicGroupingGroupedItemsForModule[]} */ (
|
167
|
+
deterministicGrouping
|
168
|
+
);
|
166
169
|
|
167
170
|
/** @type {WeakMap<Module, string>} */
|
168
171
|
const getKeyCache = new WeakMap();
|
@@ -173,9 +176,11 @@ const getKeyCache = new WeakMap();
|
|
173
176
|
* @returns {string} hashed filename
|
174
177
|
*/
|
175
178
|
const hashFilename = (name, outputOptions) => {
|
176
|
-
const digest = /** @type {string} */ (
|
177
|
-
.
|
178
|
-
|
179
|
+
const digest = /** @type {string} */ (
|
180
|
+
createHash(outputOptions.hashFunction)
|
181
|
+
.update(name)
|
182
|
+
.digest(outputOptions.hashDigest)
|
183
|
+
);
|
179
184
|
return digest.slice(0, 8);
|
180
185
|
};
|
181
186
|
|
@@ -939,10 +944,8 @@ module.exports = class SplitChunksPlugin {
|
|
939
944
|
const getCombinations = key => getCombinationsFactory()(key);
|
940
945
|
|
941
946
|
const getExportsCombinationsFactory = memoize(() => {
|
942
|
-
const {
|
943
|
-
|
944
|
-
singleChunkSets
|
945
|
-
} = getExportsChunkSetsInGraph();
|
947
|
+
const { chunkSetsInGraph, singleChunkSets } =
|
948
|
+
getExportsChunkSetsInGraph();
|
946
949
|
return createGetCombinations(
|
947
950
|
chunkSetsInGraph,
|
948
951
|
singleChunkSets,
|
@@ -1182,13 +1185,8 @@ module.exports = class SplitChunksPlugin {
|
|
1182
1185
|
chunkCombination instanceof Chunk ? 1 : chunkCombination.size;
|
1183
1186
|
if (count < cacheGroup.minChunks) continue;
|
1184
1187
|
// Select chunks by configuration
|
1185
|
-
const {
|
1186
|
-
|
1187
|
-
key: selectedChunksKey
|
1188
|
-
} = getSelectedChunks(
|
1189
|
-
chunkCombination,
|
1190
|
-
cacheGroup.chunksFilter
|
1191
|
-
);
|
1188
|
+
const { chunks: selectedChunks, key: selectedChunksKey } =
|
1189
|
+
getSelectedChunks(chunkCombination, cacheGroup.chunksFilter);
|
1192
1190
|
|
1193
1191
|
addModuleToChunksInfoMap(
|
1194
1192
|
cacheGroup,
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
|
+
const Template = require("../Template");
|
9
|
+
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
|
+
|
11
|
+
class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
12
|
+
constructor() {
|
13
|
+
super("trusted types");
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @returns {string} runtime code
|
18
|
+
*/
|
19
|
+
generate() {
|
20
|
+
const { compilation } = this;
|
21
|
+
const { runtimeTemplate, outputOptions } = compilation;
|
22
|
+
const { trustedTypes } = outputOptions;
|
23
|
+
const fn = RuntimeGlobals.createScriptUrl;
|
24
|
+
|
25
|
+
if (!trustedTypes) {
|
26
|
+
// Skip Trusted Types logic.
|
27
|
+
return Template.asString([
|
28
|
+
`${fn} = ${runtimeTemplate.returningFunction("url", "url")};`
|
29
|
+
]);
|
30
|
+
}
|
31
|
+
|
32
|
+
return Template.asString([
|
33
|
+
"var policy;",
|
34
|
+
`${fn} = ${runtimeTemplate.basicFunction("url", [
|
35
|
+
"// Create Trusted Type policy if Trusted Types are available and the policy doesn't exist yet.",
|
36
|
+
"if (policy === undefined) {",
|
37
|
+
Template.indent([
|
38
|
+
"policy = {",
|
39
|
+
Template.indent([
|
40
|
+
`createScriptURL: ${runtimeTemplate.returningFunction(
|
41
|
+
"url",
|
42
|
+
"url"
|
43
|
+
)}`
|
44
|
+
]),
|
45
|
+
"};",
|
46
|
+
'if (typeof trustedTypes !== "undefined" && trustedTypes.createPolicy) {',
|
47
|
+
Template.indent([
|
48
|
+
`policy = trustedTypes.createPolicy(${JSON.stringify(
|
49
|
+
trustedTypes.policyName
|
50
|
+
)}, policy);`
|
51
|
+
]),
|
52
|
+
"}"
|
53
|
+
]),
|
54
|
+
"}",
|
55
|
+
"return policy.createScriptURL(url);"
|
56
|
+
])};`
|
57
|
+
]);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
module.exports = CreateScriptUrlRuntimeModule;
|
@@ -26,14 +26,15 @@ class EnsureChunkRuntimeModule extends RuntimeModule {
|
|
26
26
|
`${handlers} = {};`,
|
27
27
|
"// This file contains only the entry chunk.",
|
28
28
|
"// The chunk loading function for additional chunks",
|
29
|
-
`${
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
`${RuntimeGlobals.ensureChunk} = ${runtimeTemplate.basicFunction(
|
30
|
+
"chunkId",
|
31
|
+
[
|
32
|
+
`return Promise.all(Object.keys(${handlers}).reduce(${runtimeTemplate.basicFunction(
|
33
|
+
"promises, key",
|
34
|
+
[`${handlers}[key](chunkId, promises);`, "return promises;"]
|
35
|
+
)}, []));`
|
36
|
+
]
|
37
|
+
)};`
|
37
38
|
]);
|
38
39
|
} else {
|
39
40
|
// There ensureChunk is used somewhere in the tree, so we need an empty requireEnsure
|