@@ -9,19 +9,11 @@ const debugError = createDebug('ts-autocomplete:error');
99
1010type TypeFilename = string ;
1111
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+
2316function relativeNodePath ( fileName : string ) : string {
24- //console.log(fileName);
2517 const parts = fileName . split ( / \/ n o d e _ m o d u l e s \/ / g) ;
2618 if ( parts . length === 1 && fileName . endsWith ( 'package.json' ) ) {
2719 // special case: when it looks up this package itself it isn't going to find
@@ -35,9 +27,6 @@ type EncounteredPaths = {
3527 getScriptSnapshot : string [ ] ;
3628 fileExists : string [ ] ;
3729 readFile : string [ ] ;
38- //readDirectory: string[],
39- //directoryExists: string[],
40- //getDirectories: string[]
4130} ;
4231
4332function getVirtualLanguageService ( ) : {
@@ -60,7 +49,7 @@ function getVirtualLanguageService(): {
6049 allowImportingTsExtensions : true ,
6150 } ;
6251
63- const updateCode = ( newDef : Record < TypeFilename , string > ) : void => {
52+ const updateCode = ( newDef : Record < TypeFilename , string | true > ) : void => {
6453 for ( const [ key , value ] of Object . entries ( newDef ) ) {
6554 codeHolder [ key ] = value ;
6655 versions [ key ] = ( versions [ key ] ?? 0 ) + 1 ;
@@ -75,9 +64,6 @@ function getVirtualLanguageService(): {
7564 getScriptSnapshot : [ ] ,
7665 fileExists : [ ] ,
7766 readFile : [ ] ,
78- //readDirectory: [], // unused
79- //directoryExists: [], // unused
80- //getDirectories: [] // unused
8167 } ;
8268 const listEncounteredPaths = ( ) : EncounteredPaths => {
8369 encounteredPaths . getScriptSnapshot . sort ( ) ;
@@ -100,61 +86,66 @@ function getVirtualLanguageService(): {
10086 return ts . ScriptSnapshot . fromString ( codeHolder [ fileName ] . toString ( ) ) ;
10187 }
10288
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+ ) ;
10894
109- encounteredPaths . getScriptSnapshot . push ( relativeNodePath ( fileName ) ) ;
110- return result ;
95+ encounteredPaths . getScriptSnapshot . push ( relativeNodePath ( fileName ) ) ;
96+ return result ;
97+ }
11198 } ,
11299 getCurrentDirectory : ( ) => process . cwd ( ) ,
113100 getCompilationSettings : ( ) => options ,
114101 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 ) ;
119103 } ,
120104 fileExists : ( fileName ) => {
121105 fileName = relativeNodePath ( fileName ) ;
122106 if ( fileName in codeHolder ) {
123107 return true ;
124108 }
125109
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 ;
130116 }
131- return result ;
117+
118+ return false ;
132119 } ,
133120 readFile : ( fileName ) => {
134121 fileName = relativeNodePath ( fileName ) ;
135122 if ( fileName in codeHolder ) {
136123 return codeHolder [ fileName ] . toString ( ) ;
137124 }
138125
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+ }
143131 } ,
144132 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 [ ] ;
148137 } ,
149138 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 ;
153143 } ,
154144 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 [ ] ;
158149 } ,
159150 log : ( ...args ) => debugLog ( args ) ,
160151 trace : ( ...args ) => debugTrace ( args ) ,
0 commit comments