webpack 5.36.0 → 5.37.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/ChunkGraph.js +58 -35
- package/lib/Compilation.js +116 -98
- package/lib/Compiler.js +31 -17
- 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 +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/FileSystemInfo.js +25 -31
- package/lib/FlagDependencyExportsPlugin.js +8 -7
- package/lib/FlagDependencyUsagePlugin.js +2 -4
- package/lib/HotModuleReplacementPlugin.js +20 -30
- package/lib/InitFragment.js +21 -6
- package/lib/JavascriptMetaInfoPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -3
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraph.js +2 -2
- package/lib/ModuleGraphConnection.js +6 -2
- package/lib/ModuleInfoHeaderPlugin.js +2 -3
- package/lib/MultiCompiler.js +31 -27
- package/lib/NormalModule.js +38 -7
- package/lib/NormalModuleFactory.js +27 -23
- 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 +83 -46
- package/lib/WebpackOptionsApply.js +1 -0
- package/lib/asset/AssetGenerator.js +19 -23
- package/lib/buildChunkGraph.js +28 -23
- package/lib/cache/PackFileCacheStrategy.js +77 -13
- package/lib/config/defaults.js +24 -10
- package/lib/config/normalization.js +17 -7
- 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/HarmonyExportInitFragment.js +47 -0
- 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 +47 -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/NodeWatchFileSystem.js +19 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
- package/lib/optimize/ConcatenatedModule.js +22 -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/serialization/BinaryMiddleware.js +2 -3
- package/lib/serialization/FileMiddleware.js +3 -1
- package/lib/serialization/ObjectMiddleware.js +11 -7
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -3
- 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/fs.js +8 -8
- package/lib/util/identifier.js +2 -1
- package/lib/util/internalSerializables.js +2 -0
- 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 +9 -6
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +103 -60
- package/types.d.ts +463 -280
@@ -381,10 +381,9 @@ const getFinalBinding = (
|
|
381
381
|
}
|
382
382
|
const directExport = info.exportMap && info.exportMap.get(exportId);
|
383
383
|
if (directExport) {
|
384
|
-
const usedName = /** @type {string[]} */ (
|
385
|
-
exportName,
|
386
|
-
|
387
|
-
));
|
384
|
+
const usedName = /** @type {string[]} */ (
|
385
|
+
exportsInfo.getUsedName(exportName, runtime)
|
386
|
+
);
|
388
387
|
if (!usedName) {
|
389
388
|
return {
|
390
389
|
info,
|
@@ -443,10 +442,9 @@ const getFinalBinding = (
|
|
443
442
|
);
|
444
443
|
}
|
445
444
|
if (info.namespaceExportSymbol) {
|
446
|
-
const usedName = /** @type {string[]} */ (
|
447
|
-
exportName,
|
448
|
-
|
449
|
-
));
|
445
|
+
const usedName = /** @type {string[]} */ (
|
446
|
+
exportsInfo.getUsedName(exportName, runtime)
|
447
|
+
);
|
450
448
|
return {
|
451
449
|
info,
|
452
450
|
rawName: info.namespaceObjectName,
|
@@ -462,10 +460,9 @@ const getFinalBinding = (
|
|
462
460
|
}
|
463
461
|
|
464
462
|
case "external": {
|
465
|
-
const used = /** @type {string[]} */ (
|
466
|
-
exportName,
|
467
|
-
|
468
|
-
));
|
463
|
+
const used = /** @type {string[]} */ (
|
464
|
+
exportsInfo.getUsedName(exportName, runtime)
|
465
|
+
);
|
469
466
|
if (!used) {
|
470
467
|
return {
|
471
468
|
info,
|
@@ -883,8 +880,9 @@ class ConcatenatedModule extends Module {
|
|
883
880
|
})
|
884
881
|
.map(connection => ({
|
885
882
|
connection,
|
886
|
-
sourceOrder: /** @type {HarmonyImportDependency} */ (
|
887
|
-
.
|
883
|
+
sourceOrder: /** @type {HarmonyImportDependency} */ (
|
884
|
+
connection.dependency
|
885
|
+
).sourceOrder
|
888
886
|
}));
|
889
887
|
references.sort(
|
890
888
|
concatComparators(bySourceOrder, keepOriginalOrder(references))
|
@@ -1162,13 +1160,11 @@ class ConcatenatedModule extends Module {
|
|
1162
1160
|
true
|
1163
1161
|
);
|
1164
1162
|
if (!binding.ids) continue;
|
1165
|
-
const {
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
"name" in binding ? binding.name : ""
|
1171
|
-
);
|
1163
|
+
const { usedNames, alreadyCheckedScopes } =
|
1164
|
+
getUsedNamesInScopeInfo(
|
1165
|
+
binding.info.module.identifier(),
|
1166
|
+
"name" in binding ? binding.name : ""
|
1167
|
+
);
|
1172
1168
|
for (const expr of getSuperClassExpressions(reference.from)) {
|
1173
1169
|
if (
|
1174
1170
|
expr.range[0] <= reference.identifier.range[0] &&
|
@@ -1361,9 +1357,9 @@ class ConcatenatedModule extends Module {
|
|
1361
1357
|
/** @type {Set<string>} */
|
1362
1358
|
const unusedExports = new Set();
|
1363
1359
|
|
1364
|
-
const rootInfo = /** @type {ConcatenatedModuleInfo} */ (
|
1365
|
-
this.rootModule
|
1366
|
-
)
|
1360
|
+
const rootInfo = /** @type {ConcatenatedModuleInfo} */ (
|
1361
|
+
moduleToInfoMap.get(this.rootModule)
|
1362
|
+
);
|
1367
1363
|
const strictHarmonyModule = rootInfo.module.buildMeta.strictHarmonyModule;
|
1368
1364
|
const exportsInfo = moduleGraph.getExportsInfo(rootInfo.module);
|
1369
1365
|
for (const exportInfo of exportsInfo.orderedExports) {
|
@@ -1531,9 +1527,8 @@ ${defineGetters}`
|
|
1531
1527
|
)}\n`
|
1532
1528
|
);
|
1533
1529
|
runtimeRequirements.add(RuntimeGlobals.require);
|
1534
|
-
const {
|
1535
|
-
|
1536
|
-
} = /** @type {ExternalModuleInfo | ReferenceToModuleInfo} */ (rawInfo);
|
1530
|
+
const { runtimeCondition } =
|
1531
|
+
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */ (rawInfo);
|
1537
1532
|
const condition = runtimeTemplate.runtimeConditionExpression({
|
1538
1533
|
chunkGraph,
|
1539
1534
|
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
|
@@ -42,8 +42,12 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
42
42
|
return hooks;
|
43
43
|
}
|
44
44
|
|
45
|
-
|
45
|
+
/**
|
46
|
+
* @param {boolean=} withCreateScriptUrl use create script url for trusted types
|
47
|
+
*/
|
48
|
+
constructor(withCreateScriptUrl) {
|
46
49
|
super("load script");
|
50
|
+
this._withCreateScriptUrl = withCreateScriptUrl;
|
47
51
|
}
|
48
52
|
|
49
53
|
/**
|
@@ -61,9 +65,8 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
61
65
|
} = outputOptions;
|
62
66
|
const fn = RuntimeGlobals.loadScript;
|
63
67
|
|
64
|
-
const { createScript } =
|
65
|
-
compilation
|
66
|
-
);
|
68
|
+
const { createScript } =
|
69
|
+
LoadScriptRuntimeModule.getCompilationHooks(compilation);
|
67
70
|
|
68
71
|
const code = Template.asString([
|
69
72
|
"script = document.createElement('script');",
|
@@ -78,7 +81,11 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
78
81
|
uniqueName
|
79
82
|
? 'script.setAttribute("data-webpack", dataWebpackPrefix + key);'
|
80
83
|
: "",
|
81
|
-
`script.src =
|
84
|
+
`script.src = ${
|
85
|
+
this._withCreateScriptUrl
|
86
|
+
? `${RuntimeGlobals.createScriptUrl}(url)`
|
87
|
+
: "url"
|
88
|
+
};`,
|
82
89
|
crossOriginLoading
|
83
90
|
? Template.asString([
|
84
91
|
"if (script.src.indexOf(window.location.origin + '/') !== 0) {",
|
@@ -21,49 +21,50 @@ class OnChunksLoadedRuntimeModule extends RuntimeModule {
|
|
21
21
|
const { runtimeTemplate } = compilation;
|
22
22
|
return Template.asString([
|
23
23
|
"var deferred = [];",
|
24
|
-
`${
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Template.indent([
|
29
|
-
"priority = priority || 0;",
|
30
|
-
"for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];",
|
31
|
-
"deferred[i] = [chunkIds, fn, priority];",
|
32
|
-
"return;"
|
33
|
-
]),
|
34
|
-
"}",
|
35
|
-
"var notFulfilled = Infinity;",
|
36
|
-
"for (var i = 0; i < deferred.length; i++) {",
|
37
|
-
Template.indent([
|
38
|
-
runtimeTemplate.destructureArray(
|
39
|
-
["chunkIds", "fn", "priority"],
|
40
|
-
"deferred[i]"
|
41
|
-
),
|
42
|
-
"var fulfilled = true;",
|
43
|
-
"for (var j = 0; j < chunkIds.length; j++) {",
|
24
|
+
`${RuntimeGlobals.onChunksLoaded} = ${runtimeTemplate.basicFunction(
|
25
|
+
"result, chunkIds, fn, priority",
|
26
|
+
[
|
27
|
+
"if(chunkIds) {",
|
44
28
|
Template.indent([
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
29
|
+
"priority = priority || 0;",
|
30
|
+
"for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];",
|
31
|
+
"deferred[i] = [chunkIds, fn, priority];",
|
32
|
+
"return;"
|
33
|
+
]),
|
34
|
+
"}",
|
35
|
+
"var notFulfilled = Infinity;",
|
36
|
+
"for (var i = 0; i < deferred.length; i++) {",
|
37
|
+
Template.indent([
|
38
|
+
runtimeTemplate.destructureArray(
|
39
|
+
["chunkIds", "fn", "priority"],
|
40
|
+
"deferred[i]"
|
41
|
+
),
|
42
|
+
"var fulfilled = true;",
|
43
|
+
"for (var j = 0; j < chunkIds.length; j++) {",
|
53
44
|
Template.indent([
|
54
|
-
|
55
|
-
|
45
|
+
`if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(${
|
46
|
+
RuntimeGlobals.onChunksLoaded
|
47
|
+
}).every(${runtimeTemplate.returningFunction(
|
48
|
+
`${RuntimeGlobals.onChunksLoaded}[key](chunkIds[j])`,
|
49
|
+
"key"
|
50
|
+
)})) {`,
|
51
|
+
Template.indent(["chunkIds.splice(j--, 1);"]),
|
52
|
+
"} else {",
|
53
|
+
Template.indent([
|
54
|
+
"fulfilled = false;",
|
55
|
+
"if(priority < notFulfilled) notFulfilled = priority;"
|
56
|
+
]),
|
57
|
+
"}"
|
56
58
|
]),
|
59
|
+
"}",
|
60
|
+
"if(fulfilled) {",
|
61
|
+
Template.indent(["deferred.splice(i--, 1)", "result = fn();"]),
|
57
62
|
"}"
|
58
63
|
]),
|
59
64
|
"}",
|
60
|
-
"
|
61
|
-
|
62
|
-
|
63
|
-
]),
|
64
|
-
"}",
|
65
|
-
"return result;"
|
66
|
-
])};`
|
65
|
+
"return result;"
|
66
|
+
]
|
67
|
+
)};`
|
67
68
|
]);
|
68
69
|
}
|
69
70
|
}
|
@@ -201,9 +201,8 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
201
201
|
if (!SerializerMiddleware.isLazy(thing))
|
202
202
|
throw new Error("Unexpected function " + thing);
|
203
203
|
/** @type {SerializedType | (() => SerializedType)} */
|
204
|
-
let serializedData =
|
205
|
-
thing
|
206
|
-
);
|
204
|
+
let serializedData =
|
205
|
+
SerializerMiddleware.getLazySerializedValue(thing);
|
207
206
|
if (serializedData === undefined) {
|
208
207
|
if (SerializerMiddleware.isLazy(thing, this)) {
|
209
208
|
const data = this._serialize(thing(), context);
|
@@ -135,7 +135,9 @@ const serialize = async (middleware, data, name, writeFile) => {
|
|
135
135
|
const backgroundJobs = [];
|
136
136
|
const resolvedData = (
|
137
137
|
await Promise.all(
|
138
|
-
/** @type {Promise<Buffer[] | Buffer | SerializeResult>[]} */ (
|
138
|
+
/** @type {Promise<Buffer[] | Buffer | SerializeResult>[]} */ (
|
139
|
+
processedData
|
140
|
+
)
|
139
141
|
)
|
140
142
|
).map(item => {
|
141
143
|
if (Array.isArray(item) || Buffer.isBuffer(item)) return item;
|
@@ -450,9 +450,8 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
450
450
|
);
|
451
451
|
}
|
452
452
|
|
453
|
-
const { request, name, serializer } =
|
454
|
-
item
|
455
|
-
);
|
453
|
+
const { request, name, serializer } =
|
454
|
+
ObjectMiddleware.getSerializerFor(item);
|
456
455
|
const key = `${request}/${name}`;
|
457
456
|
const lastIndex = objectTypeLookup.get(key);
|
458
457
|
|
@@ -500,9 +499,8 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
500
499
|
if (!SerializerMiddleware.isLazy(item))
|
501
500
|
throw new Error("Unexpected function " + item);
|
502
501
|
/** @type {SerializedType} */
|
503
|
-
const serializedData =
|
504
|
-
item
|
505
|
-
);
|
502
|
+
const serializedData =
|
503
|
+
SerializerMiddleware.getLazySerializedValue(item);
|
506
504
|
if (serializedData !== undefined) {
|
507
505
|
if (typeof serializedData === "function") {
|
508
506
|
result.push(serializedData);
|
@@ -539,7 +537,13 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
539
537
|
// This happens because the optimized code v8 generates
|
540
538
|
// is optimized for our "ctx.write" method so it will reference
|
541
539
|
// it from e. g. Dependency.prototype.serialize -(IC)-> ctx.write
|
542
|
-
data =
|
540
|
+
data =
|
541
|
+
result =
|
542
|
+
referenceable =
|
543
|
+
bufferDedupeMap =
|
544
|
+
objectTypeLookup =
|
545
|
+
ctx =
|
546
|
+
undefined;
|
543
547
|
}
|
544
548
|
}
|
545
549
|
|
@@ -1078,9 +1078,8 @@ const SIMPLE_EXTRACTORS = {
|
|
1078
1078
|
const { compilation, type } = context;
|
1079
1079
|
const built = compilation.builtModules.has(module);
|
1080
1080
|
const codeGenerated = compilation.codeGeneratedModules.has(module);
|
1081
|
-
const buildTimeExecuted =
|
1082
|
-
module
|
1083
|
-
);
|
1081
|
+
const buildTimeExecuted =
|
1082
|
+
compilation.buildTimeExecutedModules.has(module);
|
1084
1083
|
/** @type {{[x: string]: number}} */
|
1085
1084
|
const sizes = {};
|
1086
1085
|
for (const sourceType of module.getSourceTypes()) {
|
@@ -818,9 +818,8 @@ const SIMPLE_ITEMS_JOINER = {
|
|
818
818
|
"asset.chunkNames": itemsJoinCommaBracketsWithName("name"),
|
819
819
|
"asset.auxiliaryChunkNames": itemsJoinCommaBracketsWithName("auxiliary name"),
|
820
820
|
"asset.chunkIdHints": itemsJoinCommaBracketsWithName("id hint"),
|
821
|
-
"asset.auxiliaryChunkIdHints":
|
822
|
-
"auxiliary id hint"
|
823
|
-
),
|
821
|
+
"asset.auxiliaryChunkIdHints":
|
822
|
+
itemsJoinCommaBracketsWithName("auxiliary id hint"),
|
824
823
|
"module.chunks": itemsJoinOneLine,
|
825
824
|
"module.issuerPath": items =>
|
826
825
|
items
|
@@ -912,11 +911,13 @@ const joinExplicitNewLine = (items, indenter) => {
|
|
912
911
|
.trim();
|
913
912
|
};
|
914
913
|
|
915
|
-
const joinError =
|
916
|
-
|
917
|
-
|
918
|
-
""
|
919
|
-
|
914
|
+
const joinError =
|
915
|
+
error =>
|
916
|
+
(items, { red, yellow }) =>
|
917
|
+
`${error ? red("ERROR") : yellow("WARNING")} in ${joinExplicitNewLine(
|
918
|
+
items,
|
919
|
+
""
|
920
|
+
)}`;
|
920
921
|
|
921
922
|
/** @type {Record<string, (items: ({ element: string, content: string })[], context: StatsPrinterContext) => string>} */
|
922
923
|
const SIMPLE_ELEMENT_JOINERS = {
|
@@ -1130,7 +1131,8 @@ const AVAILABLE_FORMATS = {
|
|
1130
1131
|
format: red
|
1131
1132
|
},
|
1132
1133
|
{
|
1133
|
-
regExp:
|
1134
|
+
regExp:
|
1135
|
+
/\b(error|failed|unexpected|invalid|not found|not supported|not available|not possible|not implemented|doesn't support|conflict|conflicting|not existing|duplicate)\b/gi,
|
1134
1136
|
format: red
|
1135
1137
|
}
|
1136
1138
|
];
|