Skip to content

Commit a9ada9f

Browse files
committed
fix ProgressPlugin log
1 parent 8d509e3 commit a9ada9f

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/ProgressPlugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const median3 = (a, b, c) => {
2828
};
2929

3030
const createDefaultHandler = (profile, logger) => {
31+
let wasLogged = false;
3132
/** @type {{ value: string, time: number }[]} */
3233
const lastStateInfo = [];
3334

@@ -86,6 +87,10 @@ const createDefaultHandler = (profile, logger) => {
8687
}
8788
}
8889
}
90+
if (percentage === 0 && !wasLogged) {
91+
wasLogged = true;
92+
return;
93+
}
8994
logger.status(`${Math.floor(percentage * 100)}%`, msg, ...args);
9095
if (percentage === 1 || (!msg && args.length === 0)) logger.status();
9196
};
@@ -537,9 +542,8 @@ class ProgressPlugin {
537542
handler(0, "");
538543
}
539544
});
540-
interceptHook(compiler.hooks.initialize, 0.01, "setup", "initialize");
541-
interceptHook(compiler.hooks.beforeRun, 0.02, "setup", "before run");
542-
interceptHook(compiler.hooks.run, 0.03, "setup", "run");
545+
interceptHook(compiler.hooks.beforeRun, 0.01, "setup", "before run");
546+
interceptHook(compiler.hooks.run, 0.02, "setup", "run");
543547
interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run");
544548
interceptHook(
545549
compiler.hooks.normalModuleFactory,

test/ProgressPlugin.test.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ const createSimpleCompiler = progressOptions => {
3737
entry: "./a.js",
3838
infrastructureLogging: {
3939
debug: /Progress/
40-
}
40+
},
41+
plugins: [
42+
new webpack.ProgressPlugin({
43+
activeModules: true,
44+
...progressOptions
45+
})
46+
]
4147
});
4248

4349
compiler.outputFileSystem = createFsFromVolume(new Volume());
4450

45-
new webpack.ProgressPlugin({
46-
activeModules: true,
47-
...progressOptions
48-
}).apply(compiler);
49-
5051
return compiler;
5152
};
5253

@@ -115,6 +116,15 @@ describe("ProgressPlugin", function () {
115116
nanTest(() => createMultiCompiler(undefined, { parallelism: 1 }))
116117
);
117118

119+
it("should start print only on call run/watch", done => {
120+
const compiler = createSimpleCompiler();
121+
122+
const logs = getLogs(stderr.toString());
123+
expect(logs.join("")).toHaveLength(0);
124+
125+
compiler.close(done);
126+
});
127+
118128
it("should print profile information", () => {
119129
const compiler = createSimpleCompiler({
120130
profile: true

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy