Skip to content

Commit 30bfd1e

Browse files
author
Pooya Parsa
committed
feat: accept done callback as an option
1 parent a2c823f commit 30bfd1e

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ Show the cursor. This can be useful when a CLI accepts input from a user.
116116

117117
Auto clear console when compile is finished.
118118

119+
### `done`
120+
- Type: `Function(sharedState, ctx)`
121+
122+
A function that will be called when **all** builds are finished.
123+
124+
This function can optionally return `false` as a signal to stop rendering and printing profile stats.
125+
119126
<h2 align="center">Maintainers</h2>
120127

121128
<table>

src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const defaults = {
2323
clear: true,
2424
showCursor: false,
2525
enabled: process.stdout.isTTY && !isCI,
26+
done: null,
2627
};
2728

2829
export default class WebpackBarPlugin extends webpack.ProgressPlugin {
@@ -76,6 +77,18 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
7677
return;
7778
}
7879

80+
if (Object.values(sharedState).find((s) => s.isRunning)) {
81+
return;
82+
}
83+
84+
if (typeof this.options.done === 'function') {
85+
const result = this.options.done(sharedState, this);
86+
if (result === false) {
87+
// Special signal to do nothing
88+
return;
89+
}
90+
}
91+
7992
this.render();
8093

8194
if (this.options.profile) {

test/basic.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ describe('webpackbar', () => {
1616
const logUpdate = mockLogUpdate();
1717

1818
test('compile', async () => {
19+
const done = jest.fn();
20+
1921
const compiler = webpack(
2022
basicConfig.from({
2123
name: 'test1',
2224
enabled: true,
2325
profile: true,
2426
color: '#202020',
2527
logUpdate,
28+
done,
2629
})
2730
);
2831

@@ -31,6 +34,7 @@ describe('webpackbar', () => {
3134

3235
expect(stats.hasErrors()).toBe(false);
3336
expect(stats.hasWarnings()).toBe(false);
37+
expect(done).toHaveBeenCalledTimes(1);
3438
});
3539

3640
test('logUpdate', () => {

0 commit comments

Comments
 (0)