Skip to content

fix(module): normalize type root candidates to stop a panic with project references - #999

Merged
camc314 merged 1 commit into
oxc-project:mainfrom
magurotuna:fix/panic-symlink-project-references-main
Nov 16, 2026
Merged

camc314 merged 1 commit into
oxc-project:mainfrom
magurotuna:fix/panic-symlink-project-references-main

Conversation

@magurotuna

@magurotuna magurotuna commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

tsrs-lint panicked with "canonical symlink path did not match its presentation path" (projectreferencedtsfakinghost.rs). It happens when the program has project references and a relative type reference goes from a type root into a symlinked package (pnpm). vuejs/router has this layout: the code that Vue generates for .vue files has such references (generateGlobalTypesReference). This plain TypeScript project reproduces it:

app/
├── tsconfig.json       { "files": ["x/y/a.ts"], "references": [{ "path": "./ref" }] }
├── ref/
│   ├── tsconfig.json   { "compilerOptions": { "composite": true }, "files": ["r.ts"] }
│   └── r.ts            export const r = 1;
├── x/y/a.ts            /// <reference types="../../node_modules/foo/index.d.ts" />
│                       export const a: number = foo;
├── node_modules/
│   ├── @types/         (empty)
│   └── foo -> ../packages/foo
└── packages/foo/
    ├── package.json    { "name": "foo", "types": "index.d.ts" }
    └── index.d.ts      declare const foo: number;

In app/, OXLINT_TSGOLINT_PATH=<tsrs-lint> oxlint --type-aware . panics. The lookup in the type root node_modules/@types makes the candidate app/node_modules/@types/../../node_modules/foo/index.d.ts. This path does not start with the symlink path that the dts faking host records for node_modules/foo, so the expect fails. typeroot_candidate_test builds the same project in memory.

get_candidate_from_type_root did not normalize the candidate, so it kept the .. segments. Go getCandidateFromTypeRoot normalizes it with resolutionCandidateFromDirectoryPath, and tsrs now uses its port, resolve_path_for_module. This also fixes the --traceResolution output of tsrs -p (<dir>/types/../pkg.d.ts becomes <dir>/pkg.d.ts, as in tsgo) and the typeRoots fallback of module resolution (resolveFromTypeRoot). The expect stays, because Go panics on the same condition.

…ect references

Port Go `getCandidateFromTypeRoot` (`resolver.go:659`): build the candidate
with `resolve_path_for_module`, the port of
`resolutionCandidateFromDirectoryPath`. `combine_paths` kept the `..` segments
of a relative name such as `../../node_modules/foo/index.d.ts`.

With project references and `use_source_of_project_reference` (tsrs-lint),
the dts faking host received the unnormalized path. If the path was under a
symlinked package, `resolve_file_name` could not trim the recorded symlink
prefix, and its `expect` panicked. `tsrs -p` did not panic, but its resolution
trace printed `<type root>/../pkg.d.ts` where tsgo prints `<dir>/pkg.d.ts`.
@magurotuna
magurotuna marked this pull request as ready for review November 16, 2026 07:57
@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 8 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing magurotuna:fix/panic-symlink-project-references-main (e77bf54) with main (7de2c7e)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@camc314
camc314 added this pull request to the merge queue Nov 16, 2026
Merged via the queue into oxc-project:main with commit e26d1ee Nov 16, 2026
72 of 79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants