Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fire done logic when percent is 1, instead of using the compiler "done" hook #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const globalStates: { [key: string]: State } = {}
export default class WebpackBarPlugin extends Webpack.ProgressPlugin {
private options: any
private reporters: Reporter[]
private stats: any

constructor (options?: WebpackBarOptions) {
super({ activeModules: true })
Expand Down Expand Up @@ -150,6 +151,8 @@ export default class WebpackBarPlugin extends Webpack.ProgressPlugin {
start: process.hrtime()
})

this.stats = null

this.callReporters('start')
})

Expand All @@ -173,6 +176,13 @@ export default class WebpackBarPlugin extends Webpack.ProgressPlugin {
return
}

this.stats = stats
})
}

updateProgress (percent = 0, message = '', details = []) {
if (percent === 1) {
const { stats } = this
const hasErrors = stats.hasErrors()
const status = hasErrors ? 'with some errors' : 'successfully'

Expand All @@ -189,29 +199,25 @@ export default class WebpackBarPlugin extends Webpack.ProgressPlugin {
})

this.callReporters('progress')

this.callReporters('done', { stats })

if (!this.hasRunning) {
this.callReporters('beforeAllDone')
this.callReporters('allDone')
this.callReporters('afterAllDone')
}
})
}
} else {
const progress = Math.floor(percent * 100)
const activeModule = details.pop()

updateProgress (percent = 0, message = '', details = []) {
const progress = Math.floor(percent * 100)

const activeModule = details.pop()

Object.assign(this.state, {
progress,
message: message || '',
details,
request: parseRequest(activeModule)
})
Object.assign(this.state, {
progress,
message: message || '',
details,
request: parseRequest(activeModule)
})

this.callReporters('progress')
this.callReporters('progress')
}
}
}