Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
apply(compiler: any) {
if ('hooks' in compiler) {
// webpack 4+
try {
forkTsCheckerWebpackPlugin
.getCompilerHooks(compiler)
.receive.tap('fork-ts-checker-notifier-webpack-plugin', this.compilationDone);
} catch (error) {
console.error(`
Something went wrong in accessing the hooks.
Most likely the order of plugins is wrong.\n
Check the documentation for "fork-ts-checker-notifier-webpack-plugin"\n
`);
throw Error(`Error: ${error}`);
}
} else {
// webpack 2 / 3
compiler.plugin('fork-ts-checker-receive', this.compilationDone);
}
}
}
compiler.hooks.invalid.tap(`NextJsInvalid-${key}`, () => {
tsMessagesPromise = undefined
onEvent({ loading: true })
})
if (hasTypeChecking) {
const typescriptFormatter = createCodeframeFormatter({})
compiler.hooks.beforeCompile.tap(`NextJs-${key}-StartTypeCheck`, () => {
tsMessagesPromise = new Promise(resolve => {
tsMessagesResolver = msgs => resolve(msgs)
})
})
forkTsCheckerWebpackPlugin
.getCompilerHooks(compiler)
.receive.tap(
`NextJs-${key}-afterTypeScriptCheck`,
(diagnostics: NormalizedMessage[], lints: NormalizedMessage[]) => {
const allMsgs = [...diagnostics, ...lints]
const format = (message: NormalizedMessage) =>
typescriptFormatter(message, true)
const errors = allMsgs
.filter(msg => msg.severity === 'error')
.map(d => ({
file: (d.file || '').replace(/\\/g, '/'),
message: format(d),
}))
const warnings = allMsgs
.filter(msg => msg.severity === 'warning')