| | |
| | | const ArrayQueue = require("./util/ArrayQueue"); |
| | | |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @template T |
| | | * @typedef {import("tapable").AsyncSeriesHook<T>} AsyncSeriesHook<T> |
| | | */ |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @template T |
| | | * @template R |
| | | * @typedef {import("tapable").SyncBailHook<T, R>} SyncBailHook<T, R> |
| | |
| | | /** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */ |
| | | /** @typedef {import("./Compiler")} Compiler */ |
| | | /** |
| | | * Defines the callback type used by this module. |
| | | * @template T |
| | | * @template [R=void] |
| | | * @typedef {import("./webpack").Callback<T, R>} Callback |
| | |
| | | /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */ |
| | | |
| | | /** |
| | | * Defines the run with dependencies handler callback. |
| | | * @callback RunWithDependenciesHandler |
| | | * @param {Compiler} compiler |
| | | * @param {Callback<MultiStats>} callback |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the multi compiler options type used by this module. |
| | | * @typedef {object} MultiCompilerOptions |
| | | * @property {number=} parallelism how many Compilers are allows to run at the same time in parallel |
| | | */ |
| | |
| | | |
| | | module.exports = class MultiCompiler { |
| | | /** |
| | | * Creates an instance of MultiCompiler. |
| | | * @param {Compiler[] | Record<string, Compiler>} compilers child compilers |
| | | * @param {MultiCompilerOptions} options options |
| | | */ |
| | |
| | | _validateCompilersOptions() { |
| | | if (this.compilers.length < 2) return; |
| | | /** |
| | | * Adds the provided compiler to the multi compiler. |
| | | * @param {Compiler} compiler compiler |
| | | * @param {WebpackError} warning warning |
| | | */ |
| | |
| | | compilation.warnings.push(warning); |
| | | }); |
| | | }; |
| | | /** @type {Set<string>} */ |
| | | const cacheNames = new Set(); |
| | | for (const compiler of this.compilers) { |
| | | if (compiler.options.cache && "name" in compiler.options.cache) { |
| | | const name = compiler.options.cache.name; |
| | | const name = /** @type {string} */ (compiler.options.cache.name); |
| | | if (cacheNames.has(name)) { |
| | | addWarning( |
| | | compiler, |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets input file system. |
| | | * @param {InputFileSystem} value the new input file system |
| | | */ |
| | | set inputFileSystem(value) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets output file system. |
| | | * @param {OutputFileSystem} value the new output file system |
| | | */ |
| | | set outputFileSystem(value) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets watch file system. |
| | | * @param {WatchFileSystem} value the new watch file system |
| | | */ |
| | | set watchFileSystem(value) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets intermediate file system. |
| | | * @param {IntermediateFileSystem} value the new intermediate file system |
| | | */ |
| | | set intermediateFileSystem(value) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets infrastructure logger. |
| | | * @param {string | (() => string)} name name of the logger, or function called once to get the logger name |
| | | * @returns {Logger} a logger with that name |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates dependencies using the provided compiler. |
| | | * @param {Compiler} compiler the child compiler |
| | | * @param {string[]} dependencies its dependencies |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Validate dependencies. |
| | | * @param {Callback<MultiStats>} callback signals when the validation is complete |
| | | * @returns {boolean} true if the dependencies are valid |
| | | */ |
| | | validateDependencies(callback) { |
| | | /** @type {Set<{source: Compiler, target: Compiler}>} */ |
| | | /** @type {Set<{ source: Compiler, target: Compiler }>} */ |
| | | const edges = new Set(); |
| | | /** @type {string[]} */ |
| | | const missing = []; |
| | | /** |
| | | * Returns target was found. |
| | | * @param {Compiler} compiler compiler |
| | | * @returns {boolean} target was found |
| | | */ |
| | |
| | | return false; |
| | | }; |
| | | /** |
| | | * @param {{source: Compiler, target: Compiler}} e1 edge 1 |
| | | * @param {{source: Compiler, target: Compiler}} e2 edge 2 |
| | | * Returns result. |
| | | * @param {{ source: Compiler, target: Compiler }} e1 edge 1 |
| | | * @param {{ source: Compiler, target: Compiler }} e2 edge 2 |
| | | * @returns {number} result |
| | | */ |
| | | const sortEdges = (e1, e2) => |
| | |
| | | |
| | | // TODO webpack 6 remove |
| | | /** |
| | | * Run with dependencies. |
| | | * @deprecated This method should have been private |
| | | * @param {Compiler[]} compilers the child compilers |
| | | * @param {RunWithDependenciesHandler} fn a handler to run for each compiler |
| | |
| | | * @returns {void} |
| | | */ |
| | | runWithDependencies(compilers, fn, callback) { |
| | | /** @type {Set<string>} */ |
| | | const fulfilledNames = new Set(); |
| | | let remainingCompilers = compilers; |
| | | /** |
| | | * Checks whether this multi compiler is dependency fulfilled. |
| | | * @param {string} d dependency |
| | | * @returns {boolean} when dependency was fulfilled |
| | | */ |
| | | const isDependencyFulfilled = (d) => fulfilledNames.has(d); |
| | | /** |
| | | * Gets ready compilers. |
| | | * @returns {Compiler[]} compilers |
| | | */ |
| | | const getReadyCompilers = () => { |
| | | /** @type {Compiler[]} */ |
| | | const readyCompilers = []; |
| | | const list = remainingCompilers; |
| | | remainingCompilers = []; |
| | |
| | | return readyCompilers; |
| | | }; |
| | | /** |
| | | * Processes the provided stat. |
| | | * @param {Callback<Stats[]>} callback callback |
| | | * @returns {void} |
| | | */ |
| | |
| | | (compiler, callback) => { |
| | | fn(compiler, (err) => { |
| | | if (err) return callback(err); |
| | | fulfilledNames.add(compiler.name); |
| | | fulfilledNames.add(/** @type {string} */ (compiler.name)); |
| | | runCompilers(callback); |
| | | }); |
| | | }, |
| | | (err, results) => { |
| | | callback(err, results); |
| | | callback(/** @type {Error | null} */ (err), results); |
| | | } |
| | | ); |
| | | }; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns result of setup. |
| | | * @template SetupResult |
| | | * @param {(compiler: Compiler, index: number, doneCallback: Callback<Stats>, isBlocked: () => boolean, setChanged: () => void, setInvalid: () => void) => SetupResult} setup setup a single compiler |
| | | * @param {(compiler: Compiler, setupResult: SetupResult, callback: Callback<Stats>) => void} run run/continue a single compiler |
| | |
| | | let running = 0; |
| | | const parallelism = /** @type {number} */ (this._options.parallelism); |
| | | /** |
| | | * Processes the provided node. |
| | | * @param {Node} node node |
| | | * @param {(Error | null)=} err error |
| | | * @param {Stats=} stats result |
| | |
| | | processQueue(); |
| | | }; |
| | | /** |
| | | * Node invalid from parent. |
| | | * @param {Node} node node |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | }; |
| | | /** |
| | | * Processes the provided node. |
| | | * @param {Node} node node |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | }; |
| | | /** |
| | | * Processes the provided node. |
| | | * @param {Node} node node |
| | | * @returns {void} |
| | | */ |
| | |
| | | running === 0 && |
| | | nodes.every((node) => node.state === "done") |
| | | ) { |
| | | /** @type {Stats[]} */ |
| | | const stats = []; |
| | | for (const node of nodes) { |
| | | const result = node.result; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns a compiler watcher. |
| | | * @param {WatchOptions | WatchOptions[]} watchOptions the watcher's options |
| | | * @param {Callback<MultiStats>} handler signals when the call finishes |
| | | * @returns {MultiWatching | undefined} a compiler watcher |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided multi stat. |
| | | * @param {Callback<MultiStats>} callback signals when the call finishes |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided error callback. |
| | | * @param {ErrorCallback} callback signals when the compiler closes |
| | | * @returns {void} |
| | | */ |
| | |
| | | compiler.close(callback); |
| | | }, |
| | | (error) => { |
| | | callback(error); |
| | | callback(/** @type {Error | null} */ (error)); |
| | | } |
| | | ); |
| | | } |