Skip to content

Commit 19ca8eb

Browse files
committed
Use comparePaths via helper
1 parent 36f39fb commit 19ca8eb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/compiler/moduleSpecifiers.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,10 @@ function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOpt
548548
return maybeNonRelative;
549549
}
550550

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)) {
556555
// 2. The importing and imported files are part of different packages.
557556
//
558557
// packages/a/
@@ -572,6 +571,12 @@ function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOpt
572571
return isPathRelativeToParent(maybeNonRelative) || countPathComponents(relativePath) < countPathComponents(maybeNonRelative) ? relativePath : maybeNonRelative;
573572
}
574573

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+
575580
/** @internal */
576581
export function countPathComponents(path: string): number {
577582
let count = 0;

0 commit comments

Comments
 (0)