From 7d73f684af5b77e9b3dad9338ed9e2e6bff80e88 Mon Sep 17 00:00:00 2001 From: Sumit Date: Sat, 5 Dec 2026 18:33:55 +0530 Subject: [PATCH] fix(51782): treat bare . and .. as relative extends paths Use PathIsRelative so extends ".." / "." take filesystem resolution instead of module lookup that incorrectly finds a parent tsconfig. --- .../execute/tsctests/showconfig_test.go | 13 +++++++ tsc/internal/tsoptions/tsconfigparsing.go | 2 +- .../tsoptions/tsconfigparsing_test.go | 39 +++++++++++++++++++ ...-TSConfig-rejects-bare-relative-extends.js | 21 ++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tsc/testdata/baselines/reference/tsc/showConfig/Show-TSConfig-rejects-bare-relative-extends.js diff --git a/tsc/internal/execute/tsctests/showconfig_test.go b/tsc/internal/execute/tsctests/showconfig_test.go index a8a8bd8f3e3c0..f182e20dbe328 100644 --- a/tsc/internal/execute/tsctests/showconfig_test.go +++ b/tsc/internal/execute/tsctests/showconfig_test.go @@ -266,6 +266,19 @@ func TestShowConfig(t *testing.T) { }, commandLineArgs: []string{"-p", "tsconfig.json", "--showConfig"}, }, + { + subScenario: "Show TSConfig rejects bare relative extends", + cwd: "/home/src/workspaces/project/foo", + files: FileMap{ + "/home/src/workspaces/project/tsconfig.json": `{}`, + "/home/src/workspaces/project/foo/a.ts": `export const a = 1;`, + "/home/src/workspaces/project/foo/tsconfig.json": stringtestutil.Dedent(` + { + "extends": ".." + }`), + }, + commandLineArgs: []string{"-p", "tsconfig.json", "--showConfig"}, + }, } for _, value := range []string{"true", "false"} { diff --git a/tsc/internal/tsoptions/tsconfigparsing.go b/tsc/internal/tsoptions/tsconfigparsing.go index 92ba6b48d09ad..69c58abea83a9 100644 --- a/tsc/internal/tsoptions/tsconfigparsing.go +++ b/tsc/internal/tsoptions/tsconfigparsing.go @@ -501,7 +501,7 @@ func getExtendsConfigPath( errors = append(errors, CreateDiagnosticForNodeInSourceFileOrCompilerDiagnostic(errorFile, valueExpression, diagnostics.Network_path_0_is_not_supported, extendedConfig)) return "", errors } - if tspath.IsRootedDiskPath(extendedConfig) || strings.HasPrefix(extendedConfig, "./") || strings.HasPrefix(extendedConfig, "../") { + if tspath.IsRootedDiskPath(extendedConfig) || tspath.PathIsRelative(extendedConfig) { extendedConfigPath := tspath.ToRootedFilePath(extendedConfig, basePath) if !fs.FileExists(extendedConfigPath) && !extendedConfigPath.ExtensionIs(tspath.ExtensionJson) { extendedConfigPath = extendedConfigPath.AppendSuffix(tspath.ExtensionJson) diff --git a/tsc/internal/tsoptions/tsconfigparsing_test.go b/tsc/internal/tsoptions/tsconfigparsing_test.go index 5c66aa449b4be..e52435f1e87dc 100644 --- a/tsc/internal/tsoptions/tsconfigparsing_test.go +++ b/tsc/internal/tsoptions/tsconfigparsing_test.go @@ -1140,6 +1140,45 @@ func TestParseJsonSourceFileConfigFileContentReportsCircularExtendsChain(t *test }) } +// Bare "." / ".." must use filesystem extends resolution, not module lookup (#51782). +func TestParseJsonSourceFileConfigFileContentRejectsBareRelativeExtends(t *testing.T) { + t.Parallel() + for _, extends := range []string{".", ".."} { + t.Run(extends, func(t *testing.T) { + t.Parallel() + files := map[string]string{ + "/project/tsconfig.json": `{}`, + "/project/foo/tsconfig.json": `{ "extends": "` + extends + `" }`, + "/project/foo/main.ts": "export const x = 1;", + } + fs := tsoptionstest.NewVFS(files, tspath.CaseSensitive /*caseSensitivity*/) + configFileName := tspath.RootedFilePath("/project/foo/tsconfig.json") + configFile := tsoptions.NewTsconfigSourceFileFromFilePath( + configFileName, + fs.CaseSensitivity().PathKey(tspath.RootedPath(configFileName)), + files[configFileName.AsString()], + ) + + parsed := tsoptions.ParseJsonSourceFileConfigFileContent( + configFile, + tsoptions.NewDefaultParseConfigHost(fs), + "/project/foo", + nil, + nil, + nil, + nil, + ) + + notFound := core.Filter(parsed.Errors, func(diagnostic *ast.Diagnostic) bool { + return diagnostic.Code() == diagnostics.File_0_not_found.Code() + }) + assert.DeepEqual(t, core.Map(notFound, (*ast.Diagnostic).MessageArgs), [][]string{ + {extends}, + }) + }) + } +} + // Extending an empty config file used to panic on nil Statements (#4265). func TestParseJsonSourceFileConfigFileContentWithEmptyExtendedConfig(t *testing.T) { t.Parallel() diff --git a/tsc/testdata/baselines/reference/tsc/showConfig/Show-TSConfig-rejects-bare-relative-extends.js b/tsc/testdata/baselines/reference/tsc/showConfig/Show-TSConfig-rejects-bare-relative-extends.js new file mode 100644 index 0000000000000..1ad90e3146844 --- /dev/null +++ b/tsc/testdata/baselines/reference/tsc/showConfig/Show-TSConfig-rejects-bare-relative-extends.js @@ -0,0 +1,21 @@ +currentDirectory::/home/src/workspaces/project/foo +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/foo/a.ts] *new* +export const a = 1; +//// [/home/src/workspaces/project/foo/tsconfig.json] *new* +{ + "extends": ".." +} +//// [/home/src/workspaces/project/tsconfig.json] *new* +{} + +tsc -p tsconfig.json --showConfig +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +tsconfig.json:2:16 - error TS6053: File '..' not found. + +2 "extends": ".." +   ~~~~ + +