@@ -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+ }
0 commit comments