@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url'
44import { parentPort } from 'node:worker_threads'
55import * as colors from 'colorette'
66import invariant from 'tiny-invariant'
7- import ts from 'typescript'
7+ import type * as typescript from 'typescript'
88
99import { Checker } from '../../Checker.js'
1010import {
@@ -35,19 +35,25 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
3535 overlay = enableOverlay
3636 terminal = enableTerminal
3737 } ,
38- configureServer ( { root } ) {
38+ async configureServer ( { root } ) {
3939 invariant ( pluginConfig . typescript , 'config.typescript should be `false`' )
4040 const finalConfig =
4141 pluginConfig . typescript === true
42- ? { root, tsconfigPath : 'tsconfig.json' }
42+ ? {
43+ root,
44+ tsconfigPath : 'tsconfig.json' ,
45+ typescriptPath : 'typescript' ,
46+ }
4347 : {
4448 root : pluginConfig . typescript . root ?? root ,
4549 tsconfigPath :
4650 pluginConfig . typescript . tsconfigPath ?? 'tsconfig.json' ,
51+ typescriptPath :
52+ pluginConfig . typescript . typescriptPath ?? 'typescript' ,
4753 }
4854
4955 let configFile : string | undefined
50-
56+ const ts : typeof typescript = await import ( finalConfig . typescriptPath )
5157 configFile = ts . findConfigFile (
5258 finalConfig . root ,
5359 ts . sys . fileExists ,
@@ -63,7 +69,7 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
6369 let logChunk = ''
6470
6571 // https://github.com/microsoft/TypeScript/blob/a545ab1ac2cb24ff3b1aaf0bfbfb62c499742ac2/src/compiler/watch.ts#L12-L28
66- const reportDiagnostic = ( diagnostic : ts . Diagnostic ) => {
72+ const reportDiagnostic = ( diagnostic : typescript . Diagnostic ) => {
6773 const normalizedDiagnostic = normalizeTsDiagnostic ( diagnostic )
6874 if ( normalizedDiagnostic === null ) {
6975 return
@@ -74,7 +80,7 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
7480 os . EOL + diagnosticToTerminalLog ( normalizedDiagnostic , 'TypeScript' )
7581 }
7682
77- const reportWatchStatusChanged : ts . WatchStatusReporter = (
83+ const reportWatchStatusChanged : typescript . WatchStatusReporter = (
7884 diagnostic ,
7985 newLine ,
8086 options ,
0 commit comments