-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbuild-reporter-plugin.js
39 lines (34 loc) · 1.18 KB
/
build-reporter-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
const reportBuild = require('bugsnag-build-reporter')
class BugsnagBuildReporterPlugin {
constructor (build, options) {
this.build = Object.assign({ buildTool: 'webpack-bugsnag-plugins' }, build)
this.options = Object.assign({ logLevel: 'warn' }, options)
}
apply (compiler) {
const plugin = (compilation, cb) => {
const stats = compilation.getStats()
if (stats.hasErrors()) return cb(null)
const options = Object.assign(this.options,
!this.options.logger && compiler.getInfrastructureLogger
? { logger: compiler.getInfrastructureLogger('BugsnagBuildReporterPlugin') }
: {}
)
reportBuild(this.build, options)
.then(() => cb(null))
.catch((/* err */) => {
// ignore err: a failure to notify Bugsnag shouldn't fail the build
// plus the detail will already have been logged to the console
cb(null)
})
}
if (compiler.hooks) {
// webpack v4
compiler.hooks.afterEmit.tapAsync('BugsnagBuildReporterPlugin', plugin)
} else {
// webpack v3
compiler.plugin('after-emit', plugin)
}
}
}
module.exports = BugsnagBuildReporterPlugin