Skip to content

Commit

Permalink
Unsilence Taskr Webpack errors (#56542)
Browse files Browse the repository at this point in the history
Discovered while investigating #56526, turns out errors occuring during webpack builds do not fail the `pnpm build` which kicks off `taskr`. This is because `taskr` runs their plugins within coroutines, which based on the result, was not handling the promise rejections as expected.
  • Loading branch information
wyattjoh committed Oct 6, 2023
1 parent 67cd914 commit 50dff93
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions packages/next/taskfile-webpack.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
const webpack = require('webpack')

module.exports = function (task) {
// eslint-disable-next-line require-yield
task.plugin('webpack', {}, function* (_, options) {
options = options || {}

const compiler = webpack(options.config)

if (options.watch) {
compiler.watch({}, (err, stats) => {
return compiler.watch({}, (err, stats) => {
if (err || stats.hasErrors()) {
console.error(err || stats.toString())
} else {
console.log(`${options.name} compiled successfully.`)
}
})
} else {
yield new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err || stats.hasErrors()) {
console.error(err || stats.toString())
reject(err || stats.toString())
}
if (process.env.ANALYZE) {
require('fs').writeFileSync(
require('path').join(__dirname, options.name + '-stats.json'),
JSON.stringify(stats.toJson())
)
}
resolve()
})
})
}

return new Promise((resolve) => {
compiler.run((err, stats) => {
if (err || stats.hasErrors()) {
return this.emit('plugin_error', {
plugin: 'taskfile-webpack',
error: err?.message ?? stats.toString(),
})
}

if (process.env.ANALYZE) {
require('fs').writeFileSync(
require('path').join(__dirname, options.name + '-stats.json'),
JSON.stringify(stats.toJson())
)
}

resolve()
})
})
})
}

0 comments on commit 50dff93

Please sign in to comment.