webpack 5.90.2 → 5.91.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 +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +263 -94
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +4 -1
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/CssModule.js +0 -3
- package/lib/DefinePlugin.js +4 -2
- package/lib/DelegatedModule.js +2 -1
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +3 -1
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +120 -25
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +54 -5
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +61 -17
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +239 -86
- package/lib/NormalModuleFactory.js +163 -32
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +4 -2
- package/lib/ResolverFactory.js +5 -1
- package/lib/RuntimeModule.js +6 -5
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +12 -5
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +5 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +220 -392
- 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 +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +5 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +3 -2
- package/lib/container/RemoteModule.js +2 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- 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/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- 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 +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
- 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/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- 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 +6 -5
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -55
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +3 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedModule.js +2 -1
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/memoize.js +2 -0
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +11 -5
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -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 +1772 -673
package/lib/Compiler.js
CHANGED
@@ -40,10 +40,14 @@ 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("./logging/createConsoleLogger").LoggingFunction} LoggingFunction */
|
46
49
|
/** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
|
50
|
+
/** @typedef {import("./util/fs").IStats} IStats */
|
47
51
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
48
52
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
49
53
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
@@ -55,6 +59,13 @@ const { isSourceEqual } = require("./util/source");
|
|
55
59
|
* @property {ContextModuleFactory} contextModuleFactory
|
56
60
|
*/
|
57
61
|
|
62
|
+
/**
|
63
|
+
* @template T
|
64
|
+
* @callback RunCallback
|
65
|
+
* @param {Error | null} err
|
66
|
+
* @param {T=} result
|
67
|
+
*/
|
68
|
+
|
58
69
|
/**
|
59
70
|
* @template T
|
60
71
|
* @callback Callback
|
@@ -64,7 +75,7 @@ const { isSourceEqual } = require("./util/source");
|
|
64
75
|
|
65
76
|
/**
|
66
77
|
* @callback RunAsChildCallback
|
67
|
-
* @param {
|
78
|
+
* @param {Error | null} err
|
68
79
|
* @param {Chunk[]=} entries
|
69
80
|
* @param {Compilation=} compilation
|
70
81
|
*/
|
@@ -78,6 +89,9 @@ const { isSourceEqual } = require("./util/source");
|
|
78
89
|
* @property {string} targetPath
|
79
90
|
*/
|
80
91
|
|
92
|
+
/** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */
|
93
|
+
/** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: any, file: string }[] | undefined) }} SimilarEntry */
|
94
|
+
|
81
95
|
/**
|
82
96
|
* @param {string[]} array an array
|
83
97
|
* @returns {boolean} true, if the array is sorted
|
@@ -90,11 +104,12 @@ const isSorted = array => {
|
|
90
104
|
};
|
91
105
|
|
92
106
|
/**
|
93
|
-
* @param {Object} obj an object
|
107
|
+
* @param {Object<string, any>} obj an object
|
94
108
|
* @param {string[]} keys the keys of the object
|
95
|
-
* @returns {Object} the object with properties sorted by property name
|
109
|
+
* @returns {Object<string, any>} the object with properties sorted by property name
|
96
110
|
*/
|
97
111
|
const sortObject = (obj, keys) => {
|
112
|
+
/** @type {Object<string, any>} */
|
98
113
|
const o = {};
|
99
114
|
for (const k of keys.sort()) {
|
100
115
|
o[k] = obj[k];
|
@@ -200,9 +215,9 @@ class Compiler {
|
|
200
215
|
|
201
216
|
this.webpack = webpack;
|
202
217
|
|
203
|
-
/** @type {string
|
218
|
+
/** @type {string | undefined} */
|
204
219
|
this.name = undefined;
|
205
|
-
/** @type {Compilation
|
220
|
+
/** @type {Compilation | undefined} */
|
206
221
|
this.parentCompilation = undefined;
|
207
222
|
/** @type {Compiler} */
|
208
223
|
this.root = this;
|
@@ -211,19 +226,20 @@ class Compiler {
|
|
211
226
|
/** @type {Watching | undefined} */
|
212
227
|
this.watching = undefined;
|
213
228
|
|
214
|
-
/** @type {OutputFileSystem} */
|
229
|
+
/** @type {OutputFileSystem | null} */
|
215
230
|
this.outputFileSystem = null;
|
216
|
-
/** @type {IntermediateFileSystem} */
|
231
|
+
/** @type {IntermediateFileSystem | null} */
|
217
232
|
this.intermediateFileSystem = null;
|
218
|
-
/** @type {InputFileSystem} */
|
233
|
+
/** @type {InputFileSystem | null} */
|
219
234
|
this.inputFileSystem = null;
|
220
|
-
/** @type {WatchFileSystem} */
|
235
|
+
/** @type {WatchFileSystem | null} */
|
221
236
|
this.watchFileSystem = null;
|
222
237
|
|
223
238
|
/** @type {string|null} */
|
224
239
|
this.recordsInputPath = null;
|
225
240
|
/** @type {string|null} */
|
226
241
|
this.recordsOutputPath = null;
|
242
|
+
/** @type {Record<string, TODO>} */
|
227
243
|
this.records = {};
|
228
244
|
/** @type {Set<string | RegExp>} */
|
229
245
|
this.managedPaths = new Set();
|
@@ -246,6 +262,7 @@ class Compiler {
|
|
246
262
|
/** @type {ResolverFactory} */
|
247
263
|
this.resolverFactory = new ResolverFactory();
|
248
264
|
|
265
|
+
/** @type {LoggingFunction | undefined} */
|
249
266
|
this.infrastructureLogger = undefined;
|
250
267
|
|
251
268
|
this.options = options;
|
@@ -256,7 +273,7 @@ class Compiler {
|
|
256
273
|
|
257
274
|
this.cache = new Cache();
|
258
275
|
|
259
|
-
/** @type {Map<Module, { buildInfo:
|
276
|
+
/** @type {Map<Module, { buildInfo: BuildInfo, references: References | undefined, memCache: WeakTupleMap }> | undefined} */
|
260
277
|
this.moduleMemCaches = undefined;
|
261
278
|
|
262
279
|
this.compilerPath = "";
|
@@ -272,12 +289,12 @@ class Compiler {
|
|
272
289
|
|
273
290
|
this._backCompat = this.options.experiments.backCompat !== false;
|
274
291
|
|
275
|
-
/** @type {Compilation} */
|
292
|
+
/** @type {Compilation | undefined} */
|
276
293
|
this._lastCompilation = undefined;
|
277
|
-
/** @type {NormalModuleFactory} */
|
294
|
+
/** @type {NormalModuleFactory | undefined} */
|
278
295
|
this._lastNormalModuleFactory = undefined;
|
279
296
|
|
280
|
-
/** @private @type {WeakMap<Source,
|
297
|
+
/** @private @type {WeakMap<Source, CacheEntry>} */
|
281
298
|
this._assetEmittingSourceCache = new WeakMap();
|
282
299
|
/** @private @type {Map<string, number>} */
|
283
300
|
this._assetEmittingWrittenFiles = new Map();
|
@@ -416,7 +433,7 @@ class Compiler {
|
|
416
433
|
|
417
434
|
/**
|
418
435
|
* @param {WatchOptions} watchOptions the watcher's options
|
419
|
-
* @param {
|
436
|
+
* @param {RunCallback<Stats>} handler signals when the call finishes
|
420
437
|
* @returns {Watching} a compiler watcher
|
421
438
|
*/
|
422
439
|
watch(watchOptions, handler) {
|
@@ -431,7 +448,7 @@ class Compiler {
|
|
431
448
|
}
|
432
449
|
|
433
450
|
/**
|
434
|
-
* @param {
|
451
|
+
* @param {RunCallback<Stats>} callback signals when the call finishes
|
435
452
|
* @returns {void}
|
436
453
|
*/
|
437
454
|
run(callback) {
|
@@ -439,8 +456,13 @@ class Compiler {
|
|
439
456
|
return callback(new ConcurrentCompilationError());
|
440
457
|
}
|
441
458
|
|
459
|
+
/** @type {Logger | undefined} */
|
442
460
|
let logger;
|
443
461
|
|
462
|
+
/**
|
463
|
+
* @param {Error | null} err error
|
464
|
+
* @param {Stats=} stats stats
|
465
|
+
*/
|
444
466
|
const finalCallback = (err, stats) => {
|
445
467
|
if (logger) logger.time("beginIdle");
|
446
468
|
this.idle = true;
|
@@ -452,16 +474,23 @@ class Compiler {
|
|
452
474
|
this.hooks.failed.call(err);
|
453
475
|
}
|
454
476
|
if (callback !== undefined) callback(err, stats);
|
455
|
-
this.hooks.afterDone.call(stats);
|
477
|
+
this.hooks.afterDone.call(/** @type {Stats} */ (stats));
|
456
478
|
};
|
457
479
|
|
458
480
|
const startTime = Date.now();
|
459
481
|
|
460
482
|
this.running = true;
|
461
483
|
|
462
|
-
|
484
|
+
/**
|
485
|
+
* @param {Error | null} err error
|
486
|
+
* @param {Compilation=} _compilation compilation
|
487
|
+
* @returns {void}
|
488
|
+
*/
|
489
|
+
const onCompiled = (err, _compilation) => {
|
463
490
|
if (err) return finalCallback(err);
|
464
491
|
|
492
|
+
const compilation = /** @type {Compilation} */ (_compilation);
|
493
|
+
|
465
494
|
if (this.hooks.shouldEmit.call(compilation) === false) {
|
466
495
|
compilation.startTime = startTime;
|
467
496
|
compilation.endTime = Date.now();
|
@@ -477,7 +506,8 @@ class Compiler {
|
|
477
506
|
logger = compilation.getLogger("webpack.Compiler");
|
478
507
|
logger.time("emitAssets");
|
479
508
|
this.emitAssets(compilation, err => {
|
480
|
-
|
509
|
+
/** @type {Logger} */
|
510
|
+
(logger).timeEnd("emitAssets");
|
481
511
|
if (err) return finalCallback(err);
|
482
512
|
|
483
513
|
if (compilation.hooks.needAdditionalPass.call()) {
|
@@ -485,10 +515,12 @@ class Compiler {
|
|
485
515
|
|
486
516
|
compilation.startTime = startTime;
|
487
517
|
compilation.endTime = Date.now();
|
488
|
-
|
518
|
+
/** @type {Logger} */
|
519
|
+
(logger).time("done hook");
|
489
520
|
const stats = new Stats(compilation);
|
490
521
|
this.hooks.done.callAsync(stats, err => {
|
491
|
-
|
522
|
+
/** @type {Logger} */
|
523
|
+
(logger).timeEnd("done hook");
|
492
524
|
if (err) return finalCallback(err);
|
493
525
|
|
494
526
|
this.hooks.additionalPass.callAsync(err => {
|
@@ -499,17 +531,21 @@ class Compiler {
|
|
499
531
|
return;
|
500
532
|
}
|
501
533
|
|
502
|
-
|
534
|
+
/** @type {Logger} */
|
535
|
+
(logger).time("emitRecords");
|
503
536
|
this.emitRecords(err => {
|
504
|
-
|
537
|
+
/** @type {Logger} */
|
538
|
+
(logger).timeEnd("emitRecords");
|
505
539
|
if (err) return finalCallback(err);
|
506
540
|
|
507
541
|
compilation.startTime = startTime;
|
508
542
|
compilation.endTime = Date.now();
|
509
|
-
|
543
|
+
/** @type {Logger} */
|
544
|
+
(logger).time("done hook");
|
510
545
|
const stats = new Stats(compilation);
|
511
546
|
this.hooks.done.callAsync(stats, err => {
|
512
|
-
|
547
|
+
/** @type {Logger} */
|
548
|
+
(logger).timeEnd("done hook");
|
513
549
|
if (err) return finalCallback(err);
|
514
550
|
this.cache.storeBuildDependencies(
|
515
551
|
compilation.buildDependencies,
|
@@ -559,6 +595,11 @@ class Compiler {
|
|
559
595
|
runAsChild(callback) {
|
560
596
|
const startTime = Date.now();
|
561
597
|
|
598
|
+
/**
|
599
|
+
* @param {Error | null} err error
|
600
|
+
* @param {Chunk[]=} entries entries
|
601
|
+
* @param {Compilation=} compilation compilation
|
602
|
+
*/
|
562
603
|
const finalCallback = (err, entries, compilation) => {
|
563
604
|
try {
|
564
605
|
callback(err, entries, compilation);
|
@@ -566,20 +607,29 @@ class Compiler {
|
|
566
607
|
const err = new WebpackError(
|
567
608
|
`compiler.runAsChild callback error: ${e}`
|
568
609
|
);
|
569
|
-
err.details = e.stack;
|
570
|
-
|
610
|
+
err.details = /** @type {Error} */ (e).stack;
|
611
|
+
/** @type {Compilation} */
|
612
|
+
(this.parentCompilation).errors.push(err);
|
571
613
|
}
|
572
614
|
};
|
573
615
|
|
574
|
-
this.compile((err,
|
616
|
+
this.compile((err, _compilation) => {
|
575
617
|
if (err) return finalCallback(err);
|
576
618
|
|
577
|
-
|
619
|
+
const compilation = /** @type {Compilation} */ (_compilation);
|
620
|
+
const parentCompilation = /** @type {Compilation} */ (
|
621
|
+
this.parentCompilation
|
622
|
+
);
|
623
|
+
|
624
|
+
parentCompilation.children.push(compilation);
|
625
|
+
|
578
626
|
for (const { name, source, info } of compilation.getAssets()) {
|
579
|
-
|
627
|
+
parentCompilation.emitAsset(name, source, info);
|
580
628
|
}
|
581
629
|
|
630
|
+
/** @type {Chunk[]} */
|
582
631
|
const entries = [];
|
632
|
+
|
583
633
|
for (const ep of compilation.entrypoints.values()) {
|
584
634
|
entries.push(...ep.chunks);
|
585
635
|
}
|
@@ -603,14 +653,19 @@ class Compiler {
|
|
603
653
|
* @returns {void}
|
604
654
|
*/
|
605
655
|
emitAssets(compilation, callback) {
|
656
|
+
/** @type {string} */
|
606
657
|
let outputPath;
|
607
658
|
|
659
|
+
/**
|
660
|
+
* @param {Error=} err error
|
661
|
+
* @returns {void}
|
662
|
+
*/
|
608
663
|
const emitFiles = err => {
|
609
664
|
if (err) return callback(err);
|
610
665
|
|
611
666
|
const assets = compilation.getAssets();
|
612
667
|
compilation.assets = { ...compilation.assets };
|
613
|
-
/** @type {Map<string,
|
668
|
+
/** @type {Map<string, SimilarEntry>} */
|
614
669
|
const caseInsensitiveMap = new Map();
|
615
670
|
/** @type {Set<string>} */
|
616
671
|
const allTargetPaths = new Set();
|
@@ -634,10 +689,15 @@ class Compiler {
|
|
634
689
|
includesHash(targetFile, info.fullhash));
|
635
690
|
}
|
636
691
|
|
692
|
+
/**
|
693
|
+
* @param {Error=} err error
|
694
|
+
* @returns {void}
|
695
|
+
*/
|
637
696
|
const writeOut = err => {
|
638
697
|
if (err) return callback(err);
|
639
698
|
const targetPath = join(
|
640
|
-
|
699
|
+
/** @type {OutputFileSystem} */
|
700
|
+
(this.outputFileSystem),
|
641
701
|
outputPath,
|
642
702
|
targetFile
|
643
703
|
);
|
@@ -657,6 +717,7 @@ class Compiler {
|
|
657
717
|
this._assetEmittingSourceCache.set(source, cacheEntry);
|
658
718
|
}
|
659
719
|
|
720
|
+
/** @type {SimilarEntry | undefined} */
|
660
721
|
let similarEntry;
|
661
722
|
|
662
723
|
const checkSimilarFile = () => {
|
@@ -687,12 +748,12 @@ ${other}`);
|
|
687
748
|
} else {
|
688
749
|
caseInsensitiveMap.set(
|
689
750
|
caseInsensitiveTargetPath,
|
690
|
-
(similarEntry = {
|
751
|
+
(similarEntry = /** @type {SimilarEntry} */ ({
|
691
752
|
path: targetPath,
|
692
753
|
source,
|
693
754
|
size: undefined,
|
694
755
|
waiting: undefined
|
695
|
-
})
|
756
|
+
}))
|
696
757
|
);
|
697
758
|
return false;
|
698
759
|
}
|
@@ -720,9 +781,11 @@ ${other}`);
|
|
720
781
|
if (targetFileGeneration === undefined) {
|
721
782
|
const newGeneration = 1;
|
722
783
|
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
|
723
|
-
|
784
|
+
/** @type {CacheEntry} */
|
785
|
+
(cacheEntry).writtenTo.set(targetPath, newGeneration);
|
724
786
|
} else {
|
725
|
-
|
787
|
+
/** @type {CacheEntry} */
|
788
|
+
(cacheEntry).writtenTo.set(targetPath, targetFileGeneration);
|
726
789
|
}
|
727
790
|
callback();
|
728
791
|
};
|
@@ -733,7 +796,8 @@ ${other}`);
|
|
733
796
|
* @returns {void}
|
734
797
|
*/
|
735
798
|
const doWrite = content => {
|
736
|
-
|
799
|
+
/** @type {OutputFileSystem} */
|
800
|
+
(this.outputFileSystem).writeFile(targetPath, content, err => {
|
737
801
|
if (err) return callback(err);
|
738
802
|
|
739
803
|
// information marker that the asset has been emitted
|
@@ -744,7 +808,8 @@ ${other}`);
|
|
744
808
|
targetFileGeneration === undefined
|
745
809
|
? 1
|
746
810
|
: targetFileGeneration + 1;
|
747
|
-
|
811
|
+
/** @type {CacheEntry} */
|
812
|
+
(cacheEntry).writtenTo.set(targetPath, newGeneration);
|
748
813
|
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
|
749
814
|
this.hooks.assetEmitted.callAsync(
|
750
815
|
file,
|
@@ -760,16 +825,33 @@ ${other}`);
|
|
760
825
|
});
|
761
826
|
};
|
762
827
|
|
828
|
+
/**
|
829
|
+
* @param {number} size size
|
830
|
+
*/
|
763
831
|
const updateWithReplacementSource = size => {
|
764
|
-
updateFileWithReplacementSource(
|
765
|
-
|
766
|
-
|
767
|
-
|
832
|
+
updateFileWithReplacementSource(
|
833
|
+
file,
|
834
|
+
/** @type {CacheEntry} */ (cacheEntry),
|
835
|
+
size
|
836
|
+
);
|
837
|
+
/** @type {SimilarEntry} */
|
838
|
+
(similarEntry).size = size;
|
839
|
+
if (
|
840
|
+
/** @type {SimilarEntry} */ (similarEntry).waiting !== undefined
|
841
|
+
) {
|
842
|
+
for (const { file, cacheEntry } of /** @type {SimilarEntry} */ (
|
843
|
+
similarEntry
|
844
|
+
).waiting) {
|
768
845
|
updateFileWithReplacementSource(file, cacheEntry, size);
|
769
846
|
}
|
770
847
|
}
|
771
848
|
};
|
772
849
|
|
850
|
+
/**
|
851
|
+
* @param {string} file file
|
852
|
+
* @param {CacheEntry} cacheEntry cache entry
|
853
|
+
* @param {number} size size
|
854
|
+
*/
|
773
855
|
const updateFileWithReplacementSource = (
|
774
856
|
file,
|
775
857
|
cacheEntry,
|
@@ -786,10 +868,14 @@ ${other}`);
|
|
786
868
|
});
|
787
869
|
};
|
788
870
|
|
871
|
+
/**
|
872
|
+
* @param {IStats} stats stats
|
873
|
+
* @returns {void}
|
874
|
+
*/
|
789
875
|
const processExistingFile = stats => {
|
790
876
|
// skip emitting if it's already there and an immutable file
|
791
877
|
if (immutable) {
|
792
|
-
updateWithReplacementSource(stats.size);
|
878
|
+
updateWithReplacementSource(/** @type {number} */ (stats.size));
|
793
879
|
return alreadyWritten();
|
794
880
|
}
|
795
881
|
|
@@ -803,19 +889,18 @@ ${other}`);
|
|
803
889
|
// for a fast negative match file size is compared first
|
804
890
|
if (content.length === stats.size) {
|
805
891
|
compilation.comparedForEmitAssets.add(file);
|
806
|
-
return
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
}
|
892
|
+
return /** @type {OutputFileSystem} */ (
|
893
|
+
this.outputFileSystem
|
894
|
+
).readFile(targetPath, (err, existingContent) => {
|
895
|
+
if (
|
896
|
+
err ||
|
897
|
+
!content.equals(/** @type {Buffer} */ (existingContent))
|
898
|
+
) {
|
899
|
+
return doWrite(content);
|
900
|
+
} else {
|
901
|
+
return alreadyWritten();
|
817
902
|
}
|
818
|
-
);
|
903
|
+
});
|
819
904
|
}
|
820
905
|
|
821
906
|
return doWrite(content);
|
@@ -832,16 +917,22 @@ ${other}`);
|
|
832
917
|
// if the target file has already been written
|
833
918
|
if (targetFileGeneration !== undefined) {
|
834
919
|
// check if the Source has been written to this target file
|
835
|
-
const writtenGeneration =
|
920
|
+
const writtenGeneration = /** @type {CacheEntry} */ (
|
921
|
+
cacheEntry
|
922
|
+
).writtenTo.get(targetPath);
|
836
923
|
if (writtenGeneration === targetFileGeneration) {
|
837
924
|
// if yes, we may skip writing the file
|
838
925
|
// if it's already there
|
839
926
|
// (we assume one doesn't modify files while the Compiler is running, other then removing them)
|
840
927
|
|
841
928
|
if (this._assetEmittingPreviousFiles.has(targetPath)) {
|
929
|
+
const sizeOnlySource = /** @type {SizeOnlySource} */ (
|
930
|
+
/** @type {CacheEntry} */ (cacheEntry).sizeOnlySource
|
931
|
+
);
|
932
|
+
|
842
933
|
// We assume that assets from the last compilation say intact on disk (they are not removed)
|
843
|
-
compilation.updateAsset(file,
|
844
|
-
size:
|
934
|
+
compilation.updateAsset(file, sizeOnlySource, {
|
935
|
+
size: sizeOnlySource.size()
|
845
936
|
});
|
846
937
|
|
847
938
|
return callback();
|
@@ -860,11 +951,12 @@ ${other}`);
|
|
860
951
|
|
861
952
|
if (checkSimilarFile()) return;
|
862
953
|
if (this.options.output.compareBeforeEmit) {
|
863
|
-
|
864
|
-
|
954
|
+
/** @type {OutputFileSystem} */
|
955
|
+
(this.outputFileSystem).stat(targetPath, (err, stats) => {
|
956
|
+
const exists = !err && /** @type {IStats} */ (stats).isFile();
|
865
957
|
|
866
958
|
if (exists) {
|
867
|
-
processExistingFile(stats);
|
959
|
+
processExistingFile(/** @type {IStats} */ (stats));
|
868
960
|
} else {
|
869
961
|
processMissingFile();
|
870
962
|
}
|
@@ -875,7 +967,7 @@ ${other}`);
|
|
875
967
|
};
|
876
968
|
|
877
969
|
if (targetFile.match(/\/|\\/)) {
|
878
|
-
const fs = this.outputFileSystem;
|
970
|
+
const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem);
|
879
971
|
const dir = dirname(fs, join(fs, outputPath, targetFile));
|
880
972
|
mkdirp(fs, dir, writeOut);
|
881
973
|
} else {
|
@@ -904,7 +996,11 @@ ${other}`);
|
|
904
996
|
this.hooks.emit.callAsync(compilation, err => {
|
905
997
|
if (err) return callback(err);
|
906
998
|
outputPath = compilation.getPath(this.outputPath, {});
|
907
|
-
mkdirp(
|
999
|
+
mkdirp(
|
1000
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1001
|
+
outputPath,
|
1002
|
+
emitFiles
|
1003
|
+
);
|
908
1004
|
});
|
909
1005
|
}
|
910
1006
|
|
@@ -940,8 +1036,9 @@ ${other}`);
|
|
940
1036
|
*/
|
941
1037
|
_emitRecords(callback) {
|
942
1038
|
const writeFile = () => {
|
943
|
-
|
944
|
-
|
1039
|
+
/** @type {OutputFileSystem} */
|
1040
|
+
(this.outputFileSystem).writeFile(
|
1041
|
+
/** @type {string} */ (this.recordsOutputPath),
|
945
1042
|
JSON.stringify(
|
946
1043
|
this.records,
|
947
1044
|
(n, value) => {
|
@@ -964,16 +1061,20 @@ ${other}`);
|
|
964
1061
|
};
|
965
1062
|
|
966
1063
|
const recordsOutputPathDirectory = dirname(
|
967
|
-
this.outputFileSystem,
|
968
|
-
this.recordsOutputPath
|
1064
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1065
|
+
/** @type {string} */ (this.recordsOutputPath)
|
969
1066
|
);
|
970
1067
|
if (!recordsOutputPathDirectory) {
|
971
1068
|
return writeFile();
|
972
1069
|
}
|
973
|
-
mkdirp(
|
974
|
-
|
975
|
-
|
976
|
-
|
1070
|
+
mkdirp(
|
1071
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1072
|
+
recordsOutputPathDirectory,
|
1073
|
+
err => {
|
1074
|
+
if (err) return callback(err);
|
1075
|
+
writeFile();
|
1076
|
+
}
|
1077
|
+
);
|
977
1078
|
}
|
978
1079
|
|
979
1080
|
/**
|
@@ -1013,22 +1114,33 @@ ${other}`);
|
|
1013
1114
|
this.records = {};
|
1014
1115
|
return callback();
|
1015
1116
|
}
|
1016
|
-
|
1117
|
+
/** @type {InputFileSystem} */
|
1118
|
+
(this.inputFileSystem).stat(this.recordsInputPath, err => {
|
1017
1119
|
// It doesn't exist
|
1018
1120
|
// We can ignore this.
|
1019
1121
|
if (err) return callback();
|
1020
1122
|
|
1021
|
-
|
1022
|
-
|
1123
|
+
/** @type {InputFileSystem} */
|
1124
|
+
(this.inputFileSystem).readFile(
|
1125
|
+
/** @type {string} */ (this.recordsInputPath),
|
1126
|
+
(err, content) => {
|
1127
|
+
if (err) return callback(err);
|
1023
1128
|
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1129
|
+
try {
|
1130
|
+
this.records = parseJson(
|
1131
|
+
/** @type {Buffer} */ (content).toString("utf-8")
|
1132
|
+
);
|
1133
|
+
} catch (e) {
|
1134
|
+
return callback(
|
1135
|
+
new Error(
|
1136
|
+
`Cannot parse records: ${/** @type {Error} */ (e).message}`
|
1137
|
+
)
|
1138
|
+
);
|
1139
|
+
}
|
1029
1140
|
|
1030
|
-
|
1031
|
-
|
1141
|
+
return callback();
|
1142
|
+
}
|
1143
|
+
);
|
1032
1144
|
});
|
1033
1145
|
}
|
1034
1146
|
|
@@ -1122,6 +1234,10 @@ ${other}`);
|
|
1122
1234
|
return !!this.parentCompilation;
|
1123
1235
|
}
|
1124
1236
|
|
1237
|
+
/**
|
1238
|
+
* @param {CompilationParams} params the compilation parameters
|
1239
|
+
* @returns {Compilation} compilation
|
1240
|
+
*/
|
1125
1241
|
createCompilation(params) {
|
1126
1242
|
this._cleanupLastCompilation();
|
1127
1243
|
return (this._lastCompilation = new Compilation(this, params));
|
@@ -1144,7 +1260,7 @@ ${other}`);
|
|
1144
1260
|
this._cleanupLastNormalModuleFactory();
|
1145
1261
|
const normalModuleFactory = new NormalModuleFactory({
|
1146
1262
|
context: this.options.context,
|
1147
|
-
fs: this.inputFileSystem,
|
1263
|
+
fs: /** @type {InputFileSystem} */ (this.inputFileSystem),
|
1148
1264
|
resolverFactory: this.resolverFactory,
|
1149
1265
|
options: this.options.module,
|
1150
1266
|
associatedObjectForCache: this.root,
|
@@ -1170,7 +1286,7 @@ ${other}`);
|
|
1170
1286
|
}
|
1171
1287
|
|
1172
1288
|
/**
|
1173
|
-
* @param {
|
1289
|
+
* @param {RunCallback<Compilation>} callback signals when the compilation finishes
|
1174
1290
|
* @returns {void}
|
1175
1291
|
*/
|
1176
1292
|
compile(callback) {
|
@@ -1221,7 +1337,7 @@ ${other}`);
|
|
1221
1337
|
}
|
1222
1338
|
|
1223
1339
|
/**
|
1224
|
-
* @param {
|
1340
|
+
* @param {RunCallback<void>} callback signals when the compiler closes
|
1225
1341
|
* @returns {void}
|
1226
1342
|
*/
|
1227
1343
|
close(callback) {
|
@@ -37,17 +37,16 @@ const wrapInCondition = (condition, source) => {
|
|
37
37
|
};
|
38
38
|
|
39
39
|
/**
|
40
|
-
* @
|
41
|
-
* @extends {InitFragment<Context>}
|
40
|
+
* @extends {InitFragment<GenerateContext>}
|
42
41
|
*/
|
43
42
|
class ConditionalInitFragment extends InitFragment {
|
44
43
|
/**
|
45
|
-
* @param {string|Source} content the source code that will be included as initialization code
|
44
|
+
* @param {string | Source | undefined} content the source code that will be included as initialization code
|
46
45
|
* @param {number} stage category of initialization code (contribute to order)
|
47
46
|
* @param {number} position position in the category (contribute to order)
|
48
47
|
* @param {string | undefined} key unique key to avoid emitting the same initialization code twice
|
49
48
|
* @param {RuntimeSpec | boolean} runtimeCondition in which runtime this fragment should be executed
|
50
|
-
* @param {string|Source=} endContent the source code that will be included at the end of the module
|
49
|
+
* @param {string | Source=} endContent the source code that will be included at the end of the module
|
51
50
|
*/
|
52
51
|
constructor(
|
53
52
|
content,
|
@@ -63,7 +62,7 @@ class ConditionalInitFragment extends InitFragment {
|
|
63
62
|
|
64
63
|
/**
|
65
64
|
* @param {GenerateContext} context context
|
66
|
-
* @returns {string | Source} the source code that will be included as initialization code
|
65
|
+
* @returns {string | Source | undefined} the source code that will be included as initialization code
|
67
66
|
*/
|
68
67
|
getContent(context) {
|
69
68
|
if (this.runtimeCondition === false || !this.content) return "";
|