Skip to content

Commit

Permalink
fix: watching.close() is slow
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed May 30, 2024
1 parent 140b621 commit 50e436e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lib/scenarios/build-plugin.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const WARMUP_BUILDS = 10;
const TOTAL_BUILDS = 20;
const TOTAL_BUILDS = 110;

module.exports = class BuildPlugin {
apply(compiler) {
Expand All @@ -8,22 +8,16 @@ module.exports = class BuildPlugin {
compiler.hooks.watchRun.tap("BuildPlugin", () => {
isWatching = true;
});
(compiler.hooks.afterDone || compiler.hooks.done).tap("BuildPlugin", () => {
setTimeout(() => {
if (counter === WARMUP_BUILDS) console.log("#!# start");
if (isWatching && counter <= TOTAL_BUILDS) console.log("#!# next");
}, 10);
compiler.hooks.afterDone.tap("BuildPlugin", () => {
if (counter === WARMUP_BUILDS) console.log("#!# start");
if (isWatching && counter <= TOTAL_BUILDS) console.log("#!# next");
});
compiler.hooks.done.tap("BuildPlugin", stats => {
if (isWatching) {
counter++;
if (counter <= WARMUP_BUILDS) return;
if (counter > TOTAL_BUILDS) {
if (compiler.watching) {
compiler.watching.close();
} else {
process.nextTick(() => process.exit(0));
}
process.nextTick(() => process.exit(0));
}
}
const { logging, time } = stats.toJson({
Expand Down Expand Up @@ -69,10 +63,7 @@ module.exports = class BuildPlugin {
if (type !== "time") return;
const ms = args[1] * 1000 + args[2] / 1000000;
console.log(
`#!# ${name}.${args[0].replace(
/restore cache content \d.+$/,
"restore cache content"
)} = ${ms}`
`#!# ${name}.${args[0].replace(/restore cache content \d.+$/, "restore cache content")} = ${ms}`
);
};
}
Expand Down
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 50e436e

Please sign in to comment.