2021-01-14 02:59:08 +01:00
|
|
|
import { webpack } from 'next/dist/compiled/webpack/webpack'
|
2020-05-13 17:43:41 +02:00
|
|
|
import { getModuleBuildError } from './webpackModuleError'
|
|
|
|
|
|
|
|
export class WellKnownErrorsPlugin {
|
2021-01-14 02:59:08 +01:00
|
|
|
apply(compiler: webpack.Compiler) {
|
2020-05-18 21:24:37 +02:00
|
|
|
compiler.hooks.compilation.tap('WellKnownErrorsPlugin', (compilation) => {
|
2020-08-05 21:11:35 +02:00
|
|
|
compilation.hooks.afterSeal.tapPromise(
|
|
|
|
'WellKnownErrorsPlugin',
|
|
|
|
async () => {
|
|
|
|
if (compilation.errors?.length) {
|
|
|
|
compilation.errors = await Promise.all(
|
|
|
|
compilation.errors.map(async (err) => {
|
|
|
|
try {
|
|
|
|
const moduleError = await getModuleBuildError(
|
|
|
|
compilation,
|
|
|
|
err
|
|
|
|
)
|
|
|
|
return moduleError === false ? err : moduleError
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2020-05-13 17:43:41 +02:00
|
|
|
}
|
2020-08-05 21:11:35 +02:00
|
|
|
)
|
2020-05-13 17:43:41 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|