@@ -702,7 +702,7 @@ namespace ts {
702
702
let processingDefaultLibFiles : SourceFile [ ] | undefined ;
703
703
let processingOtherFiles : SourceFile [ ] | undefined ;
704
704
let files : SourceFile [ ] ;
705
- let symlinks : ReadonlyESMap < string , string > | undefined ;
705
+ let symlinks : SymlinkCache | undefined ;
706
706
let commonSourceDirectory : string ;
707
707
let diagnosticsProducingTypeChecker : TypeChecker ;
708
708
let noDiagnosticsTypeChecker : TypeChecker ;
@@ -811,8 +811,9 @@ namespace ts {
811
811
812
812
const useSourceOfProjectReferenceRedirect = ! ! host . useSourceOfProjectReferenceRedirect ?.( ) &&
813
813
! options . disableSourceOfProjectReferenceRedirect ;
814
- const { onProgramCreateComplete, fileExists } = updateHostForUseSourceOfProjectReferenceRedirect ( {
814
+ const { onProgramCreateComplete, fileExists, directoryExists } = updateHostForUseSourceOfProjectReferenceRedirect ( {
815
815
compilerHost : host ,
816
+ getSymlinkCache,
816
817
useSourceOfProjectReferenceRedirect,
817
818
toPath,
818
819
getResolvedProjectReferences,
@@ -974,7 +975,9 @@ namespace ts {
974
975
isSourceOfProjectReferenceRedirect,
975
976
emitBuildInfo,
976
977
fileExists,
977
- getProbableSymlinks,
978
+ directoryExists,
979
+ getSymlinkCache,
980
+ realpath : host . realpath ?. bind ( host ) ,
978
981
useCaseSensitiveFileNames : ( ) => host . useCaseSensitiveFileNames ( ) ,
979
982
} ;
980
983
@@ -1490,7 +1493,7 @@ namespace ts {
1490
1493
getResolvedProjectReferenceToRedirect,
1491
1494
getProjectReferenceRedirect,
1492
1495
isSourceOfProjectReferenceRedirect,
1493
- getProbableSymlinks ,
1496
+ getSymlinkCache ,
1494
1497
writeFile : writeFileCallback || (
1495
1498
( fileName , data , writeByteOrderMark , onError , sourceFiles ) => host . writeFile ( fileName , data , writeByteOrderMark , onError , sourceFiles ) ) ,
1496
1499
isEmitBlocked,
@@ -3468,9 +3471,9 @@ namespace ts {
3468
3471
return comparePaths ( file1 , file2 , currentDirectory , ! host . useCaseSensitiveFileNames ( ) ) === Comparison . EqualTo ;
3469
3472
}
3470
3473
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 ( ) ;
3474
3477
}
3475
3478
return symlinks || ( symlinks = discoverProbableSymlinks (
3476
3479
files ,
@@ -3479,13 +3482,9 @@ namespace ts {
3479
3482
}
3480
3483
}
3481
3484
3482
- interface SymlinkedDirectory {
3483
- real : string ;
3484
- realPath : Path ;
3485
- }
3486
-
3487
3485
interface HostForUseSourceOfProjectReferenceRedirect {
3488
3486
compilerHost : CompilerHost ;
3487
+ getSymlinkCache : ( ) => SymlinkCache ;
3489
3488
useSourceOfProjectReferenceRedirect : boolean ;
3490
3489
toPath ( fileName : string ) : Path ;
3491
3490
getResolvedProjectReferences ( ) : readonly ( ResolvedProjectReference | undefined ) [ ] | undefined ;
@@ -3495,9 +3494,6 @@ namespace ts {
3495
3494
3496
3495
function updateHostForUseSourceOfProjectReferenceRedirect ( host : HostForUseSourceOfProjectReferenceRedirect ) {
3497
3496
let setOfDeclarationDirectories : Set < Path > | undefined ;
3498
- let symlinkedDirectories : ESMap < Path , SymlinkedDirectory | false > | undefined ;
3499
- let symlinkedFiles : ESMap < Path , string > | undefined ;
3500
-
3501
3497
const originalFileExists = host . compilerHost . fileExists ;
3502
3498
const originalDirectoryExists = host . compilerHost . directoryExists ;
3503
3499
const originalGetDirectories = host . compilerHost . getDirectories ;
@@ -3507,11 +3503,12 @@ namespace ts {
3507
3503
3508
3504
host . compilerHost . fileExists = fileExists ;
3509
3505
3506
+ let directoryExists ;
3510
3507
if ( originalDirectoryExists ) {
3511
3508
// This implementation of directoryExists checks if the directory being requested is
3512
3509
// directory of .d.ts file for the referenced Project.
3513
3510
// 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 => {
3515
3512
if ( originalDirectoryExists . call ( host . compilerHost , path ) ) {
3516
3513
handleDirectoryCouldBeSymlink ( path ) ;
3517
3514
return true ;
@@ -3553,11 +3550,11 @@ namespace ts {
3553
3550
// This is something we keep for life time of the host
3554
3551
if ( originalRealpath ) {
3555
3552
host . compilerHost . realpath = s =>
3556
- symlinkedFiles ?. get ( host . toPath ( s ) ) ||
3553
+ host . getSymlinkCache ( ) . getSymlinkedFiles ( ) ?. get ( host . toPath ( s ) ) ||
3557
3554
originalRealpath . call ( host . compilerHost , s ) ;
3558
3555
}
3559
3556
3560
- return { onProgramCreateComplete, fileExists } ;
3557
+ return { onProgramCreateComplete, fileExists, directoryExists } ;
3561
3558
3562
3559
function onProgramCreateComplete ( ) {
3563
3560
host . compilerHost . fileExists = originalFileExists ;
@@ -3603,20 +3600,20 @@ namespace ts {
3603
3600
3604
3601
// Because we already watch node_modules, handle symlinks in there
3605
3602
if ( ! originalRealpath || ! stringContains ( directory , nodeModulesPathPart ) ) return ;
3606
- if ( ! symlinkedDirectories ) symlinkedDirectories = new Map ( ) ;
3603
+ const symlinkCache = host . getSymlinkCache ( ) ;
3607
3604
const directoryPath = ensureTrailingDirectorySeparator ( host . toPath ( directory ) ) ;
3608
- if ( symlinkedDirectories . has ( directoryPath ) ) return ;
3605
+ if ( symlinkCache . getSymlinkedDirectories ( ) ? .has ( directoryPath ) ) return ;
3609
3606
3610
3607
const real = normalizePath ( originalRealpath . call ( host . compilerHost , directory ) ) ;
3611
3608
let realPath : Path ;
3612
3609
if ( real === directory ||
3613
3610
( realPath = ensureTrailingDirectorySeparator ( host . toPath ( real ) ) ) === directoryPath ) {
3614
3611
// not symlinked
3615
- symlinkedDirectories . set ( directoryPath , false ) ;
3612
+ symlinkCache . setSymlinkedDirectory ( directoryPath , false ) ;
3616
3613
return ;
3617
3614
}
3618
3615
3619
- symlinkedDirectories . set ( directoryPath , {
3616
+ symlinkCache . setSymlinkedDirectory ( directoryPath , {
3620
3617
real : ensureTrailingDirectorySeparator ( real ) ,
3621
3618
realPath
3622
3619
} ) ;
@@ -3630,10 +3627,12 @@ namespace ts {
3630
3627
const result = fileOrDirectoryExistsUsingSource ( fileOrDirectory ) ;
3631
3628
if ( result !== undefined ) return result ;
3632
3629
3630
+ const symlinkCache = host . getSymlinkCache ( ) ;
3631
+ const symlinkedDirectories = symlinkCache . getSymlinkedDirectories ( ) ;
3633
3632
if ( ! symlinkedDirectories ) return false ;
3634
3633
const fileOrDirectoryPath = host . toPath ( fileOrDirectory ) ;
3635
3634
if ( ! stringContains ( fileOrDirectoryPath , nodeModulesPathPart ) ) return false ;
3636
- if ( isFile && symlinkedFiles && symlinkedFiles . has ( fileOrDirectoryPath ) ) return true ;
3635
+ if ( isFile && symlinkCache . getSymlinkedFiles ( ) ? .has ( fileOrDirectoryPath ) ) return true ;
3637
3636
3638
3637
// If it contains node_modules check if its one of the symlinked path we know of
3639
3638
return firstDefinedIterator (
@@ -3642,10 +3641,9 @@ namespace ts {
3642
3641
if ( ! symlinkedDirectory || ! startsWith ( fileOrDirectoryPath , directoryPath ) ) return undefined ;
3643
3642
const result = fileOrDirectoryExistsUsingSource ( fileOrDirectoryPath . replace ( directoryPath , symlinkedDirectory . realPath ) ) ;
3644
3643
if ( isFile && result ) {
3645
- if ( ! symlinkedFiles ) symlinkedFiles = new Map ( ) ;
3646
3644
// Store the real path for the file'
3647
3645
const absolutePath = getNormalizedAbsolutePath ( fileOrDirectory , host . compilerHost . getCurrentDirectory ( ) ) ;
3648
- symlinkedFiles . set (
3646
+ symlinkCache . setSymlinkedFile (
3649
3647
fileOrDirectoryPath ,
3650
3648
`${ symlinkedDirectory . real } ${ absolutePath . replace ( new RegExp ( directoryPath , "i" ) , "" ) } `
3651
3649
) ;
0 commit comments