| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-16 20:01:53 +08:00
										 |  |  | const parseJson = require("json-parse-even-better-errors"); | 
					
						
							| 
									
										
										
										
											2018-02-11 12:27:09 +08:00
										 |  |  | const asyncLib = require("neo-async"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	AsyncParallelHook, | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	AsyncSeriesHook, | 
					
						
							|  |  |  | 	SyncBailHook, | 
					
						
							|  |  |  | 	SyncHook | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | const { SizeOnlySource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | const Cache = require("./Cache"); | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | const CacheFacade = require("./CacheFacade"); | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | const ChunkGraph = require("./ChunkGraph"); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | const Compilation = require("./Compilation"); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | const ConcurrentCompilationError = require("./ConcurrentCompilationError"); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | const ContextModuleFactory = require("./ContextModuleFactory"); | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | const ModuleGraph = require("./ModuleGraph"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const NormalModuleFactory = require("./NormalModuleFactory"); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | const RequestShortener = require("./RequestShortener"); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | const ResolverFactory = require("./ResolverFactory"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const Stats = require("./Stats"); | 
					
						
							|  |  |  | const Watching = require("./Watching"); | 
					
						
							| 
									
										
										
										
											2020-07-08 15:26:50 +08:00
										 |  |  | const WebpackError = require("./WebpackError"); | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  | const { Logger } = require("./logging/Logger"); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const { dirname, join, mkdirp } = require("./util/fs"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { makePathsRelative } = require("./util/identifier"); | 
					
						
							| 
									
										
										
										
											2020-12-09 23:10:32 +08:00
										 |  |  | const { isSourceEqual } = require("./util/source"); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const webpack = require("."); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").EntryNormalized} Entry */ | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */ | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */ | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").Plugins} Plugins */ | 
					
						
							|  |  |  | /** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */ | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */ | 
					
						
							| 
									
										
										
										
											2021-09-29 15:09:42 +08:00
										 |  |  | /** @typedef {import("./Dependency")} Dependency */ | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | /** @typedef {import("./HotModuleReplacementPlugin").ChunkHashes} ChunkHashes */ | 
					
						
							|  |  |  | /** @typedef {import("./HotModuleReplacementPlugin").ChunkModuleHashes} ChunkModuleHashes */ | 
					
						
							|  |  |  | /** @typedef {import("./HotModuleReplacementPlugin").ChunkModuleIds} ChunkModuleIds */ | 
					
						
							|  |  |  | /** @typedef {import("./HotModuleReplacementPlugin").ChunkRuntime} ChunkRuntime */ | 
					
						
							|  |  |  | /** @typedef {import("./HotModuleReplacementPlugin").FullHashChunkModuleHashes} FullHashChunkModuleHashes */ | 
					
						
							|  |  |  | /** @typedef {import("./HotModuleReplacementPlugin").HotIndex} HotIndex */ | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2024-03-18 01:15:44 +08:00
										 |  |  | /** @typedef {import("./Module").BuildInfo} BuildInfo */ | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | /** @typedef {import("./RecordIdsPlugin").RecordsChunks} RecordsChunks */ | 
					
						
							|  |  |  | /** @typedef {import("./RecordIdsPlugin").RecordsModules} RecordsModules */ | 
					
						
							| 
									
										
										
										
											2024-05-01 22:22:45 +08:00
										 |  |  | /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */ | 
					
						
							| 
									
										
										
										
											2024-02-21 22:55:02 +08:00
										 |  |  | /** @typedef {import("./logging/createConsoleLogger").LoggingFunction} LoggingFunction */ | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | /** @typedef {import("./optimize/AggressiveSplittingPlugin").SplitData} SplitData */ | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | /** @typedef {import("./util/fs").IStats} IStats */ | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ | 
					
						
							|  |  |  | /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */ | 
					
						
							|  |  |  | /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */ | 
					
						
							| 
									
										
										
										
											2025-03-11 22:20:50 +08:00
										 |  |  | /** @typedef {import("./util/fs").TimeInfoEntries} TimeInfoEntries */ | 
					
						
							| 
									
										
										
										
											2020-07-08 16:21:31 +08:00
										 |  |  | /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */ | 
					
						
							| 
									
										
										
										
											2018-09-19 19:05:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2024-06-11 21:09:50 +08:00
										 |  |  |  * @typedef {object} CompilationParams | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  |  * @property {NormalModuleFactory} normalModuleFactory | 
					
						
							|  |  |  |  * @property {ContextModuleFactory} contextModuleFactory | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  |  * @template [R=void] | 
					
						
							|  |  |  |  * @typedef {import("./webpack").Callback<T, R>} Callback | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | /** @typedef {import("./webpack").ErrorCallback} ErrorCallback */ | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @callback RunAsChildCallback | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  |  * @param {Error | null} err | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  |  * @param {Chunk[]=} entries | 
					
						
							|  |  |  |  * @param {Compilation=} compilation | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {object} KnownRecords | 
					
						
							|  |  |  |  * @property {SplitData[]=} aggressiveSplits | 
					
						
							|  |  |  |  * @property {RecordsChunks=} chunks | 
					
						
							|  |  |  |  * @property {RecordsModules=} modules | 
					
						
							|  |  |  |  * @property {string=} hash | 
					
						
							|  |  |  |  * @property {HotIndex=} hotIndex | 
					
						
							|  |  |  |  * @property {FullHashChunkModuleHashes=} fullHashChunkModuleHashes | 
					
						
							|  |  |  |  * @property {ChunkModuleHashes=} chunkModuleHashes | 
					
						
							|  |  |  |  * @property {ChunkHashes=} chunkHashes | 
					
						
							|  |  |  |  * @property {ChunkRuntime=} chunkRuntime | 
					
						
							|  |  |  |  * @property {ChunkModuleIds=} chunkModuleIds | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {KnownRecords & Record<string, KnownRecords[]> & Record<string, EXPECTED_ANY>} Records */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 20:10:16 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2024-06-11 21:09:50 +08:00
										 |  |  |  * @typedef {object} AssetEmittedInfo | 
					
						
							| 
									
										
										
										
											2019-09-05 20:10:16 +08:00
										 |  |  |  * @property {Buffer} content | 
					
						
							|  |  |  |  * @property {Source} source | 
					
						
							|  |  |  |  * @property {Compilation} compilation | 
					
						
							|  |  |  |  * @property {string} outputPath | 
					
						
							|  |  |  |  * @property {string} targetPath | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | /** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */ | 
					
						
							| 
									
										
										
										
											2025-04-04 21:38:51 +08:00
										 |  |  | /** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: CacheEntry, file: string }[] | undefined) }} SimilarEntry */ | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | /** @typedef {WeakMap<Dependency, Module>} WeakReferences */ | 
					
						
							|  |  |  | /** @typedef {import("./util/WeakTupleMap")<EXPECTED_ANY[], EXPECTED_ANY>} MemCache */ | 
					
						
							|  |  |  | /** @typedef {{ buildInfo: BuildInfo, references: WeakReferences | undefined, memCache: MemCache }} ModuleMemCachesItem */ | 
					
						
							| 
									
										
										
										
											2024-10-25 02:13:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-27 18:47:31 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string[]} array an array | 
					
						
							|  |  |  |  * @returns {boolean} true, if the array is sorted | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | const isSorted = (array) => { | 
					
						
							| 
									
										
										
										
											2019-01-27 18:47:31 +08:00
										 |  |  | 	for (let i = 1; i < array.length; i++) { | 
					
						
							|  |  |  | 		if (array[i - 1] > array[i]) return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2025-03-27 08:07:25 +08:00
										 |  |  |  * @template {object} T | 
					
						
							|  |  |  |  * @param {T} obj an object | 
					
						
							|  |  |  |  * @param {(keyof T)[]} keys the keys of the object | 
					
						
							|  |  |  |  * @returns {T} the object with properties sorted by property name | 
					
						
							| 
									
										
										
										
											2019-01-27 18:47:31 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const sortObject = (obj, keys) => { | 
					
						
							| 
									
										
										
										
											2025-03-27 08:07:25 +08:00
										 |  |  | 	const o = /** @type {T} */ ({}); | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 	for (const k of keys.sort()) { | 
					
						
							| 
									
										
										
										
											2019-01-27 18:47:31 +08:00
										 |  |  | 		o[k] = obj[k]; | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return o; | 
					
						
							| 
									
										
										
										
											2019-01-27 18:47:31 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-26 23:25:45 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string} filename filename | 
					
						
							|  |  |  |  * @param {string | string[] | undefined} hashes list of hashes | 
					
						
							|  |  |  |  * @returns {boolean} true, if the filename contains any hash | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const includesHash = (filename, hashes) => { | 
					
						
							|  |  |  | 	if (!hashes) return false; | 
					
						
							|  |  |  | 	if (Array.isArray(hashes)) { | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		return hashes.some((hash) => filename.includes(hash)); | 
					
						
							| 
									
										
										
										
											2020-10-26 23:25:45 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 	return filename.includes(hashes); | 
					
						
							| 
									
										
										
										
											2020-10-26 23:25:45 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 14:27:44 +08:00
										 |  |  | class Compiler { | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} context the compilation path | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 	 * @param {WebpackOptions} options options | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 	constructor(context, options = /** @type {WebpackOptions} */ ({})) { | 
					
						
							| 
									
										
										
										
											2018-07-30 20:25:40 +08:00
										 |  |  | 		this.hooks = Object.freeze({ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | 			/** @type {SyncHook<[]>} */ | 
					
						
							|  |  |  | 			initialize: new SyncHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 22:09:39 +08:00
										 |  |  | 			/** @type {SyncBailHook<[Compilation], boolean | void>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			shouldEmit: new SyncBailHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Stats]>} */ | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 			done: new AsyncSeriesHook(["stats"]), | 
					
						
							| 
									
										
										
										
											2019-07-10 03:14:40 +08:00
										 |  |  | 			/** @type {SyncHook<[Stats]>} */ | 
					
						
							| 
									
										
										
										
											2018-12-25 15:08:12 +08:00
										 |  |  | 			afterDone: new SyncHook(["stats"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			additionalPass: new AsyncSeriesHook([]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 			beforeRun: new AsyncSeriesHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 			run: new AsyncSeriesHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compilation]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			emit: new AsyncSeriesHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2019-09-05 20:10:16 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[string, AssetEmittedInfo]>} */ | 
					
						
							|  |  |  | 			assetEmitted: new AsyncSeriesHook(["file", "info"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compilation]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterEmit: new AsyncSeriesHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Compilation, CompilationParams]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			thisCompilation: new SyncHook(["compilation", "params"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Compilation, CompilationParams]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			compilation: new SyncHook(["compilation", "params"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[NormalModuleFactory]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			normalModuleFactory: new SyncHook(["normalModuleFactory"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[ContextModuleFactory]>}  */ | 
					
						
							| 
									
										
										
										
											2020-03-13 00:51:26 +08:00
										 |  |  | 			contextModuleFactory: new SyncHook(["contextModuleFactory"]), | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[CompilationParams]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			beforeCompile: new AsyncSeriesHook(["params"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[CompilationParams]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			compile: new SyncHook(["params"]), | 
					
						
							| 
									
										
										
										
											2020-11-09 18:58:18 +08:00
										 |  |  | 			/** @type {AsyncParallelHook<[Compilation]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			make: new AsyncParallelHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2020-11-09 18:58:18 +08:00
										 |  |  | 			/** @type {AsyncParallelHook<[Compilation]>} */ | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 			finishMake: new AsyncSeriesHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compilation]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterCompile: new AsyncSeriesHook(["compilation"]), | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[]>} */ | 
					
						
							|  |  |  | 			readRecords: new AsyncSeriesHook([]), | 
					
						
							|  |  |  | 			/** @type {AsyncSeriesHook<[]>} */ | 
					
						
							|  |  |  | 			emitRecords: new AsyncSeriesHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			watchRun: new AsyncSeriesHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Error]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			failed: new SyncHook(["error"]), | 
					
						
							| 
									
										
										
										
											2020-07-15 21:49:34 +08:00
										 |  |  | 			/** @type {SyncHook<[string | null, number]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			invalid: new SyncHook(["filename", "changeTime"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			watchClose: new SyncHook([]), | 
					
						
							| 
									
										
										
										
											2021-01-21 23:32:49 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[]>} */ | 
					
						
							|  |  |  | 			shutdown: new AsyncSeriesHook([]), | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-27 08:07:25 +08:00
										 |  |  | 			/** @type {SyncBailHook<[string, string, EXPECTED_ANY[] | undefined], true | void>} */ | 
					
						
							| 
									
										
										
										
											2019-07-31 22:57:01 +08:00
										 |  |  | 			infrastructureLog: new SyncBailHook(["origin", "type", "args"]), | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			// TODO the following hooks are weirdly located here
 | 
					
						
							|  |  |  | 			// TODO move them for webpack 5
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			environment: new SyncHook([]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterEnvironment: new SyncHook([]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterPlugins: new SyncHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			/** @type {SyncHook<[Compiler]>} */ | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			afterResolvers: new SyncHook(["compiler"]), | 
					
						
							| 
									
										
										
										
											2024-10-24 22:09:39 +08:00
										 |  |  | 			/** @type {SyncBailHook<[string, Entry], boolean | void>} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			entryOption: new SyncBailHook(["context", "entry"]) | 
					
						
							| 
									
										
										
										
											2018-07-30 20:25:40 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-13 02:16:58 +08:00
										 |  |  | 		this.webpack = webpack; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {string | undefined} */ | 
					
						
							| 
									
										
										
										
											2018-03-30 08:33:19 +08:00
										 |  |  | 		this.name = undefined; | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {Compilation | undefined} */ | 
					
						
							| 
									
										
										
										
											2018-03-30 08:33:19 +08:00
										 |  |  | 		this.parentCompilation = undefined; | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		/** @type {Compiler} */ | 
					
						
							|  |  |  | 		this.root = this; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.outputPath = ""; | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		/** @type {Watching | undefined} */ | 
					
						
							| 
									
										
										
										
											2020-09-19 12:23:03 +08:00
										 |  |  | 		this.watching = undefined; | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {OutputFileSystem | null} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.outputFileSystem = null; | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {IntermediateFileSystem | null} */ | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		this.intermediateFileSystem = null; | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {InputFileSystem | null} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.inputFileSystem = null; | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {WatchFileSystem | null} */ | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		this.watchFileSystem = null; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 		/** @type {string | null} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.recordsInputPath = null; | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 		/** @type {string | null} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.recordsOutputPath = null; | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 		/** @type {Records} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.records = {}; | 
					
						
							| 
									
										
										
										
											2021-10-18 22:07:41 +08:00
										 |  |  | 		/** @type {Set<string | RegExp>} */ | 
					
						
							| 
									
										
										
										
											2019-08-13 04:59:09 +08:00
										 |  |  | 		this.managedPaths = new Set(); | 
					
						
							| 
									
										
										
										
											2021-10-18 22:07:41 +08:00
										 |  |  | 		/** @type {Set<string | RegExp>} */ | 
					
						
							| 
									
										
										
										
											2023-10-05 05:28:11 +08:00
										 |  |  | 		this.unmanagedPaths = new Set(); | 
					
						
							|  |  |  | 		/** @type {Set<string | RegExp>} */ | 
					
						
							| 
									
										
										
										
											2019-08-16 17:55:10 +08:00
										 |  |  | 		this.immutablePaths = new Set(); | 
					
						
							| 
									
										
										
										
											2019-08-29 03:12:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		/** @type {ReadonlySet<string> | undefined} */ | 
					
						
							| 
									
										
										
										
											2019-10-21 21:35:38 +08:00
										 |  |  | 		this.modifiedFiles = undefined; | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		/** @type {ReadonlySet<string> | undefined} */ | 
					
						
							| 
									
										
										
										
											2019-08-29 03:12:59 +08:00
										 |  |  | 		this.removedFiles = undefined; | 
					
						
							| 
									
										
										
										
											2025-03-11 22:20:50 +08:00
										 |  |  | 		/** @type {TimeInfoEntries | undefined} */ | 
					
						
							| 
									
										
										
										
											2019-08-29 03:12:59 +08:00
										 |  |  | 		this.fileTimestamps = undefined; | 
					
						
							| 
									
										
										
										
											2025-03-11 22:20:50 +08:00
										 |  |  | 		/** @type {TimeInfoEntries | undefined} */ | 
					
						
							| 
									
										
										
										
											2019-08-29 03:12:59 +08:00
										 |  |  | 		this.contextTimestamps = undefined; | 
					
						
							| 
									
										
										
										
											2023-06-22 05:55:05 +08:00
										 |  |  | 		/** @type {number | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-05-19 22:18:37 +08:00
										 |  |  | 		this.fsStartTime = undefined; | 
					
						
							| 
									
										
										
										
											2019-08-29 03:12:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {ResolverFactory} */ | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		this.resolverFactory = new ResolverFactory(); | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:55:02 +08:00
										 |  |  | 		/** @type {LoggingFunction | undefined} */ | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 		this.infrastructureLogger = undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-01 23:10:57 +08:00
										 |  |  | 		/** @type {Readonly<PlatformTargetProperties>} */ | 
					
						
							|  |  |  | 		this.platform = { | 
					
						
							| 
									
										
										
										
											2024-05-01 22:22:45 +08:00
										 |  |  | 			web: null, | 
					
						
							|  |  |  | 			browser: null, | 
					
						
							|  |  |  | 			webworker: null, | 
					
						
							|  |  |  | 			node: null, | 
					
						
							|  |  |  | 			nwjs: null, | 
					
						
							|  |  |  | 			electron: null | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 		this.options = options; | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.context = context; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-15 06:20:30 +08:00
										 |  |  | 		this.requestShortener = new RequestShortener(context, this.root); | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		this.cache = new Cache(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-25 02:13:59 +08:00
										 |  |  | 		/** @type {Map<Module, ModuleMemCachesItem> | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-09-24 17:35:28 +08:00
										 |  |  | 		this.moduleMemCaches = undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 16:28:16 +08:00
										 |  |  | 		this.compilerPath = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 		this.running = false; | 
					
						
							| 
									
										
										
										
											2018-10-23 06:23:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							|  |  |  | 		this.idle = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 06:23:47 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							|  |  |  | 		this.watchMode = false; | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 		this._backCompat = this.options.experiments.backCompat !== false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 		/** @type {Compilation | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | 		this._lastCompilation = undefined; | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 		/** @type {NormalModuleFactory | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-07-01 17:46:59 +08:00
										 |  |  | 		this._lastNormalModuleFactory = undefined; | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-11 20:32:02 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @private | 
					
						
							|  |  |  | 		 * @type {WeakMap<Source, CacheEntry>} | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 		this._assetEmittingSourceCache = new WeakMap(); | 
					
						
							| 
									
										
										
										
											2024-06-11 20:32:02 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @private | 
					
						
							|  |  |  | 		 * @type {Map<string, number>} | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 		this._assetEmittingWrittenFiles = new Map(); | 
					
						
							| 
									
										
										
										
											2024-06-11 20:32:02 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @private | 
					
						
							|  |  |  | 		 * @type {Set<string>} | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2021-04-30 17:07:19 +08:00
										 |  |  | 		this._assetEmittingPreviousFiles = new Set(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} name cache name | 
					
						
							|  |  |  | 	 * @returns {CacheFacade} the cache facade instance | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getCache(name) { | 
					
						
							| 
									
										
										
										
											2021-09-22 18:12:46 +08:00
										 |  |  | 		return new CacheFacade( | 
					
						
							|  |  |  | 			this.cache, | 
					
						
							|  |  |  | 			`${this.compilerPath}${name}`, | 
					
						
							|  |  |  | 			this.options.output.hashFunction | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-03-12 09:56:14 +08:00
										 |  |  | 	 * @param {string | (() => string)} name name of the logger, or function called once to get the logger name | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 	 * @returns {Logger} a logger with that name | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getInfrastructureLogger(name) { | 
					
						
							|  |  |  | 		if (!name) { | 
					
						
							|  |  |  | 			throw new TypeError( | 
					
						
							|  |  |  | 				"Compiler.getInfrastructureLogger(name) called without a name" | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-11-05 23:47:45 +08:00
										 |  |  | 		return new Logger( | 
					
						
							|  |  |  | 			(type, args) => { | 
					
						
							|  |  |  | 				if (typeof name === "function") { | 
					
						
							|  |  |  | 					name = name(); | 
					
						
							|  |  |  | 					if (!name) { | 
					
						
							|  |  |  | 						throw new TypeError( | 
					
						
							|  |  |  | 							"Compiler.getInfrastructureLogger(name) called with a function not returning a name" | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 				if ( | 
					
						
							|  |  |  | 					this.hooks.infrastructureLog.call(name, type, args) === undefined && | 
					
						
							|  |  |  | 					this.infrastructureLogger !== undefined | 
					
						
							|  |  |  | 				) { | 
					
						
							|  |  |  | 					this.infrastructureLogger(name, type, args); | 
					
						
							| 
									
										
										
										
											2019-11-05 23:47:45 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			(childName) => { | 
					
						
							| 
									
										
										
										
											2019-11-05 23:47:45 +08:00
										 |  |  | 				if (typeof name === "function") { | 
					
						
							|  |  |  | 					if (typeof childName === "function") { | 
					
						
							|  |  |  | 						return this.getInfrastructureLogger(() => { | 
					
						
							|  |  |  | 							if (typeof name === "function") { | 
					
						
							|  |  |  | 								name = name(); | 
					
						
							|  |  |  | 								if (!name) { | 
					
						
							|  |  |  | 									throw new TypeError( | 
					
						
							|  |  |  | 										"Compiler.getInfrastructureLogger(name) called with a function not returning a name" | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							if (typeof childName === "function") { | 
					
						
							|  |  |  | 								childName = childName(); | 
					
						
							|  |  |  | 								if (!childName) { | 
					
						
							|  |  |  | 									throw new TypeError( | 
					
						
							|  |  |  | 										"Logger.getChildLogger(name) called with a function not returning a name" | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							return `${name}/${childName}`; | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 					return this.getInfrastructureLogger(() => { | 
					
						
							|  |  |  | 						if (typeof name === "function") { | 
					
						
							|  |  |  | 							name = name(); | 
					
						
							|  |  |  | 							if (!name) { | 
					
						
							|  |  |  | 								throw new TypeError( | 
					
						
							|  |  |  | 									"Compiler.getInfrastructureLogger(name) called with a function not returning a name" | 
					
						
							|  |  |  | 								); | 
					
						
							| 
									
										
										
										
											2019-11-05 23:47:45 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 						return `${name}/${childName}`; | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (typeof childName === "function") { | 
					
						
							|  |  |  | 					return this.getInfrastructureLogger(() => { | 
					
						
							|  |  |  | 						if (typeof childName === "function") { | 
					
						
							|  |  |  | 							childName = childName(); | 
					
						
							|  |  |  | 							if (!childName) { | 
					
						
							|  |  |  | 								throw new TypeError( | 
					
						
							|  |  |  | 									"Logger.getChildLogger(name) called with a function not returning a name" | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						return `${name}/${childName}`; | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 				return this.getInfrastructureLogger(`${name}/${childName}`); | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-11-05 23:47:45 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
											2019-07-18 23:13:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | 	// TODO webpack 6: solve this in a better way
 | 
					
						
							|  |  |  | 	// e.g. move compilation specific info from Modules into ModuleGraph
 | 
					
						
							|  |  |  | 	_cleanupLastCompilation() { | 
					
						
							|  |  |  | 		if (this._lastCompilation !== undefined) { | 
					
						
							| 
									
										
										
										
											2023-12-07 12:04:12 +08:00
										 |  |  | 			for (const childCompilation of this._lastCompilation.children) { | 
					
						
							| 
									
										
										
										
											2023-12-08 10:45:04 +08:00
										 |  |  | 				for (const module of childCompilation.modules) { | 
					
						
							|  |  |  | 					ChunkGraph.clearChunkGraphForModule(module); | 
					
						
							|  |  |  | 					ModuleGraph.clearModuleGraphForModule(module); | 
					
						
							|  |  |  | 					module.cleanupForCache(); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-12-07 12:04:12 +08:00
										 |  |  | 				for (const chunk of childCompilation.chunks) { | 
					
						
							|  |  |  | 					ChunkGraph.clearChunkGraphForChunk(chunk); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-10 01:50:13 +08:00
										 |  |  | 			for (const module of this._lastCompilation.modules) { | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | 				ChunkGraph.clearChunkGraphForModule(module); | 
					
						
							|  |  |  | 				ModuleGraph.clearModuleGraphForModule(module); | 
					
						
							|  |  |  | 				module.cleanupForCache(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-04-10 01:50:13 +08:00
										 |  |  | 			for (const chunk of this._lastCompilation.chunks) { | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | 				ChunkGraph.clearChunkGraphForChunk(chunk); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			this._lastCompilation = undefined; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-01 17:46:59 +08:00
										 |  |  | 	// TODO webpack 6: solve this in a better way
 | 
					
						
							|  |  |  | 	_cleanupLastNormalModuleFactory() { | 
					
						
							|  |  |  | 		if (this._lastNormalModuleFactory !== undefined) { | 
					
						
							|  |  |  | 			this._lastNormalModuleFactory.cleanupForCache(); | 
					
						
							|  |  |  | 			this._lastNormalModuleFactory = undefined; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {WatchOptions} watchOptions the watcher's options | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {Callback<Stats>} handler signals when the call finishes | 
					
						
							|  |  |  | 	 * @returns {Watching | undefined} a compiler watcher | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	watch(watchOptions, handler) { | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 		if (this.running) { | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 			handler(new ConcurrentCompilationError()); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.running = true; | 
					
						
							| 
									
										
										
										
											2018-10-24 01:52:32 +08:00
										 |  |  | 		this.watchMode = true; | 
					
						
							| 
									
										
										
										
											2020-09-17 21:01:07 +08:00
										 |  |  | 		this.watching = new Watching(this, watchOptions, handler); | 
					
						
							|  |  |  | 		return this.watching; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {Callback<Stats>} callback signals when the call finishes | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	run(callback) { | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 		if (this.running) { | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 			callback(new ConcurrentCompilationError()); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 		/** @type {Logger | undefined} */ | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 		let logger; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Error | null} err error | 
					
						
							|  |  |  | 		 * @param {Stats=} stats stats | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 		const finalCallback = (err, stats) => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 			if (logger) logger.time("beginIdle"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			this.idle = true; | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 			this.cache.beginIdle(); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			this.idle = true; | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 			if (logger) logger.timeEnd("beginIdle"); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 			this.running = false; | 
					
						
							| 
									
										
										
										
											2018-11-22 00:03:18 +08:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				this.hooks.failed.call(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-12-25 18:43:34 +08:00
										 |  |  | 			if (callback !== undefined) callback(err, stats); | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 			this.hooks.afterDone.call(/** @type {Stats} */ (stats)); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		const startTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-07 05:56:31 +08:00
										 |  |  | 		this.running = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Error | null} err error | 
					
						
							|  |  |  | 		 * @param {Compilation=} _compilation compilation | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		const onCompiled = (err, _compilation) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 			if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 			const compilation = /** @type {Compilation} */ (_compilation); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (this.hooks.shouldEmit.call(compilation) === false) { | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 				compilation.startTime = startTime; | 
					
						
							|  |  |  | 				compilation.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				const stats = new Stats(compilation); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				this.hooks.done.callAsync(stats, (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 					if (err) return finalCallback(err); | 
					
						
							|  |  |  | 					return finalCallback(null, stats); | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 			process.nextTick(() => { | 
					
						
							| 
									
										
										
										
											2019-07-26 17:09:14 +08:00
										 |  |  | 				logger = compilation.getLogger("webpack.Compiler"); | 
					
						
							|  |  |  | 				logger.time("emitAssets"); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				this.emitAssets(compilation, (err) => { | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 					/** @type {Logger} */ | 
					
						
							|  |  |  | 					(logger).timeEnd("emitAssets"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 					if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 					if (compilation.hooks.needAdditionalPass.call()) { | 
					
						
							|  |  |  | 						compilation.needAdditionalPass = true; | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 						compilation.startTime = startTime; | 
					
						
							|  |  |  | 						compilation.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 						/** @type {Logger} */ | 
					
						
							|  |  |  | 						(logger).time("done hook"); | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 						const stats = new Stats(compilation); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						this.hooks.done.callAsync(stats, (err) => { | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 							/** @type {Logger} */ | 
					
						
							|  |  |  | 							(logger).timeEnd("done hook"); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 							if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 							this.hooks.additionalPass.callAsync((err) => { | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 								if (err) return finalCallback(err); | 
					
						
							|  |  |  | 								this.compile(onCompiled); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						return; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 					/** @type {Logger} */ | 
					
						
							|  |  |  | 					(logger).time("emitRecords"); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					this.emitRecords((err) => { | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 						/** @type {Logger} */ | 
					
						
							|  |  |  | 						(logger).timeEnd("emitRecords"); | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 						if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 						compilation.startTime = startTime; | 
					
						
							|  |  |  | 						compilation.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 						/** @type {Logger} */ | 
					
						
							|  |  |  | 						(logger).time("done hook"); | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 						const stats = new Stats(compilation); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						this.hooks.done.callAsync(stats, (err) => { | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 							/** @type {Logger} */ | 
					
						
							|  |  |  | 							(logger).timeEnd("done hook"); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 							if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 							this.cache.storeBuildDependencies( | 
					
						
							|  |  |  | 								compilation.buildDependencies, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								(err) => { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 									if (err) return finalCallback(err); | 
					
						
							|  |  |  | 									return finalCallback(null, stats); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2019-01-05 20:49:42 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-01-25 20:56:50 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		const run = () => { | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			this.hooks.beforeRun.callAsync(this, (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 				if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				this.hooks.run.callAsync(this, (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 17:14:51 +08:00
										 |  |  | 					if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					this.readRecords((err) => { | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 						if (err) return finalCallback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						this.compile(onCompiled); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (this.idle) { | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			this.cache.endIdle((err) => { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 				if (err) return finalCallback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				this.idle = false; | 
					
						
							|  |  |  | 				run(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			run(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {RunAsChildCallback} callback signals when the call finishes | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	runAsChild(callback) { | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 		const startTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2022-03-23 23:41:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Error | null} err error | 
					
						
							|  |  |  | 		 * @param {Chunk[]=} entries entries | 
					
						
							|  |  |  | 		 * @param {Compilation=} compilation compilation | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2022-03-23 23:41:16 +08:00
										 |  |  | 		const finalCallback = (err, entries, compilation) => { | 
					
						
							|  |  |  | 			try { | 
					
						
							| 
									
										
										
										
											2022-03-28 20:37:52 +08:00
										 |  |  | 				callback(err, entries, compilation); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 			} catch (runAsChildErr) { | 
					
						
							| 
									
										
										
										
											2022-03-23 23:41:16 +08:00
										 |  |  | 				const err = new WebpackError( | 
					
						
							| 
									
										
										
										
											2025-04-23 05:24:52 +08:00
										 |  |  | 					`compiler.runAsChild callback error: ${runAsChildErr}`, | 
					
						
							|  |  |  | 					{ cause: runAsChildErr } | 
					
						
							| 
									
										
										
										
											2022-03-23 23:41:16 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 				err.details = /** @type {Error} */ (runAsChildErr).stack; | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 				/** @type {Compilation} */ | 
					
						
							|  |  |  | 				(this.parentCompilation).errors.push(err); | 
					
						
							| 
									
										
										
										
											2022-03-23 23:41:16 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 		this.compile((err, _compilation) => { | 
					
						
							| 
									
										
										
										
											2022-03-23 23:41:16 +08:00
										 |  |  | 			if (err) return finalCallback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 			const compilation = /** @type {Compilation} */ (_compilation); | 
					
						
							|  |  |  | 			const parentCompilation = /** @type {Compilation} */ ( | 
					
						
							|  |  |  | 				this.parentCompilation | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			parentCompilation.children.push(compilation); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 17:13:46 +08:00
										 |  |  | 			for (const { name, source, info } of compilation.getAssets()) { | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 				parentCompilation.emitAsset(name, source, info); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-01-05 21:30:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 			/** @type {Chunk[]} */ | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 			const entries = []; | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 			for (const ep of compilation.entrypoints.values()) { | 
					
						
							|  |  |  | 				entries.push(...ep.chunks); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 			compilation.startTime = startTime; | 
					
						
							|  |  |  | 			compilation.endTime = Date.now(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-23 23:41:16 +08:00
										 |  |  | 			return finalCallback(null, entries, compilation); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	purgeInputFileSystem() { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (this.inputFileSystem && this.inputFileSystem.purge) { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			this.inputFileSystem.purge(); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-12 04:52:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {ErrorCallback} callback signals when the assets are emitted | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	emitAssets(compilation, callback) { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		let outputPath; | 
					
						
							| 
									
										
										
										
											2014-03-12 01:42:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Error=} err error | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const emitFiles = (err) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | 			const assets = compilation.getAssets(); | 
					
						
							|  |  |  | 			compilation.assets = { ...compilation.assets }; | 
					
						
							| 
									
										
										
										
											2024-03-18 01:15:44 +08:00
										 |  |  | 			/** @type {Map<string, SimilarEntry>} */ | 
					
						
							| 
									
										
										
										
											2020-07-08 15:26:50 +08:00
										 |  |  | 			const caseInsensitiveMap = new Map(); | 
					
						
							| 
									
										
										
										
											2021-04-30 17:07:19 +08:00
										 |  |  | 			/** @type {Set<string>} */ | 
					
						
							|  |  |  | 			const allTargetPaths = new Set(); | 
					
						
							| 
									
										
										
										
											2019-01-10 03:53:04 +08:00
										 |  |  | 			asyncLib.forEachLimit( | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | 				assets, | 
					
						
							| 
									
										
										
										
											2019-01-10 03:25:44 +08:00
										 |  |  | 				15, | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 				({ name: file, source, info }, callback) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					let targetFile = file; | 
					
						
							| 
									
										
										
										
											2020-10-26 23:25:45 +08:00
										 |  |  | 					let immutable = info.immutable; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const queryStringIdx = targetFile.indexOf("?"); | 
					
						
							|  |  |  | 					if (queryStringIdx >= 0) { | 
					
						
							| 
									
										
										
										
											2022-03-14 05:54:18 +08:00
										 |  |  | 						targetFile = targetFile.slice(0, queryStringIdx); | 
					
						
							| 
									
										
										
										
											2020-10-26 23:25:45 +08:00
										 |  |  | 						// We may remove the hash, which is in the query string
 | 
					
						
							|  |  |  | 						// So we recheck if the file is immutable
 | 
					
						
							|  |  |  | 						// This doesn't cover all cases, but immutable is only a performance optimization anyway
 | 
					
						
							|  |  |  | 						immutable = | 
					
						
							|  |  |  | 							immutable && | 
					
						
							|  |  |  | 							(includesHash(targetFile, info.contenthash) || | 
					
						
							|  |  |  | 								includesHash(targetFile, info.chunkhash) || | 
					
						
							|  |  |  | 								includesHash(targetFile, info.modulehash) || | 
					
						
							|  |  |  | 								includesHash(targetFile, info.fullhash)); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-17 13:57:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 					/** | 
					
						
							|  |  |  | 					 * @param {Error=} err error | 
					
						
							|  |  |  | 					 * @returns {void} | 
					
						
							|  |  |  | 					 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					const writeOut = (err) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 						const targetPath = join( | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 							/** @type {OutputFileSystem} */ | 
					
						
							|  |  |  | 							(this.outputFileSystem), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							outputPath, | 
					
						
							|  |  |  | 							targetFile | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2021-04-30 17:07:19 +08:00
										 |  |  | 						allTargetPaths.add(targetPath); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// check if the target file has already been written by this Compiler
 | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 						const targetFileGeneration = | 
					
						
							|  |  |  | 							this._assetEmittingWrittenFiles.get(targetPath); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// create an cache entry for this Source if not already existing
 | 
					
						
							|  |  |  | 						let cacheEntry = this._assetEmittingSourceCache.get(source); | 
					
						
							|  |  |  | 						if (cacheEntry === undefined) { | 
					
						
							|  |  |  | 							cacheEntry = { | 
					
						
							|  |  |  | 								sizeOnlySource: undefined, | 
					
						
							|  |  |  | 								writtenTo: new Map() | 
					
						
							|  |  |  | 							}; | 
					
						
							|  |  |  | 							this._assetEmittingSourceCache.set(source, cacheEntry); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 						/** @type {SimilarEntry | undefined} */ | 
					
						
							| 
									
										
										
										
											2020-12-09 23:10:32 +08:00
										 |  |  | 						let similarEntry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						const checkSimilarFile = () => { | 
					
						
							|  |  |  | 							const caseInsensitiveTargetPath = targetPath.toLowerCase(); | 
					
						
							|  |  |  | 							similarEntry = caseInsensitiveMap.get(caseInsensitiveTargetPath); | 
					
						
							|  |  |  | 							if (similarEntry !== undefined) { | 
					
						
							|  |  |  | 								const { path: other, source: otherSource } = similarEntry; | 
					
						
							|  |  |  | 								if (isSourceEqual(otherSource, source)) { | 
					
						
							|  |  |  | 									// Size may or may not be available at this point.
 | 
					
						
							|  |  |  | 									// If it's not available add to "waiting" list and it will be updated once available
 | 
					
						
							|  |  |  | 									if (similarEntry.size !== undefined) { | 
					
						
							|  |  |  | 										updateWithReplacementSource(similarEntry.size); | 
					
						
							|  |  |  | 									} else { | 
					
						
							|  |  |  | 										if (!similarEntry.waiting) similarEntry.waiting = []; | 
					
						
							|  |  |  | 										similarEntry.waiting.push({ file, cacheEntry }); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 									alreadyWritten(); | 
					
						
							|  |  |  | 								} else { | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 									const err = | 
					
						
							|  |  |  | 										new WebpackError(`Prevent writing to file that only differs in casing or query string from already written file.
 | 
					
						
							| 
									
										
										
										
											2020-12-09 23:10:32 +08:00
										 |  |  | This will lead to a race-condition and corrupted files on case-insensitive file systems. | 
					
						
							|  |  |  | ${targetPath} | 
					
						
							|  |  |  | ${other}`);
 | 
					
						
							|  |  |  | 									err.file = file; | 
					
						
							|  |  |  | 									callback(err); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								return true; | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 							caseInsensitiveMap.set( | 
					
						
							|  |  |  | 								caseInsensitiveTargetPath, | 
					
						
							|  |  |  | 								(similarEntry = /** @type {SimilarEntry} */ ({ | 
					
						
							|  |  |  | 									path: targetPath, | 
					
						
							|  |  |  | 									source, | 
					
						
							|  |  |  | 									size: undefined, | 
					
						
							|  |  |  | 									waiting: undefined | 
					
						
							|  |  |  | 								})) | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 							return false; | 
					
						
							| 
									
										
										
										
											2020-12-09 23:10:32 +08:00
										 |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 						/** | 
					
						
							|  |  |  | 						 * get the binary (Buffer) content from the Source | 
					
						
							|  |  |  | 						 * @returns {Buffer} content for the source | 
					
						
							|  |  |  | 						 */ | 
					
						
							|  |  |  | 						const getContent = () => { | 
					
						
							|  |  |  | 							if (typeof source.buffer === "function") { | 
					
						
							|  |  |  | 								return source.buffer(); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 							const bufferOrString = source.source(); | 
					
						
							|  |  |  | 							if (Buffer.isBuffer(bufferOrString)) { | 
					
						
							|  |  |  | 								return bufferOrString; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							return Buffer.from(bufferOrString, "utf8"); | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						const alreadyWritten = () => { | 
					
						
							|  |  |  | 							// cache the information that the Source has been already been written to that location
 | 
					
						
							|  |  |  | 							if (targetFileGeneration === undefined) { | 
					
						
							|  |  |  | 								const newGeneration = 1; | 
					
						
							|  |  |  | 								this._assetEmittingWrittenFiles.set(targetPath, newGeneration); | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 								/** @type {CacheEntry} */ | 
					
						
							|  |  |  | 								(cacheEntry).writtenTo.set(targetPath, newGeneration); | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 							} else { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 								/** @type {CacheEntry} */ | 
					
						
							|  |  |  | 								(cacheEntry).writtenTo.set(targetPath, targetFileGeneration); | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 							callback(); | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						/** | 
					
						
							|  |  |  | 						 * Write the file to output file system | 
					
						
							|  |  |  | 						 * @param {Buffer} content content to be written | 
					
						
							|  |  |  | 						 * @returns {void} | 
					
						
							|  |  |  | 						 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						const doWrite = (content) => { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 							/** @type {OutputFileSystem} */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 							(this.outputFileSystem).writeFile(targetPath, content, (err) => { | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 								if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								// information marker that the asset has been emitted
 | 
					
						
							|  |  |  | 								compilation.emittedAssets.add(file); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								// cache the information that the Source has been written to that location
 | 
					
						
							|  |  |  | 								const newGeneration = | 
					
						
							|  |  |  | 									targetFileGeneration === undefined | 
					
						
							|  |  |  | 										? 1 | 
					
						
							|  |  |  | 										: targetFileGeneration + 1; | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 								/** @type {CacheEntry} */ | 
					
						
							|  |  |  | 								(cacheEntry).writtenTo.set(targetPath, newGeneration); | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 								this._assetEmittingWrittenFiles.set(targetPath, newGeneration); | 
					
						
							|  |  |  | 								this.hooks.assetEmitted.callAsync( | 
					
						
							|  |  |  | 									file, | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										content, | 
					
						
							|  |  |  | 										source, | 
					
						
							|  |  |  | 										outputPath, | 
					
						
							|  |  |  | 										compilation, | 
					
						
							|  |  |  | 										targetPath | 
					
						
							|  |  |  | 									}, | 
					
						
							|  |  |  | 									callback | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 						/** | 
					
						
							|  |  |  | 						 * @param {number} size size | 
					
						
							|  |  |  | 						 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						const updateWithReplacementSource = (size) => { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 							updateFileWithReplacementSource( | 
					
						
							|  |  |  | 								file, | 
					
						
							|  |  |  | 								/** @type {CacheEntry} */ (cacheEntry), | 
					
						
							|  |  |  | 								size | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 							/** @type {SimilarEntry} */ | 
					
						
							|  |  |  | 							(similarEntry).size = size; | 
					
						
							|  |  |  | 							if ( | 
					
						
							|  |  |  | 								/** @type {SimilarEntry} */ (similarEntry).waiting !== undefined | 
					
						
							|  |  |  | 							) { | 
					
						
							|  |  |  | 								for (const { file, cacheEntry } of /** @type {SimilarEntry} */ ( | 
					
						
							|  |  |  | 									similarEntry | 
					
						
							|  |  |  | 								).waiting) { | 
					
						
							| 
									
										
										
										
											2020-12-09 23:10:32 +08:00
										 |  |  | 									updateFileWithReplacementSource(file, cacheEntry, size); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 						/** | 
					
						
							|  |  |  | 						 * @param {string} file file | 
					
						
							|  |  |  | 						 * @param {CacheEntry} cacheEntry cache entry | 
					
						
							|  |  |  | 						 * @param {number} size size | 
					
						
							|  |  |  | 						 */ | 
					
						
							| 
									
										
										
										
											2020-12-09 23:10:32 +08:00
										 |  |  | 						const updateFileWithReplacementSource = ( | 
					
						
							|  |  |  | 							file, | 
					
						
							|  |  |  | 							cacheEntry, | 
					
						
							|  |  |  | 							size | 
					
						
							|  |  |  | 						) => { | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 							// Create a replacement resource which only allows to ask for size
 | 
					
						
							|  |  |  | 							// This allows to GC all memory allocated by the Source
 | 
					
						
							|  |  |  | 							// (expect when the Source is stored in any other cache)
 | 
					
						
							|  |  |  | 							if (!cacheEntry.sizeOnlySource) { | 
					
						
							|  |  |  | 								cacheEntry.sizeOnlySource = new SizeOnlySource(size); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							compilation.updateAsset(file, cacheEntry.sizeOnlySource, { | 
					
						
							|  |  |  | 								size | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 						/** | 
					
						
							|  |  |  | 						 * @param {IStats} stats stats | 
					
						
							|  |  |  | 						 * @returns {void} | 
					
						
							|  |  |  | 						 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						const processExistingFile = (stats) => { | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 							// skip emitting if it's already there and an immutable file
 | 
					
						
							| 
									
										
										
										
											2020-10-26 23:25:45 +08:00
										 |  |  | 							if (immutable) { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:36:36 +08:00
										 |  |  | 								updateWithReplacementSource(/** @type {number} */ (stats.size)); | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 								return alreadyWritten(); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							const content = getContent(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							updateWithReplacementSource(content.length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							// if it exists and content on disk matches content
 | 
					
						
							|  |  |  | 							// skip writing the same content again
 | 
					
						
							|  |  |  | 							// (to keep mtime and don't trigger watchers)
 | 
					
						
							|  |  |  | 							// for a fast negative match file size is compared first
 | 
					
						
							|  |  |  | 							if (content.length === stats.size) { | 
					
						
							|  |  |  | 								compilation.comparedForEmitAssets.add(file); | 
					
						
							| 
									
										
										
										
											2024-03-12 00:33:52 +08:00
										 |  |  | 								return /** @type {OutputFileSystem} */ ( | 
					
						
							|  |  |  | 									this.outputFileSystem | 
					
						
							|  |  |  | 								).readFile(targetPath, (err, existingContent) => { | 
					
						
							|  |  |  | 									if ( | 
					
						
							|  |  |  | 										err || | 
					
						
							|  |  |  | 										!content.equals(/** @type {Buffer} */ (existingContent)) | 
					
						
							|  |  |  | 									) { | 
					
						
							|  |  |  | 										return doWrite(content); | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 									return alreadyWritten(); | 
					
						
							| 
									
										
										
										
											2024-03-12 00:33:52 +08:00
										 |  |  | 								}); | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							return doWrite(content); | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						const processMissingFile = () => { | 
					
						
							|  |  |  | 							const content = getContent(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							updateWithReplacementSource(content.length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							return doWrite(content); | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 						// if the target file has already been written
 | 
					
						
							|  |  |  | 						if (targetFileGeneration !== undefined) { | 
					
						
							|  |  |  | 							// check if the Source has been written to this target file
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 							const writtenGeneration = /** @type {CacheEntry} */ ( | 
					
						
							|  |  |  | 								cacheEntry | 
					
						
							|  |  |  | 							).writtenTo.get(targetPath); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 							if (writtenGeneration === targetFileGeneration) { | 
					
						
							| 
									
										
										
										
											2021-04-30 17:07:19 +08:00
										 |  |  | 								// if yes, we may skip writing the file
 | 
					
						
							|  |  |  | 								// if it's already there
 | 
					
						
							|  |  |  | 								// (we assume one doesn't modify files while the Compiler is running, other then removing them)
 | 
					
						
							| 
									
										
										
										
											2019-09-11 17:13:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-30 17:07:19 +08:00
										 |  |  | 								if (this._assetEmittingPreviousFiles.has(targetPath)) { | 
					
						
							| 
									
										
										
										
											2024-03-12 00:33:52 +08:00
										 |  |  | 									const sizeOnlySource = /** @type {SizeOnlySource} */ ( | 
					
						
							|  |  |  | 										/** @type {CacheEntry} */ (cacheEntry).sizeOnlySource | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 									); | 
					
						
							| 
									
										
										
										
											2019-01-17 20:07:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-12 00:33:52 +08:00
										 |  |  | 									// We assume that assets from the last compilation say intact on disk (they are not removed)
 | 
					
						
							|  |  |  | 									compilation.updateAsset(file, sizeOnlySource, { | 
					
						
							|  |  |  | 										size: sizeOnlySource.size() | 
					
						
							|  |  |  | 									}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-30 17:07:19 +08:00
										 |  |  | 									return callback(); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 								// Settings immutable will make it accept file content without comparing when file exist
 | 
					
						
							|  |  |  | 								immutable = true; | 
					
						
							| 
									
										
										
										
											2021-04-30 17:07:19 +08:00
										 |  |  | 							} else if (!immutable) { | 
					
						
							| 
									
										
										
										
											2020-12-09 23:10:32 +08:00
										 |  |  | 								if (checkSimilarFile()) return; | 
					
						
							| 
									
										
										
										
											2020-03-13 00:51:26 +08:00
										 |  |  | 								// We wrote to this file before which has very likely a different content
 | 
					
						
							| 
									
										
										
										
											2019-11-04 16:23:18 +08:00
										 |  |  | 								// skip comparing and assume content is different for performance
 | 
					
						
							|  |  |  | 								// This case happens often during watch mode.
 | 
					
						
							|  |  |  | 								return processMissingFile(); | 
					
						
							| 
									
										
										
										
											2019-01-18 23:26:16 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-09 23:10:32 +08:00
										 |  |  | 						if (checkSimilarFile()) return; | 
					
						
							| 
									
										
										
										
											2019-11-04 23:46:45 +08:00
										 |  |  | 						if (this.options.output.compareBeforeEmit) { | 
					
						
							| 
									
										
										
										
											2024-03-12 00:33:52 +08:00
										 |  |  | 							/** @type {OutputFileSystem} */ | 
					
						
							|  |  |  | 							(this.outputFileSystem).stat(targetPath, (err, stats) => { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 								const exists = !err && /** @type {IStats} */ (stats).isFile(); | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-04 23:46:45 +08:00
										 |  |  | 								if (exists) { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 									processExistingFile(/** @type {IStats} */ (stats)); | 
					
						
							| 
									
										
										
										
											2019-11-04 23:46:45 +08:00
										 |  |  | 								} else { | 
					
						
							|  |  |  | 									processMissingFile(); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							processMissingFile(); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 					if (/\/|\\/.test(targetFile)) { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 						const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 						const dir = dirname(fs, join(fs, outputPath, targetFile)); | 
					
						
							|  |  |  | 						mkdirp(fs, dir, writeOut); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						writeOut(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				(err) => { | 
					
						
							| 
									
										
										
										
											2021-04-08 02:50:42 +08:00
										 |  |  | 					// Clear map to free up memory
 | 
					
						
							|  |  |  | 					caseInsensitiveMap.clear(); | 
					
						
							| 
									
										
										
										
											2021-04-30 17:07:19 +08:00
										 |  |  | 					if (err) { | 
					
						
							|  |  |  | 						this._assetEmittingPreviousFiles.clear(); | 
					
						
							|  |  |  | 						return callback(err); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					this._assetEmittingPreviousFiles = allTargetPaths; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					this.hooks.afterEmit.callAsync(compilation, (err) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 						return callback(null); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		this.hooks.emit.callAsync(compilation, (err) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 			outputPath = compilation.getPath(this.outputPath, {}); | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 			mkdirp( | 
					
						
							|  |  |  | 				/** @type {OutputFileSystem} */ (this.outputFileSystem), | 
					
						
							|  |  |  | 				outputPath, | 
					
						
							|  |  |  | 				emitFiles | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {ErrorCallback} callback signals when the call finishes | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	emitRecords(callback) { | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 		if (this.hooks.emitRecords.isUsed()) { | 
					
						
							|  |  |  | 			if (this.recordsOutputPath) { | 
					
						
							|  |  |  | 				asyncLib.parallel( | 
					
						
							|  |  |  | 					[ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						(cb) => this.hooks.emitRecords.callAsync(cb), | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 						this._emitRecords.bind(this) | 
					
						
							|  |  |  | 					], | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					(err) => callback(err) | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				this.hooks.emitRecords.callAsync(callback); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | 		} else if (this.recordsOutputPath) { | 
					
						
							|  |  |  | 			this._emitRecords(callback); | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 			callback(null); | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {ErrorCallback} callback signals when the call finishes | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_emitRecords(callback) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const writeFile = () => { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 			/** @type {OutputFileSystem} */ | 
					
						
							|  |  |  | 			(this.outputFileSystem).writeFile( | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 				/** @type {string} */ (this.recordsOutputPath), | 
					
						
							| 
									
										
										
										
											2019-01-27 18:47:31 +08:00
										 |  |  | 				JSON.stringify( | 
					
						
							|  |  |  | 					this.records, | 
					
						
							|  |  |  | 					(n, value) => { | 
					
						
							|  |  |  | 						if ( | 
					
						
							|  |  |  | 							typeof value === "object" && | 
					
						
							|  |  |  | 							value !== null && | 
					
						
							|  |  |  | 							!Array.isArray(value) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							const keys = Object.keys(value); | 
					
						
							|  |  |  | 							if (!isSorted(keys)) { | 
					
						
							|  |  |  | 								return sortObject(value, keys); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						return value; | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					2 | 
					
						
							|  |  |  | 				), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				callback | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		const recordsOutputPathDirectory = dirname( | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 			/** @type {OutputFileSystem} */ | 
					
						
							|  |  |  | 			(this.outputFileSystem), | 
					
						
							|  |  |  | 			/** @type {string} */ | 
					
						
							|  |  |  | 			(this.recordsOutputPath) | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (!recordsOutputPathDirectory) { | 
					
						
							|  |  |  | 			return writeFile(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		mkdirp( | 
					
						
							|  |  |  | 			/** @type {OutputFileSystem} */ (this.outputFileSystem), | 
					
						
							|  |  |  | 			recordsOutputPathDirectory, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			(err) => { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 				if (err) return callback(err); | 
					
						
							|  |  |  | 				writeFile(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {ErrorCallback} callback signals when the call finishes | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	readRecords(callback) { | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 		if (this.hooks.readRecords.isUsed()) { | 
					
						
							|  |  |  | 			if (this.recordsInputPath) { | 
					
						
							| 
									
										
										
										
											2023-04-08 12:12:16 +08:00
										 |  |  | 				asyncLib.parallel( | 
					
						
							|  |  |  | 					[ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						(cb) => this.hooks.readRecords.callAsync(cb), | 
					
						
							| 
									
										
										
										
											2023-04-08 12:12:16 +08:00
										 |  |  | 						this._readRecords.bind(this) | 
					
						
							|  |  |  | 					], | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					(err) => callback(err) | 
					
						
							| 
									
										
										
										
											2023-04-08 12:12:16 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				this.records = {}; | 
					
						
							|  |  |  | 				this.hooks.readRecords.callAsync(callback); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | 		} else if (this.recordsInputPath) { | 
					
						
							|  |  |  | 			this._readRecords(callback); | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | 			this.records = {}; | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 			callback(null); | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {ErrorCallback} callback signals when the call finishes | 
					
						
							| 
									
										
										
										
											2022-01-19 21:21:10 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_readRecords(callback) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this.recordsInputPath) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			this.records = {}; | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 			return callback(null); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 		/** @type {InputFileSystem} */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		(this.inputFileSystem).stat(this.recordsInputPath, (err) => { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			// It doesn't exist
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			// We can ignore this.
 | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 			if (err) return callback(null); | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 			/** @type {InputFileSystem} */ | 
					
						
							|  |  |  | 			(this.inputFileSystem).readFile( | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 				/** @type {string} */ | 
					
						
							|  |  |  | 				(this.recordsInputPath), | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 				(err, content) => { | 
					
						
							|  |  |  | 					if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 					try { | 
					
						
							|  |  |  | 						this.records = parseJson( | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 							/** @type {Buffer} */ (content).toString("utf8") | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 						); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 					} catch (parseErr) { | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 						return callback( | 
					
						
							|  |  |  | 							new Error( | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 								`Cannot parse records: ${/** @type {Error} */ (parseErr).message}` | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 							) | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 					return callback(null); | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							|  |  |  | 	 * @param {string} compilerName the compiler's name | 
					
						
							|  |  |  | 	 * @param {number} compilerIndex the compiler's index | 
					
						
							| 
									
										
										
										
											2024-10-02 05:29:48 +08:00
										 |  |  | 	 * @param {Partial<OutputOptions>=} outputOptions the output options | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 	 * @param {Plugins=} plugins the plugins to apply | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @returns {Compiler} a child compiler | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	createChildCompiler( | 
					
						
							|  |  |  | 		compilation, | 
					
						
							|  |  |  | 		compilerName, | 
					
						
							|  |  |  | 		compilerIndex, | 
					
						
							|  |  |  | 		outputOptions, | 
					
						
							|  |  |  | 		plugins | 
					
						
							|  |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 		const childCompiler = new Compiler(this.context, { | 
					
						
							|  |  |  | 			...this.options, | 
					
						
							|  |  |  | 			output: { | 
					
						
							|  |  |  | 				...this.options.output, | 
					
						
							|  |  |  | 				...outputOptions | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		childCompiler.name = compilerName; | 
					
						
							|  |  |  | 		childCompiler.outputPath = this.outputPath; | 
					
						
							|  |  |  | 		childCompiler.inputFileSystem = this.inputFileSystem; | 
					
						
							|  |  |  | 		childCompiler.outputFileSystem = null; | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		childCompiler.resolverFactory = this.resolverFactory; | 
					
						
							| 
									
										
										
										
											2019-10-21 21:35:38 +08:00
										 |  |  | 		childCompiler.modifiedFiles = this.modifiedFiles; | 
					
						
							| 
									
										
										
										
											2019-08-29 03:12:59 +08:00
										 |  |  | 		childCompiler.removedFiles = this.removedFiles; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		childCompiler.fileTimestamps = this.fileTimestamps; | 
					
						
							|  |  |  | 		childCompiler.contextTimestamps = this.contextTimestamps; | 
					
						
							| 
									
										
										
										
											2021-05-19 22:18:37 +08:00
										 |  |  | 		childCompiler.fsStartTime = this.fsStartTime; | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 		childCompiler.cache = this.cache; | 
					
						
							| 
									
										
										
										
											2020-08-24 23:09:16 +08:00
										 |  |  | 		childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`; | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 		childCompiler._backCompat = this._backCompat; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		const relativeCompilerName = makePathsRelative( | 
					
						
							|  |  |  | 			this.context, | 
					
						
							|  |  |  | 			compilerName, | 
					
						
							|  |  |  | 			this.root | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (!this.records[relativeCompilerName]) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			this.records[relativeCompilerName] = []; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.records[relativeCompilerName][compilerIndex]) { | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 			childCompiler.records = | 
					
						
							|  |  |  | 				/** @type {Records} */ | 
					
						
							|  |  |  | 				(this.records[relativeCompilerName][compilerIndex]); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			this.records[relativeCompilerName].push((childCompiler.records = {})); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		childCompiler.parentCompilation = compilation; | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		childCompiler.root = this.root; | 
					
						
							| 
									
										
										
										
											2020-08-28 17:13:30 +08:00
										 |  |  | 		if (Array.isArray(plugins)) { | 
					
						
							|  |  |  | 			for (const plugin of plugins) { | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 				if (typeof plugin === "function") { | 
					
						
							|  |  |  | 					/** @type {WebpackPluginFunction} */ | 
					
						
							|  |  |  | 					(plugin).call(childCompiler, childCompiler); | 
					
						
							|  |  |  | 				} else if (plugin) { | 
					
						
							| 
									
										
										
										
											2023-06-07 09:07:31 +08:00
										 |  |  | 					plugin.apply(childCompiler); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-08-28 17:13:30 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		for (const name in this.hooks) { | 
					
						
							|  |  |  | 			if ( | 
					
						
							|  |  |  | 				![ | 
					
						
							|  |  |  | 					"make", | 
					
						
							|  |  |  | 					"compile", | 
					
						
							|  |  |  | 					"emit", | 
					
						
							|  |  |  | 					"afterEmit", | 
					
						
							|  |  |  | 					"invalid", | 
					
						
							|  |  |  | 					"done", | 
					
						
							|  |  |  | 					"thisCompilation" | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 				].includes(name) && | 
					
						
							| 
									
										
										
										
											2024-08-07 23:22:25 +08:00
										 |  |  | 				childCompiler.hooks[/** @type {keyof Compiler["hooks"]} */ (name)] | 
					
						
							| 
									
										
										
										
											2020-08-28 17:13:30 +08:00
										 |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2024-08-07 23:22:25 +08:00
										 |  |  | 				childCompiler.hooks[ | 
					
						
							|  |  |  | 					/** @type {keyof Compiler["hooks"]} */ | 
					
						
							|  |  |  | 					(name) | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 				].taps = [ | 
					
						
							|  |  |  | 					...this.hooks[ | 
					
						
							| 
									
										
										
										
											2024-08-07 23:22:25 +08:00
										 |  |  | 						/** @type {keyof Compiler["hooks"]} */ | 
					
						
							|  |  |  | 						(name) | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 					].taps | 
					
						
							|  |  |  | 				]; | 
					
						
							| 
									
										
										
										
											2020-08-28 17:13:30 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-09-13 22:29:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compilation.hooks.childCompiler.call( | 
					
						
							|  |  |  | 			childCompiler, | 
					
						
							|  |  |  | 			compilerName, | 
					
						
							|  |  |  | 			compilerIndex | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-09-13 22:29:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return childCompiler; | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	isChild() { | 
					
						
							| 
									
										
										
										
											2024-07-31 11:11:11 +08:00
										 |  |  | 		return Boolean(this.parentCompilation); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-21 22:05:29 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {CompilationParams} params the compilation parameters | 
					
						
							|  |  |  | 	 * @returns {Compilation} compilation | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-09-28 01:03:55 +08:00
										 |  |  | 	createCompilation(params) { | 
					
						
							| 
									
										
										
										
											2021-03-15 17:29:51 +08:00
										 |  |  | 		this._cleanupLastCompilation(); | 
					
						
							| 
									
										
										
										
											2021-09-28 01:03:55 +08:00
										 |  |  | 		return (this._lastCompilation = new Compilation(this, params)); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {CompilationParams} params the compilation parameters | 
					
						
							|  |  |  | 	 * @returns {Compilation} the created compilation | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	newCompilation(params) { | 
					
						
							| 
									
										
										
										
											2021-09-28 01:03:55 +08:00
										 |  |  | 		const compilation = this.createCompilation(params); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		compilation.name = this.name; | 
					
						
							|  |  |  | 		compilation.records = this.records; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.thisCompilation.call(compilation, params); | 
					
						
							|  |  |  | 		this.hooks.compilation.call(compilation, params); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return compilation; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createNormalModuleFactory() { | 
					
						
							| 
									
										
										
										
											2021-07-01 17:46:59 +08:00
										 |  |  | 		this._cleanupLastNormalModuleFactory(); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		const normalModuleFactory = new NormalModuleFactory({ | 
					
						
							|  |  |  | 			context: this.options.context, | 
					
						
							| 
									
										
										
										
											2024-03-12 00:33:52 +08:00
										 |  |  | 			fs: /** @type {InputFileSystem} */ (this.inputFileSystem), | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 			resolverFactory: this.resolverFactory, | 
					
						
							| 
									
										
										
										
											2021-01-20 22:08:58 +08:00
										 |  |  | 			options: this.options.module, | 
					
						
							| 
									
										
										
										
											2025-08-29 21:08:28 +08:00
										 |  |  | 			associatedObjectForCache: this.root | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2021-07-01 17:46:59 +08:00
										 |  |  | 		this._lastNormalModuleFactory = normalModuleFactory; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.normalModuleFactory.call(normalModuleFactory); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return normalModuleFactory; | 
					
						
							| 
									
										
										
										
											2017-01-18 05:26:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-02-04 21:44:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createContextModuleFactory() { | 
					
						
							| 
									
										
										
										
											2018-03-29 13:03:28 +08:00
										 |  |  | 		const contextModuleFactory = new ContextModuleFactory(this.resolverFactory); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.contextModuleFactory.call(contextModuleFactory); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return contextModuleFactory; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	newCompilationParams() { | 
					
						
							|  |  |  | 		const params = { | 
					
						
							|  |  |  | 			normalModuleFactory: this.createNormalModuleFactory(), | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			contextModuleFactory: this.createContextModuleFactory() | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		return params; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {Callback<Compilation>} callback signals when the compilation finishes | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	compile(callback) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		const params = this.newCompilationParams(); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		this.hooks.beforeCompile.callAsync(params, (err) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.hooks.compile.call(params); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			const compilation = this.newCompilation(params); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 			const logger = compilation.getLogger("webpack.Compiler"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			logger.time("make hook"); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			this.hooks.make.callAsync(compilation, (err) => { | 
					
						
							| 
									
										
										
										
											2019-07-26 19:44:28 +08:00
										 |  |  | 				logger.timeEnd("make hook"); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 				logger.time("finish make hook"); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				this.hooks.finishMake.callAsync(compilation, (err) => { | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 					logger.timeEnd("finish make hook"); | 
					
						
							|  |  |  | 					if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 					process.nextTick(() => { | 
					
						
							|  |  |  | 						logger.time("finish compilation"); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						compilation.finish((err) => { | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 							logger.timeEnd("finish compilation"); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 							if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 							logger.time("seal compilation"); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 							compilation.seal((err) => { | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 								logger.timeEnd("seal compilation"); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 								if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 								logger.time("afterCompile hook"); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								this.hooks.afterCompile.callAsync(compilation, (err) => { | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 									logger.timeEnd("afterCompile hook"); | 
					
						
							|  |  |  | 									if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									return callback(null, compilation); | 
					
						
							|  |  |  | 								}); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 							}); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-08-22 06:40:41 +08:00
										 |  |  | 	 * @param {ErrorCallback} callback signals when the compiler closes | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 	close(callback) { | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 		if (this.watching) { | 
					
						
							|  |  |  | 			// When there is still an active watching, close this first
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			this.watching.close((_err) => { | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 				this.close(callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		this.hooks.shutdown.callAsync((err) => { | 
					
						
							| 
									
										
										
										
											2021-01-21 23:32:49 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2021-03-25 23:35:19 +08:00
										 |  |  | 			// Get rid of reference to last compilation to avoid leaking memory
 | 
					
						
							|  |  |  | 			// We can't run this._cleanupLastCompilation() as the Stats to this compilation
 | 
					
						
							| 
									
										
										
										
											2021-07-01 17:46:59 +08:00
										 |  |  | 			// might be still in use. We try to get rid of the reference to the cache instead.
 | 
					
						
							| 
									
										
										
										
											2021-03-25 23:35:19 +08:00
										 |  |  | 			this._lastCompilation = undefined; | 
					
						
							| 
									
										
										
										
											2021-07-01 17:46:59 +08:00
										 |  |  | 			this._lastNormalModuleFactory = undefined; | 
					
						
							| 
									
										
										
										
											2021-01-21 23:32:49 +08:00
										 |  |  | 			this.cache.shutdown(callback); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-01 23:59:43 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = Compiler; |