How to use the fork-ts-checker-webpack-plugin/lib/formatter/codeframeFormatter.createCodeframeFormatter function in fork-ts-checker-webpack-plugin

To help you get started, we’ve selected a few fork-ts-checker-webpack-plugin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / next.js / packages / next / build / output / index.ts View on Github external
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)