forked from bugsnag/webpack-bugsnag-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-reporter-plugin.js
33 lines (29 loc) · 989 Bytes
/
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
'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)
reportBuild(this.build, this.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