Skip to content

Commit

Permalink
fix: prevent calling done hook twice
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 9, 2018
1 parent 4e0dc73 commit 1753826
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const DEFAULTS = {
const DEFAULT_STATE = {
start: null,
progress: -1,
done: false,
message: '',
details: [],
request: null,
Expand Down Expand Up @@ -100,7 +101,7 @@ export default class WebpackBarPlugin extends ProgressPlugin {
}

get hasRunning() {
return Object.values(this.states).some((state) => state.progress !== 100);
return Object.values(this.states).some((state) => !state.done);
}

get hasErrors() {
Expand Down Expand Up @@ -169,6 +170,11 @@ export default class WebpackBarPlugin extends ProgressPlugin {
hook(compiler, 'done', (stats) => {
this._ensureState();

// Prevent calling done twice
if (this.state.done) {
return;
}

const hasErrors = stats.hasErrors();
const status = hasErrors ? 'with some errors' : 'succesfuly';

Expand All @@ -179,6 +185,7 @@ export default class WebpackBarPlugin extends ProgressPlugin {
Object.assign(this.state, {
...DEFAULT_STATE,
progress: 100,
done: true,
message: `Compiled ${status}${time}`,
hasErrors,
});
Expand Down

0 comments on commit 1753826

Please sign in to comment.