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
package/lib/Compiler.js
CHANGED
@@ -40,21 +40,33 @@ const { isSourceEqual } = require("./util/source");
|
|
40
40
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
41
41
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
42
42
|
/** @typedef {import("./Chunk")} Chunk */
|
43
|
+
/** @typedef {import("./Compilation").References} References */
|
43
44
|
/** @typedef {import("./Dependency")} Dependency */
|
44
45
|
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
45
46
|
/** @typedef {import("./Module")} Module */
|
47
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
48
|
+
/** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
|
49
|
+
/** @typedef {import("./logging/createConsoleLogger").LoggingFunction} LoggingFunction */
|
46
50
|
/** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
|
51
|
+
/** @typedef {import("./util/fs").IStats} IStats */
|
47
52
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
48
53
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
49
54
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
50
55
|
/** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
|
51
56
|
|
52
57
|
/**
|
53
|
-
* @typedef {
|
58
|
+
* @typedef {object} CompilationParams
|
54
59
|
* @property {NormalModuleFactory} normalModuleFactory
|
55
60
|
* @property {ContextModuleFactory} contextModuleFactory
|
56
61
|
*/
|
57
62
|
|
63
|
+
/**
|
64
|
+
* @template T
|
65
|
+
* @callback RunCallback
|
66
|
+
* @param {Error | null} err
|
67
|
+
* @param {T=} result
|
68
|
+
*/
|
69
|
+
|
58
70
|
/**
|
59
71
|
* @template T
|
60
72
|
* @callback Callback
|
@@ -64,13 +76,13 @@ const { isSourceEqual } = require("./util/source");
|
|
64
76
|
|
65
77
|
/**
|
66
78
|
* @callback RunAsChildCallback
|
67
|
-
* @param {
|
79
|
+
* @param {Error | null} err
|
68
80
|
* @param {Chunk[]=} entries
|
69
81
|
* @param {Compilation=} compilation
|
70
82
|
*/
|
71
83
|
|
72
84
|
/**
|
73
|
-
* @typedef {
|
85
|
+
* @typedef {object} AssetEmittedInfo
|
74
86
|
* @property {Buffer} content
|
75
87
|
* @property {Source} source
|
76
88
|
* @property {Compilation} compilation
|
@@ -78,6 +90,9 @@ const { isSourceEqual } = require("./util/source");
|
|
78
90
|
* @property {string} targetPath
|
79
91
|
*/
|
80
92
|
|
93
|
+
/** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */
|
94
|
+
/** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: any, file: string }[] | undefined) }} SimilarEntry */
|
95
|
+
|
81
96
|
/**
|
82
97
|
* @param {string[]} array an array
|
83
98
|
* @returns {boolean} true, if the array is sorted
|
@@ -90,11 +105,12 @@ const isSorted = array => {
|
|
90
105
|
};
|
91
106
|
|
92
107
|
/**
|
93
|
-
* @param {
|
108
|
+
* @param {{[key: string]: any}} obj an object
|
94
109
|
* @param {string[]} keys the keys of the object
|
95
|
-
* @returns {
|
110
|
+
* @returns {{[key: string]: any}} the object with properties sorted by property name
|
96
111
|
*/
|
97
112
|
const sortObject = (obj, keys) => {
|
113
|
+
/** @type {{[key: string]: any}} */
|
98
114
|
const o = {};
|
99
115
|
for (const k of keys.sort()) {
|
100
116
|
o[k] = obj[k];
|
@@ -200,9 +216,9 @@ class Compiler {
|
|
200
216
|
|
201
217
|
this.webpack = webpack;
|
202
218
|
|
203
|
-
/** @type {string
|
219
|
+
/** @type {string | undefined} */
|
204
220
|
this.name = undefined;
|
205
|
-
/** @type {Compilation
|
221
|
+
/** @type {Compilation | undefined} */
|
206
222
|
this.parentCompilation = undefined;
|
207
223
|
/** @type {Compiler} */
|
208
224
|
this.root = this;
|
@@ -211,19 +227,20 @@ class Compiler {
|
|
211
227
|
/** @type {Watching | undefined} */
|
212
228
|
this.watching = undefined;
|
213
229
|
|
214
|
-
/** @type {OutputFileSystem} */
|
230
|
+
/** @type {OutputFileSystem | null} */
|
215
231
|
this.outputFileSystem = null;
|
216
|
-
/** @type {IntermediateFileSystem} */
|
232
|
+
/** @type {IntermediateFileSystem | null} */
|
217
233
|
this.intermediateFileSystem = null;
|
218
|
-
/** @type {InputFileSystem} */
|
234
|
+
/** @type {InputFileSystem | null} */
|
219
235
|
this.inputFileSystem = null;
|
220
|
-
/** @type {WatchFileSystem} */
|
236
|
+
/** @type {WatchFileSystem | null} */
|
221
237
|
this.watchFileSystem = null;
|
222
238
|
|
223
239
|
/** @type {string|null} */
|
224
240
|
this.recordsInputPath = null;
|
225
241
|
/** @type {string|null} */
|
226
242
|
this.recordsOutputPath = null;
|
243
|
+
/** @type {Record<string, TODO>} */
|
227
244
|
this.records = {};
|
228
245
|
/** @type {Set<string | RegExp>} */
|
229
246
|
this.managedPaths = new Set();
|
@@ -246,8 +263,19 @@ class Compiler {
|
|
246
263
|
/** @type {ResolverFactory} */
|
247
264
|
this.resolverFactory = new ResolverFactory();
|
248
265
|
|
266
|
+
/** @type {LoggingFunction | undefined} */
|
249
267
|
this.infrastructureLogger = undefined;
|
250
268
|
|
269
|
+
/** @type {Readonly<PlatformTargetProperties>} */
|
270
|
+
this.platform = {
|
271
|
+
web: null,
|
272
|
+
browser: null,
|
273
|
+
webworker: null,
|
274
|
+
node: null,
|
275
|
+
nwjs: null,
|
276
|
+
electron: null
|
277
|
+
};
|
278
|
+
|
251
279
|
this.options = options;
|
252
280
|
|
253
281
|
this.context = context;
|
@@ -256,7 +284,7 @@ class Compiler {
|
|
256
284
|
|
257
285
|
this.cache = new Cache();
|
258
286
|
|
259
|
-
/** @type {Map<Module, { buildInfo:
|
287
|
+
/** @type {Map<Module, { buildInfo: BuildInfo, references: References | undefined, memCache: WeakTupleMap }> | undefined} */
|
260
288
|
this.moduleMemCaches = undefined;
|
261
289
|
|
262
290
|
this.compilerPath = "";
|
@@ -272,16 +300,25 @@ class Compiler {
|
|
272
300
|
|
273
301
|
this._backCompat = this.options.experiments.backCompat !== false;
|
274
302
|
|
275
|
-
/** @type {Compilation} */
|
303
|
+
/** @type {Compilation | undefined} */
|
276
304
|
this._lastCompilation = undefined;
|
277
|
-
/** @type {NormalModuleFactory} */
|
305
|
+
/** @type {NormalModuleFactory | undefined} */
|
278
306
|
this._lastNormalModuleFactory = undefined;
|
279
307
|
|
280
|
-
/**
|
308
|
+
/**
|
309
|
+
* @private
|
310
|
+
* @type {WeakMap<Source, CacheEntry>}
|
311
|
+
*/
|
281
312
|
this._assetEmittingSourceCache = new WeakMap();
|
282
|
-
/**
|
313
|
+
/**
|
314
|
+
* @private
|
315
|
+
* @type {Map<string, number>}
|
316
|
+
*/
|
283
317
|
this._assetEmittingWrittenFiles = new Map();
|
284
|
-
/**
|
318
|
+
/**
|
319
|
+
* @private
|
320
|
+
* @type {Set<string>}
|
321
|
+
*/
|
285
322
|
this._assetEmittingPreviousFiles = new Set();
|
286
323
|
}
|
287
324
|
|
@@ -416,7 +453,7 @@ class Compiler {
|
|
416
453
|
|
417
454
|
/**
|
418
455
|
* @param {WatchOptions} watchOptions the watcher's options
|
419
|
-
* @param {
|
456
|
+
* @param {RunCallback<Stats>} handler signals when the call finishes
|
420
457
|
* @returns {Watching} a compiler watcher
|
421
458
|
*/
|
422
459
|
watch(watchOptions, handler) {
|
@@ -431,7 +468,7 @@ class Compiler {
|
|
431
468
|
}
|
432
469
|
|
433
470
|
/**
|
434
|
-
* @param {
|
471
|
+
* @param {RunCallback<Stats>} callback signals when the call finishes
|
435
472
|
* @returns {void}
|
436
473
|
*/
|
437
474
|
run(callback) {
|
@@ -439,8 +476,13 @@ class Compiler {
|
|
439
476
|
return callback(new ConcurrentCompilationError());
|
440
477
|
}
|
441
478
|
|
479
|
+
/** @type {Logger | undefined} */
|
442
480
|
let logger;
|
443
481
|
|
482
|
+
/**
|
483
|
+
* @param {Error | null} err error
|
484
|
+
* @param {Stats=} stats stats
|
485
|
+
*/
|
444
486
|
const finalCallback = (err, stats) => {
|
445
487
|
if (logger) logger.time("beginIdle");
|
446
488
|
this.idle = true;
|
@@ -452,16 +494,23 @@ class Compiler {
|
|
452
494
|
this.hooks.failed.call(err);
|
453
495
|
}
|
454
496
|
if (callback !== undefined) callback(err, stats);
|
455
|
-
this.hooks.afterDone.call(stats);
|
497
|
+
this.hooks.afterDone.call(/** @type {Stats} */ (stats));
|
456
498
|
};
|
457
499
|
|
458
500
|
const startTime = Date.now();
|
459
501
|
|
460
502
|
this.running = true;
|
461
503
|
|
462
|
-
|
504
|
+
/**
|
505
|
+
* @param {Error | null} err error
|
506
|
+
* @param {Compilation=} _compilation compilation
|
507
|
+
* @returns {void}
|
508
|
+
*/
|
509
|
+
const onCompiled = (err, _compilation) => {
|
463
510
|
if (err) return finalCallback(err);
|
464
511
|
|
512
|
+
const compilation = /** @type {Compilation} */ (_compilation);
|
513
|
+
|
465
514
|
if (this.hooks.shouldEmit.call(compilation) === false) {
|
466
515
|
compilation.startTime = startTime;
|
467
516
|
compilation.endTime = Date.now();
|
@@ -477,7 +526,8 @@ class Compiler {
|
|
477
526
|
logger = compilation.getLogger("webpack.Compiler");
|
478
527
|
logger.time("emitAssets");
|
479
528
|
this.emitAssets(compilation, err => {
|
480
|
-
|
529
|
+
/** @type {Logger} */
|
530
|
+
(logger).timeEnd("emitAssets");
|
481
531
|
if (err) return finalCallback(err);
|
482
532
|
|
483
533
|
if (compilation.hooks.needAdditionalPass.call()) {
|
@@ -485,10 +535,12 @@ class Compiler {
|
|
485
535
|
|
486
536
|
compilation.startTime = startTime;
|
487
537
|
compilation.endTime = Date.now();
|
488
|
-
|
538
|
+
/** @type {Logger} */
|
539
|
+
(logger).time("done hook");
|
489
540
|
const stats = new Stats(compilation);
|
490
541
|
this.hooks.done.callAsync(stats, err => {
|
491
|
-
|
542
|
+
/** @type {Logger} */
|
543
|
+
(logger).timeEnd("done hook");
|
492
544
|
if (err) return finalCallback(err);
|
493
545
|
|
494
546
|
this.hooks.additionalPass.callAsync(err => {
|
@@ -499,17 +551,21 @@ class Compiler {
|
|
499
551
|
return;
|
500
552
|
}
|
501
553
|
|
502
|
-
|
554
|
+
/** @type {Logger} */
|
555
|
+
(logger).time("emitRecords");
|
503
556
|
this.emitRecords(err => {
|
504
|
-
|
557
|
+
/** @type {Logger} */
|
558
|
+
(logger).timeEnd("emitRecords");
|
505
559
|
if (err) return finalCallback(err);
|
506
560
|
|
507
561
|
compilation.startTime = startTime;
|
508
562
|
compilation.endTime = Date.now();
|
509
|
-
|
563
|
+
/** @type {Logger} */
|
564
|
+
(logger).time("done hook");
|
510
565
|
const stats = new Stats(compilation);
|
511
566
|
this.hooks.done.callAsync(stats, err => {
|
512
|
-
|
567
|
+
/** @type {Logger} */
|
568
|
+
(logger).timeEnd("done hook");
|
513
569
|
if (err) return finalCallback(err);
|
514
570
|
this.cache.storeBuildDependencies(
|
515
571
|
compilation.buildDependencies,
|
@@ -559,6 +615,11 @@ class Compiler {
|
|
559
615
|
runAsChild(callback) {
|
560
616
|
const startTime = Date.now();
|
561
617
|
|
618
|
+
/**
|
619
|
+
* @param {Error | null} err error
|
620
|
+
* @param {Chunk[]=} entries entries
|
621
|
+
* @param {Compilation=} compilation compilation
|
622
|
+
*/
|
562
623
|
const finalCallback = (err, entries, compilation) => {
|
563
624
|
try {
|
564
625
|
callback(err, entries, compilation);
|
@@ -566,20 +627,29 @@ class Compiler {
|
|
566
627
|
const err = new WebpackError(
|
567
628
|
`compiler.runAsChild callback error: ${e}`
|
568
629
|
);
|
569
|
-
err.details = e.stack;
|
570
|
-
|
630
|
+
err.details = /** @type {Error} */ (e).stack;
|
631
|
+
/** @type {Compilation} */
|
632
|
+
(this.parentCompilation).errors.push(err);
|
571
633
|
}
|
572
634
|
};
|
573
635
|
|
574
|
-
this.compile((err,
|
636
|
+
this.compile((err, _compilation) => {
|
575
637
|
if (err) return finalCallback(err);
|
576
638
|
|
577
|
-
|
639
|
+
const compilation = /** @type {Compilation} */ (_compilation);
|
640
|
+
const parentCompilation = /** @type {Compilation} */ (
|
641
|
+
this.parentCompilation
|
642
|
+
);
|
643
|
+
|
644
|
+
parentCompilation.children.push(compilation);
|
645
|
+
|
578
646
|
for (const { name, source, info } of compilation.getAssets()) {
|
579
|
-
|
647
|
+
parentCompilation.emitAsset(name, source, info);
|
580
648
|
}
|
581
649
|
|
650
|
+
/** @type {Chunk[]} */
|
582
651
|
const entries = [];
|
652
|
+
|
583
653
|
for (const ep of compilation.entrypoints.values()) {
|
584
654
|
entries.push(...ep.chunks);
|
585
655
|
}
|
@@ -603,14 +673,19 @@ class Compiler {
|
|
603
673
|
* @returns {void}
|
604
674
|
*/
|
605
675
|
emitAssets(compilation, callback) {
|
676
|
+
/** @type {string} */
|
606
677
|
let outputPath;
|
607
678
|
|
679
|
+
/**
|
680
|
+
* @param {Error=} err error
|
681
|
+
* @returns {void}
|
682
|
+
*/
|
608
683
|
const emitFiles = err => {
|
609
684
|
if (err) return callback(err);
|
610
685
|
|
611
686
|
const assets = compilation.getAssets();
|
612
687
|
compilation.assets = { ...compilation.assets };
|
613
|
-
/** @type {Map<string,
|
688
|
+
/** @type {Map<string, SimilarEntry>} */
|
614
689
|
const caseInsensitiveMap = new Map();
|
615
690
|
/** @type {Set<string>} */
|
616
691
|
const allTargetPaths = new Set();
|
@@ -634,10 +709,15 @@ class Compiler {
|
|
634
709
|
includesHash(targetFile, info.fullhash));
|
635
710
|
}
|
636
711
|
|
712
|
+
/**
|
713
|
+
* @param {Error=} err error
|
714
|
+
* @returns {void}
|
715
|
+
*/
|
637
716
|
const writeOut = err => {
|
638
717
|
if (err) return callback(err);
|
639
718
|
const targetPath = join(
|
640
|
-
|
719
|
+
/** @type {OutputFileSystem} */
|
720
|
+
(this.outputFileSystem),
|
641
721
|
outputPath,
|
642
722
|
targetFile
|
643
723
|
);
|
@@ -657,6 +737,7 @@ class Compiler {
|
|
657
737
|
this._assetEmittingSourceCache.set(source, cacheEntry);
|
658
738
|
}
|
659
739
|
|
740
|
+
/** @type {SimilarEntry | undefined} */
|
660
741
|
let similarEntry;
|
661
742
|
|
662
743
|
const checkSimilarFile = () => {
|
@@ -687,12 +768,12 @@ ${other}`);
|
|
687
768
|
} else {
|
688
769
|
caseInsensitiveMap.set(
|
689
770
|
caseInsensitiveTargetPath,
|
690
|
-
(similarEntry = {
|
771
|
+
(similarEntry = /** @type {SimilarEntry} */ ({
|
691
772
|
path: targetPath,
|
692
773
|
source,
|
693
774
|
size: undefined,
|
694
775
|
waiting: undefined
|
695
|
-
})
|
776
|
+
}))
|
696
777
|
);
|
697
778
|
return false;
|
698
779
|
}
|
@@ -720,9 +801,11 @@ ${other}`);
|
|
720
801
|
if (targetFileGeneration === undefined) {
|
721
802
|
const newGeneration = 1;
|
722
803
|
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
|
723
|
-
|
804
|
+
/** @type {CacheEntry} */
|
805
|
+
(cacheEntry).writtenTo.set(targetPath, newGeneration);
|
724
806
|
} else {
|
725
|
-
|
807
|
+
/** @type {CacheEntry} */
|
808
|
+
(cacheEntry).writtenTo.set(targetPath, targetFileGeneration);
|
726
809
|
}
|
727
810
|
callback();
|
728
811
|
};
|
@@ -733,7 +816,8 @@ ${other}`);
|
|
733
816
|
* @returns {void}
|
734
817
|
*/
|
735
818
|
const doWrite = content => {
|
736
|
-
|
819
|
+
/** @type {OutputFileSystem} */
|
820
|
+
(this.outputFileSystem).writeFile(targetPath, content, err => {
|
737
821
|
if (err) return callback(err);
|
738
822
|
|
739
823
|
// information marker that the asset has been emitted
|
@@ -744,7 +828,8 @@ ${other}`);
|
|
744
828
|
targetFileGeneration === undefined
|
745
829
|
? 1
|
746
830
|
: targetFileGeneration + 1;
|
747
|
-
|
831
|
+
/** @type {CacheEntry} */
|
832
|
+
(cacheEntry).writtenTo.set(targetPath, newGeneration);
|
748
833
|
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
|
749
834
|
this.hooks.assetEmitted.callAsync(
|
750
835
|
file,
|
@@ -760,16 +845,33 @@ ${other}`);
|
|
760
845
|
});
|
761
846
|
};
|
762
847
|
|
848
|
+
/**
|
849
|
+
* @param {number} size size
|
850
|
+
*/
|
763
851
|
const updateWithReplacementSource = size => {
|
764
|
-
updateFileWithReplacementSource(
|
765
|
-
|
766
|
-
|
767
|
-
|
852
|
+
updateFileWithReplacementSource(
|
853
|
+
file,
|
854
|
+
/** @type {CacheEntry} */ (cacheEntry),
|
855
|
+
size
|
856
|
+
);
|
857
|
+
/** @type {SimilarEntry} */
|
858
|
+
(similarEntry).size = size;
|
859
|
+
if (
|
860
|
+
/** @type {SimilarEntry} */ (similarEntry).waiting !== undefined
|
861
|
+
) {
|
862
|
+
for (const { file, cacheEntry } of /** @type {SimilarEntry} */ (
|
863
|
+
similarEntry
|
864
|
+
).waiting) {
|
768
865
|
updateFileWithReplacementSource(file, cacheEntry, size);
|
769
866
|
}
|
770
867
|
}
|
771
868
|
};
|
772
869
|
|
870
|
+
/**
|
871
|
+
* @param {string} file file
|
872
|
+
* @param {CacheEntry} cacheEntry cache entry
|
873
|
+
* @param {number} size size
|
874
|
+
*/
|
773
875
|
const updateFileWithReplacementSource = (
|
774
876
|
file,
|
775
877
|
cacheEntry,
|
@@ -786,10 +888,14 @@ ${other}`);
|
|
786
888
|
});
|
787
889
|
};
|
788
890
|
|
891
|
+
/**
|
892
|
+
* @param {IStats} stats stats
|
893
|
+
* @returns {void}
|
894
|
+
*/
|
789
895
|
const processExistingFile = stats => {
|
790
896
|
// skip emitting if it's already there and an immutable file
|
791
897
|
if (immutable) {
|
792
|
-
updateWithReplacementSource(stats.size);
|
898
|
+
updateWithReplacementSource(/** @type {number} */ (stats.size));
|
793
899
|
return alreadyWritten();
|
794
900
|
}
|
795
901
|
|
@@ -803,19 +909,18 @@ ${other}`);
|
|
803
909
|
// for a fast negative match file size is compared first
|
804
910
|
if (content.length === stats.size) {
|
805
911
|
compilation.comparedForEmitAssets.add(file);
|
806
|
-
return
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
}
|
912
|
+
return /** @type {OutputFileSystem} */ (
|
913
|
+
this.outputFileSystem
|
914
|
+
).readFile(targetPath, (err, existingContent) => {
|
915
|
+
if (
|
916
|
+
err ||
|
917
|
+
!content.equals(/** @type {Buffer} */ (existingContent))
|
918
|
+
) {
|
919
|
+
return doWrite(content);
|
920
|
+
} else {
|
921
|
+
return alreadyWritten();
|
817
922
|
}
|
818
|
-
);
|
923
|
+
});
|
819
924
|
}
|
820
925
|
|
821
926
|
return doWrite(content);
|
@@ -832,16 +937,22 @@ ${other}`);
|
|
832
937
|
// if the target file has already been written
|
833
938
|
if (targetFileGeneration !== undefined) {
|
834
939
|
// check if the Source has been written to this target file
|
835
|
-
const writtenGeneration =
|
940
|
+
const writtenGeneration = /** @type {CacheEntry} */ (
|
941
|
+
cacheEntry
|
942
|
+
).writtenTo.get(targetPath);
|
836
943
|
if (writtenGeneration === targetFileGeneration) {
|
837
944
|
// if yes, we may skip writing the file
|
838
945
|
// if it's already there
|
839
946
|
// (we assume one doesn't modify files while the Compiler is running, other then removing them)
|
840
947
|
|
841
948
|
if (this._assetEmittingPreviousFiles.has(targetPath)) {
|
949
|
+
const sizeOnlySource = /** @type {SizeOnlySource} */ (
|
950
|
+
/** @type {CacheEntry} */ (cacheEntry).sizeOnlySource
|
951
|
+
);
|
952
|
+
|
842
953
|
// We assume that assets from the last compilation say intact on disk (they are not removed)
|
843
|
-
compilation.updateAsset(file,
|
844
|
-
size:
|
954
|
+
compilation.updateAsset(file, sizeOnlySource, {
|
955
|
+
size: sizeOnlySource.size()
|
845
956
|
});
|
846
957
|
|
847
958
|
return callback();
|
@@ -860,11 +971,12 @@ ${other}`);
|
|
860
971
|
|
861
972
|
if (checkSimilarFile()) return;
|
862
973
|
if (this.options.output.compareBeforeEmit) {
|
863
|
-
|
864
|
-
|
974
|
+
/** @type {OutputFileSystem} */
|
975
|
+
(this.outputFileSystem).stat(targetPath, (err, stats) => {
|
976
|
+
const exists = !err && /** @type {IStats} */ (stats).isFile();
|
865
977
|
|
866
978
|
if (exists) {
|
867
|
-
processExistingFile(stats);
|
979
|
+
processExistingFile(/** @type {IStats} */ (stats));
|
868
980
|
} else {
|
869
981
|
processMissingFile();
|
870
982
|
}
|
@@ -875,7 +987,7 @@ ${other}`);
|
|
875
987
|
};
|
876
988
|
|
877
989
|
if (targetFile.match(/\/|\\/)) {
|
878
|
-
const fs = this.outputFileSystem;
|
990
|
+
const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem);
|
879
991
|
const dir = dirname(fs, join(fs, outputPath, targetFile));
|
880
992
|
mkdirp(fs, dir, writeOut);
|
881
993
|
} else {
|
@@ -904,7 +1016,11 @@ ${other}`);
|
|
904
1016
|
this.hooks.emit.callAsync(compilation, err => {
|
905
1017
|
if (err) return callback(err);
|
906
1018
|
outputPath = compilation.getPath(this.outputPath, {});
|
907
|
-
mkdirp(
|
1019
|
+
mkdirp(
|
1020
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1021
|
+
outputPath,
|
1022
|
+
emitFiles
|
1023
|
+
);
|
908
1024
|
});
|
909
1025
|
}
|
910
1026
|
|
@@ -940,8 +1056,9 @@ ${other}`);
|
|
940
1056
|
*/
|
941
1057
|
_emitRecords(callback) {
|
942
1058
|
const writeFile = () => {
|
943
|
-
|
944
|
-
|
1059
|
+
/** @type {OutputFileSystem} */
|
1060
|
+
(this.outputFileSystem).writeFile(
|
1061
|
+
/** @type {string} */ (this.recordsOutputPath),
|
945
1062
|
JSON.stringify(
|
946
1063
|
this.records,
|
947
1064
|
(n, value) => {
|
@@ -964,16 +1081,20 @@ ${other}`);
|
|
964
1081
|
};
|
965
1082
|
|
966
1083
|
const recordsOutputPathDirectory = dirname(
|
967
|
-
this.outputFileSystem,
|
968
|
-
this.recordsOutputPath
|
1084
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1085
|
+
/** @type {string} */ (this.recordsOutputPath)
|
969
1086
|
);
|
970
1087
|
if (!recordsOutputPathDirectory) {
|
971
1088
|
return writeFile();
|
972
1089
|
}
|
973
|
-
mkdirp(
|
974
|
-
|
975
|
-
|
976
|
-
|
1090
|
+
mkdirp(
|
1091
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1092
|
+
recordsOutputPathDirectory,
|
1093
|
+
err => {
|
1094
|
+
if (err) return callback(err);
|
1095
|
+
writeFile();
|
1096
|
+
}
|
1097
|
+
);
|
977
1098
|
}
|
978
1099
|
|
979
1100
|
/**
|
@@ -1013,22 +1134,33 @@ ${other}`);
|
|
1013
1134
|
this.records = {};
|
1014
1135
|
return callback();
|
1015
1136
|
}
|
1016
|
-
|
1137
|
+
/** @type {InputFileSystem} */
|
1138
|
+
(this.inputFileSystem).stat(this.recordsInputPath, err => {
|
1017
1139
|
// It doesn't exist
|
1018
1140
|
// We can ignore this.
|
1019
1141
|
if (err) return callback();
|
1020
1142
|
|
1021
|
-
|
1022
|
-
|
1143
|
+
/** @type {InputFileSystem} */
|
1144
|
+
(this.inputFileSystem).readFile(
|
1145
|
+
/** @type {string} */ (this.recordsInputPath),
|
1146
|
+
(err, content) => {
|
1147
|
+
if (err) return callback(err);
|
1023
1148
|
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1149
|
+
try {
|
1150
|
+
this.records = parseJson(
|
1151
|
+
/** @type {Buffer} */ (content).toString("utf-8")
|
1152
|
+
);
|
1153
|
+
} catch (e) {
|
1154
|
+
return callback(
|
1155
|
+
new Error(
|
1156
|
+
`Cannot parse records: ${/** @type {Error} */ (e).message}`
|
1157
|
+
)
|
1158
|
+
);
|
1159
|
+
}
|
1029
1160
|
|
1030
|
-
|
1031
|
-
|
1161
|
+
return callback();
|
1162
|
+
}
|
1163
|
+
);
|
1032
1164
|
});
|
1033
1165
|
}
|
1034
1166
|
|
@@ -1122,6 +1254,10 @@ ${other}`);
|
|
1122
1254
|
return !!this.parentCompilation;
|
1123
1255
|
}
|
1124
1256
|
|
1257
|
+
/**
|
1258
|
+
* @param {CompilationParams} params the compilation parameters
|
1259
|
+
* @returns {Compilation} compilation
|
1260
|
+
*/
|
1125
1261
|
createCompilation(params) {
|
1126
1262
|
this._cleanupLastCompilation();
|
1127
1263
|
return (this._lastCompilation = new Compilation(this, params));
|
@@ -1144,7 +1280,7 @@ ${other}`);
|
|
1144
1280
|
this._cleanupLastNormalModuleFactory();
|
1145
1281
|
const normalModuleFactory = new NormalModuleFactory({
|
1146
1282
|
context: this.options.context,
|
1147
|
-
fs: this.inputFileSystem,
|
1283
|
+
fs: /** @type {InputFileSystem} */ (this.inputFileSystem),
|
1148
1284
|
resolverFactory: this.resolverFactory,
|
1149
1285
|
options: this.options.module,
|
1150
1286
|
associatedObjectForCache: this.root,
|
@@ -1170,7 +1306,7 @@ ${other}`);
|
|
1170
1306
|
}
|
1171
1307
|
|
1172
1308
|
/**
|
1173
|
-
* @param {
|
1309
|
+
* @param {RunCallback<Compilation>} callback signals when the compilation finishes
|
1174
1310
|
* @returns {void}
|
1175
1311
|
*/
|
1176
1312
|
compile(callback) {
|
@@ -1221,7 +1357,7 @@ ${other}`);
|
|
1221
1357
|
}
|
1222
1358
|
|
1223
1359
|
/**
|
1224
|
-
* @param {
|
1360
|
+
* @param {RunCallback<void>} callback signals when the compiler closes
|
1225
1361
|
* @returns {void}
|
1226
1362
|
*/
|
1227
1363
|
close(callback) {
|