Skip to content

Commit 9de8b7a

Browse files
Ensure pathsBasePath is correctly forwarded from the API (#64843)
1 parent 39be28b commit 9de8b7a

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎tsc/internal/api/session_createprogram_test.go‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,49 @@ func TestCreateProgramReportsNonCompositeProjectReference(t *testing.T) {
316316
}
317317
assert.DeepEqual(t, codes, []int32{6306})
318318
}
319+
320+
func TestCreateSnapshotResolvesPathsRelativeToParsedConfigDirectory(t *testing.T) {
321+
t.Parallel()
322+
323+
const (
324+
mainFile = "/project/main.ts"
325+
libFile = "/project/types/lib.d.ts"
326+
)
327+
init, _ := projecttestutil.GetSessionInitOptions(map[string]any{
328+
mainFile: `import { x } from "lib"; export const y: number = x;`,
329+
libFile: `export declare const x: number;`,
330+
}, nil, &projecttestutil.TypingsInstallerOptions{})
331+
init.Options.CurrentDirectory = "/somewhere-else"
332+
session := NewStandaloneSession(init, nil)
333+
defer session.Close()
334+
335+
var parseParams ParseJsonConfigFileContentParams
336+
assert.NilError(t, json.Unmarshal([]byte(`{
337+
"json": {
338+
"compilerOptions": {
339+
"module": "esnext",
340+
"moduleResolution": "bundler",
341+
"noLib": true,
342+
"types": [],
343+
"paths": { "lib": ["./types/lib.d.ts"] }
344+
}
345+
},
346+
"configDirectory": "/project"
347+
}`), &parseParams))
348+
parsed, err := session.handleParseJsonConfigFileContent(context.Background(), &parseParams)
349+
assert.NilError(t, err)
350+
351+
// Round-trip the parsed options through JSON as an API client would.
352+
encodedOptions, err := json.Marshal(parsed.Options)
353+
assert.NilError(t, err)
354+
var createParams CreateSnapshotParams
355+
assert.NilError(t, json.Unmarshal([]byte(`{"createPrograms":[{"rootFiles":["`+mainFile+`"],"compilerOptions":`+string(encodedOptions)+`}]}`), &createParams))
356+
357+
response, err := session.handleCreateSnapshot(context.Background(), &createParams)
358+
assert.NilError(t, err)
359+
snapshot, err := session.getSnapshotData(response.Snapshot)
360+
assert.NilError(t, err)
361+
program, err := snapshot.getProgram(response.Projects[0].Id)
362+
assert.NilError(t, err)
363+
assert.Assert(t, program.GetSourceFile(libFile) != nil, "expected 'lib' to resolve via paths relative to /project")
364+
}

‎tsc/internal/tsoptions/rawcompileroptions.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ func (o *RawCompilerOptions) Finalize(basePath tspath.RootedDirectoryPath) (*cor
8585
}
8686
} else if key == "configFilePath" {
8787
pathKind = CommandLineOptionPathKindFile
88+
} else if key == "pathsBasePath" {
89+
pathKind = CommandLineOptionPathKindDirectory
8890
} else if key != "allowNonTsExtensions" && key != "suppressOutputPathCheck" {
8991
continue
9092
}

‎tsc/internal/tsoptions/rawcompileroptions_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestRawCompilerOptionsFinalizePaths(t *testing.T) {
2727
"allowNonTsExtensions": true,
2828
"suppressOutputPathCheck": true,
2929
"configFilePath": "",
30+
"pathsBasePath": "config",
3031
"NoImplicitAny": true
3132
}`), &raw))
3233

@@ -46,5 +47,6 @@ func TestRawCompilerOptionsFinalizePaths(t *testing.T) {
4647
assert.Equal(t, options.AllowNonTsExtensions, core.TSTrue)
4748
assert.Equal(t, options.SuppressOutputPathCheck, core.TSTrue)
4849
assert.Equal(t, options.ConfigFilePath, tspath.RootedFilePath(""))
50+
assert.Equal(t, options.PathsBasePath, tspath.RootedDirectoryPath("/project/config"))
4951
assert.Equal(t, options.NoImplicitAny, core.TSUnknown)
5052
}

0 commit comments

Comments
 (0)