Skip to content

fix(module): map output paths back to input files as Go does - #1079

Merged
camc314 merged 2 commits into
oxc-project:mainfrom
magurotuna:fix/module-input-file-root-out-dir
Nov 24, 2026
Merged

camc314 merged 2 commits into
oxc-project:mainfrom
magurotuna:fix/module-input-file-root-out-dir

Conversation

@magurotuna

Copy link
Copy Markdown
Member

A self-import through exports did not find the input file in two cases:

// "outDir": "/", "rootDir": "/", exports "./lib": "./lib.d.ts"
import { w } from "me/lib"; // tsgo: lib.ts      tsrs: error TS2307
// "outDir": "dist", "rootDir": "src", exports "./x": "./dist/^/x.js"
import { x } from "pkg/x";  // tsgo: src/^/x.ts  tsrs: error TS2307

Go tryLoadInputFileForPath cuts the output directory off with RelativeFilePathFromDirectory and appends the rest to rootDir with ResolveRelativeFile. tsrs cut one character too many when the output directory is /, and its combine_paths join read a first segment such as ^ or c: as a root. This PR ports both Go functions to tspath.

Tests: the input-file-for-output-root-dir-slice and selfname-outdir-drive-like-dir regressions.

AI assistance: written with Claude Code.

A self-import through `exports` did not find the input file in two cases:

```ts
// "outDir": "/", "rootDir": "/", exports "./lib": "./lib.d.ts"
import { w } from "me/lib"; // tsgo: lib.ts      tsrs: error TS2307
// "outDir": "dist", "rootDir": "src", exports "./x": "./dist/^/x.js"
import { x } from "pkg/x";  // tsgo: src/^/x.ts  tsrs: error TS2307
```

Go `tryLoadInputFileForPath` (`module/resolver.go:1136`) cuts the output
directory off with `RelativeFilePathFromDirectory` and appends the rest to
`rootDir` with `ResolveRelativeFile`. tsrs cut one character too many when
the output directory is `/`, and its `combine_paths` join read a first
segment such as `^` or `c:` as a root. Port both Go functions to `tspath`.

Tests: the `input-file-for-output-root-dir-slice` and
`selfname-outdir-drive-like-dir` regressions.

AI assistance: written with Claude Code.
@codspeed

codspeed Bot commented Nov 24, 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/module-input-file-root-out-dir (339daf0) with main (bd3f2ab)

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 enabled auto-merge November 24, 2026 09:11
@camc314
camc314 added this pull request to the merge queue Nov 24, 2026
Merged via the queue into oxc-project:main with commit 7d1c2dc Nov 24, 2026
69 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