@@ -702,7 +702,7 @@ namespace ts {
702702 let processingDefaultLibFiles : SourceFile [ ] | undefined ;
703703 let processingOtherFiles : SourceFile [ ] | undefined ;
704704 let files : SourceFile [ ] ;
705- let symlinks : ReadonlyESMap < string , string > | undefined ;
705+ let symlinks : SymlinkCache | undefined ;
706706 let commonSourceDirectory : string ;
707707 let diagnosticsProducingTypeChecker : TypeChecker ;
708708 let noDiagnosticsTypeChecker : TypeChecker ;
@@ -811,8 +811,9 @@ namespace ts {
811811
812812 const useSourceOfProjectReferenceRedirect = ! ! host . useSourceOfProjectReferenceRedirect ?.( ) &&
813813 ! options . disableSourceOfProjectReferenceRedirect ;
814- const { onProgramCreateComplete, fileExists } = updateHostForUseSourceOfProjectReferenceRedirect ( {
814+ const { onProgramCreateComplete, fileExists, directoryExists } = updateHostForUseSourceOfProjectReferenceRedirect ( {
815815 compilerHost : host ,
816+ getSymlinkCache,
816817 useSourceOfProjectReferenceRedirect,
817818 toPath,
818819 getResolvedProjectReferences,
@@ -974,7 +975,9 @@ namespace ts {
974975 isSourceOfProjectReferenceRedirect,
975976 emitBuildInfo,
976977 fileExists,
977- getProbableSymlinks,
978+ directoryExists,
979+ getSymlinkCache,
980+ realpath : host . realpath ?. bind ( host ) ,
978981 useCaseSensitiveFileNames : ( ) => host . useCaseSensitiveFileNames ( ) ,
979982 } ;
980983
@@ -1490,7 +1493,7 @@ namespace ts {
14901493 getResolvedProjectReferenceToRedirect,
14911494 getProjectReferenceRedirect,
14921495 isSourceOfProjectReferenceRedirect,
1493- getProbableSymlinks ,
1496+ getSymlinkCache ,
14941497 writeFile : writeFileCallback || (
14951498 ( fileName , data , writeByteOrderMark , onError , sourceFiles ) => host . writeFile ( fileName , data , writeByteOrderMark , onError , sourceFiles ) ) ,
14961499 isEmitBlocked,
@@ -3468,9 +3471,9 @@ namespace ts {
34683471 return comparePaths ( file1 , file2 , currentDirectory , ! host . useCaseSensitiveFileNames ( ) ) === Comparison . EqualTo ;
34693472 }
34703473
3471- function getProbableSymlinks ( ) : ReadonlyESMap < string , string > {
3472- if ( host . getSymlinks ) {
3473- return host . getSymlinks ( ) ;
3474+ function getSymlinkCache ( ) : SymlinkCache {
3475+ if ( host . getSymlinkCache ) {
3476+ return host . getSymlinkCache ( ) ;
34743477 }
34753478 return symlinks || ( symlinks = discoverProbableSymlinks (
34763479 files ,
@@ -3479,13 +3482,9 @@ namespace ts {
34793482 }
34803483 }
34813484
3482- interface SymlinkedDirectory {
3483- real : string ;
3484- realPath : Path ;
3485- }
3486-
34873485 interface HostForUseSourceOfProjectReferenceRedirect {
34883486 compilerHost : CompilerHost ;
3487+ getSymlinkCache : ( ) => SymlinkCache ;
34893488 useSourceOfProjectReferenceRedirect : boolean ;
34903489 toPath ( fileName : string ) : Path ;
34913490 getResolvedProjectReferences ( ) : readonly ( ResolvedProjectReference | undefined ) [ ] | undefined ;
@@ -3495,9 +3494,6 @@ namespace ts {
34953494
34963495 function updateHostForUseSourceOfProjectReferenceRedirect ( host : HostForUseSourceOfProjectReferenceRedirect ) {
34973496 let setOfDeclarationDirectories : Set < Path > | undefined ;
3498- let symlinkedDirectories : ESMap < Path , SymlinkedDirectory | false > | undefined ;
3499- let symlinkedFiles : ESMap < Path , string > | undefined ;
3500-
35013497 const originalFileExists = host . compilerHost . fileExists ;
35023498 const originalDirectoryExists = host . compilerHost . directoryExists ;
35033499 const originalGetDirectories = host . compilerHost . getDirectories ;
@@ -3507,11 +3503,12 @@ namespace ts {
35073503
35083504 host . compilerHost . fileExists = fileExists ;
35093505
3506+ let directoryExists ;
35103507 if ( originalDirectoryExists ) {
35113508 // This implementation of directoryExists checks if the directory being requested is
35123509 // directory of .d.ts file for the referenced Project.
35133510 // If it is it returns true irrespective of whether that directory exists on host
3514- host . compilerHost . directoryExists = path => {
3511+ directoryExists = host . compilerHost . directoryExists = path => {
35153512 if ( originalDirectoryExists . call ( host . compilerHost , path ) ) {
35163513 handleDirectoryCouldBeSymlink ( path ) ;
35173514 return true ;
@@ -3553,11 +3550,11 @@ namespace ts {
35533550 // This is something we keep for life time of the host
35543551 if ( originalRealpath ) {
35553552 host . compilerHost . realpath = s =>
3556- symlinkedFiles ?. get ( host . toPath ( s ) ) ||
3553+ host . getSymlinkCache ( ) . getSymlinkedFiles ( ) ?. get ( host . toPath ( s ) ) ||
35573554 originalRealpath . call ( host . compilerHost , s ) ;
35583555 }
35593556
3560- return { onProgramCreateComplete, fileExists } ;
3557+ return { onProgramCreateComplete, fileExists, directoryExists } ;
35613558
35623559 function onProgramCreateComplete ( ) {
35633560 host . compilerHost . fileExists = originalFileExists ;
@@ -3603,20 +3600,20 @@ namespace ts {
36033600
36043601 // Because we already watch node_modules, handle symlinks in there
36053602 if ( ! originalRealpath || ! stringContains ( directory , nodeModulesPathPart ) ) return ;
3606- if ( ! symlinkedDirectories ) symlinkedDirectories = new Map ( ) ;
3603+ const symlinkCache = host . getSymlinkCache ( ) ;
36073604 const directoryPath = ensureTrailingDirectorySeparator ( host . toPath ( directory ) ) ;
3608- if ( symlinkedDirectories . has ( directoryPath ) ) return ;
3605+ if ( symlinkCache . getSymlinkedDirectories ( ) ? .has ( directoryPath ) ) return ;
36093606
36103607 const real = normalizePath ( originalRealpath . call ( host . compilerHost , directory ) ) ;
36113608 let realPath : Path ;
36123609 if ( real === directory ||
36133610 ( realPath = ensureTrailingDirectorySeparator ( host . toPath ( real ) ) ) === directoryPath ) {
36143611 // not symlinked
3615- symlinkedDirectories . set ( directoryPath , false ) ;
3612+ symlinkCache . setSymlinkedDirectory ( directoryPath , false ) ;
36163613 return ;
36173614 }
36183615
3619- symlinkedDirectories . set ( directoryPath , {
3616+ symlinkCache . setSymlinkedDirectory ( directoryPath , {
36203617 real : ensureTrailingDirectorySeparator ( real ) ,
36213618 realPath
36223619 } ) ;
@@ -3630,10 +3627,12 @@ namespace ts {
36303627 const result = fileOrDirectoryExistsUsingSource ( fileOrDirectory ) ;
36313628 if ( result !== undefined ) return result ;
36323629
3630+ const symlinkCache = host . getSymlinkCache ( ) ;
3631+ const symlinkedDirectories = symlinkCache . getSymlinkedDirectories ( ) ;
36333632 if ( ! symlinkedDirectories ) return false ;
36343633 const fileOrDirectoryPath = host . toPath ( fileOrDirectory ) ;
36353634 if ( ! stringContains ( fileOrDirectoryPath , nodeModulesPathPart ) ) return false ;
3636- if ( isFile && symlinkedFiles && symlinkedFiles . has ( fileOrDirectoryPath ) ) return true ;
3635+ if ( isFile && symlinkCache . getSymlinkedFiles ( ) ? .has ( fileOrDirectoryPath ) ) return true ;
36373636
36383637 // If it contains node_modules check if its one of the symlinked path we know of
36393638 return firstDefinedIterator (
@@ -3642,10 +3641,9 @@ namespace ts {
36423641 if ( ! symlinkedDirectory || ! startsWith ( fileOrDirectoryPath , directoryPath ) ) return undefined ;
36433642 const result = fileOrDirectoryExistsUsingSource ( fileOrDirectoryPath . replace ( directoryPath , symlinkedDirectory . realPath ) ) ;
36443643 if ( isFile && result ) {
3645- if ( ! symlinkedFiles ) symlinkedFiles = new Map ( ) ;
36463644 // Store the real path for the file'
36473645 const absolutePath = getNormalizedAbsolutePath ( fileOrDirectory , host . compilerHost . getCurrentDirectory ( ) ) ;
3648- symlinkedFiles . set (
3646+ symlinkCache . setSymlinkedFile (
36493647 fileOrDirectoryPath ,
36503648 `${ symlinkedDirectory . real } ${ absolutePath . replace ( new RegExp ( directoryPath , "i" ) , "" ) } `
36513649 ) ;
0 commit comments