webpack 5.84.1 → 5.85.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/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 +16 -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 +12 -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 +42 -18
- 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 +189 -141
@@ -17,7 +17,9 @@ const {
|
|
17
17
|
} = require("../javascript/JavascriptModulesPlugin");
|
18
18
|
const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
|
19
19
|
|
20
|
+
/** @typedef {import("../Chunk")} Chunk */
|
20
21
|
/** @typedef {import("../Compiler")} Compiler */
|
22
|
+
/** @typedef {import("../Entrypoint")} Entrypoint */
|
21
23
|
|
22
24
|
class ModuleChunkFormatPlugin {
|
23
25
|
/**
|
@@ -73,7 +75,9 @@ class ModuleChunkFormatPlugin {
|
|
73
75
|
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
74
76
|
);
|
75
77
|
if (entries.length > 0) {
|
76
|
-
const runtimeChunk =
|
78
|
+
const runtimeChunk =
|
79
|
+
/** @type {Entrypoint[][]} */
|
80
|
+
(entries)[0][1].getRuntimeChunk();
|
77
81
|
const currentOutputName = compilation
|
78
82
|
.getPath(
|
79
83
|
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
@@ -87,6 +91,10 @@ class ModuleChunkFormatPlugin {
|
|
87
91
|
// remove filename, we only need the directory
|
88
92
|
currentOutputName.pop();
|
89
93
|
|
94
|
+
/**
|
95
|
+
* @param {Chunk} chunk the chunk
|
96
|
+
* @returns {string} the relative path
|
97
|
+
*/
|
90
98
|
const getRelativePath = chunk => {
|
91
99
|
const baseOutputName = currentOutputName.slice();
|
92
100
|
const chunkOutputName = compilation
|
@@ -124,7 +132,7 @@ class ModuleChunkFormatPlugin {
|
|
124
132
|
entrySource.add(";\n\n// load runtime\n");
|
125
133
|
entrySource.add(
|
126
134
|
`import ${RuntimeGlobals.require} from ${JSON.stringify(
|
127
|
-
getRelativePath(runtimeChunk)
|
135
|
+
getRelativePath(/** @type {Chunk} */ (runtimeChunk))
|
128
136
|
)};\n`
|
129
137
|
);
|
130
138
|
|
@@ -143,8 +151,8 @@ class ModuleChunkFormatPlugin {
|
|
143
151
|
const final = i + 1 === entries.length;
|
144
152
|
const moduleId = chunkGraph.getModuleId(module);
|
145
153
|
const chunks = getAllChunks(
|
146
|
-
entrypoint,
|
147
|
-
runtimeChunk,
|
154
|
+
/** @type {Entrypoint} */ (entrypoint),
|
155
|
+
/** @type {Chunk} */ (runtimeChunk),
|
148
156
|
undefined
|
149
157
|
);
|
150
158
|
for (const chunk of chunks) {
|
@@ -166,7 +174,7 @@ class ModuleChunkFormatPlugin {
|
|
166
174
|
}
|
167
175
|
startupSource.add(
|
168
176
|
`${
|
169
|
-
final ?
|
177
|
+
final ? `var ${RuntimeGlobals.exports} = ` : ""
|
170
178
|
}__webpack_exec__(${JSON.stringify(moduleId)});\n`
|
171
179
|
);
|
172
180
|
}
|
@@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const ExportWebpackRequireRuntimeModule = require("./ExportWebpackRequireRuntimeModule");
|
10
10
|
const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModule");
|
11
11
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
12
13
|
/** @typedef {import("../Compiler")} Compiler */
|
13
14
|
|
14
15
|
class ModuleChunkLoadingPlugin {
|
@@ -22,6 +23,10 @@ class ModuleChunkLoadingPlugin {
|
|
22
23
|
"ModuleChunkLoadingPlugin",
|
23
24
|
compilation => {
|
24
25
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
26
|
+
/**
|
27
|
+
* @param {Chunk} chunk chunk to check
|
28
|
+
* @returns {boolean} true, when the plugin is enabled for the chunk
|
29
|
+
*/
|
25
30
|
const isEnabledForChunk = chunk => {
|
26
31
|
const options = chunk.getEntryOptions();
|
27
32
|
const chunkLoading =
|
@@ -31,6 +36,10 @@ class ModuleChunkLoadingPlugin {
|
|
31
36
|
return chunkLoading === "import";
|
32
37
|
};
|
33
38
|
const onceForChunkSet = new WeakSet();
|
39
|
+
/**
|
40
|
+
* @param {Chunk} chunk chunk to check
|
41
|
+
* @param {Set<string>} set runtime requirements
|
42
|
+
*/
|
34
43
|
const handler = (chunk, set) => {
|
35
44
|
if (onceForChunkSet.has(chunk)) return;
|
36
45
|
onceForChunkSet.add(chunk);
|
@@ -18,6 +18,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
18
18
|
const { getUndoPath } = require("../util/identifier");
|
19
19
|
|
20
20
|
/** @typedef {import("../Chunk")} Chunk */
|
21
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
21
22
|
|
22
23
|
/**
|
23
24
|
* @typedef {Object} JsonpCompilationPluginHooks
|
@@ -69,11 +70,10 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
69
70
|
if (options && options.baseUri) {
|
70
71
|
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
71
72
|
}
|
73
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
72
74
|
const {
|
73
|
-
|
74
|
-
|
75
|
-
}
|
76
|
-
} = this;
|
75
|
+
outputOptions: { importMetaName }
|
76
|
+
} = compilation;
|
77
77
|
return `${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
|
78
78
|
rootOutputDir
|
79
79
|
)}, ${importMetaName}.url);`;
|
@@ -83,7 +83,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
83
83
|
* @returns {string} runtime code
|
84
84
|
*/
|
85
85
|
generate() {
|
86
|
-
const
|
86
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
87
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
88
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
87
89
|
const {
|
88
90
|
runtimeTemplate,
|
89
91
|
outputOptions: { importFunctionName }
|
@@ -106,8 +108,8 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
106
108
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
107
109
|
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
108
110
|
|
109
|
-
const outputName =
|
110
|
-
getChunkFilenameTemplate(chunk,
|
111
|
+
const outputName = compilation.getPath(
|
112
|
+
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
111
113
|
{
|
112
114
|
chunk,
|
113
115
|
contentHashType: "javascript"
|
@@ -115,7 +117,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
115
117
|
);
|
116
118
|
const rootOutputDir = getUndoPath(
|
117
119
|
outputName,
|
118
|
-
/** @type {string} */ (
|
120
|
+
/** @type {string} */ (compilation.outputOptions.path),
|
119
121
|
true
|
120
122
|
);
|
121
123
|
|
@@ -303,7 +303,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
|
|
303
303
|
|
304
304
|
/**
|
305
305
|
* @param {ModuleFactoryCreateData} data data object
|
306
|
-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
|
306
|
+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
|
307
307
|
* @returns {void}
|
308
308
|
*/
|
309
309
|
create(data, callback) {
|
@@ -13,7 +13,18 @@ const {
|
|
13
13
|
|
14
14
|
/** @typedef {import("../Compiler")} Compiler */
|
15
15
|
|
16
|
+
/**
|
17
|
+
* @typedef {Object} ChunkModuleIdRangePluginOptions
|
18
|
+
* @property {string} name the chunk name
|
19
|
+
* @property {("index" | "index2" | "preOrderIndex" | "postOrderIndex")=} order order
|
20
|
+
* @property {number=} start start id
|
21
|
+
* @property {number=} end end id
|
22
|
+
*/
|
23
|
+
|
16
24
|
class ChunkModuleIdRangePlugin {
|
25
|
+
/**
|
26
|
+
* @param {ChunkModuleIdRangePluginOptions} options options object
|
27
|
+
*/
|
17
28
|
constructor(options) {
|
18
29
|
this.options = options;
|
19
30
|
}
|
@@ -15,9 +15,18 @@ const {
|
|
15
15
|
/** @typedef {import("../Compiler")} Compiler */
|
16
16
|
/** @typedef {import("../Module")} Module */
|
17
17
|
|
18
|
+
/**
|
19
|
+
* @typedef {Object} DeterministicChunkIdsPluginOptions
|
20
|
+
* @property {string=} context context for ids
|
21
|
+
* @property {number=} maxLength maximum length of ids
|
22
|
+
*/
|
23
|
+
|
18
24
|
class DeterministicChunkIdsPlugin {
|
19
|
-
|
20
|
-
|
25
|
+
/**
|
26
|
+
* @param {DeterministicChunkIdsPluginOptions} [options] options
|
27
|
+
*/
|
28
|
+
constructor(options = {}) {
|
29
|
+
this.options = options;
|
21
30
|
}
|
22
31
|
|
23
32
|
/**
|
@@ -17,15 +17,19 @@ const {
|
|
17
17
|
/** @typedef {import("../Compiler")} Compiler */
|
18
18
|
/** @typedef {import("../Module")} Module */
|
19
19
|
|
20
|
+
/**
|
21
|
+
* @typedef {Object} DeterministicModuleIdsPluginOptions
|
22
|
+
* @property {string=} context context relative to which module identifiers are computed
|
23
|
+
* @property {function(Module): boolean=} test selector function for modules
|
24
|
+
* @property {number=} maxLength maximum id length in digits (used as starting point)
|
25
|
+
* @property {number=} salt hash salt for ids
|
26
|
+
* @property {boolean=} fixedLength do not increase the maxLength to find an optimal id space size
|
27
|
+
* @property {boolean=} failOnConflict throw an error when id conflicts occur (instead of rehashing)
|
28
|
+
*/
|
29
|
+
|
20
30
|
class DeterministicModuleIdsPlugin {
|
21
31
|
/**
|
22
|
-
* @param {
|
23
|
-
* @param {string=} options.context context relative to which module identifiers are computed
|
24
|
-
* @param {function(Module): boolean=} options.test selector function for modules
|
25
|
-
* @param {number=} options.maxLength maximum id length in digits (used as starting point)
|
26
|
-
* @param {number=} options.salt hash salt for ids
|
27
|
-
* @param {boolean=} options.fixedLength do not increase the maxLength to find an optimal id space size
|
28
|
-
* @param {boolean=} options.failOnConflict throw an error when id conflicts occur (instead of rehashing)
|
32
|
+
* @param {DeterministicModuleIdsPluginOptions} [options] options
|
29
33
|
*/
|
30
34
|
constructor(options = {}) {
|
31
35
|
this.options = options;
|
@@ -16,6 +16,7 @@ const {
|
|
16
16
|
} = require("./IdHelpers");
|
17
17
|
|
18
18
|
/** @typedef {import("../../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
|
19
|
+
/** @typedef {import("../Compiler")} Compiler */
|
19
20
|
|
20
21
|
const validate = createSchemaValidation(
|
21
22
|
require("../../schemas/plugins/HashedModuleIdsPlugin.check.js"),
|
@@ -43,6 +44,11 @@ class HashedModuleIdsPlugin {
|
|
43
44
|
};
|
44
45
|
}
|
45
46
|
|
47
|
+
/**
|
48
|
+
* Apply the plugin
|
49
|
+
* @param {Compiler} compiler the compiler instance
|
50
|
+
* @returns {void}
|
51
|
+
*/
|
46
52
|
apply(compiler) {
|
47
53
|
const options = this.options;
|
48
54
|
compiler.hooks.compilation.tap("HashedModuleIdsPlugin", compilation => {
|
@@ -64,7 +70,8 @@ class HashedModuleIdsPlugin {
|
|
64
70
|
hash.digest(options.hashDigest)
|
65
71
|
);
|
66
72
|
let len = options.hashDigestLength;
|
67
|
-
while (usedIds.has(hashId.slice(0, len)))
|
73
|
+
while (usedIds.has(hashId.slice(0, len)))
|
74
|
+
/** @type {number} */ (len)++;
|
68
75
|
const moduleId = hashId.slice(0, len);
|
69
76
|
chunkGraph.setModuleId(module, moduleId);
|
70
77
|
usedIds.add(moduleId);
|
package/lib/ids/IdHelpers.js
CHANGED
@@ -427,6 +427,9 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
|
|
427
427
|
let nextId = 0;
|
428
428
|
let assignId;
|
429
429
|
if (usedIds.size > 0) {
|
430
|
+
/**
|
431
|
+
* @param {Module} module the module
|
432
|
+
*/
|
430
433
|
assignId = module => {
|
431
434
|
if (chunkGraph.getModuleId(module) === null) {
|
432
435
|
while (usedIds.has(nextId + "")) nextId++;
|
@@ -434,6 +437,9 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
|
|
434
437
|
}
|
435
438
|
};
|
436
439
|
} else {
|
440
|
+
/**
|
441
|
+
* @param {Module} module the module
|
442
|
+
*/
|
437
443
|
assignId = module => {
|
438
444
|
if (chunkGraph.getModuleId(module) === null) {
|
439
445
|
chunkGraph.setModuleId(module, nextId++);
|
@@ -14,11 +14,21 @@ const {
|
|
14
14
|
assignAscendingChunkIds
|
15
15
|
} = require("./IdHelpers");
|
16
16
|
|
17
|
+
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
|
17
18
|
/** @typedef {import("../Chunk")} Chunk */
|
18
19
|
/** @typedef {import("../Compiler")} Compiler */
|
19
20
|
/** @typedef {import("../Module")} Module */
|
20
21
|
|
22
|
+
/**
|
23
|
+
* @typedef {Object} NamedChunkIdsPluginOptions
|
24
|
+
* @property {string} [context] context
|
25
|
+
* @property {string} [delimiter] delimiter
|
26
|
+
*/
|
27
|
+
|
21
28
|
class NamedChunkIdsPlugin {
|
29
|
+
/**
|
30
|
+
* @param {NamedChunkIdsPluginOptions=} options options
|
31
|
+
*/
|
22
32
|
constructor(options) {
|
23
33
|
this.delimiter = (options && options.delimiter) || "-";
|
24
34
|
this.context = options && options.context;
|
@@ -31,7 +41,9 @@ class NamedChunkIdsPlugin {
|
|
31
41
|
*/
|
32
42
|
apply(compiler) {
|
33
43
|
compiler.hooks.compilation.tap("NamedChunkIdsPlugin", compilation => {
|
34
|
-
const
|
44
|
+
const hashFunction =
|
45
|
+
/** @type {NonNullable<Output["hashFunction"]>} */
|
46
|
+
(compilation.outputOptions.hashFunction);
|
35
47
|
compilation.hooks.chunkIds.tap("NamedChunkIdsPlugin", chunks => {
|
36
48
|
const chunkGraph = compilation.chunkGraph;
|
37
49
|
const context = this.context ? this.context : compiler.context;
|
@@ -14,12 +14,21 @@ const {
|
|
14
14
|
assignAscendingModuleIds
|
15
15
|
} = require("./IdHelpers");
|
16
16
|
|
17
|
+
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
|
17
18
|
/** @typedef {import("../Compiler")} Compiler */
|
18
19
|
/** @typedef {import("../Module")} Module */
|
19
20
|
|
21
|
+
/**
|
22
|
+
* @typedef {Object} NamedModuleIdsPluginOptions
|
23
|
+
* @property {string} [context] context
|
24
|
+
*/
|
25
|
+
|
20
26
|
class NamedModuleIdsPlugin {
|
21
|
-
|
22
|
-
|
27
|
+
/**
|
28
|
+
* @param {NamedModuleIdsPluginOptions} [options] options
|
29
|
+
*/
|
30
|
+
constructor(options = {}) {
|
31
|
+
this.options = options;
|
23
32
|
}
|
24
33
|
|
25
34
|
/**
|
@@ -30,7 +39,9 @@ class NamedModuleIdsPlugin {
|
|
30
39
|
apply(compiler) {
|
31
40
|
const { root } = compiler;
|
32
41
|
compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => {
|
33
|
-
const
|
42
|
+
const hashFunction =
|
43
|
+
/** @type {NonNullable<Output["hashFunction"]>} */
|
44
|
+
(compilation.outputOptions.hashFunction);
|
34
45
|
compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin", () => {
|
35
46
|
const chunkGraph = compilation.chunkGraph;
|
36
47
|
const context = this.options.context
|
@@ -60,8 +60,12 @@ class OccurrenceChunkIdsPlugin {
|
|
60
60
|
|
61
61
|
const chunksInOccurrenceOrder = Array.from(chunks).sort((a, b) => {
|
62
62
|
if (prioritiseInitial) {
|
63
|
-
const aEntryOccurs =
|
64
|
-
|
63
|
+
const aEntryOccurs =
|
64
|
+
/** @type {number} */
|
65
|
+
(occursInInitialChunksMap.get(a));
|
66
|
+
const bEntryOccurs =
|
67
|
+
/** @type {number} */
|
68
|
+
(occursInInitialChunksMap.get(b));
|
65
69
|
if (aEntryOccurs > bEntryOccurs) return -1;
|
66
70
|
if (aEntryOccurs < bEntryOccurs) return 1;
|
67
71
|
}
|
@@ -50,7 +50,7 @@ class SyncModuleIdsPlugin {
|
|
50
50
|
}
|
51
51
|
return callback();
|
52
52
|
}
|
53
|
-
const json = JSON.parse(buffer.toString());
|
53
|
+
const json = JSON.parse(/** @type {Buffer} */ (buffer).toString());
|
54
54
|
data = new Map();
|
55
55
|
for (const key of Object.keys(json)) {
|
56
56
|
data.set(key, json[key]);
|
@@ -98,7 +98,7 @@ class SyncModuleIdsPlugin {
|
|
98
98
|
err.module = module;
|
99
99
|
compilation.errors.push(err);
|
100
100
|
}
|
101
|
-
chunkGraph.setModuleId(module, id);
|
101
|
+
chunkGraph.setModuleId(module, /** @type {string | number} */ (id));
|
102
102
|
usedIds.add(idAsString);
|
103
103
|
}
|
104
104
|
});
|
@@ -121,7 +121,7 @@ class ArrayPushCallbackChunkFormatPlugin {
|
|
121
121
|
.getChunkRuntimeRequirements(chunk)
|
122
122
|
.has(RuntimeGlobals.returnExportsFromRuntime)
|
123
123
|
) {
|
124
|
-
runtime.add(
|
124
|
+
runtime.add(`return ${RuntimeGlobals.exports};\n`);
|
125
125
|
}
|
126
126
|
}
|
127
127
|
runtime.add("}\n");
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/** @typedef {import("estree").Node} EsTreeNode */
|
9
|
+
/** @typedef {import("./JavascriptParser").Range} Range */
|
9
10
|
/** @typedef {import("./JavascriptParser").VariableInfoInterface} VariableInfoInterface */
|
10
11
|
|
11
12
|
const TypeUnknown = 0;
|
@@ -70,6 +71,8 @@ class BasicEvaluatedExpression {
|
|
70
71
|
this.getMembers = undefined;
|
71
72
|
/** @type {() => boolean[]} */
|
72
73
|
this.getMembersOptionals = undefined;
|
74
|
+
/** @type {() => Range[]} */
|
75
|
+
this.getMemberRanges = undefined;
|
73
76
|
/** @type {EsTreeNode} */
|
74
77
|
this.expression = undefined;
|
75
78
|
}
|
@@ -384,14 +387,22 @@ class BasicEvaluatedExpression {
|
|
384
387
|
* @param {string | VariableInfoInterface} rootInfo root info
|
385
388
|
* @param {() => string[]} getMembers members
|
386
389
|
* @param {() => boolean[]=} getMembersOptionals optional members
|
390
|
+
* @param {() => Range[]=} getMemberRanges ranges of progressively increasing sub-expressions
|
387
391
|
* @returns {this} this
|
388
392
|
*/
|
389
|
-
setIdentifier(
|
393
|
+
setIdentifier(
|
394
|
+
identifier,
|
395
|
+
rootInfo,
|
396
|
+
getMembers,
|
397
|
+
getMembersOptionals,
|
398
|
+
getMemberRanges
|
399
|
+
) {
|
390
400
|
this.type = TypeIdentifier;
|
391
401
|
this.identifier = identifier;
|
392
402
|
this.rootInfo = rootInfo;
|
393
403
|
this.getMembers = getMembers;
|
394
404
|
this.getMembersOptionals = getMembersOptionals;
|
405
|
+
this.getMemberRanges = getMemberRanges;
|
395
406
|
this.sideEffects = true;
|
396
407
|
return this;
|
397
408
|
}
|
@@ -11,8 +11,8 @@ const Entrypoint = require("../Entrypoint");
|
|
11
11
|
|
12
12
|
/**
|
13
13
|
* @param {Entrypoint} entrypoint a chunk group
|
14
|
-
* @param {Chunk} excludedChunk1 current chunk which is excluded
|
15
|
-
* @param {Chunk} excludedChunk2 runtime chunk which is excluded
|
14
|
+
* @param {Chunk=} excludedChunk1 current chunk which is excluded
|
15
|
+
* @param {Chunk=} excludedChunk2 runtime chunk which is excluded
|
16
16
|
* @returns {Set<Chunk>} chunks
|
17
17
|
*/
|
18
18
|
const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
|
@@ -11,6 +11,10 @@
|
|
11
11
|
/** @type {WeakMap<Compiler, Set<ChunkLoadingType>>} */
|
12
12
|
const enabledTypes = new WeakMap();
|
13
13
|
|
14
|
+
/**
|
15
|
+
* @param {Compiler} compiler compiler
|
16
|
+
* @returns {Set<ChunkLoadingType>} enabled types
|
17
|
+
*/
|
14
18
|
const getEnabledTypes = compiler => {
|
15
19
|
let set = enabledTypes.get(compiler);
|
16
20
|
if (set === undefined) {
|
@@ -130,8 +130,8 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
130
130
|
* @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
|
131
131
|
* @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
|
132
132
|
* @property {SyncBailHook<[Module, RenderBootstrapContext], string>} inlineInRuntimeBailout
|
133
|
-
* @property {SyncBailHook<[Module, RenderContext], string>} embedInRuntimeBailout
|
134
|
-
* @property {SyncBailHook<[RenderContext], string>} strictRuntimeBailout
|
133
|
+
* @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
|
134
|
+
* @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
|
135
135
|
* @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
|
136
136
|
* @property {SyncBailHook<[Chunk, RenderContext], boolean>} useSourceMap
|
137
137
|
*/
|
@@ -691,6 +691,7 @@ class JavascriptModulesPlugin {
|
|
691
691
|
);
|
692
692
|
|
693
693
|
const hasEntryModules = chunkGraph.getNumberOfEntryModules(chunk) > 0;
|
694
|
+
/** @type {Set<Module> | undefined} */
|
694
695
|
let inlinedModules;
|
695
696
|
if (bootstrap.allowInlineStartup && hasEntryModules) {
|
696
697
|
inlinedModules = new Set(chunkGraph.getChunkEntryModulesIterable(chunk));
|
@@ -732,7 +733,9 @@ class JavascriptModulesPlugin {
|
|
732
733
|
const chunkModules = Template.renderChunkModules(
|
733
734
|
chunkRenderContext,
|
734
735
|
inlinedModules
|
735
|
-
? allModules.filter(
|
736
|
+
? allModules.filter(
|
737
|
+
m => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
|
738
|
+
)
|
736
739
|
: allModules,
|
737
740
|
module => this.renderModule(module, chunkRenderContext, hooks, true),
|
738
741
|
prefix
|
@@ -798,7 +801,7 @@ class JavascriptModulesPlugin {
|
|
798
801
|
}
|
799
802
|
const lastInlinedModule = last(inlinedModules);
|
800
803
|
const startupSource = new ConcatSource();
|
801
|
-
startupSource.add(`var
|
804
|
+
startupSource.add(`var ${RuntimeGlobals.exports} = {};\n`);
|
802
805
|
for (const m of inlinedModules) {
|
803
806
|
const renderedModule = this.renderModule(
|
804
807
|
m,
|
@@ -814,7 +817,7 @@ class JavascriptModulesPlugin {
|
|
814
817
|
);
|
815
818
|
const exports = runtimeRequirements.has(RuntimeGlobals.exports);
|
816
819
|
const webpackExports =
|
817
|
-
exports && m.exportsArgument ===
|
820
|
+
exports && m.exportsArgument === RuntimeGlobals.exports;
|
818
821
|
let iife = innerStrict
|
819
822
|
? "it need to be in strict mode."
|
820
823
|
: inlinedModules.size > 1
|
@@ -846,9 +849,9 @@ class JavascriptModulesPlugin {
|
|
846
849
|
if (exports) {
|
847
850
|
if (m !== lastInlinedModule)
|
848
851
|
startupSource.add(`var ${m.exportsArgument} = {};\n`);
|
849
|
-
else if (m.exportsArgument !==
|
852
|
+
else if (m.exportsArgument !== RuntimeGlobals.exports)
|
850
853
|
startupSource.add(
|
851
|
-
`var ${m.exportsArgument} =
|
854
|
+
`var ${m.exportsArgument} = ${RuntimeGlobals.exports};\n`
|
852
855
|
);
|
853
856
|
}
|
854
857
|
startupSource.add(renderedModule);
|
@@ -857,7 +860,7 @@ class JavascriptModulesPlugin {
|
|
857
860
|
}
|
858
861
|
if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
|
859
862
|
startupSource.add(
|
860
|
-
|
863
|
+
`${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});\n`
|
861
864
|
);
|
862
865
|
}
|
863
866
|
source.add(
|
@@ -909,7 +912,7 @@ class JavascriptModulesPlugin {
|
|
909
912
|
hasEntryModules &&
|
910
913
|
runtimeRequirements.has(RuntimeGlobals.returnExportsFromRuntime)
|
911
914
|
) {
|
912
|
-
source.add(`${prefix}return
|
915
|
+
source.add(`${prefix}return ${RuntimeGlobals.exports};\n`);
|
913
916
|
}
|
914
917
|
if (iife) {
|
915
918
|
source.add("/******/ })()\n");
|
@@ -1158,7 +1161,7 @@ class JavascriptModulesPlugin {
|
|
1158
1161
|
}
|
1159
1162
|
if (chunks.length > 0) {
|
1160
1163
|
buf2.push(
|
1161
|
-
`${i === 0 ?
|
1164
|
+
`${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
|
1162
1165
|
RuntimeGlobals.onChunksLoaded
|
1163
1166
|
}(undefined, ${JSON.stringify(
|
1164
1167
|
chunks.map(c => c.id)
|
@@ -1168,22 +1171,22 @@ class JavascriptModulesPlugin {
|
|
1168
1171
|
);
|
1169
1172
|
} else if (useRequire) {
|
1170
1173
|
buf2.push(
|
1171
|
-
`${i === 0 ?
|
1174
|
+
`${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
|
1172
1175
|
RuntimeGlobals.require
|
1173
1176
|
}(${moduleIdExpr});`
|
1174
1177
|
);
|
1175
1178
|
} else {
|
1176
|
-
if (i === 0) buf2.push(
|
1179
|
+
if (i === 0) buf2.push(`var ${RuntimeGlobals.exports} = {};`);
|
1177
1180
|
if (requireScopeUsed) {
|
1178
1181
|
buf2.push(
|
1179
1182
|
`__webpack_modules__[${moduleIdExpr}](0, ${
|
1180
|
-
i === 0 ?
|
1183
|
+
i === 0 ? RuntimeGlobals.exports : "{}"
|
1181
1184
|
}, ${RuntimeGlobals.require});`
|
1182
1185
|
);
|
1183
1186
|
} else if (entryRuntimeRequirements.has(RuntimeGlobals.exports)) {
|
1184
1187
|
buf2.push(
|
1185
1188
|
`__webpack_modules__[${moduleIdExpr}](0, ${
|
1186
|
-
i === 0 ?
|
1189
|
+
i === 0 ? RuntimeGlobals.exports : "{}"
|
1187
1190
|
});`
|
1188
1191
|
);
|
1189
1192
|
} else {
|
@@ -1193,7 +1196,7 @@ class JavascriptModulesPlugin {
|
|
1193
1196
|
}
|
1194
1197
|
if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
|
1195
1198
|
buf2.push(
|
1196
|
-
|
1199
|
+
`${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});`
|
1197
1200
|
);
|
1198
1201
|
}
|
1199
1202
|
if (
|
@@ -1206,13 +1209,13 @@ class JavascriptModulesPlugin {
|
|
1206
1209
|
buf.push(
|
1207
1210
|
`${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction("", [
|
1208
1211
|
...buf2,
|
1209
|
-
|
1212
|
+
`return ${RuntimeGlobals.exports};`
|
1210
1213
|
])};`
|
1211
1214
|
);
|
1212
1215
|
buf.push("");
|
1213
1216
|
startup.push("// run startup");
|
1214
1217
|
startup.push(
|
1215
|
-
`var
|
1218
|
+
`var ${RuntimeGlobals.exports} = ${RuntimeGlobals.startup}();`
|
1216
1219
|
);
|
1217
1220
|
} else if (runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore)) {
|
1218
1221
|
buf.push("// the startup function");
|
@@ -1260,7 +1263,9 @@ class JavascriptModulesPlugin {
|
|
1260
1263
|
`${RuntimeGlobals.startup} = ${runtimeTemplate.emptyFunction()};`
|
1261
1264
|
);
|
1262
1265
|
startup.push("// run startup");
|
1263
|
-
startup.push(
|
1266
|
+
startup.push(
|
1267
|
+
`var ${RuntimeGlobals.exports} = ${RuntimeGlobals.startup}();`
|
1268
|
+
);
|
1264
1269
|
}
|
1265
1270
|
return result;
|
1266
1271
|
}
|
@@ -1346,7 +1351,7 @@ class JavascriptModulesPlugin {
|
|
1346
1351
|
? Template.asString([
|
1347
1352
|
"",
|
1348
1353
|
"// Flag the module as loaded",
|
1349
|
-
|
1354
|
+
`${RuntimeGlobals.moduleLoaded} = true;`,
|
1350
1355
|
""
|
1351
1356
|
])
|
1352
1357
|
: "",
|