| 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | const asyncLib = require("neo-async");
|
|---|
| 9 |
|
|---|
| 10 | /** @typedef {import("./MultiCompiler")} MultiCompiler */
|
|---|
| 11 | /** @typedef {import("./Watching")} Watching */
|
|---|
| 12 | /** @typedef {import("./webpack").ErrorCallback} ErrorCallback */
|
|---|
| 13 |
|
|---|
| 14 | class MultiWatching {
|
|---|
| 15 | /**
|
|---|
| 16 | * Creates an instance of MultiWatching.
|
|---|
| 17 | * @param {Watching[]} watchings child compilers' watchers
|
|---|
| 18 | * @param {MultiCompiler} compiler the compiler
|
|---|
| 19 | */
|
|---|
| 20 | constructor(watchings, compiler) {
|
|---|
| 21 | this.watchings = watchings;
|
|---|
| 22 | this.compiler = compiler;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | /**
|
|---|
| 26 | * Processes the provided error callback.
|
|---|
| 27 | * @param {ErrorCallback=} callback signals when the build has completed again
|
|---|
| 28 | * @returns {void}
|
|---|
| 29 | */
|
|---|
| 30 | invalidate(callback) {
|
|---|
| 31 | if (callback) {
|
|---|
| 32 | asyncLib.each(
|
|---|
| 33 | this.watchings,
|
|---|
| 34 | (watching, callback) => watching.invalidate(callback),
|
|---|
| 35 | (err) => {
|
|---|
| 36 | callback(/** @type {Error | null} */ (err));
|
|---|
| 37 | }
|
|---|
| 38 | );
|
|---|
| 39 | } else {
|
|---|
| 40 | for (const watching of this.watchings) {
|
|---|
| 41 | watching.invalidate();
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | suspend() {
|
|---|
| 47 | for (const watching of this.watchings) {
|
|---|
| 48 | watching.suspend();
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | resume() {
|
|---|
| 53 | for (const watching of this.watchings) {
|
|---|
| 54 | watching.resume();
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | /**
|
|---|
| 59 | * Processes the provided error callback.
|
|---|
| 60 | * @param {ErrorCallback} callback signals when the watcher is closed
|
|---|
| 61 | * @returns {void}
|
|---|
| 62 | */
|
|---|
| 63 | close(callback) {
|
|---|
| 64 | asyncLib.each(
|
|---|
| 65 | this.watchings,
|
|---|
| 66 | (watching, finishedCallback) => {
|
|---|
| 67 | watching.close(finishedCallback);
|
|---|
| 68 | },
|
|---|
| 69 | (err) => {
|
|---|
| 70 | this.compiler.hooks.watchClose.call();
|
|---|
| 71 | if (typeof callback === "function") {
|
|---|
| 72 | this.compiler.running = false;
|
|---|
| 73 | callback(/** @type {Error | null} */ (err));
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | );
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | module.exports = MultiWatching;
|
|---|