@@ -548,11 +548,10 @@ function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOpt
548
548
return maybeNonRelative ;
549
549
}
550
550
551
- let nearestTargetPackageJson = getNearestAncestorDirectoryWithPackageJson ( host , getDirectoryPath ( modulePath ) ) ;
552
- let nearestSourcePackageJson = getNearestAncestorDirectoryWithPackageJson ( host , sourceDirectory ) ;
553
- nearestTargetPackageJson &&= toPath ( nearestTargetPackageJson , projectDirectory , getCanonicalFileName ) ;
554
- nearestSourcePackageJson &&= toPath ( nearestSourcePackageJson , projectDirectory , getCanonicalFileName ) ;
555
- if ( nearestSourcePackageJson !== nearestTargetPackageJson ) {
551
+ const nearestTargetPackageJson = getNearestAncestorDirectoryWithPackageJson ( host , getDirectoryPath ( modulePath ) ) ;
552
+ const nearestSourcePackageJson = getNearestAncestorDirectoryWithPackageJson ( host , sourceDirectory ) ;
553
+ const ignoreCase = ! hostUsesCaseSensitiveFileNames ( host ) ;
554
+ if ( ! packageJsonPathsAreEqual ( nearestTargetPackageJson , nearestSourcePackageJson , ignoreCase ) ) {
556
555
// 2. The importing and imported files are part of different packages.
557
556
//
558
557
// packages/a/
@@ -572,6 +571,12 @@ function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOpt
572
571
return isPathRelativeToParent ( maybeNonRelative ) || countPathComponents ( relativePath ) < countPathComponents ( maybeNonRelative ) ? relativePath : maybeNonRelative ;
573
572
}
574
573
574
+ function packageJsonPathsAreEqual ( a : string | undefined , b : string | undefined , ignoreCase ?: boolean ) {
575
+ if ( a === b ) return true ;
576
+ if ( a === undefined || b === undefined ) return false ;
577
+ return comparePaths ( a , b , ignoreCase ) === Comparison . EqualTo ;
578
+ }
579
+
575
580
/** @internal */
576
581
export function countPathComponents ( path : string ) : number {
577
582
let count = 0 ;
0 commit comments