Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function tapCompiler(
key: string,
compiler: any,
hasTypeChecking: boolean,
onEvent: (status: WebpackStatus) => void
) {
let tsMessagesPromise: Promise | undefined
let tsMessagesResolver: (diagnostics: CompilerDiagnosticsWithFile) => void
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)