@@ -35,38 +35,16 @@ interface Array<T> { length: number; [n: number]: T; }`
35
35
executingFilePath ?: string ;
36
36
currentDirectory ?: string ;
37
37
newLine ?: string ;
38
- useWindowsStylePaths ?: boolean ;
38
+ windowsStyleRoot ?: string ;
39
39
environmentVariables ?: Map < string > ;
40
40
}
41
41
42
42
export function createWatchedSystem ( fileOrFolderList : readonly FileOrFolderOrSymLink [ ] , params ?: TestServerHostCreationParameters ) : TestServerHost {
43
- if ( ! params ) {
44
- params = { } ;
45
- }
46
- const host = new TestServerHost ( /*withSafelist*/ false ,
47
- params . useCaseSensitiveFileNames !== undefined ? params . useCaseSensitiveFileNames : false ,
48
- params . executingFilePath || getExecutingFilePathFromLibFile ( ) ,
49
- params . currentDirectory || "/" ,
50
- fileOrFolderList ,
51
- params . newLine ,
52
- params . useWindowsStylePaths ,
53
- params . environmentVariables ) ;
54
- return host ;
43
+ return new TestServerHost ( /*withSafelist*/ false , fileOrFolderList , params ) ;
55
44
}
56
45
57
46
export function createServerHost ( fileOrFolderList : readonly FileOrFolderOrSymLink [ ] , params ?: TestServerHostCreationParameters ) : TestServerHost {
58
- if ( ! params ) {
59
- params = { } ;
60
- }
61
- const host = new TestServerHost ( /*withSafelist*/ true ,
62
- params . useCaseSensitiveFileNames !== undefined ? params . useCaseSensitiveFileNames : false ,
63
- params . executingFilePath || getExecutingFilePathFromLibFile ( ) ,
64
- params . currentDirectory || "/" ,
65
- fileOrFolderList ,
66
- params . newLine ,
67
- params . useWindowsStylePaths ,
68
- params . environmentVariables ) ;
69
- return host ;
47
+ return new TestServerHost ( /*withSafelist*/ true , fileOrFolderList , params ) ;
70
48
}
71
49
72
50
export interface File {
@@ -326,6 +304,16 @@ interface Array<T> { length: number; [n: number]: T; }`
326
304
}
327
305
328
306
const timeIncrements = 1000 ;
307
+ export interface TestServerHostOptions {
308
+ useCaseSensitiveFileNames : boolean ;
309
+ executingFilePath : string ;
310
+ currentDirectory : string ;
311
+ fileOrFolderorSymLinkList : readonly FileOrFolderOrSymLink [ ] ;
312
+ newLine ?: string ;
313
+ useWindowsStylePaths ?: boolean ;
314
+ environmentVariables ?: Map < string > ;
315
+ }
316
+
329
317
export class TestServerHost implements server . ServerHost , FormatDiagnosticsHost , ModuleResolutionHost {
330
318
args : string [ ] = [ ] ;
331
319
@@ -342,16 +330,31 @@ interface Array<T> { length: number; [n: number]: T; }`
342
330
readonly watchedDirectories = createMultiMap < TestDirectoryWatcher > ( ) ;
343
331
readonly watchedDirectoriesRecursive = createMultiMap < TestDirectoryWatcher > ( ) ;
344
332
readonly watchedFiles = createMultiMap < TestFileWatcher > ( ) ;
333
+ public readonly useCaseSensitiveFileNames : boolean ;
334
+ public readonly newLine : string ;
335
+ public readonly windowsStyleRoot ?: string ;
336
+ private readonly environmentVariables ?: Map < string > ;
345
337
private readonly executingFilePath : string ;
346
338
private readonly currentDirectory : string ;
347
339
private readonly customWatchFile : HostWatchFile | undefined ;
348
340
private readonly customRecursiveWatchDirectory : HostWatchDirectory | undefined ;
349
341
public require : ( ( initialPath : string , moduleName : string ) => server . RequireResult ) | undefined ;
350
342
351
- constructor ( public withSafeList : boolean , public useCaseSensitiveFileNames : boolean , executingFilePath : string , currentDirectory : string , fileOrFolderorSymLinkList : readonly FileOrFolderOrSymLink [ ] , public readonly newLine = "\n" , public readonly useWindowsStylePath ?: boolean , private readonly environmentVariables ?: Map < string > ) {
352
- this . getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitiveFileNames ) ;
343
+ constructor (
344
+ public withSafeList : boolean ,
345
+ fileOrFolderorSymLinkList : readonly FileOrFolderOrSymLink [ ] ,
346
+ {
347
+ useCaseSensitiveFileNames, executingFilePath, currentDirectory,
348
+ newLine, windowsStyleRoot, environmentVariables
349
+ } : TestServerHostCreationParameters = { } ) {
350
+ this . useCaseSensitiveFileNames = ! ! useCaseSensitiveFileNames ;
351
+ this . newLine = newLine || "\n" ;
352
+ this . windowsStyleRoot = windowsStyleRoot ;
353
+ this . environmentVariables = environmentVariables ;
354
+ currentDirectory = currentDirectory || "/" ;
355
+ this . getCanonicalFileName = createGetCanonicalFileName ( ! ! useCaseSensitiveFileNames ) ;
353
356
this . toPath = s => toPath ( s , currentDirectory , this . getCanonicalFileName ) ;
354
- this . executingFilePath = this . getHostSpecificPath ( executingFilePath ) ;
357
+ this . executingFilePath = this . getHostSpecificPath ( executingFilePath || getExecutingFilePathFromLibFile ( ) ) ;
355
358
this . currentDirectory = this . getHostSpecificPath ( currentDirectory ) ;
356
359
this . reloadFS ( fileOrFolderorSymLinkList ) ;
357
360
const tscWatchFile = this . environmentVariables && this . environmentVariables . get ( "TSC_WATCHFILE" ) as Tsc_WatchFile ;
@@ -418,8 +421,8 @@ interface Array<T> { length: number; [n: number]: T; }`
418
421
}
419
422
420
423
getHostSpecificPath ( s : string ) {
421
- if ( this . useWindowsStylePath && s . startsWith ( directorySeparator ) ) {
422
- return "c:/" + s . substring ( 1 ) ;
424
+ if ( this . windowsStyleRoot && s . startsWith ( directorySeparator ) ) {
425
+ return this . windowsStyleRoot + s . substring ( 1 ) ;
423
426
}
424
427
return s ;
425
428
}
@@ -433,7 +436,7 @@ interface Array<T> { length: number; [n: number]: T; }`
433
436
const mapNewLeaves = createMap < true > ( ) ;
434
437
const isNewFs = this . fs . size === 0 ;
435
438
fileOrFolderOrSymLinkList = fileOrFolderOrSymLinkList . concat ( this . withSafeList ? safeList : [ ] ) ;
436
- const filesOrFoldersToLoad : readonly FileOrFolderOrSymLink [ ] = ! this . useWindowsStylePath ? fileOrFolderOrSymLinkList :
439
+ const filesOrFoldersToLoad : readonly FileOrFolderOrSymLink [ ] = ! this . windowsStyleRoot ? fileOrFolderOrSymLinkList :
437
440
fileOrFolderOrSymLinkList . map < FileOrFolderOrSymLink > ( f => {
438
441
const result = clone ( f ) ;
439
442
result . path = this . getHostSpecificPath ( f . path ) ;
0 commit comments