@@ -71,14 +71,16 @@ export class MockTypescriptHost implements ts.LanguageServiceHost {
71
71
private options : ts . CompilerOptions ;
72
72
private overrideDirectory = new Set < string > ( ) ;
73
73
74
- constructor ( private scriptNames : string [ ] , private data : MockData ) {
74
+ constructor (
75
+ private scriptNames : string [ ] , private data : MockData ,
76
+ private node_modules : string = 'node_modules' , private myPath : typeof path = path ) {
75
77
const moduleFilename = module . filename . replace ( / \\ / g, '/' ) ;
76
78
let angularIndex = moduleFilename . indexOf ( '@angular' ) ;
77
79
if ( angularIndex >= 0 )
78
80
this . angularPath = moduleFilename . substr ( 0 , angularIndex ) . replace ( '/all/' , '/all/@angular/' ) ;
79
81
let distIndex = moduleFilename . indexOf ( '/dist/all' ) ;
80
82
if ( distIndex >= 0 )
81
- this . nodeModulesPath = path . join ( moduleFilename . substr ( 0 , distIndex ) , 'node_modules' ) ;
83
+ this . nodeModulesPath = myPath . join ( moduleFilename . substr ( 0 , distIndex ) , 'node_modules' ) ;
82
84
this . options = {
83
85
target : ts . ScriptTarget . ES5 ,
84
86
module : ts . ModuleKind . CommonJS ,
@@ -141,10 +143,13 @@ export class MockTypescriptHost implements ts.LanguageServiceHost {
141
143
directoryExists ( directoryName : string ) : boolean {
142
144
if ( this . overrideDirectory . has ( directoryName ) ) return true ;
143
145
let effectiveName = this . getEffectiveName ( directoryName ) ;
144
- if ( effectiveName === directoryName )
146
+ if ( effectiveName === directoryName ) {
145
147
return directoryExists ( directoryName , this . data ) ;
146
- else
148
+ } else if ( effectiveName == '/' + this . node_modules ) {
149
+ return true ;
150
+ } else {
147
151
return fs . existsSync ( effectiveName ) ;
152
+ }
148
153
}
149
154
150
155
fileExists ( fileName : string ) : boolean { return this . getRawFileContent ( fileName ) != null ; }
@@ -175,7 +180,7 @@ export class MockTypescriptHost implements ts.LanguageServiceHost {
175
180
let basename = path . basename ( fileName ) ;
176
181
if ( / ^ l i b .* \. d \. t s $ / . test ( basename ) ) {
177
182
let libPath = ts . getDefaultLibFilePath ( this . getCompilationSettings ( ) ) ;
178
- return fs . readFileSync ( path . join ( path . dirname ( libPath ) , basename ) , 'utf8' ) ;
183
+ return fs . readFileSync ( this . myPath . join ( path . dirname ( libPath ) , basename ) , 'utf8' ) ;
179
184
} else {
180
185
if ( missingCache . has ( fileName ) ) {
181
186
cacheUsed . add ( fileName ) ;
@@ -199,18 +204,18 @@ export class MockTypescriptHost implements ts.LanguageServiceHost {
199
204
}
200
205
201
206
private getEffectiveName ( name : string ) : string {
202
- const node_modules = ' node_modules' ;
207
+ const node_modules = this . node_modules ;
203
208
const at_angular = '/@angular' ;
204
209
if ( name . startsWith ( '/' + node_modules ) ) {
205
210
if ( this . nodeModulesPath && ! name . startsWith ( '/' + node_modules + at_angular ) ) {
206
- let result = path . join ( this . nodeModulesPath , name . substr ( node_modules . length + 1 ) ) ;
211
+ let result = this . myPath . join ( this . nodeModulesPath , name . substr ( node_modules . length + 1 ) ) ;
207
212
if ( ! name . match ( rxjsts ) )
208
213
if ( fs . existsSync ( result ) ) {
209
214
return result ;
210
215
}
211
216
}
212
217
if ( this . angularPath && name . startsWith ( '/' + node_modules + at_angular ) ) {
213
- return path . join (
218
+ return this . myPath . join (
214
219
this . angularPath , name . substr ( node_modules . length + at_angular . length + 1 ) ) ;
215
220
}
216
221
}
0 commit comments