1
1
import os from 'os'
2
2
import path from 'path'
3
3
import invariant from 'tiny-invariant'
4
- import ts from 'typescript'
4
+ import type * as typescript from 'typescript'
5
5
import { fileURLToPath } from 'url'
6
6
import { parentPort } from 'worker_threads'
7
7
@@ -30,18 +30,19 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
30
30
overlay = enableOverlay
31
31
terminal = enableTerminal
32
32
} ,
33
- configureServer ( { root } ) {
33
+ async configureServer ( { root } ) {
34
34
invariant ( pluginConfig . typescript , 'config.typescript should be `false`' )
35
35
const finalConfig =
36
36
pluginConfig . typescript === true
37
- ? { root, tsconfigPath : 'tsconfig.json' }
37
+ ? { root, tsconfigPath : 'tsconfig.json' , typescriptPath : 'typescript' }
38
38
: {
39
39
root : pluginConfig . typescript . root ?? root ,
40
40
tsconfigPath : pluginConfig . typescript . tsconfigPath ?? 'tsconfig.json' ,
41
+ typescriptPath : pluginConfig . typescript . typescriptPath ?? 'typescript' ,
41
42
}
42
43
43
44
let configFile : string | undefined
44
-
45
+ const ts : typeof typescript = await import ( finalConfig . typescriptPath )
45
46
configFile = ts . findConfigFile ( finalConfig . root , ts . sys . fileExists , finalConfig . tsconfigPath )
46
47
47
48
if ( configFile === undefined ) {
@@ -53,7 +54,7 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
53
54
let logChunk = ''
54
55
55
56
// https://github.com/microsoft/TypeScript/blob/a545ab1ac2cb24ff3b1aaf0bfbfb62c499742ac2/src/compiler/watch.ts#L12-L28
56
- const reportDiagnostic = ( diagnostic : ts . Diagnostic ) => {
57
+ const reportDiagnostic = ( diagnostic : typescript . Diagnostic ) => {
57
58
const normalizedDiagnostic = normalizeTsDiagnostic ( diagnostic )
58
59
if ( normalizedDiagnostic === null ) {
59
60
return
@@ -63,7 +64,7 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
63
64
logChunk += os . EOL + diagnosticToTerminalLog ( normalizedDiagnostic , 'TypeScript' )
64
65
}
65
66
66
- const reportWatchStatusChanged : ts . WatchStatusReporter = (
67
+ const reportWatchStatusChanged : typescript . WatchStatusReporter = (
67
68
diagnostic ,
68
69
newLine ,
69
70
options ,
0 commit comments