@@ -9,19 +9,11 @@ const debugError = createDebug('ts-autocomplete:error');
9
9
10
10
type TypeFilename = string ;
11
11
12
- type UpdateDefinitionFunction = ( newDef : Record < TypeFilename , string > ) => void ;
13
-
14
- // TODO
15
- /*
16
- function createIOError(code: string, details = ""): NodeJS.ErrnoException {
17
- const err: NodeJS.ErrnoException = new Error(`${code} ${details}`);
18
- err.code = code;
19
- if (Error.captureStackTrace) Error.captureStackTrace(err, createIOError);
20
- return err;
21
- }
22
- */
12
+ type UpdateDefinitionFunction = (
13
+ newDef : Record < TypeFilename , string | true > ,
14
+ ) => void ;
15
+
23
16
function relativeNodePath ( fileName : string ) : string {
24
- //console.log(fileName);
25
17
const parts = fileName . split ( / \/ n o d e _ m o d u l e s \/ / g) ;
26
18
if ( parts . length === 1 && fileName . endsWith ( 'package.json' ) ) {
27
19
// special case: when it looks up this package itself it isn't going to find
@@ -35,9 +27,6 @@ type EncounteredPaths = {
35
27
getScriptSnapshot : string [ ] ;
36
28
fileExists : string [ ] ;
37
29
readFile : string [ ] ;
38
- //readDirectory: string[],
39
- //directoryExists: string[],
40
- //getDirectories: string[]
41
30
} ;
42
31
43
32
function getVirtualLanguageService ( ) : {
@@ -60,7 +49,7 @@ function getVirtualLanguageService(): {
60
49
allowImportingTsExtensions : true ,
61
50
} ;
62
51
63
- const updateCode = ( newDef : Record < TypeFilename , string > ) : void => {
52
+ const updateCode = ( newDef : Record < TypeFilename , string | true > ) : void => {
64
53
for ( const [ key , value ] of Object . entries ( newDef ) ) {
65
54
codeHolder [ key ] = value ;
66
55
versions [ key ] = ( versions [ key ] ?? 0 ) + 1 ;
@@ -75,9 +64,6 @@ function getVirtualLanguageService(): {
75
64
getScriptSnapshot : [ ] ,
76
65
fileExists : [ ] ,
77
66
readFile : [ ] ,
78
- //readDirectory: [], // unused
79
- //directoryExists: [], // unused
80
- //getDirectories: [] // unused
81
67
} ;
82
68
const listEncounteredPaths = ( ) : EncounteredPaths => {
83
69
encounteredPaths . getScriptSnapshot . sort ( ) ;
@@ -100,61 +86,66 @@ function getVirtualLanguageService(): {
100
86
return ts . ScriptSnapshot . fromString ( codeHolder [ fileName ] . toString ( ) ) ;
101
87
}
102
88
103
- // TODO: this should not be encountered outside of CI
104
- const result = ts . ScriptSnapshot . fromString (
105
- // NOTE: some files do not exist. A good example is "typescript/lib/es2023.ts"
106
- ts . sys . readFile ( fileName ) || '' ,
107
- ) ;
89
+ if ( process . env . CI ) {
90
+ const result = ts . ScriptSnapshot . fromString (
91
+ // NOTE: some files do not exist. A good example is "typescript/lib/es2023.ts"
92
+ ts . sys . readFile ( fileName ) || '' ,
93
+ ) ;
108
94
109
- encounteredPaths . getScriptSnapshot . push ( relativeNodePath ( fileName ) ) ;
110
- return result ;
95
+ encounteredPaths . getScriptSnapshot . push ( relativeNodePath ( fileName ) ) ;
96
+ return result ;
97
+ }
111
98
} ,
112
99
getCurrentDirectory : ( ) => process . cwd ( ) ,
113
100
getCompilationSettings : ( ) => options ,
114
101
getDefaultLibFileName : ( options ) => {
115
- const defaultLibFileName = ts . getDefaultLibFilePath ( options ) ;
116
- //console.log({ defaultLibFileName })
117
- //return '/lib.es2022.full.d.ts'
118
- return defaultLibFileName ;
102
+ return ts . getDefaultLibFilePath ( options ) ;
119
103
} ,
120
104
fileExists : ( fileName ) => {
121
105
fileName = relativeNodePath ( fileName ) ;
122
106
if ( fileName in codeHolder ) {
123
107
return true ;
124
108
}
125
109
126
- // TODO: this should not be encountered outside of CI when tests will fail
127
- const result = ts . sys . fileExists ( fileName ) ;
128
- if ( result ) {
129
- encounteredPaths . fileExists . push ( relativeNodePath ( fileName ) ) ;
110
+ if ( process . env . CI ) {
111
+ const result = ts . sys . fileExists ( fileName ) ;
112
+ if ( result ) {
113
+ encounteredPaths . fileExists . push ( relativeNodePath ( fileName ) ) ;
114
+ }
115
+ return result ;
130
116
}
131
- return result ;
117
+
118
+ return false ;
132
119
} ,
133
120
readFile : ( fileName ) => {
134
121
fileName = relativeNodePath ( fileName ) ;
135
122
if ( fileName in codeHolder ) {
136
123
return codeHolder [ fileName ] . toString ( ) ;
137
124
}
138
125
139
- // TODO: this should not be encountered outside of CI when tests will fail
140
- const result = ts . sys . readFile ( fileName ) ;
141
- encounteredPaths . readFile . push ( relativeNodePath ( fileName ) ) ;
142
- return result ;
126
+ if ( process . env . CI ) {
127
+ const result = ts . sys . readFile ( fileName ) ;
128
+ encounteredPaths . readFile . push ( relativeNodePath ( fileName ) ) ;
129
+ return result ;
130
+ }
143
131
} ,
144
132
readDirectory : ( ...args ) => {
145
- // TODO: this should not be encountered outside of CI when tests will fail
146
- const result = ts . sys . readDirectory ( ...args ) ;
147
- return result ;
133
+ if ( process . env . CI ) {
134
+ return ts . sys . readDirectory ( ...args ) ;
135
+ }
136
+ return [ ] ;
148
137
} ,
149
138
directoryExists : ( ...args ) => {
150
- // TODO: this should not be encountered outside of CI when tests will fail
151
- const result = ts . sys . directoryExists ( ...args ) ;
152
- return result ;
139
+ if ( process . env . CI ) {
140
+ return ts . sys . directoryExists ( ...args ) ;
141
+ }
142
+ return false ;
153
143
} ,
154
144
getDirectories : ( ...args ) => {
155
- // TODO: this should not be encountered outside of CI when tests will fail
156
- const result = ts . sys . getDirectories ( ...args ) ;
157
- return result ;
145
+ if ( process . env . CI ) {
146
+ return ts . sys . getDirectories ( ...args ) ;
147
+ }
148
+ return [ ] ;
158
149
} ,
159
150
log : ( ...args ) => debugLog ( args ) ,
160
151
trace : ( ...args ) => debugTrace ( args ) ,
0 commit comments