rsnext/packages/next/build/webpack/plugins/wellknown-errors-plugin/index.ts
Tobias Koppers d2f96f5f9c
partially migrate to webpack 5 types (#30189)
fix type declarations to avoid import from webpack/webpack4/webpack5 in type declarations
2021-10-24 23:04:26 +02:00

31 lines
967 B
TypeScript

import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
import { getModuleBuildError } from './webpackModuleError'
export class WellKnownErrorsPlugin {
apply(compiler: webpack.Compiler) {
compiler.hooks.compilation.tap('WellKnownErrorsPlugin', (compilation) => {
compilation.hooks.afterSeal.tapPromise(
'WellKnownErrorsPlugin',
async () => {
if (compilation.errors?.length) {
await Promise.all(
compilation.errors.map(async (err, i) => {
try {
const moduleError = await getModuleBuildError(
compilation,
err
)
if (moduleError !== false) {
compilation.errors[i] = moduleError
}
} catch (e) {
console.log(e)
}
})
)
}
}
)
})
}
}