1
+ import type { VirtualTypeScriptEnvironment } from 'next/dist/compiled/@typescript/vfs'
2
+ import {
3
+ createSystem ,
4
+ createVirtualTypeScriptEnvironment ,
5
+ } from 'next/dist/compiled/@typescript/vfs'
6
+
1
7
import path from 'path'
2
8
3
9
import type tsModule from 'typescript/lib/tsserverlibrary'
@@ -6,23 +12,34 @@ type TypeScript = typeof import('typescript/lib/tsserverlibrary')
6
12
let ts : TypeScript
7
13
let info : tsModule . server . PluginCreateInfo
8
14
let appDirRegExp : RegExp
15
+ export let virtualTsEnv : VirtualTypeScriptEnvironment
9
16
10
17
export function log ( message : string ) {
11
18
info . project . projectService . logger . info ( message )
12
19
}
13
20
14
21
// This function has to be called initially.
15
- export function init ( opts : {
16
- ts : TypeScript
17
- info : tsModule . server . PluginCreateInfo
18
- } ) {
22
+ export function init ( opts : { ts : TypeScript ; info : tsModule . server . PluginCreateInfo } ) {
23
+ const projectDir = opts . info . project . getCurrentDirectory ( )
19
24
ts = opts . ts
20
25
info = opts . info
21
- const projectDir = info . project . getCurrentDirectory ( )
22
26
appDirRegExp = new RegExp (
23
27
'^' + ( projectDir + '(/src)?/app' ) . replace ( / [ \\ / ] / g, '[\\/]' )
24
28
)
25
- log ( 'Starting Next.js TypeScript plugin: ' + projectDir )
29
+
30
+ log ( '[next] Initializing Next.js TypeScript plugin at ' + projectDir )
31
+
32
+ const fsMap = new Map < string , string > ( )
33
+ const system = createSystem ( fsMap )
34
+ const compilerOptions = info . project . getCompilerOptions ( )
35
+ virtualTsEnv = createVirtualTypeScriptEnvironment (
36
+ system ,
37
+ [ ] ,
38
+ ts ,
39
+ compilerOptions
40
+ )
41
+
42
+ log ( '[next] Successfully initialized Next.js TypeScript plugin!' )
26
43
}
27
44
28
45
export function getTs ( ) {
0 commit comments