webpack 5.90.3 → 5.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -5
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +14 -6
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +8 -2
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +52 -25
- package/lib/ChunkGroup.js +23 -17
- package/lib/CleanPlugin.js +8 -6
- package/lib/Compilation.js +295 -120
- package/lib/Compiler.js +223 -87
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +95 -41
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +18 -6
- package/lib/Dependency.js +12 -10
- package/lib/DependencyTemplate.js +17 -7
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +7 -3
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +23 -8
- package/lib/ExternalModule.js +160 -35
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +69 -42
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +4 -4
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +17 -9
- package/lib/Module.js +41 -14
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +30 -17
- package/lib/ModuleGraph.js +60 -31
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +62 -9
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +13 -13
- package/lib/NormalModuleFactory.js +18 -9
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +6 -4
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +124 -52
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +11 -4
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +48 -7
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +120 -67
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +51 -18
- package/lib/cache/ResolverCachePlugin.js +22 -14
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +108 -34
- package/lib/config/normalization.js +3 -1
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +68 -25
- package/lib/css/CssGenerator.js +34 -6
- package/lib/css/CssLoadingRuntimeModule.js +217 -98
- package/lib/css/CssModulesPlugin.js +238 -107
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +28 -3
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
- package/lib/dependencies/CssUrlDependency.js +10 -7
- package/lib/dependencies/ExportsInfoDependency.js +5 -4
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +15 -5
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +64 -47
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +204 -71
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +13 -9
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -121
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +8 -3
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
- package/lib/optimize/SplitChunksPlugin.js +10 -10
- package/lib/performance/SizeLimitsPlugin.js +13 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +4 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +8 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +19 -0
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +13 -6
- package/lib/sharing/resolveMatchedConfigs.js +3 -3
- package/lib/sharing/utils.js +13 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +26 -13
- package/lib/util/comparators.js +37 -15
- package/lib/util/conventions.js +129 -0
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +383 -69
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
- package/lib/webpack.js +19 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +40 -39
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +97 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1826 -639
@@ -42,19 +42,28 @@ const {
|
|
42
42
|
WEBPACK_MODULE_TYPE_RUNTIME
|
43
43
|
} = require("./ModuleTypeConstants");
|
44
44
|
|
45
|
+
/** @typedef {import("estree").CallExpression} CallExpression */
|
46
|
+
/** @typedef {import("estree").Expression} Expression */
|
45
47
|
/** @typedef {import("./Chunk")} Chunk */
|
48
|
+
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
46
49
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
47
50
|
/** @typedef {import("./Compiler")} Compiler */
|
51
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
48
52
|
/** @typedef {import("./Module")} Module */
|
53
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
49
54
|
/** @typedef {import("./RuntimeModule")} RuntimeModule */
|
55
|
+
/** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
56
|
+
/** @typedef {import("./javascript/JavascriptParserHelpers").Range} Range */
|
50
57
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
51
58
|
|
52
59
|
/**
|
53
|
-
* @typedef {
|
60
|
+
* @typedef {object} HMRJavascriptParserHooks
|
54
61
|
* @property {SyncBailHook<[TODO, string[]], void>} hotAcceptCallback
|
55
62
|
* @property {SyncBailHook<[TODO, string[]], void>} hotAcceptWithoutCallback
|
56
63
|
*/
|
57
64
|
|
65
|
+
/** @typedef {Map<string, { updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }>} HotUpdateMainContentByRuntime */
|
66
|
+
|
58
67
|
/** @type {WeakMap<JavascriptParser, HMRJavascriptParserHooks>} */
|
59
68
|
const parserHooksMap = new WeakMap();
|
60
69
|
|
@@ -82,6 +91,9 @@ class HotModuleReplacementPlugin {
|
|
82
91
|
return hooks;
|
83
92
|
}
|
84
93
|
|
94
|
+
/**
|
95
|
+
* @param {object=} options options
|
96
|
+
*/
|
85
97
|
constructor(options) {
|
86
98
|
this.options = options || {};
|
87
99
|
}
|
@@ -97,6 +109,11 @@ class HotModuleReplacementPlugin {
|
|
97
109
|
compiler.options.output.strictModuleErrorHandling = true;
|
98
110
|
const runtimeRequirements = [RuntimeGlobals.module];
|
99
111
|
|
112
|
+
/**
|
113
|
+
* @param {JavascriptParser} parser the parser
|
114
|
+
* @param {typeof ModuleHotAcceptDependency} ParamDependency dependency
|
115
|
+
* @returns {(expr: CallExpression) => boolean | undefined} callback
|
116
|
+
*/
|
100
117
|
const createAcceptHandler = (parser, ParamDependency) => {
|
101
118
|
const { hotAcceptCallback, hotAcceptWithoutCallback } =
|
102
119
|
HotModuleReplacementPlugin.getParserHooks(parser);
|
@@ -105,27 +122,38 @@ class HotModuleReplacementPlugin {
|
|
105
122
|
const module = parser.state.module;
|
106
123
|
const dep = new ConstDependency(
|
107
124
|
`${module.moduleArgument}.hot.accept`,
|
108
|
-
expr.callee.range,
|
125
|
+
/** @type {Range} */ (expr.callee.range),
|
109
126
|
runtimeRequirements
|
110
127
|
);
|
111
|
-
dep.loc = expr.loc;
|
128
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
112
129
|
module.addPresentationalDependency(dep);
|
113
|
-
|
130
|
+
/** @type {BuildInfo} */
|
131
|
+
(module.buildInfo).moduleConcatenationBailout =
|
132
|
+
"Hot Module Replacement";
|
114
133
|
if (expr.arguments.length >= 1) {
|
115
134
|
const arg = parser.evaluateExpression(expr.arguments[0]);
|
135
|
+
/** @type {BasicEvaluatedExpression[]} */
|
116
136
|
let params = [];
|
117
|
-
let requests = [];
|
118
137
|
if (arg.isString()) {
|
119
138
|
params = [arg];
|
120
139
|
} else if (arg.isArray()) {
|
121
|
-
params =
|
140
|
+
params =
|
141
|
+
/** @type {BasicEvaluatedExpression[]} */
|
142
|
+
(arg.items).filter(param => param.isString());
|
122
143
|
}
|
144
|
+
/** @type {string[]} */
|
145
|
+
let requests = [];
|
123
146
|
if (params.length > 0) {
|
124
147
|
params.forEach((param, idx) => {
|
125
|
-
const request = param.string;
|
126
|
-
const dep = new ParamDependency(
|
148
|
+
const request = /** @type {string} */ (param.string);
|
149
|
+
const dep = new ParamDependency(
|
150
|
+
request,
|
151
|
+
/** @type {Range} */ (param.range)
|
152
|
+
);
|
127
153
|
dep.optional = true;
|
128
|
-
dep.loc = Object.create(
|
154
|
+
dep.loc = Object.create(
|
155
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
156
|
+
);
|
129
157
|
dep.loc.index = idx;
|
130
158
|
module.addDependency(dep);
|
131
159
|
requests.push(request);
|
@@ -147,28 +175,40 @@ class HotModuleReplacementPlugin {
|
|
147
175
|
};
|
148
176
|
};
|
149
177
|
|
178
|
+
/**
|
179
|
+
* @param {JavascriptParser} parser the parser
|
180
|
+
* @param {typeof ModuleHotDeclineDependency} ParamDependency dependency
|
181
|
+
* @returns {(expr: CallExpression) => boolean | undefined} callback
|
182
|
+
*/
|
150
183
|
const createDeclineHandler = (parser, ParamDependency) => expr => {
|
151
184
|
const module = parser.state.module;
|
152
185
|
const dep = new ConstDependency(
|
153
186
|
`${module.moduleArgument}.hot.decline`,
|
154
|
-
expr.callee.range,
|
187
|
+
/** @type {Range} */ (expr.callee.range),
|
155
188
|
runtimeRequirements
|
156
189
|
);
|
157
|
-
dep.loc = expr.loc;
|
190
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
158
191
|
module.addPresentationalDependency(dep);
|
159
|
-
|
192
|
+
/** @type {BuildInfo} */
|
193
|
+
(module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
|
160
194
|
if (expr.arguments.length === 1) {
|
161
195
|
const arg = parser.evaluateExpression(expr.arguments[0]);
|
196
|
+
/** @type {BasicEvaluatedExpression[]} */
|
162
197
|
let params = [];
|
163
198
|
if (arg.isString()) {
|
164
199
|
params = [arg];
|
165
200
|
} else if (arg.isArray()) {
|
166
|
-
params =
|
201
|
+
params =
|
202
|
+
/** @type {BasicEvaluatedExpression[]} */
|
203
|
+
(arg.items).filter(param => param.isString());
|
167
204
|
}
|
168
205
|
params.forEach((param, idx) => {
|
169
|
-
const dep = new ParamDependency(
|
206
|
+
const dep = new ParamDependency(
|
207
|
+
/** @type {string} */ (param.string),
|
208
|
+
/** @type {Range} */ (param.range)
|
209
|
+
);
|
170
210
|
dep.optional = true;
|
171
|
-
dep.loc = Object.create(expr.loc);
|
211
|
+
dep.loc = Object.create(/** @type {DependencyLocation} */ (expr.loc));
|
172
212
|
dep.loc.index = idx;
|
173
213
|
module.addDependency(dep);
|
174
214
|
});
|
@@ -176,16 +216,21 @@ class HotModuleReplacementPlugin {
|
|
176
216
|
return true;
|
177
217
|
};
|
178
218
|
|
219
|
+
/**
|
220
|
+
* @param {JavascriptParser} parser the parser
|
221
|
+
* @returns {(expr: Expression) => boolean | undefined} callback
|
222
|
+
*/
|
179
223
|
const createHMRExpressionHandler = parser => expr => {
|
180
224
|
const module = parser.state.module;
|
181
225
|
const dep = new ConstDependency(
|
182
226
|
`${module.moduleArgument}.hot`,
|
183
|
-
expr.range,
|
227
|
+
/** @type {Range} */ (expr.range),
|
184
228
|
runtimeRequirements
|
185
229
|
);
|
186
|
-
dep.loc = expr.loc;
|
230
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
187
231
|
module.addPresentationalDependency(dep);
|
188
|
-
|
232
|
+
/** @type {BuildInfo} */
|
233
|
+
(module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
|
189
234
|
return true;
|
190
235
|
};
|
191
236
|
|
@@ -303,7 +348,9 @@ class HotModuleReplacementPlugin {
|
|
303
348
|
//#endregion
|
304
349
|
|
305
350
|
let hotIndex = 0;
|
351
|
+
/** @type {Record<string, string>} */
|
306
352
|
const fullHashChunkModuleHashes = {};
|
353
|
+
/** @type {Record<string, string>} */
|
307
354
|
const chunkModuleHashes = {};
|
308
355
|
|
309
356
|
compilation.hooks.record.tap(PLUGIN_NAME, (compilation, records) => {
|
@@ -316,18 +363,20 @@ class HotModuleReplacementPlugin {
|
|
316
363
|
records.chunkHashes = {};
|
317
364
|
records.chunkRuntime = {};
|
318
365
|
for (const chunk of compilation.chunks) {
|
319
|
-
|
320
|
-
records.
|
366
|
+
const chunkId = /** @type {ChunkId} */ (chunk.id);
|
367
|
+
records.chunkHashes[chunkId] = chunk.hash;
|
368
|
+
records.chunkRuntime[chunkId] = getRuntimeKey(chunk.runtime);
|
321
369
|
}
|
322
370
|
records.chunkModuleIds = {};
|
323
371
|
for (const chunk of compilation.chunks) {
|
324
|
-
records.chunkModuleIds[chunk.id] =
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
372
|
+
records.chunkModuleIds[/** @type {ChunkId} */ (chunk.id)] =
|
373
|
+
Array.from(
|
374
|
+
chunkGraph.getOrderedChunkModulesIterable(
|
375
|
+
chunk,
|
376
|
+
compareModulesById(chunkGraph)
|
377
|
+
),
|
378
|
+
m => chunkGraph.getModuleId(m)
|
379
|
+
);
|
331
380
|
}
|
332
381
|
});
|
333
382
|
/** @type {TupleSet<[Module, Chunk]>} */
|
@@ -340,6 +389,10 @@ class HotModuleReplacementPlugin {
|
|
340
389
|
const chunkGraph = compilation.chunkGraph;
|
341
390
|
const records = compilation.records;
|
342
391
|
for (const chunk of compilation.chunks) {
|
392
|
+
/**
|
393
|
+
* @param {Module} module module
|
394
|
+
* @returns {string} module hash
|
395
|
+
*/
|
343
396
|
const getModuleHash = module => {
|
344
397
|
if (
|
345
398
|
compilation.codeGenerationResults.has(module, chunk.runtime)
|
@@ -454,7 +507,7 @@ class HotModuleReplacementPlugin {
|
|
454
507
|
chunkModuleHashes[key] = hash;
|
455
508
|
}
|
456
509
|
|
457
|
-
/** @type {
|
510
|
+
/** @type {HotUpdateMainContentByRuntime} */
|
458
511
|
const hotUpdateMainContentByRuntime = new Map();
|
459
512
|
let allOldRuntime;
|
460
513
|
for (const key of Object.keys(records.chunkRuntime)) {
|
@@ -470,13 +523,16 @@ class HotModuleReplacementPlugin {
|
|
470
523
|
runtime
|
471
524
|
}
|
472
525
|
);
|
473
|
-
hotUpdateMainContentByRuntime.set(
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
526
|
+
hotUpdateMainContentByRuntime.set(
|
527
|
+
/** @type {string} */ (runtime),
|
528
|
+
{
|
529
|
+
updatedChunkIds: new Set(),
|
530
|
+
removedChunkIds: new Set(),
|
531
|
+
removedModules: new Set(),
|
532
|
+
filename,
|
533
|
+
assetInfo
|
534
|
+
}
|
535
|
+
);
|
480
536
|
});
|
481
537
|
if (hotUpdateMainContentByRuntime.size === 0) return;
|
482
538
|
|
@@ -506,6 +562,7 @@ class HotModuleReplacementPlugin {
|
|
506
562
|
}
|
507
563
|
}
|
508
564
|
|
565
|
+
/** @type {ChunkId | null} */
|
509
566
|
let chunkId;
|
510
567
|
let newModules;
|
511
568
|
let newRuntimeModules;
|
@@ -554,9 +611,10 @@ class HotModuleReplacementPlugin {
|
|
554
611
|
if (removedFromRuntime) {
|
555
612
|
// chunk was removed from some runtimes
|
556
613
|
forEachRuntime(removedFromRuntime, runtime => {
|
557
|
-
hotUpdateMainContentByRuntime
|
558
|
-
|
559
|
-
|
614
|
+
const item = hotUpdateMainContentByRuntime.get(
|
615
|
+
/** @type {string} */ (runtime)
|
616
|
+
);
|
617
|
+
item.removedChunkIds.add(/** @type {ChunkId} */ (chunkId));
|
560
618
|
});
|
561
619
|
// dispose modules from the chunk in these runtimes
|
562
620
|
// where they are no longer in this runtime
|
@@ -597,12 +655,16 @@ class HotModuleReplacementPlugin {
|
|
597
655
|
if (typeof moduleRuntime === "string") {
|
598
656
|
if (moduleRuntime === runtime) return;
|
599
657
|
} else if (moduleRuntime !== undefined) {
|
600
|
-
if (
|
658
|
+
if (
|
659
|
+
moduleRuntime.has(/** @type {string} */ (runtime))
|
660
|
+
)
|
661
|
+
return;
|
601
662
|
}
|
602
663
|
}
|
603
|
-
hotUpdateMainContentByRuntime
|
604
|
-
|
605
|
-
|
664
|
+
const item = hotUpdateMainContentByRuntime.get(
|
665
|
+
/** @type {string} */ (runtime)
|
666
|
+
);
|
667
|
+
item.removedModules.add(module);
|
606
668
|
});
|
607
669
|
}
|
608
670
|
}
|
@@ -676,9 +738,10 @@ class HotModuleReplacementPlugin {
|
|
676
738
|
}
|
677
739
|
}
|
678
740
|
forEachRuntime(newRuntime, runtime => {
|
679
|
-
hotUpdateMainContentByRuntime
|
680
|
-
|
681
|
-
|
741
|
+
const item = hotUpdateMainContentByRuntime.get(
|
742
|
+
/** @type {string} */ (runtime)
|
743
|
+
);
|
744
|
+
item.updatedChunkIds.add(/** @type {ChunkId} */ (chunkId));
|
682
745
|
});
|
683
746
|
}
|
684
747
|
}
|
package/lib/IgnorePlugin.js
CHANGED
package/lib/InitFragment.js
CHANGED
@@ -40,7 +40,7 @@ const sortFragmentWithIndex = ([a, i], [b, j]) => {
|
|
40
40
|
*/
|
41
41
|
class InitFragment {
|
42
42
|
/**
|
43
|
-
* @param {string | Source} content the source code that will be included as initialization code
|
43
|
+
* @param {string | Source | undefined} content the source code that will be included as initialization code
|
44
44
|
* @param {number} stage category of initialization code (contribute to order)
|
45
45
|
* @param {number} position position in the category (contribute to order)
|
46
46
|
* @param {string=} key unique key to avoid emitting the same initialization code twice
|
@@ -56,7 +56,7 @@ class InitFragment {
|
|
56
56
|
|
57
57
|
/**
|
58
58
|
* @param {GenerateContext} context context
|
59
|
-
* @returns {string | Source} the source code that will be included as initialization code
|
59
|
+
* @returns {string | Source | undefined} the source code that will be included as initialization code
|
60
60
|
*/
|
61
61
|
getContent(context) {
|
62
62
|
return this.content;
|
@@ -171,7 +171,9 @@ class InitFragment {
|
|
171
171
|
|
172
172
|
makeSerializable(InitFragment, "webpack/lib/InitFragment");
|
173
173
|
|
174
|
-
InitFragment.prototype.merge =
|
174
|
+
InitFragment.prototype.merge =
|
175
|
+
/** @type {TODO} */
|
176
|
+
(undefined);
|
175
177
|
|
176
178
|
InitFragment.STAGE_CONSTANTS = 10;
|
177
179
|
InitFragment.STAGE_ASYNC_BOUNDARY = 20;
|
package/lib/LibManifestPlugin.js
CHANGED
@@ -12,17 +12,18 @@ const { compareModulesById } = require("./util/comparators");
|
|
12
12
|
const { dirname, mkdirp } = require("./util/fs");
|
13
13
|
|
14
14
|
/** @typedef {import("./Compiler")} Compiler */
|
15
|
+
/** @typedef {import("./Compiler").IntermediateFileSystem} IntermediateFileSystem */
|
15
16
|
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
16
17
|
|
17
18
|
/**
|
18
|
-
* @typedef {
|
19
|
+
* @typedef {object} ManifestModuleData
|
19
20
|
* @property {string | number} id
|
20
21
|
* @property {BuildMeta} buildMeta
|
21
22
|
* @property {boolean | string[] | undefined} exports
|
22
23
|
*/
|
23
24
|
|
24
25
|
/**
|
25
|
-
* @typedef {
|
26
|
+
* @typedef {object} LibManifestPluginOptions
|
26
27
|
* @property {string=} context Context of requests in the manifest file (defaults to the webpack context).
|
27
28
|
* @property {boolean=} entryOnly If true, only entry points will be exposed (default: true).
|
28
29
|
* @property {boolean=} format If true, manifest json file (output) will be formatted.
|
@@ -52,6 +53,8 @@ class LibManifestPlugin {
|
|
52
53
|
},
|
53
54
|
(compilation, callback) => {
|
54
55
|
const moduleGraph = compilation.moduleGraph;
|
56
|
+
// store used paths to detect issue and output an error. #18200
|
57
|
+
const usedPaths = new Set();
|
55
58
|
asyncLib.forEach(
|
56
59
|
Array.from(compilation.chunks),
|
57
60
|
(chunk, callback) => {
|
@@ -63,6 +66,11 @@ class LibManifestPlugin {
|
|
63
66
|
const targetPath = compilation.getPath(this.options.path, {
|
64
67
|
chunk
|
65
68
|
});
|
69
|
+
if (usedPaths.has(targetPath)) {
|
70
|
+
callback(new Error(`each chunk must have a unique path`));
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
usedPaths.add(targetPath);
|
66
74
|
const name =
|
67
75
|
this.options.name &&
|
68
76
|
compilation.getPath(this.options.name, {
|
@@ -113,16 +121,16 @@ class LibManifestPlugin {
|
|
113
121
|
? JSON.stringify(manifest, null, 2)
|
114
122
|
: JSON.stringify(manifest);
|
115
123
|
const buffer = Buffer.from(manifestContent, "utf8");
|
124
|
+
const intermediateFileSystem =
|
125
|
+
/** @type {IntermediateFileSystem} */ (
|
126
|
+
compiler.intermediateFileSystem
|
127
|
+
);
|
116
128
|
mkdirp(
|
117
|
-
|
118
|
-
dirname(
|
129
|
+
intermediateFileSystem,
|
130
|
+
dirname(intermediateFileSystem, targetPath),
|
119
131
|
err => {
|
120
132
|
if (err) return callback(err);
|
121
|
-
|
122
|
-
targetPath,
|
123
|
-
buffer,
|
124
|
-
callback
|
125
|
-
);
|
133
|
+
intermediateFileSystem.writeFile(targetPath, buffer, callback);
|
126
134
|
}
|
127
135
|
);
|
128
136
|
},
|
package/lib/Module.js
CHANGED
@@ -45,7 +45,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
45
45
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
46
46
|
|
47
47
|
/**
|
48
|
-
* @typedef {
|
48
|
+
* @typedef {object} SourceContext
|
49
49
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
50
50
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
51
51
|
* @property {ModuleGraph} moduleGraph the module graph
|
@@ -56,41 +56,43 @@ const makeSerializable = require("./util/makeSerializable");
|
|
56
56
|
|
57
57
|
// TODO webpack 6: compilation will be required in CodeGenerationContext
|
58
58
|
/**
|
59
|
-
* @typedef {
|
59
|
+
* @typedef {object} CodeGenerationContext
|
60
60
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
61
61
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
62
62
|
* @property {ModuleGraph} moduleGraph the module graph
|
63
63
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
64
|
-
* @property {RuntimeSpec} runtime the
|
65
|
-
* @property {RuntimeSpec[]} [runtimes] the runtimes code should be generated for
|
64
|
+
* @property {RuntimeSpec} runtime the runtimes code should be generated for
|
66
65
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
67
|
-
* @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
66
|
+
* @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
68
67
|
* @property {Compilation=} compilation the compilation
|
69
68
|
* @property {ReadonlySet<string>=} sourceTypes source types
|
70
69
|
*/
|
71
70
|
|
72
71
|
/**
|
73
|
-
* @typedef {
|
72
|
+
* @typedef {object} ConcatenationBailoutReasonContext
|
74
73
|
* @property {ModuleGraph} moduleGraph the module graph
|
75
74
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
76
75
|
*/
|
77
76
|
|
77
|
+
/** @typedef {Set<string>} RuntimeRequirements */
|
78
|
+
/** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
|
79
|
+
|
78
80
|
/**
|
79
|
-
* @typedef {
|
81
|
+
* @typedef {object} CodeGenerationResult
|
80
82
|
* @property {Map<string, Source>} sources the resulting sources for all source types
|
81
83
|
* @property {Map<string, any>=} data the resulting data for all source types
|
82
|
-
* @property {
|
84
|
+
* @property {ReadOnlyRuntimeRequirements} runtimeRequirements the runtime requirements
|
83
85
|
* @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
|
84
86
|
*/
|
85
87
|
|
86
88
|
/**
|
87
|
-
* @typedef {
|
89
|
+
* @typedef {object} LibIdentOptions
|
88
90
|
* @property {string} context absolute context path to which lib ident is relative to
|
89
|
-
* @property {
|
91
|
+
* @property {object=} associatedObjectForCache object for caching
|
90
92
|
*/
|
91
93
|
|
92
94
|
/**
|
93
|
-
* @typedef {
|
95
|
+
* @typedef {object} KnownBuildMeta
|
94
96
|
* @property {string=} moduleArgument
|
95
97
|
* @property {string=} exportsArgument
|
96
98
|
* @property {boolean=} strict
|
@@ -103,7 +105,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
103
105
|
*/
|
104
106
|
|
105
107
|
/**
|
106
|
-
* @typedef {
|
108
|
+
* @typedef {object} KnownBuildInfo
|
107
109
|
* @property {boolean=} cacheable
|
108
110
|
* @property {boolean=} parsed
|
109
111
|
* @property {LazySet<string>=} fileDependencies
|
@@ -118,7 +120,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
118
120
|
*/
|
119
121
|
|
120
122
|
/**
|
121
|
-
* @typedef {
|
123
|
+
* @typedef {object} NeedBuildContext
|
122
124
|
* @property {Compilation} compilation
|
123
125
|
* @property {FileSystemInfo} fileSystemInfo
|
124
126
|
* @property {Map<string, string | Set<string>>} valueCacheVersions
|
@@ -128,7 +130,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
128
130
|
/** @typedef {KnownBuildInfo & Record<string, any>} BuildInfo */
|
129
131
|
|
130
132
|
/**
|
131
|
-
* @typedef {
|
133
|
+
* @typedef {object} FactoryMeta
|
132
134
|
* @property {boolean=} sideEffectFree
|
133
135
|
*/
|
134
136
|
|
@@ -270,6 +272,9 @@ class Module extends DependenciesBlock {
|
|
270
272
|
).setProfile(this, value);
|
271
273
|
}
|
272
274
|
|
275
|
+
/**
|
276
|
+
* @returns {number | null} the pre order index
|
277
|
+
*/
|
273
278
|
get index() {
|
274
279
|
return ModuleGraph.getModuleGraphForModule(
|
275
280
|
this,
|
@@ -278,6 +283,9 @@ class Module extends DependenciesBlock {
|
|
278
283
|
).getPreOrderIndex(this);
|
279
284
|
}
|
280
285
|
|
286
|
+
/**
|
287
|
+
* @param {number} value the pre order index
|
288
|
+
*/
|
281
289
|
set index(value) {
|
282
290
|
ModuleGraph.getModuleGraphForModule(
|
283
291
|
this,
|
@@ -286,6 +294,9 @@ class Module extends DependenciesBlock {
|
|
286
294
|
).setPreOrderIndex(this, value);
|
287
295
|
}
|
288
296
|
|
297
|
+
/**
|
298
|
+
* @returns {number | null} the post order index
|
299
|
+
*/
|
289
300
|
get index2() {
|
290
301
|
return ModuleGraph.getModuleGraphForModule(
|
291
302
|
this,
|
@@ -294,6 +305,9 @@ class Module extends DependenciesBlock {
|
|
294
305
|
).getPostOrderIndex(this);
|
295
306
|
}
|
296
307
|
|
308
|
+
/**
|
309
|
+
* @param {number} value the post order index
|
310
|
+
*/
|
297
311
|
set index2(value) {
|
298
312
|
ModuleGraph.getModuleGraphForModule(
|
299
313
|
this,
|
@@ -302,6 +316,9 @@ class Module extends DependenciesBlock {
|
|
302
316
|
).setPostOrderIndex(this, value);
|
303
317
|
}
|
304
318
|
|
319
|
+
/**
|
320
|
+
* @returns {number | null} the depth
|
321
|
+
*/
|
305
322
|
get depth() {
|
306
323
|
return ModuleGraph.getModuleGraphForModule(
|
307
324
|
this,
|
@@ -310,6 +327,9 @@ class Module extends DependenciesBlock {
|
|
310
327
|
).getDepth(this);
|
311
328
|
}
|
312
329
|
|
330
|
+
/**
|
331
|
+
* @param {number} value the depth
|
332
|
+
*/
|
313
333
|
set depth(value) {
|
314
334
|
ModuleGraph.getModuleGraphForModule(
|
315
335
|
this,
|
@@ -318,6 +338,9 @@ class Module extends DependenciesBlock {
|
|
318
338
|
).setDepth(this, value);
|
319
339
|
}
|
320
340
|
|
341
|
+
/**
|
342
|
+
* @returns {Module | null | undefined} issuer
|
343
|
+
*/
|
321
344
|
get issuer() {
|
322
345
|
return ModuleGraph.getModuleGraphForModule(
|
323
346
|
this,
|
@@ -326,6 +349,9 @@ class Module extends DependenciesBlock {
|
|
326
349
|
).getIssuer(this);
|
327
350
|
}
|
328
351
|
|
352
|
+
/**
|
353
|
+
* @param {Module | null} value issuer
|
354
|
+
*/
|
329
355
|
set issuer(value) {
|
330
356
|
ModuleGraph.getModuleGraphForModule(
|
331
357
|
this,
|
@@ -872,6 +898,7 @@ class Module extends DependenciesBlock {
|
|
872
898
|
codeGenerationResults: undefined
|
873
899
|
};
|
874
900
|
const sources = this.codeGeneration(codeGenContext).sources;
|
901
|
+
|
875
902
|
return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
|
876
903
|
}
|
877
904
|
|
package/lib/ModuleFactory.js
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
/** @typedef {import("./Module")} Module */
|
11
11
|
|
12
12
|
/**
|
13
|
-
* @typedef {
|
13
|
+
* @typedef {object} ModuleFactoryResult
|
14
14
|
* @property {Module=} module the created module or unset if no module was created
|
15
15
|
* @property {Set<string>=} fileDependencies
|
16
16
|
* @property {Set<string>=} contextDependencies
|
@@ -19,14 +19,14 @@
|
|
19
19
|
*/
|
20
20
|
|
21
21
|
/**
|
22
|
-
* @typedef {
|
22
|
+
* @typedef {object} ModuleFactoryCreateDataContextInfo
|
23
23
|
* @property {string} issuer
|
24
24
|
* @property {string | null=} issuerLayer
|
25
25
|
* @property {string} compiler
|
26
26
|
*/
|
27
27
|
|
28
28
|
/**
|
29
|
-
* @typedef {
|
29
|
+
* @typedef {object} ModuleFactoryCreateData
|
30
30
|
* @property {ModuleFactoryCreateDataContextInfo} contextInfo
|
31
31
|
* @property {ResolveOptions=} resolveOptions
|
32
32
|
* @property {string} context
|