2017-01-07 14:56:47 +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-01-13 01:05:47 +08:00
|
|
|
"use strict";
|
2017-01-07 14:56:47 +08:00
|
|
|
|
2018-02-11 12:27:09 +08:00
|
|
|
const asyncLib = require("neo-async");
|
2017-01-13 01:05:47 +08:00
|
|
|
|
2018-12-10 18:34:59 +08:00
|
|
|
/** @typedef {import("./MultiCompiler")} MultiCompiler */
|
|
|
|
/** @typedef {import("./Watching")} Watching */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @template T
|
|
|
|
* @callback Callback
|
|
|
|
* @param {Error=} err
|
|
|
|
* @param {T=} result
|
|
|
|
*/
|
|
|
|
|
2017-01-13 01:05:47 +08:00
|
|
|
class MultiWatching {
|
2018-12-10 18:34:59 +08:00
|
|
|
/**
|
|
|
|
* @param {Watching[]} watchings child compilers' watchers
|
|
|
|
* @param {MultiCompiler} compiler the compiler
|
|
|
|
*/
|
2017-03-06 11:32:34 +08:00
|
|
|
constructor(watchings, compiler) {
|
2017-01-13 01:05:47 +08:00
|
|
|
this.watchings = watchings;
|
2017-03-06 11:32:34 +08:00
|
|
|
this.compiler = compiler;
|
2017-01-13 01:05:47 +08:00
|
|
|
}
|
2017-01-07 14:56:47 +08:00
|
|
|
|
2020-07-31 23:38:33 +08:00
|
|
|
invalidate(callback) {
|
|
|
|
if (callback) {
|
|
|
|
asyncLib.each(
|
|
|
|
this.watchings,
|
|
|
|
(watching, callback) => watching.invalidate(callback),
|
|
|
|
callback
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
for (const watching of this.watchings) {
|
|
|
|
watching.invalidate();
|
|
|
|
}
|
2018-01-22 20:52:43 +08:00
|
|
|
}
|
2017-01-13 01:05:47 +08:00
|
|
|
}
|
2017-01-07 14:56:47 +08:00
|
|
|
|
2019-06-01 00:53:33 +08:00
|
|
|
suspend() {
|
|
|
|
for (const watching of this.watchings) {
|
|
|
|
watching.suspend();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resume() {
|
|
|
|
for (const watching of this.watchings) {
|
|
|
|
watching.resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 18:34:59 +08:00
|
|
|
/**
|
|
|
|
* @param {Callback<void>} callback signals when the watcher is closed
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-01-13 01:05:47 +08:00
|
|
|
close(callback) {
|
2018-02-25 09:00:20 +08:00
|
|
|
asyncLib.forEach(
|
|
|
|
this.watchings,
|
|
|
|
(watching, finishedCallback) => {
|
|
|
|
watching.close(finishedCallback);
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.compiler.hooks.watchClose.call();
|
|
|
|
if (typeof callback === "function") {
|
2018-03-07 18:45:38 +08:00
|
|
|
this.compiler.running = false;
|
2018-02-25 09:00:20 +08:00
|
|
|
callback(err);
|
|
|
|
}
|
2018-01-22 20:52:43 +08:00
|
|
|
}
|
2018-02-25 09:00:20 +08:00
|
|
|
);
|
2017-01-13 01:05:47 +08:00
|
|
|
}
|
|
|
|
}
|
2017-01-07 14:56:47 +08:00
|
|
|
|
|
|
|
module.exports = MultiWatching;
|