diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index c16abc9a809..ae2025148fd 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -459,7 +459,7 @@ function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOpt } const baseDirectory = getNormalizedAbsolutePath(getPathsBasePath(compilerOptions, host) || baseUrl!, host.getCurrentDirectory()); - const relativeToBaseUrl = getRelativePathIfInDirectory(moduleFileName, baseDirectory, getCanonicalFileName); + const relativeToBaseUrl = getRelativePathIfInSameVolume(moduleFileName, baseDirectory, getCanonicalFileName); if (!relativeToBaseUrl) { return pathsOnly ? undefined : relativePath; } @@ -773,7 +773,7 @@ function tryGetModuleNameFromPaths(relativeToBaseUrl: string, paths: MapLike { - const relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName); + const relativePath = getRelativePathIfInSameVolume(path, rootDir, getCanonicalFileName); return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath; }); } @@ -1133,7 +1133,7 @@ export function tryGetJSExtensionForFile(fileName: string, options: CompilerOpti } } -function getRelativePathIfInDirectory(path: string, directoryPath: string, getCanonicalFileName: GetCanonicalFileName): string | undefined { +function getRelativePathIfInSameVolume(path: string, directoryPath: string, getCanonicalFileName: GetCanonicalFileName): string | undefined { const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); return isRootedDiskPath(relativePath) ? undefined : relativePath; } diff --git a/tests/cases/fourslash/server/autoImportCrossPackage_pathsAndSymlink.ts b/tests/cases/fourslash/server/autoImportCrossPackage_pathsAndSymlink.ts new file mode 100644 index 00000000000..d98863cd7a9 --- /dev/null +++ b/tests/cases/fourslash/server/autoImportCrossPackage_pathsAndSymlink.ts @@ -0,0 +1,40 @@ +/// + +// @Filename: /project/packages/common/package.json +//// { +//// "name": "@company/common", +//// "version": "1.0.0", +//// "main": "./lib/index.tsx" +//// } + +// @Filename: /project/packages/common/lib/index.tsx +//// export function Tooltip {}; + +// @Filename: /project/packages/app/package.json +//// { +//// "name": "@company/app", +//// "version": "1.0.0", +//// "dependencies": { +//// "@company/common": "1.0.0" +//// } +//// } + +// @Filename: /project/packages/app/tsconfig.json +//// { +//// "compilerOptions": { +//// "composite": true, +//// "module": "esnext", +//// "moduleResolution": "bundler", +//// "paths": { +//// "@/*": ["./*"] +//// } +//// } +//// } + +// @Filename: /project/packages/app/lib/index.ts +//// Tooltip/**/ + +// @link: /project/packages/common -> /project/node_modules/@company/common + +goTo.marker(""); +verify.importFixModuleSpecifiers("", ["@company/common"]);