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