webpack 5.66.0 → 5.69.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 +1 -1
- package/lib/APIPlugin.js +33 -0
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +2 -2
- package/lib/ChunkGraph.js +1 -2
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +14 -9
- package/lib/Compiler.js +57 -3
- package/lib/ContextModule.js +21 -17
- package/lib/DelegatedModule.js +1 -1
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +18 -1
- package/lib/ExportsInfo.js +4 -4
- package/lib/ExternalModule.js +1 -1
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +29 -25
- package/lib/HookWebpackError.js +1 -1
- package/lib/Module.js +1 -3
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +6 -4
- package/lib/NormalModuleFactory.js +25 -27
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +18 -0
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +28 -3
- package/lib/RuntimeTemplate.js +1 -1
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/Watching.js +1 -1
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +65 -26
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/RawDataUrlModule.js +8 -5
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/buildChunkGraph.js +1 -1
- package/lib/cache/ResolverCachePlugin.js +1 -1
- package/lib/cli.js +44 -3
- package/lib/config/defaults.js +30 -7
- package/lib/config/normalization.js +5 -0
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/RemoteModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +3 -0
- package/lib/css/CssLoadingRuntimeModule.js +201 -154
- package/lib/css/CssModulesPlugin.js +22 -4
- package/lib/debug/ProfilingPlugin.js +15 -14
- package/lib/dependencies/ContextElementDependency.js +8 -2
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/hmr/LazyCompilationPlugin.js +45 -21
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +9 -12
- package/lib/ids/IdHelpers.js +24 -10
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +10 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/StartupHelpers.js +3 -2
- package/lib/library/AssignLibraryPlugin.js +8 -2
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +11 -5
- package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/schemes/HttpUriPlugin.js +32 -11
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
- package/lib/stats/DefaultStatsPrinterPlugin.js +88 -23
- package/lib/util/ArrayHelpers.js +18 -4
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/identifier.js +65 -44
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/package.json +14 -21
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +47 -6
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/types.d.ts +207 -60
@@ -10,7 +10,7 @@ const {
|
|
10
10
|
getShortModuleName,
|
11
11
|
getLongModuleName,
|
12
12
|
assignNames,
|
13
|
-
|
13
|
+
getUsedModuleIdsAndModules,
|
14
14
|
assignAscendingModuleIds
|
15
15
|
} = require("./IdHelpers");
|
16
16
|
|
@@ -31,27 +31,24 @@ class NamedModuleIdsPlugin {
|
|
31
31
|
const { root } = compiler;
|
32
32
|
compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => {
|
33
33
|
const { hashFunction } = compilation.outputOptions;
|
34
|
-
compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin",
|
34
|
+
compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin", () => {
|
35
35
|
const chunkGraph = compilation.chunkGraph;
|
36
36
|
const context = this.options.context
|
37
37
|
? this.options.context
|
38
38
|
: compiler.context;
|
39
39
|
|
40
|
+
const [usedIds, modules] = getUsedModuleIdsAndModules(compilation);
|
40
41
|
const unnamedModules = assignNames(
|
41
|
-
|
42
|
-
if (!module.needId) return false;
|
43
|
-
if (chunkGraph.getNumberOfModuleChunks(module) === 0) return false;
|
44
|
-
return chunkGraph.getModuleId(module) === null;
|
45
|
-
}),
|
42
|
+
modules,
|
46
43
|
m => getShortModuleName(m, context, root),
|
47
44
|
(m, shortName) =>
|
48
45
|
getLongModuleName(shortName, m, context, hashFunction, root),
|
49
46
|
compareModulesByIdentifier,
|
50
|
-
|
47
|
+
usedIds,
|
51
48
|
(m, name) => chunkGraph.setModuleId(m, name)
|
52
49
|
);
|
53
50
|
if (unnamedModules.length > 0) {
|
54
|
-
assignAscendingModuleIds(unnamedModules, compilation);
|
51
|
+
assignAscendingModuleIds(usedIds, unnamedModules, compilation);
|
55
52
|
}
|
56
53
|
});
|
57
54
|
});
|
@@ -8,7 +8,10 @@
|
|
8
8
|
const {
|
9
9
|
compareModulesByPreOrderIndexOrIdentifier
|
10
10
|
} = require("../util/comparators");
|
11
|
-
const {
|
11
|
+
const {
|
12
|
+
assignAscendingModuleIds,
|
13
|
+
getUsedModuleIdsAndModules
|
14
|
+
} = require("./IdHelpers");
|
12
15
|
|
13
16
|
/** @typedef {import("../Compiler")} Compiler */
|
14
17
|
/** @typedef {import("../Module")} Module */
|
@@ -22,18 +25,12 @@ class NaturalModuleIdsPlugin {
|
|
22
25
|
apply(compiler) {
|
23
26
|
compiler.hooks.compilation.tap("NaturalModuleIdsPlugin", compilation => {
|
24
27
|
compilation.hooks.moduleIds.tap("NaturalModuleIdsPlugin", modules => {
|
25
|
-
const
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
chunkGraph.getModuleId(m) === null
|
32
|
-
)
|
33
|
-
.sort(
|
34
|
-
compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
|
35
|
-
);
|
36
|
-
assignAscendingModuleIds(modulesInNaturalOrder, compilation);
|
28
|
+
const [usedIds, modulesInNaturalOrder] =
|
29
|
+
getUsedModuleIdsAndModules(compilation);
|
30
|
+
modulesInNaturalOrder.sort(
|
31
|
+
compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
|
32
|
+
);
|
33
|
+
assignAscendingModuleIds(usedIds, modulesInNaturalOrder, compilation);
|
37
34
|
});
|
38
35
|
});
|
39
36
|
}
|
@@ -9,7 +9,10 @@ const {
|
|
9
9
|
compareModulesByPreOrderIndexOrIdentifier
|
10
10
|
} = require("../util/comparators");
|
11
11
|
const createSchemaValidation = require("../util/create-schema-validation");
|
12
|
-
const {
|
12
|
+
const {
|
13
|
+
assignAscendingModuleIds,
|
14
|
+
getUsedModuleIdsAndModules
|
15
|
+
} = require("./IdHelpers");
|
13
16
|
|
14
17
|
/** @typedef {import("../../declarations/plugins/ids/OccurrenceModuleIdsPlugin").OccurrenceModuleIdsPluginOptions} OccurrenceModuleIdsPluginOptions */
|
15
18
|
/** @typedef {import("../Compiler")} Compiler */
|
@@ -44,15 +47,11 @@ class OccurrenceModuleIdsPlugin {
|
|
44
47
|
compiler.hooks.compilation.tap("OccurrenceModuleIdsPlugin", compilation => {
|
45
48
|
const moduleGraph = compilation.moduleGraph;
|
46
49
|
|
47
|
-
compilation.hooks.moduleIds.tap("OccurrenceModuleIdsPlugin",
|
50
|
+
compilation.hooks.moduleIds.tap("OccurrenceModuleIdsPlugin", () => {
|
48
51
|
const chunkGraph = compilation.chunkGraph;
|
49
52
|
|
50
|
-
const modulesInOccurrenceOrder =
|
51
|
-
|
52
|
-
m.needId &&
|
53
|
-
chunkGraph.getNumberOfModuleChunks(m) > 0 &&
|
54
|
-
chunkGraph.getModuleId(m) === null
|
55
|
-
);
|
53
|
+
const [usedIds, modulesInOccurrenceOrder] =
|
54
|
+
getUsedModuleIdsAndModules(compilation);
|
56
55
|
|
57
56
|
const occursInInitialChunksMap = new Map();
|
58
57
|
const occursInAllChunksMap = new Map();
|
@@ -121,7 +120,7 @@ class OccurrenceModuleIdsPlugin {
|
|
121
120
|
}
|
122
121
|
}
|
123
122
|
|
124
|
-
for (const m of
|
123
|
+
for (const m of modulesInOccurrenceOrder) {
|
125
124
|
const result =
|
126
125
|
countOccurs(m) +
|
127
126
|
chunkGraph.getNumberOfModuleChunks(m) +
|
@@ -147,7 +146,11 @@ class OccurrenceModuleIdsPlugin {
|
|
147
146
|
return naturalCompare(a, b);
|
148
147
|
});
|
149
148
|
|
150
|
-
assignAscendingModuleIds(
|
149
|
+
assignAscendingModuleIds(
|
150
|
+
usedIds,
|
151
|
+
modulesInOccurrenceOrder,
|
152
|
+
compilation
|
153
|
+
);
|
151
154
|
});
|
152
155
|
});
|
153
156
|
}
|
@@ -0,0 +1,140 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const { WebpackError } = require("..");
|
9
|
+
const { getUsedModuleIdsAndModules } = require("./IdHelpers");
|
10
|
+
|
11
|
+
/** @typedef {import("../Compiler")} Compiler */
|
12
|
+
/** @typedef {import("../Module")} Module */
|
13
|
+
|
14
|
+
const plugin = "SyncModuleIdsPlugin";
|
15
|
+
|
16
|
+
class SyncModuleIdsPlugin {
|
17
|
+
/**
|
18
|
+
* @param {Object} options options
|
19
|
+
* @param {string} options.path path to file
|
20
|
+
* @param {string=} options.context context for module names
|
21
|
+
* @param {function(Module): boolean} options.test selector for modules
|
22
|
+
* @param {"read" | "create" | "merge" | "update"=} options.mode operation mode (defaults to merge)
|
23
|
+
*/
|
24
|
+
constructor({ path, context, test, mode }) {
|
25
|
+
this._path = path;
|
26
|
+
this._context = context;
|
27
|
+
this._test = test || (() => true);
|
28
|
+
const readAndWrite = !mode || mode === "merge" || mode === "update";
|
29
|
+
this._read = readAndWrite || mode === "read";
|
30
|
+
this._write = readAndWrite || mode === "create";
|
31
|
+
this._prune = mode === "update";
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Apply the plugin
|
36
|
+
* @param {Compiler} compiler the compiler instance
|
37
|
+
* @returns {void}
|
38
|
+
*/
|
39
|
+
apply(compiler) {
|
40
|
+
/** @type {Map<string, string | number>} */
|
41
|
+
let data;
|
42
|
+
let dataChanged = false;
|
43
|
+
if (this._read) {
|
44
|
+
compiler.hooks.readRecords.tapAsync(plugin, callback => {
|
45
|
+
const fs = compiler.intermediateFileSystem;
|
46
|
+
fs.readFile(this._path, (err, buffer) => {
|
47
|
+
if (err) {
|
48
|
+
if (err.code !== "ENOENT") {
|
49
|
+
return callback(err);
|
50
|
+
}
|
51
|
+
return callback();
|
52
|
+
}
|
53
|
+
const json = JSON.parse(buffer.toString());
|
54
|
+
data = new Map();
|
55
|
+
for (const key of Object.keys(json)) {
|
56
|
+
data.set(key, json[key]);
|
57
|
+
}
|
58
|
+
dataChanged = false;
|
59
|
+
return callback();
|
60
|
+
});
|
61
|
+
});
|
62
|
+
}
|
63
|
+
if (this._write) {
|
64
|
+
compiler.hooks.emitRecords.tapAsync(plugin, callback => {
|
65
|
+
if (!data || !dataChanged) return callback();
|
66
|
+
const json = {};
|
67
|
+
const sorted = Array.from(data).sort(([a], [b]) => (a < b ? -1 : 1));
|
68
|
+
for (const [key, value] of sorted) {
|
69
|
+
json[key] = value;
|
70
|
+
}
|
71
|
+
const fs = compiler.intermediateFileSystem;
|
72
|
+
fs.writeFile(this._path, JSON.stringify(json), callback);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
compiler.hooks.thisCompilation.tap(plugin, compilation => {
|
76
|
+
const associatedObjectForCache = compiler.root;
|
77
|
+
const context = this._context || compiler.context;
|
78
|
+
if (this._read) {
|
79
|
+
compilation.hooks.reviveModules.tap(plugin, (_1, _2) => {
|
80
|
+
if (!data) return;
|
81
|
+
const { chunkGraph } = compilation;
|
82
|
+
const [usedIds, modules] = getUsedModuleIdsAndModules(
|
83
|
+
compilation,
|
84
|
+
this._test
|
85
|
+
);
|
86
|
+
for (const module of modules) {
|
87
|
+
const name = module.libIdent({
|
88
|
+
context,
|
89
|
+
associatedObjectForCache
|
90
|
+
});
|
91
|
+
if (!name) continue;
|
92
|
+
const id = data.get(name);
|
93
|
+
const idAsString = `${id}`;
|
94
|
+
if (usedIds.has(idAsString)) {
|
95
|
+
const err = new WebpackError(
|
96
|
+
`SyncModuleIdsPlugin: Unable to restore id '${id}' from '${this._path}' as it's already used.`
|
97
|
+
);
|
98
|
+
err.module = module;
|
99
|
+
compilation.errors.push(err);
|
100
|
+
}
|
101
|
+
chunkGraph.setModuleId(module, id);
|
102
|
+
usedIds.add(idAsString);
|
103
|
+
}
|
104
|
+
});
|
105
|
+
}
|
106
|
+
if (this._write) {
|
107
|
+
compilation.hooks.recordModules.tap(plugin, modules => {
|
108
|
+
const { chunkGraph } = compilation;
|
109
|
+
let oldData = data;
|
110
|
+
if (!oldData) {
|
111
|
+
oldData = data = new Map();
|
112
|
+
} else if (this._prune) {
|
113
|
+
data = new Map();
|
114
|
+
}
|
115
|
+
for (const module of modules) {
|
116
|
+
if (this._test(module)) {
|
117
|
+
const name = module.libIdent({
|
118
|
+
context,
|
119
|
+
associatedObjectForCache
|
120
|
+
});
|
121
|
+
if (!name) continue;
|
122
|
+
const id = chunkGraph.getModuleId(module);
|
123
|
+
if (id === null) continue;
|
124
|
+
const oldId = oldData.get(name);
|
125
|
+
if (oldId !== id) {
|
126
|
+
dataChanged = true;
|
127
|
+
} else if (data === oldData) {
|
128
|
+
continue;
|
129
|
+
}
|
130
|
+
data.set(name, id);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
if (data.size !== oldData.size) dataChanged = true;
|
134
|
+
});
|
135
|
+
}
|
136
|
+
});
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
module.exports = SyncModuleIdsPlugin;
|
package/lib/index.js
CHANGED
@@ -11,6 +11,7 @@ const memoize = require("./util/memoize");
|
|
11
11
|
/** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
|
12
12
|
/** @typedef {import("../declarations/WebpackOptions").EntryNormalized} EntryNormalized */
|
13
13
|
/** @typedef {import("../declarations/WebpackOptions").EntryObject} EntryObject */
|
14
|
+
/** @typedef {import("../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
|
14
15
|
/** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
15
16
|
/** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
|
16
17
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
@@ -26,11 +27,15 @@ const memoize = require("./util/memoize");
|
|
26
27
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
27
28
|
/** @typedef {import("./Compilation").Asset} Asset */
|
28
29
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
30
|
+
/** @typedef {import("./Compilation").EntryOptions} EntryOptions */
|
31
|
+
/** @typedef {import("./Compiler").AssetEmittedInfo} AssetEmittedInfo */
|
29
32
|
/** @typedef {import("./MultiStats")} MultiStats */
|
30
33
|
/** @typedef {import("./Parser").ParserState} ParserState */
|
31
34
|
/** @typedef {import("./ResolverFactory").ResolvePluginInstance} ResolvePluginInstance */
|
32
35
|
/** @typedef {import("./ResolverFactory").Resolver} Resolver */
|
33
36
|
/** @typedef {import("./Watching")} Watching */
|
37
|
+
/** @typedef {import("./cli").Argument} Argument */
|
38
|
+
/** @typedef {import("./cli").Problem} Problem */
|
34
39
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
|
35
40
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
|
36
41
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
|
@@ -564,6 +569,11 @@ module.exports = mergeExports(fn, {
|
|
564
569
|
get HttpUriPlugin() {
|
565
570
|
return require("./schemes/HttpUriPlugin");
|
566
571
|
}
|
572
|
+
},
|
573
|
+
ids: {
|
574
|
+
get SyncModuleIdsPlugin() {
|
575
|
+
return require("./ids/SyncModuleIdsPlugin");
|
576
|
+
}
|
567
577
|
}
|
568
578
|
}
|
569
579
|
});
|
@@ -24,6 +24,7 @@ const { last, someInIterable } = require("../util/IterableHelpers");
|
|
24
24
|
const StringXor = require("../util/StringXor");
|
25
25
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
26
26
|
const createHash = require("../util/createHash");
|
27
|
+
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
27
28
|
const { intersectRuntime } = require("../util/runtime");
|
28
29
|
const JavascriptGenerator = require("./JavascriptGenerator");
|
29
30
|
const JavascriptParser = require("./JavascriptParser");
|
@@ -102,6 +103,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
102
103
|
/**
|
103
104
|
* @typedef {Object} RenderBootstrapContext
|
104
105
|
* @property {Chunk} chunk the chunk
|
106
|
+
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
105
107
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
106
108
|
* @property {ModuleGraph} moduleGraph the module graph
|
107
109
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
@@ -331,6 +333,7 @@ class JavascriptModulesPlugin {
|
|
331
333
|
{
|
332
334
|
hash: "0000",
|
333
335
|
chunk,
|
336
|
+
codeGenerationResults: context.codeGenerationResults,
|
334
337
|
chunkGraph: context.chunkGraph,
|
335
338
|
moduleGraph: context.moduleGraph,
|
336
339
|
runtimeTemplate: context.runtimeTemplate
|
@@ -343,6 +346,7 @@ class JavascriptModulesPlugin {
|
|
343
346
|
compilation.hooks.contentHash.tap("JavascriptModulesPlugin", chunk => {
|
344
347
|
const {
|
345
348
|
chunkGraph,
|
349
|
+
codeGenerationResults,
|
346
350
|
moduleGraph,
|
347
351
|
runtimeTemplate,
|
348
352
|
outputOptions: {
|
@@ -360,6 +364,7 @@ class JavascriptModulesPlugin {
|
|
360
364
|
{
|
361
365
|
hash: "0000",
|
362
366
|
chunk,
|
367
|
+
codeGenerationResults,
|
363
368
|
chunkGraph: compilation.chunkGraph,
|
364
369
|
moduleGraph: compilation.moduleGraph,
|
365
370
|
runtimeTemplate: compilation.runtimeTemplate
|
@@ -372,6 +377,7 @@ class JavascriptModulesPlugin {
|
|
372
377
|
}
|
373
378
|
hooks.chunkHash.call(chunk, hash, {
|
374
379
|
chunkGraph,
|
380
|
+
codeGenerationResults,
|
375
381
|
moduleGraph,
|
376
382
|
runtimeTemplate
|
377
383
|
});
|
@@ -398,7 +404,10 @@ class JavascriptModulesPlugin {
|
|
398
404
|
xor.updateHash(hash);
|
399
405
|
}
|
400
406
|
const digest = /** @type {string} */ (hash.digest(hashDigest));
|
401
|
-
chunk.contentHash.javascript =
|
407
|
+
chunk.contentHash.javascript = nonNumericOnlyHash(
|
408
|
+
digest,
|
409
|
+
hashDigestLength
|
410
|
+
);
|
402
411
|
});
|
403
412
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
404
413
|
"JavascriptModulesPlugin",
|
@@ -974,7 +983,13 @@ class JavascriptModulesPlugin {
|
|
974
983
|
* @returns {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} the generated source of the bootstrap code
|
975
984
|
*/
|
976
985
|
renderBootstrap(renderContext, hooks) {
|
977
|
-
const {
|
986
|
+
const {
|
987
|
+
chunkGraph,
|
988
|
+
codeGenerationResults,
|
989
|
+
moduleGraph,
|
990
|
+
chunk,
|
991
|
+
runtimeTemplate
|
992
|
+
} = renderContext;
|
978
993
|
|
979
994
|
const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
|
980
995
|
|
@@ -1098,8 +1113,18 @@ class JavascriptModulesPlugin {
|
|
1098
1113
|
);
|
1099
1114
|
result.allowInlineStartup = false;
|
1100
1115
|
}
|
1116
|
+
|
1117
|
+
let data;
|
1118
|
+
if (codeGenerationResults.has(entryModule, chunk.runtime)) {
|
1119
|
+
const result = codeGenerationResults.get(
|
1120
|
+
entryModule,
|
1121
|
+
chunk.runtime
|
1122
|
+
);
|
1123
|
+
data = result.data;
|
1124
|
+
}
|
1101
1125
|
if (
|
1102
1126
|
result.allowInlineStartup &&
|
1127
|
+
(!data || !data.get("topLevelDeclarations")) &&
|
1103
1128
|
(!entryModule.buildInfo ||
|
1104
1129
|
!entryModule.buildInfo.topLevelDeclarations)
|
1105
1130
|
) {
|
@@ -14,6 +14,7 @@ const { getAllChunks } = require("./ChunkHelpers");
|
|
14
14
|
/** @typedef {import("../Chunk")} Chunk */
|
15
15
|
/** @typedef {import("../Compilation")} Compilation */
|
16
16
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
|
+
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
|
17
18
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
18
19
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
19
20
|
/** @typedef {(string|number)[]} EntryItem */
|
@@ -23,7 +24,7 @@ const EXPORT_PREFIX = "var __webpack_exports__ = ";
|
|
23
24
|
/**
|
24
25
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
25
26
|
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
26
|
-
* @param {
|
27
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
27
28
|
* @param {Chunk} chunk chunk
|
28
29
|
* @param {boolean} passive true: passive startup with on chunks loaded
|
29
30
|
* @returns {string} runtime code
|
@@ -101,7 +102,7 @@ exports.generateEntryStartup = (
|
|
101
102
|
/**
|
102
103
|
* @param {Hash} hash the hash to update
|
103
104
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
104
|
-
* @param {
|
105
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
105
106
|
* @param {Chunk} chunk chunk
|
106
107
|
* @returns {void}
|
107
108
|
*/
|
@@ -222,9 +222,15 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
222
222
|
* @param {LibraryContext<T>} libraryContext context
|
223
223
|
* @returns {string | undefined} bailout reason
|
224
224
|
*/
|
225
|
-
embedInRuntimeBailout(
|
225
|
+
embedInRuntimeBailout(
|
226
|
+
module,
|
227
|
+
{ chunk, codeGenerationResults },
|
228
|
+
{ options, compilation }
|
229
|
+
) {
|
230
|
+
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
226
231
|
const topLevelDeclarations =
|
227
|
-
|
232
|
+
(data && data.get("topLevelDeclarations")) ||
|
233
|
+
(module.buildInfo && module.buildInfo.topLevelDeclarations);
|
228
234
|
if (!topLevelDeclarations)
|
229
235
|
return "it doesn't tell about top level declarations.";
|
230
236
|
const fullNameResolved = this._getResolvedFullName(
|
@@ -822,10 +822,6 @@ class ConcatenatedModule extends Module {
|
|
822
822
|
const topLevelDeclarations = this.buildInfo.topLevelDeclarations;
|
823
823
|
if (topLevelDeclarations !== undefined) {
|
824
824
|
for (const decl of m.buildInfo.topLevelDeclarations) {
|
825
|
-
// reserved names will always be renamed
|
826
|
-
if (RESERVED_NAMES.has(decl)) continue;
|
827
|
-
// TODO actually this is incorrect since with renaming there could be more
|
828
|
-
// We should do the renaming during build
|
829
825
|
topLevelDeclarations.add(decl);
|
830
826
|
}
|
831
827
|
}
|
@@ -1113,6 +1109,8 @@ class ConcatenatedModule extends Module {
|
|
1113
1109
|
|
1114
1110
|
// List of all used names to avoid conflicts
|
1115
1111
|
const allUsedNames = new Set(RESERVED_NAMES);
|
1112
|
+
// Updated Top level declarations are created by renaming
|
1113
|
+
const topLevelDeclarations = new Set();
|
1116
1114
|
|
1117
1115
|
// List of additional names in scope for module references
|
1118
1116
|
/** @type {Map<string, { usedNames: Set<string>, alreadyCheckedScopes: Set<TODO> }>} */
|
@@ -1257,6 +1255,7 @@ class ConcatenatedModule extends Module {
|
|
1257
1255
|
);
|
1258
1256
|
allUsedNames.add(newName);
|
1259
1257
|
info.internalNames.set(name, newName);
|
1258
|
+
topLevelDeclarations.add(newName);
|
1260
1259
|
const source = info.source;
|
1261
1260
|
const allIdentifiers = new Set(
|
1262
1261
|
references.map(r => r.identifier).concat(variable.identifiers)
|
@@ -1283,6 +1282,7 @@ class ConcatenatedModule extends Module {
|
|
1283
1282
|
} else {
|
1284
1283
|
allUsedNames.add(name);
|
1285
1284
|
info.internalNames.set(name, name);
|
1285
|
+
topLevelDeclarations.add(name);
|
1286
1286
|
}
|
1287
1287
|
}
|
1288
1288
|
let namespaceObjectName;
|
@@ -1300,6 +1300,7 @@ class ConcatenatedModule extends Module {
|
|
1300
1300
|
allUsedNames.add(namespaceObjectName);
|
1301
1301
|
}
|
1302
1302
|
info.namespaceObjectName = namespaceObjectName;
|
1303
|
+
topLevelDeclarations.add(namespaceObjectName);
|
1303
1304
|
break;
|
1304
1305
|
}
|
1305
1306
|
case "external": {
|
@@ -1311,6 +1312,7 @@ class ConcatenatedModule extends Module {
|
|
1311
1312
|
);
|
1312
1313
|
allUsedNames.add(externalName);
|
1313
1314
|
info.name = externalName;
|
1315
|
+
topLevelDeclarations.add(externalName);
|
1314
1316
|
break;
|
1315
1317
|
}
|
1316
1318
|
}
|
@@ -1323,6 +1325,7 @@ class ConcatenatedModule extends Module {
|
|
1323
1325
|
);
|
1324
1326
|
allUsedNames.add(externalNameInterop);
|
1325
1327
|
info.interopNamespaceObjectName = externalNameInterop;
|
1328
|
+
topLevelDeclarations.add(externalNameInterop);
|
1326
1329
|
}
|
1327
1330
|
if (
|
1328
1331
|
info.module.buildMeta.exportsType === "default" &&
|
@@ -1336,6 +1339,7 @@ class ConcatenatedModule extends Module {
|
|
1336
1339
|
);
|
1337
1340
|
allUsedNames.add(externalNameInterop);
|
1338
1341
|
info.interopNamespaceObject2Name = externalNameInterop;
|
1342
|
+
topLevelDeclarations.add(externalNameInterop);
|
1339
1343
|
}
|
1340
1344
|
if (
|
1341
1345
|
info.module.buildMeta.exportsType === "dynamic" ||
|
@@ -1349,6 +1353,7 @@ class ConcatenatedModule extends Module {
|
|
1349
1353
|
);
|
1350
1354
|
allUsedNames.add(externalNameInterop);
|
1351
1355
|
info.interopDefaultAccessName = externalNameInterop;
|
1356
|
+
topLevelDeclarations.add(externalNameInterop);
|
1352
1357
|
}
|
1353
1358
|
}
|
1354
1359
|
|
@@ -1618,6 +1623,7 @@ ${defineGetters}`
|
|
1618
1623
|
const data = new Map();
|
1619
1624
|
if (chunkInitFragments.length > 0)
|
1620
1625
|
data.set("chunkInitFragments", chunkInitFragments);
|
1626
|
+
data.set("topLevelDeclarations", topLevelDeclarations);
|
1621
1627
|
|
1622
1628
|
/** @type {CodeGenerationResult} */
|
1623
1629
|
const resultEntry = {
|
@@ -1708,7 +1714,7 @@ ${defineGetters}`
|
|
1708
1714
|
info.globalScope = globalScope;
|
1709
1715
|
info.moduleScope = moduleScope;
|
1710
1716
|
} catch (err) {
|
1711
|
-
err.message += `\nwhile
|
1717
|
+
err.message += `\nwhile analyzing module ${m.identifier()} for concatenation`;
|
1712
1718
|
throw err;
|
1713
1719
|
}
|
1714
1720
|
}
|
@@ -22,6 +22,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
22
22
|
return Template.asString([
|
23
23
|
'var webpackThen = typeof Symbol === "function" ? Symbol("webpack then") : "__webpack_then__";',
|
24
24
|
'var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";',
|
25
|
+
'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
|
25
26
|
`var completeQueue = ${runtimeTemplate.basicFunction("queue", [
|
26
27
|
"if(queue) {",
|
27
28
|
Template.indent([
|
@@ -56,9 +57,13 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
56
57
|
"obj[webpackExports] = r;",
|
57
58
|
"completeQueue(queue);",
|
58
59
|
"queue = 0;"
|
60
|
+
])}, ${runtimeTemplate.basicFunction("e", [
|
61
|
+
"obj[webpackError] = e;",
|
62
|
+
"completeQueue(queue);",
|
63
|
+
"queue = 0;"
|
59
64
|
])});`,
|
60
|
-
|
61
|
-
obj[webpackThen] = ${runtimeTemplate.expressionFunction(
|
65
|
+
"var obj = {};",
|
66
|
+
`obj[webpackThen] = ${runtimeTemplate.expressionFunction(
|
62
67
|
"queueFunction(queue, fn), dep['catch'](reject)",
|
63
68
|
"fn, reject"
|
64
69
|
)};`,
|
@@ -67,13 +72,13 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
67
72
|
"}"
|
68
73
|
]),
|
69
74
|
"}",
|
70
|
-
|
71
|
-
ret[webpackThen] = ${runtimeTemplate.expressionFunction(
|
75
|
+
"var ret = {};",
|
76
|
+
`ret[webpackThen] = ${runtimeTemplate.expressionFunction(
|
72
77
|
"completeFunction(fn)",
|
73
78
|
"fn"
|
74
|
-
)}
|
75
|
-
ret[webpackExports] = dep;
|
76
|
-
return ret
|
79
|
+
)};`,
|
80
|
+
"ret[webpackExports] = dep;",
|
81
|
+
"return ret;"
|
77
82
|
])})`,
|
78
83
|
"deps"
|
79
84
|
)};`,
|
@@ -119,24 +124,29 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
119
124
|
)};`,
|
120
125
|
"module.exports = promise;",
|
121
126
|
`body(${runtimeTemplate.basicFunction("deps", [
|
122
|
-
"if(!deps) return outerResolve();",
|
123
127
|
"currentDeps = wrapDeps(deps);",
|
124
|
-
"var fn
|
128
|
+
"var fn;",
|
129
|
+
`var getResult = ${runtimeTemplate.returningFunction(
|
130
|
+
`currentDeps.map(${runtimeTemplate.basicFunction("d", [
|
131
|
+
"if(d[webpackError]) throw d[webpackError];",
|
132
|
+
"return d[webpackExports];"
|
133
|
+
])})`
|
134
|
+
)}`,
|
125
135
|
`var promise = new Promise(${runtimeTemplate.basicFunction(
|
126
136
|
"resolve, reject",
|
127
137
|
[
|
128
138
|
`fn = ${runtimeTemplate.expressionFunction(
|
129
|
-
|
130
|
-
"d[webpackExports]",
|
131
|
-
"d"
|
132
|
-
)}))`
|
139
|
+
"resolve(getResult)"
|
133
140
|
)};`,
|
134
141
|
"fn.r = 0;",
|
135
142
|
"whenAll(currentDeps, fn, reject);"
|
136
143
|
]
|
137
144
|
)});`,
|
138
|
-
"return fn.r ? promise :
|
139
|
-
])}
|
145
|
+
"return fn.r ? promise : getResult();"
|
146
|
+
])}, ${runtimeTemplate.expressionFunction(
|
147
|
+
"err && reject(promise[webpackError] = err), outerResolve()",
|
148
|
+
"err"
|
149
|
+
)});`,
|
140
150
|
"isEvaluating = false;"
|
141
151
|
])};`
|
142
152
|
]);
|
@@ -0,0 +1,36 @@
|
|
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 CreateScriptRuntimeModule extends HelperRuntimeModule {
|
12
|
+
constructor() {
|
13
|
+
super("trusted types script");
|
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.createScript;
|
24
|
+
|
25
|
+
return Template.asString(
|
26
|
+
`${fn} = ${runtimeTemplate.returningFunction(
|
27
|
+
trustedTypes
|
28
|
+
? `${RuntimeGlobals.getTrustedTypesPolicy}().createScript(script)`
|
29
|
+
: "script",
|
30
|
+
"script"
|
31
|
+
)};`
|
32
|
+
);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
module.exports = CreateScriptRuntimeModule;
|