@@ -35,38 +35,16 @@ interface Array<T> { length: number; [n: number]: T; }`
3535 executingFilePath ?: string ;
3636 currentDirectory ?: string ;
3737 newLine ?: string ;
38- useWindowsStylePaths ?: boolean ;
38+ windowsStyleRoot ?: string ;
3939 environmentVariables ?: Map < string > ;
4040 }
4141
4242 export function createWatchedSystem ( fileOrFolderList : ReadonlyArray < 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 ) ;
5544 }
5645
5746 export function createServerHost ( fileOrFolderList : ReadonlyArray < 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 ) ;
7048 }
7149
7250 export interface File {
@@ -326,6 +304,16 @@ interface Array<T> { length: number; [n: number]: T; }`
326304 }
327305
328306 const timeIncrements = 1000 ;
307+ export interface TestServerHostOptions {
308+ useCaseSensitiveFileNames : boolean ;
309+ executingFilePath : string ;
310+ currentDirectory : string ;
311+ fileOrFolderorSymLinkList : ReadonlyArray < FileOrFolderOrSymLink > ;
312+ newLine ?: string ;
313+ useWindowsStylePaths ?: boolean ;
314+ environmentVariables ?: Map < string > ;
315+ }
316+
329317 export class TestServerHost implements server . ServerHost , FormatDiagnosticsHost , ModuleResolutionHost {
330318 args : string [ ] = [ ] ;
331319
@@ -342,16 +330,31 @@ interface Array<T> { length: number; [n: number]: T; }`
342330 readonly watchedDirectories = createMultiMap < TestDirectoryWatcher > ( ) ;
343331 readonly watchedDirectoriesRecursive = createMultiMap < TestDirectoryWatcher > ( ) ;
344332 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 > ;
345337 private readonly executingFilePath : string ;
346338 private readonly currentDirectory : string ;
347339 private readonly customWatchFile : HostWatchFile | undefined ;
348340 private readonly customRecursiveWatchDirectory : HostWatchDirectory | undefined ;
349341 public require : ( ( initialPath : string , moduleName : string ) => server . RequireResult ) | undefined ;
350342
351- constructor ( public withSafeList : boolean , public useCaseSensitiveFileNames : boolean , executingFilePath : string , currentDirectory : string , fileOrFolderorSymLinkList : ReadonlyArray < 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 : ReadonlyArray < 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 ) ;
353356 this . toPath = s => toPath ( s , currentDirectory , this . getCanonicalFileName ) ;
354- this . executingFilePath = this . getHostSpecificPath ( executingFilePath ) ;
357+ this . executingFilePath = this . getHostSpecificPath ( executingFilePath || getExecutingFilePathFromLibFile ( ) ) ;
355358 this . currentDirectory = this . getHostSpecificPath ( currentDirectory ) ;
356359 this . reloadFS ( fileOrFolderorSymLinkList ) ;
357360 const tscWatchFile = this . environmentVariables && this . environmentVariables . get ( "TSC_WATCHFILE" ) as Tsc_WatchFile ;
@@ -418,8 +421,8 @@ interface Array<T> { length: number; [n: number]: T; }`
418421 }
419422
420423 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 ) ;
423426 }
424427 return s ;
425428 }
@@ -433,7 +436,7 @@ interface Array<T> { length: number; [n: number]: T; }`
433436 const mapNewLeaves = createMap < true > ( ) ;
434437 const isNewFs = this . fs . size === 0 ;
435438 fileOrFolderOrSymLinkList = fileOrFolderOrSymLinkList . concat ( this . withSafeList ? safeList : [ ] ) ;
436- const filesOrFoldersToLoad : ReadonlyArray < FileOrFolderOrSymLink > = ! this . useWindowsStylePath ? fileOrFolderOrSymLinkList :
439+ const filesOrFoldersToLoad : ReadonlyArray < FileOrFolderOrSymLink > = ! this . windowsStyleRoot ? fileOrFolderOrSymLinkList :
437440 fileOrFolderOrSymLinkList . map < FileOrFolderOrSymLink > ( f => {
438441 const result = clone ( f ) ;
439442 result . path = this . getHostSpecificPath ( f . path ) ;
0 commit comments