Skip to content

Commit 4d18200

Browse files
Copilotjakebailey
andauthored
Fix panic on CLI --typeRoots with relative path (#3866)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent 16eae3f commit 4d18200

6 files changed

Lines changed: 53 additions & 0 deletions

File tree

internal/tsoptions/commandlineparser_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ func TestCommandLineParseResult(t *testing.T) {
8787
}
8888
}
8989

90+
func TestParseCommandLineTypeRootsRelativePath(t *testing.T) {
91+
t.Parallel()
92+
93+
host := tsoptionstest.NewVFSParseConfigHost(map[string]string{
94+
"/home/project/bug.ts": `let x = 1;`,
95+
}, "/home/project", true)
96+
97+
cmdLine := tsoptions.ParseCommandLine([]string{"--typeRoots", "t", "bug.ts"}, host)
98+
99+
typeRoots := cmdLine.CompilerOptions().TypeRoots
100+
assert.Assert(t, typeRoots != nil, "typeRoots should not be nil")
101+
assert.Equal(t, len(typeRoots), 1)
102+
assert.Assert(t, tspath.IsRootedDiskPath(typeRoots[0]), "typeRoots entry should be an absolute path, got: %s", typeRoots[0])
103+
assert.Assert(t, strings.HasSuffix(typeRoots[0], "/t"), "typeRoots entry should end with '/t', got: %s", typeRoots[0])
104+
}
105+
90106
func TestCustomConditionsNullOverride(t *testing.T) {
91107
t.Parallel()
92108

internal/tsoptions/parsinghelpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,14 @@ func ConvertOptionToAbsolutePath(o string, v any, optionMap CommandLineOptionNam
642642
return tspath.GetNormalizedAbsolutePath(item, cwd)
643643
}), true
644644
}
645+
if arr, ok := v.([]any); ok {
646+
return core.Map(arr, func(item any) any {
647+
if s, isStr := item.(string); isStr {
648+
return tspath.GetNormalizedAbsolutePath(s, cwd)
649+
}
650+
return item
651+
}), true
652+
}
645653
}
646654
} else if option.IsFilePath {
647655
if value, ok := v.(string); ok {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error TS2688: Cannot find type definition file for 'n'.
2+
The file is in the program because:
3+
Entry point of type library 'n' specified in compilerOptions
4+
5+
6+
!!! error TS2688: Cannot find type definition file for 'n'.
7+
!!! error TS2688: The file is in the program because:
8+
!!! error TS2688: Entry point of type library 'n' specified in compilerOptions
9+
==== typeRootsRelativePath.ts (0 errors) ====
10+
let x = 1;
11+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [tests/cases/compiler/typeRootsRelativePath.ts] ////
2+
3+
=== typeRootsRelativePath.ts ===
4+
let x = 1;
5+
>x : Symbol(x, Decl(typeRootsRelativePath.ts, 0, 3))
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [tests/cases/compiler/typeRootsRelativePath.ts] ////
2+
3+
=== typeRootsRelativePath.ts ===
4+
let x = 1;
5+
>x : number
6+
>1 : 1
7+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @typeRoots: t
2+
// @types: n
3+
// @noEmit: true
4+
5+
let x = 1;

0 commit comments

Comments
 (0)