* Creates an instance of MultiCompiler. * @param {Compiler[] | Record<string, Compiler>} compilers child compilers * @param {MultiCompilerOptions} options options
(compilers, options)
| 67 | * @param {MultiCompilerOptions} options options |
| 68 | */ |
| 69 | constructor(compilers, options) { |
| 70 | if (!Array.isArray(compilers)) { |
| 71 | /** @type {Compiler[]} */ |
| 72 | compilers = Object.keys(compilers).map((name) => { |
| 73 | /** @type {Record<string, Compiler>} */ |
| 74 | (compilers)[name].name = name; |
| 75 | return /** @type {Record<string, Compiler>} */ (compilers)[name]; |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | this.hooks = Object.freeze({ |
| 80 | /** @type {SyncHook<[MultiStats]>} */ |
| 81 | done: new SyncHook([class="st">"stats"]), |
| 82 | /** @type {MultiHook<SyncHook<[string | null, number]>>} */ |
| 83 | invalid: new MultiHook(compilers.map((c) => c.hooks.invalid)), |
| 84 | /** @type {MultiHook<AsyncSeriesHook<[Compiler]>>} */ |
| 85 | run: new MultiHook(compilers.map((c) => c.hooks.run)), |
| 86 | /** @type {SyncHook<[]>} */ |
| 87 | watchClose: new SyncHook([]), |
| 88 | /** @type {MultiHook<AsyncSeriesHook<[Compiler]>>} */ |
| 89 | watchRun: new MultiHook(compilers.map((c) => c.hooks.watchRun)), |
| 90 | /** @type {MultiHook<SyncBailHook<[string, string, EXPECTED_ANY[] | undefined], true | void>>} */ |
| 91 | infrastructureLog: new MultiHook( |
| 92 | compilers.map((c) => c.hooks.infrastructureLog) |
| 93 | ) |
| 94 | }); |
| 95 | /** @type {Compiler[]} */ |
| 96 | this.compilers = compilers; |
| 97 | /** @type {MultiCompilerOptions} */ |
| 98 | this._options = { |
| 99 | parallelism: options.parallelism || Infinity |
| 100 | }; |
| 101 | /** @type {WeakMap<Compiler, string[]>} */ |
| 102 | this.dependencies = new WeakMap(); |
| 103 | /** @type {boolean} */ |
| 104 | this.running = false; |
| 105 | |
| 106 | /** @type {(Stats | null)[]} */ |
| 107 | const compilerStats = this.compilers.map(() => null); |
| 108 | let doneCompilers = 0; |
| 109 | for (let index = 0; index < this.compilers.length; index++) { |
| 110 | const compiler = this.compilers[index]; |
| 111 | const compilerIndex = index; |
| 112 | let compilerDone = false; |
| 113 | class="cm">// eslint-disable-next-line no-loop-func |
| 114 | compiler.hooks.done.tap(CLASS_NAME, (stats) => { |
| 115 | if (!compilerDone) { |
| 116 | compilerDone = true; |
| 117 | doneCompilers++; |
| 118 | } |
| 119 | compilerStats[compilerIndex] = stats; |
| 120 | if (doneCompilers === this.compilers.length) { |
| 121 | this.hooks.done.call( |
| 122 | new MultiStats(/** @type {Stats[]} */ (compilerStats)) |
| 123 | ); |
| 124 | } |
| 125 | }); |
| 126 | class="cm">// eslint-disable-next-line no-loop-func |
nothing calls this directly
no test coverage detected