MultiCompiler.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const asyncLib = require("neo-async");
  7. const { MultiHook, SyncHook } = require("tapable");
  8. const ConcurrentCompilationError = require("./ConcurrentCompilationError");
  9. const MultiStats = require("./MultiStats");
  10. const MultiWatching = require("./MultiWatching");
  11. const WebpackError = require("./WebpackError");
  12. const ArrayQueue = require("./util/ArrayQueue");
  13. /**
  14. * Defines the shared type used by this module.
  15. * @template T
  16. * @typedef {import("tapable").AsyncSeriesHook<T>} AsyncSeriesHook<T>
  17. */
  18. /**
  19. * Defines the shared type used by this module.
  20. * @template T
  21. * @template R
  22. * @typedef {import("tapable").SyncBailHook<T, R>} SyncBailHook<T, R>
  23. */
  24. /** @typedef {import("../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
  25. /** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */
  26. /** @typedef {import("./Compiler")} Compiler */
  27. /**
  28. * Defines the callback type used by this module.
  29. * @template T
  30. * @template [R=void]
  31. * @typedef {import("./webpack").Callback<T, R>} Callback
  32. */
  33. /** @typedef {import("./webpack").ErrorCallback} ErrorCallback */
  34. /** @typedef {import("./Stats")} Stats */
  35. /** @typedef {import("./logging/Logger").Logger} Logger */
  36. /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
  37. /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
  38. /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
  39. /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
  40. /**
  41. * Defines the run with dependencies handler callback.
  42. * @callback RunWithDependenciesHandler
  43. * @param {Compiler} compiler
  44. * @param {Callback<MultiStats>} callback
  45. * @returns {void}
  46. */
  47. /**
  48. * Defines the multi compiler options type used by this module.
  49. * @typedef {object} MultiCompilerOptions
  50. * @property {number=} parallelism how many Compilers are allows to run at the same time in parallel
  51. */
  52. /** @typedef {ReadonlyArray<WebpackOptions> & MultiCompilerOptions} MultiWebpackOptions */
  53. const CLASS_NAME = "MultiCompiler";
  54. module.exports = class MultiCompiler {
  55. /**
  56. * Creates an instance of MultiCompiler.
  57. * @param {Compiler[] | Record<string, Compiler>} compilers child compilers
  58. * @param {MultiCompilerOptions} options options
  59. */
  60. constructor(compilers, options) {
  61. if (!Array.isArray(compilers)) {
  62. /** @type {Compiler[]} */
  63. compilers = Object.keys(compilers).map((name) => {
  64. /** @type {Record<string, Compiler>} */
  65. (compilers)[name].name = name;
  66. return /** @type {Record<string, Compiler>} */ (compilers)[name];
  67. });
  68. }
  69. this.hooks = Object.freeze({
  70. /** @type {SyncHook<[MultiStats]>} */
  71. done: new SyncHook(["stats"]),
  72. /** @type {MultiHook<SyncHook<[string | null, number]>>} */
  73. invalid: new MultiHook(compilers.map((c) => c.hooks.invalid)),
  74. /** @type {MultiHook<AsyncSeriesHook<[Compiler]>>} */
  75. run: new MultiHook(compilers.map((c) => c.hooks.run)),
  76. /** @type {SyncHook<[]>} */
  77. watchClose: new SyncHook([]),
  78. /** @type {MultiHook<AsyncSeriesHook<[Compiler]>>} */
  79. watchRun: new MultiHook(compilers.map((c) => c.hooks.watchRun)),
  80. /** @type {MultiHook<SyncBailHook<[string, string, EXPECTED_ANY[] | undefined], true | void>>} */
  81. infrastructureLog: new MultiHook(
  82. compilers.map((c) => c.hooks.infrastructureLog)
  83. )
  84. });
  85. this.compilers = compilers;
  86. /** @type {MultiCompilerOptions} */
  87. this._options = {
  88. parallelism: options.parallelism || Infinity
  89. };
  90. /** @type {WeakMap<Compiler, string[]>} */
  91. this.dependencies = new WeakMap();
  92. this.running = false;
  93. /** @type {(Stats | null)[]} */
  94. const compilerStats = this.compilers.map(() => null);
  95. let doneCompilers = 0;
  96. for (let index = 0; index < this.compilers.length; index++) {
  97. const compiler = this.compilers[index];
  98. const compilerIndex = index;
  99. let compilerDone = false;
  100. // eslint-disable-next-line no-loop-func
  101. compiler.hooks.done.tap(CLASS_NAME, (stats) => {
  102. if (!compilerDone) {
  103. compilerDone = true;
  104. doneCompilers++;
  105. }
  106. compilerStats[compilerIndex] = stats;
  107. if (doneCompilers === this.compilers.length) {
  108. this.hooks.done.call(
  109. new MultiStats(/** @type {Stats[]} */ (compilerStats))
  110. );
  111. }
  112. });
  113. // eslint-disable-next-line no-loop-func
  114. compiler.hooks.invalid.tap(CLASS_NAME, () => {
  115. if (compilerDone) {
  116. compilerDone = false;
  117. doneCompilers--;
  118. }
  119. });
  120. }
  121. this._validateCompilersOptions();
  122. }
  123. _validateCompilersOptions() {
  124. if (this.compilers.length < 2) return;
  125. /**
  126. * Adds the provided compiler to the multi compiler.
  127. * @param {Compiler} compiler compiler
  128. * @param {WebpackError} warning warning
  129. */
  130. const addWarning = (compiler, warning) => {
  131. compiler.hooks.thisCompilation.tap(CLASS_NAME, (compilation) => {
  132. compilation.warnings.push(warning);
  133. });
  134. };
  135. /** @type {Set<string>} */
  136. const cacheNames = new Set();
  137. for (const compiler of this.compilers) {
  138. if (compiler.options.cache && "name" in compiler.options.cache) {
  139. const name = /** @type {string} */ (compiler.options.cache.name);
  140. if (cacheNames.has(name)) {
  141. addWarning(
  142. compiler,
  143. new WebpackError(
  144. `${
  145. compiler.name
  146. ? `Compiler with name "${compiler.name}" doesn't use unique cache name. `
  147. : ""
  148. }Please set unique "cache.name" option. Name "${name}" already used.`
  149. )
  150. );
  151. } else {
  152. cacheNames.add(name);
  153. }
  154. }
  155. }
  156. }
  157. get options() {
  158. return Object.assign(
  159. this.compilers.map((c) => c.options),
  160. this._options
  161. );
  162. }
  163. get outputPath() {
  164. let commonPath = this.compilers[0].outputPath;
  165. for (const compiler of this.compilers) {
  166. while (
  167. compiler.outputPath.indexOf(commonPath) !== 0 &&
  168. /[/\\]/.test(commonPath)
  169. ) {
  170. commonPath = commonPath.replace(/[/\\][^/\\]*$/, "");
  171. }
  172. }
  173. if (!commonPath && this.compilers[0].outputPath[0] === "/") return "/";
  174. return commonPath;
  175. }
  176. get inputFileSystem() {
  177. throw new Error("Cannot read inputFileSystem of a MultiCompiler");
  178. }
  179. /**
  180. * Sets input file system.
  181. * @param {InputFileSystem} value the new input file system
  182. */
  183. set inputFileSystem(value) {
  184. for (const compiler of this.compilers) {
  185. compiler.inputFileSystem = value;
  186. }
  187. }
  188. get outputFileSystem() {
  189. throw new Error("Cannot read outputFileSystem of a MultiCompiler");
  190. }
  191. /**
  192. * Sets output file system.
  193. * @param {OutputFileSystem} value the new output file system
  194. */
  195. set outputFileSystem(value) {
  196. for (const compiler of this.compilers) {
  197. compiler.outputFileSystem = value;
  198. }
  199. }
  200. get watchFileSystem() {
  201. throw new Error("Cannot read watchFileSystem of a MultiCompiler");
  202. }
  203. /**
  204. * Sets watch file system.
  205. * @param {WatchFileSystem} value the new watch file system
  206. */
  207. set watchFileSystem(value) {
  208. for (const compiler of this.compilers) {
  209. compiler.watchFileSystem = value;
  210. }
  211. }
  212. /**
  213. * Sets intermediate file system.
  214. * @param {IntermediateFileSystem} value the new intermediate file system
  215. */
  216. set intermediateFileSystem(value) {
  217. for (const compiler of this.compilers) {
  218. compiler.intermediateFileSystem = value;
  219. }
  220. }
  221. get intermediateFileSystem() {
  222. throw new Error("Cannot read outputFileSystem of a MultiCompiler");
  223. }
  224. /**
  225. * Gets infrastructure logger.
  226. * @param {string | (() => string)} name name of the logger, or function called once to get the logger name
  227. * @returns {Logger} a logger with that name
  228. */
  229. getInfrastructureLogger(name) {
  230. return this.compilers[0].getInfrastructureLogger(name);
  231. }
  232. /**
  233. * Updates dependencies using the provided compiler.
  234. * @param {Compiler} compiler the child compiler
  235. * @param {string[]} dependencies its dependencies
  236. * @returns {void}
  237. */
  238. setDependencies(compiler, dependencies) {
  239. this.dependencies.set(compiler, dependencies);
  240. }
  241. /**
  242. * Validate dependencies.
  243. * @param {Callback<MultiStats>} callback signals when the validation is complete
  244. * @returns {boolean} true if the dependencies are valid
  245. */
  246. validateDependencies(callback) {
  247. /** @type {Set<{ source: Compiler, target: Compiler }>} */
  248. const edges = new Set();
  249. /** @type {string[]} */
  250. const missing = [];
  251. /**
  252. * Returns target was found.
  253. * @param {Compiler} compiler compiler
  254. * @returns {boolean} target was found
  255. */
  256. const targetFound = (compiler) => {
  257. for (const edge of edges) {
  258. if (edge.target === compiler) {
  259. return true;
  260. }
  261. }
  262. return false;
  263. };
  264. /**
  265. * Returns result.
  266. * @param {{ source: Compiler, target: Compiler }} e1 edge 1
  267. * @param {{ source: Compiler, target: Compiler }} e2 edge 2
  268. * @returns {number} result
  269. */
  270. const sortEdges = (e1, e2) =>
  271. /** @type {string} */
  272. (e1.source.name).localeCompare(/** @type {string} */ (e2.source.name)) ||
  273. /** @type {string} */
  274. (e1.target.name).localeCompare(/** @type {string} */ (e2.target.name));
  275. for (const source of this.compilers) {
  276. const dependencies = this.dependencies.get(source);
  277. if (dependencies) {
  278. for (const dep of dependencies) {
  279. const target = this.compilers.find((c) => c.name === dep);
  280. if (!target) {
  281. missing.push(dep);
  282. } else {
  283. edges.add({
  284. source,
  285. target
  286. });
  287. }
  288. }
  289. }
  290. }
  291. /** @type {string[]} */
  292. const errors = missing.map(
  293. (m) => `Compiler dependency \`${m}\` not found.`
  294. );
  295. const stack = this.compilers.filter((c) => !targetFound(c));
  296. while (stack.length > 0) {
  297. const current = stack.pop();
  298. for (const edge of edges) {
  299. if (edge.source === current) {
  300. edges.delete(edge);
  301. const target = edge.target;
  302. if (!targetFound(target)) {
  303. stack.push(target);
  304. }
  305. }
  306. }
  307. }
  308. if (edges.size > 0) {
  309. /** @type {string[]} */
  310. const lines = [...edges]
  311. .sort(sortEdges)
  312. .map((edge) => `${edge.source.name} -> ${edge.target.name}`);
  313. lines.unshift("Circular dependency found in compiler dependencies.");
  314. errors.unshift(lines.join("\n"));
  315. }
  316. if (errors.length > 0) {
  317. const message = errors.join("\n");
  318. callback(new Error(message));
  319. return false;
  320. }
  321. return true;
  322. }
  323. // TODO webpack 6 remove
  324. /**
  325. * Run with dependencies.
  326. * @deprecated This method should have been private
  327. * @param {Compiler[]} compilers the child compilers
  328. * @param {RunWithDependenciesHandler} fn a handler to run for each compiler
  329. * @param {Callback<Stats[]>} callback the compiler's handler
  330. * @returns {void}
  331. */
  332. runWithDependencies(compilers, fn, callback) {
  333. /** @type {Set<string>} */
  334. const fulfilledNames = new Set();
  335. let remainingCompilers = compilers;
  336. /**
  337. * Checks whether this multi compiler is dependency fulfilled.
  338. * @param {string} d dependency
  339. * @returns {boolean} when dependency was fulfilled
  340. */
  341. const isDependencyFulfilled = (d) => fulfilledNames.has(d);
  342. /**
  343. * Gets ready compilers.
  344. * @returns {Compiler[]} compilers
  345. */
  346. const getReadyCompilers = () => {
  347. /** @type {Compiler[]} */
  348. const readyCompilers = [];
  349. const list = remainingCompilers;
  350. remainingCompilers = [];
  351. for (const c of list) {
  352. const dependencies = this.dependencies.get(c);
  353. const ready =
  354. !dependencies || dependencies.every(isDependencyFulfilled);
  355. if (ready) {
  356. readyCompilers.push(c);
  357. } else {
  358. remainingCompilers.push(c);
  359. }
  360. }
  361. return readyCompilers;
  362. };
  363. /**
  364. * Processes the provided stat.
  365. * @param {Callback<Stats[]>} callback callback
  366. * @returns {void}
  367. */
  368. const runCompilers = (callback) => {
  369. if (remainingCompilers.length === 0) return callback(null);
  370. asyncLib.map(
  371. getReadyCompilers(),
  372. (compiler, callback) => {
  373. fn(compiler, (err) => {
  374. if (err) return callback(err);
  375. fulfilledNames.add(/** @type {string} */ (compiler.name));
  376. runCompilers(callback);
  377. });
  378. },
  379. (err, results) => {
  380. callback(/** @type {Error | null} */ (err), results);
  381. }
  382. );
  383. };
  384. runCompilers(callback);
  385. }
  386. /**
  387. * Returns result of setup.
  388. * @template SetupResult
  389. * @param {(compiler: Compiler, index: number, doneCallback: Callback<Stats>, isBlocked: () => boolean, setChanged: () => void, setInvalid: () => void) => SetupResult} setup setup a single compiler
  390. * @param {(compiler: Compiler, setupResult: SetupResult, callback: Callback<Stats>) => void} run run/continue a single compiler
  391. * @param {Callback<MultiStats>} callback callback when all compilers are done, result includes Stats of all changed compilers
  392. * @returns {SetupResult[]} result of setup
  393. */
  394. _runGraph(setup, run, callback) {
  395. /** @typedef {{ compiler: Compiler, setupResult: undefined | SetupResult, result: undefined | Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
  396. // State transitions for nodes:
  397. // -> blocked (initial)
  398. // blocked -> starting [running++] (when all parents done)
  399. // queued -> starting [running++] (when processing the queue)
  400. // starting -> running (when run has been called)
  401. // running -> done [running--] (when compilation is done)
  402. // done -> pending (when invalidated from file change)
  403. // pending -> blocked [add to queue] (when invalidated from aggregated changes)
  404. // done -> blocked [add to queue] (when invalidated, from parent invalidation)
  405. // running -> running-outdated (when invalidated, either from change or parent invalidation)
  406. // running-outdated -> blocked [running--] (when compilation is done)
  407. /** @type {Node[]} */
  408. const nodes = this.compilers.map((compiler) => ({
  409. compiler,
  410. setupResult: undefined,
  411. result: undefined,
  412. state: "blocked",
  413. children: [],
  414. parents: []
  415. }));
  416. /** @type {Map<string, Node>} */
  417. const compilerToNode = new Map();
  418. for (const node of nodes) {
  419. compilerToNode.set(/** @type {string} */ (node.compiler.name), node);
  420. }
  421. for (const node of nodes) {
  422. const dependencies = this.dependencies.get(node.compiler);
  423. if (!dependencies) continue;
  424. for (const dep of dependencies) {
  425. const parent = /** @type {Node} */ (compilerToNode.get(dep));
  426. node.parents.push(parent);
  427. parent.children.push(node);
  428. }
  429. }
  430. /** @type {ArrayQueue<Node>} */
  431. const queue = new ArrayQueue();
  432. for (const node of nodes) {
  433. if (node.parents.length === 0) {
  434. node.state = "queued";
  435. queue.enqueue(node);
  436. }
  437. }
  438. let errored = false;
  439. let running = 0;
  440. const parallelism = /** @type {number} */ (this._options.parallelism);
  441. /**
  442. * Processes the provided node.
  443. * @param {Node} node node
  444. * @param {(Error | null)=} err error
  445. * @param {Stats=} stats result
  446. * @returns {void}
  447. */
  448. const nodeDone = (node, err, stats) => {
  449. if (errored) return;
  450. if (err) {
  451. errored = true;
  452. return asyncLib.each(
  453. nodes,
  454. (node, callback) => {
  455. if (node.compiler.watching) {
  456. node.compiler.watching.close(callback);
  457. } else {
  458. callback();
  459. }
  460. },
  461. () => callback(err)
  462. );
  463. }
  464. node.result = stats;
  465. running--;
  466. if (node.state === "running") {
  467. node.state = "done";
  468. for (const child of node.children) {
  469. if (child.state === "blocked") queue.enqueue(child);
  470. }
  471. } else if (node.state === "running-outdated") {
  472. node.state = "blocked";
  473. queue.enqueue(node);
  474. }
  475. processQueue();
  476. };
  477. /**
  478. * Node invalid from parent.
  479. * @param {Node} node node
  480. * @returns {void}
  481. */
  482. const nodeInvalidFromParent = (node) => {
  483. if (node.state === "done") {
  484. node.state = "blocked";
  485. } else if (node.state === "running") {
  486. node.state = "running-outdated";
  487. }
  488. for (const child of node.children) {
  489. nodeInvalidFromParent(child);
  490. }
  491. };
  492. /**
  493. * Processes the provided node.
  494. * @param {Node} node node
  495. * @returns {void}
  496. */
  497. const nodeInvalid = (node) => {
  498. if (node.state === "done") {
  499. node.state = "pending";
  500. } else if (node.state === "running") {
  501. node.state = "running-outdated";
  502. }
  503. for (const child of node.children) {
  504. nodeInvalidFromParent(child);
  505. }
  506. };
  507. /**
  508. * Processes the provided node.
  509. * @param {Node} node node
  510. * @returns {void}
  511. */
  512. const nodeChange = (node) => {
  513. nodeInvalid(node);
  514. if (node.state === "pending") {
  515. node.state = "blocked";
  516. }
  517. if (node.state === "blocked") {
  518. queue.enqueue(node);
  519. processQueue();
  520. }
  521. };
  522. /** @type {SetupResult[]} */
  523. const setupResults = [];
  524. for (const [i, node] of nodes.entries()) {
  525. setupResults.push(
  526. (node.setupResult = setup(
  527. node.compiler,
  528. i,
  529. nodeDone.bind(null, node),
  530. () => node.state !== "starting" && node.state !== "running",
  531. () => nodeChange(node),
  532. () => nodeInvalid(node)
  533. ))
  534. );
  535. }
  536. let processing = true;
  537. const processQueue = () => {
  538. if (processing) return;
  539. processing = true;
  540. process.nextTick(processQueueWorker);
  541. };
  542. const processQueueWorker = () => {
  543. // eslint-disable-next-line no-unmodified-loop-condition
  544. while (running < parallelism && queue.length > 0 && !errored) {
  545. const node = /** @type {Node} */ (queue.dequeue());
  546. if (
  547. node.state === "queued" ||
  548. (node.state === "blocked" &&
  549. node.parents.every((p) => p.state === "done"))
  550. ) {
  551. running++;
  552. node.state = "starting";
  553. run(
  554. node.compiler,
  555. /** @type {SetupResult} */ (node.setupResult),
  556. nodeDone.bind(null, node)
  557. );
  558. node.state = "running";
  559. }
  560. }
  561. processing = false;
  562. if (
  563. !errored &&
  564. running === 0 &&
  565. nodes.every((node) => node.state === "done")
  566. ) {
  567. /** @type {Stats[]} */
  568. const stats = [];
  569. for (const node of nodes) {
  570. const result = node.result;
  571. if (result) {
  572. node.result = undefined;
  573. stats.push(result);
  574. }
  575. }
  576. if (stats.length > 0) {
  577. callback(null, new MultiStats(stats));
  578. }
  579. }
  580. };
  581. processQueueWorker();
  582. return setupResults;
  583. }
  584. /**
  585. * Returns a compiler watcher.
  586. * @param {WatchOptions | WatchOptions[]} watchOptions the watcher's options
  587. * @param {Callback<MultiStats>} handler signals when the call finishes
  588. * @returns {MultiWatching | undefined} a compiler watcher
  589. */
  590. watch(watchOptions, handler) {
  591. if (this.running) {
  592. handler(new ConcurrentCompilationError());
  593. return;
  594. }
  595. this.running = true;
  596. if (this.validateDependencies(handler)) {
  597. const watchings = this._runGraph(
  598. (compiler, idx, callback, isBlocked, setChanged, setInvalid) => {
  599. const watching = compiler.watch(
  600. Array.isArray(watchOptions) ? watchOptions[idx] : watchOptions,
  601. callback
  602. );
  603. if (watching) {
  604. watching._onInvalid = setInvalid;
  605. watching._onChange = setChanged;
  606. watching._isBlocked = isBlocked;
  607. }
  608. return watching;
  609. },
  610. (compiler, watching, _callback) => {
  611. if (compiler.watching !== watching) return;
  612. if (!watching.running) watching.invalidate();
  613. },
  614. handler
  615. );
  616. return new MultiWatching(watchings, this);
  617. }
  618. return new MultiWatching([], this);
  619. }
  620. /**
  621. * Processes the provided multi stat.
  622. * @param {Callback<MultiStats>} callback signals when the call finishes
  623. * @returns {void}
  624. */
  625. run(callback) {
  626. if (this.running) {
  627. callback(new ConcurrentCompilationError());
  628. return;
  629. }
  630. this.running = true;
  631. if (this.validateDependencies(callback)) {
  632. this._runGraph(
  633. () => {},
  634. (compiler, setupResult, callback) => compiler.run(callback),
  635. (err, stats) => {
  636. this.running = false;
  637. if (callback !== undefined) {
  638. return callback(err, stats);
  639. }
  640. }
  641. );
  642. }
  643. }
  644. purgeInputFileSystem() {
  645. for (const compiler of this.compilers) {
  646. if (compiler.inputFileSystem && compiler.inputFileSystem.purge) {
  647. compiler.inputFileSystem.purge();
  648. }
  649. }
  650. }
  651. /**
  652. * Processes the provided error callback.
  653. * @param {ErrorCallback} callback signals when the compiler closes
  654. * @returns {void}
  655. */
  656. close(callback) {
  657. asyncLib.each(
  658. this.compilers,
  659. (compiler, callback) => {
  660. compiler.close(callback);
  661. },
  662. (error) => {
  663. callback(/** @type {Error | null} */ (error));
  664. }
  665. );
  666. }
  667. };