mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Ensure paths-based resolution does not generate module specifiers with .. in the middle (#53957)
This commit is contained in:
@@ -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<rea
|
||||
validateEnding({ ending, value })
|
||||
) {
|
||||
const matchedStar = value.substring(prefix.length, value.length - suffix.length);
|
||||
return key.replace("*", matchedStar);
|
||||
return pathIsRelative(matchedStar) ? undefined : key.replace("*", matchedStar);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1038,7 +1038,7 @@ function tryGetAnyFileFromPath(host: ModuleSpecifierResolutionHost, path: string
|
||||
|
||||
function getPathsRelativeToRootDirs(path: string, rootDirs: readonly string[], getCanonicalFileName: GetCanonicalFileName): string[] | undefined {
|
||||
return mapDefined(rootDirs, rootDir => {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/// <reference path="../fourslash.ts" />
|
||||
|
||||
// @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"]);
|
||||
Reference in New Issue
Block a user