@@ -286,7 +286,8 @@ namespace ts.moduleSpecifiers {
286
286
const getCanonicalFileName = hostGetCanonicalFileName ( host ) ;
287
287
const cwd = host . getCurrentDirectory ( ) ;
288
288
const referenceRedirect = host . isSourceOfProjectReferenceRedirect ( importedFileName ) ? host . getProjectReferenceRedirect ( importedFileName ) : undefined ;
289
- const redirects = host . redirectTargetsMap . get ( toPath ( importedFileName , cwd , getCanonicalFileName ) ) || emptyArray ;
289
+ const importedPath = toPath ( importedFileName , cwd , getCanonicalFileName ) ;
290
+ const redirects = host . redirectTargetsMap . get ( importedPath ) || emptyArray ;
290
291
const importedFileNames = [ ...( referenceRedirect ? [ referenceRedirect ] : emptyArray ) , importedFileName , ...redirects ] ;
291
292
const targets = importedFileNames . map ( f => getNormalizedAbsolutePath ( f , cwd ) ) ;
292
293
if ( ! preferSymlinks ) {
@@ -299,22 +300,24 @@ namespace ts.moduleSpecifiers {
299
300
? host . getSymlinkCache ( )
300
301
: discoverProbableSymlinks ( host . getSourceFiles ( ) , getCanonicalFileName , cwd ) ;
301
302
302
- const symlinkedDirectories = links . getSymlinkedDirectories ( ) ;
303
- const useCaseSensitiveFileNames = ! host . useCaseSensitiveFileNames || host . useCaseSensitiveFileNames ( ) ;
304
- const result = symlinkedDirectories && forEachEntry ( symlinkedDirectories , ( resolved , path ) => {
305
- if ( resolved === false ) return undefined ;
306
- if ( startsWithDirectory ( importingFileName , resolved . realPath , getCanonicalFileName ) ) {
307
- return undefined ; // Don't want to a package to globally import from itself
303
+ const symlinkedDirectories = links . getSymlinkedDirectoriesByRealpath ( ) ;
304
+ const result = symlinkedDirectories && forEachAncestorDirectory ( getDirectoryPath ( importedPath ) , realPathDirectory => {
305
+ const symlinkDirectories = symlinkedDirectories . get ( realPathDirectory ) ;
306
+ if ( ! symlinkDirectories ) return undefined ; // Continue to ancestor directory
307
+
308
+ // Don't want to a package to globally import from itself (importNameCodeFix_symlink_own_package.ts)
309
+ if ( startsWithDirectory ( importingFileName , realPathDirectory , getCanonicalFileName ) ) {
310
+ return false ; // Stop search, each ancestor directory will also hit this condition
308
311
}
309
312
310
313
return forEach ( targets , target => {
311
- if ( ! containsPath ( resolved . real , target , ! useCaseSensitiveFileNames ) ) {
314
+ if ( ! startsWithDirectory ( target , realPathDirectory , getCanonicalFileName ) ) {
312
315
return ;
313
316
}
314
317
315
- const relative = getRelativePathFromDirectory ( resolved . real , target , getCanonicalFileName ) ;
316
- const option = resolvePath ( path , relative ) ;
317
- if ( ! host . fileExists || host . fileExists ( option ) ) {
318
+ const relative = getRelativePathFromDirectory ( realPathDirectory , target , getCanonicalFileName ) ;
319
+ for ( const symlinkDirectory of symlinkDirectories ) {
320
+ const option = resolvePath ( symlinkDirectory , relative ) ;
318
321
const result = cb ( option , target === referenceRedirect ) ;
319
322
if ( result ) return result ;
320
323
}
0 commit comments