Skip to content

fix(module): set the package ID sub-module only for files in the package - #1038

Merged
camc314 merged 2 commits into
oxc-project:mainfrom
magurotuna:fix/package-id-outside-package
Nov 19, 2026
Merged

camc314 merged 2 commits into
oxc-project:mainfrom
magurotuna:fix/package-id-outside-package

Conversation

@magurotuna

Copy link
Copy Markdown
Member

When the types field of node_modules/pkg/package.json points outside the package, get_package_id still cut the sub-module name at the length of the package directory:

  • "types": "../pkgΓ©/index.d.ts" panicked (start byte index ... is not a char boundary).
  • "types": "../pkg-x/index.d.ts" gave the ID pkg/x/index.d.ts@1.0.0. A file of another package with the same ID was then redirected as a duplicate, and a TS2322 that tsgo reports was missing.

Go getPackageId sets the sub-module name only when RelativeTo(packageDirectory) succeeds. This PR ports RelativeTo (Go trimContainedPath) as relative_to_directory.

Tests: the package-id-outside-package-utf8 and package-id-outside-package-dedup regressions, with expected output from tsgo. Both fail without the fix.

AI assistance: written with Claude Code.

`get_package_id` took the sub-module name by slicing the resolved file
name at the length of the package directory, without a check that the
file is in that directory. A `types`, `typings`, or `main` field that
leaves the package (for example `"types": "../pkg-x/index.d.ts"`) then
gave a wrong sub-module name (`x/index.d.ts`), and a multi-byte character
at the cut point (`../pkgΓ©/index.d.ts`) panicked.

Go `getPackageId` (`resolver.go:2035`) sets `subModuleName` only when
`resolvedFileName.RelativeTo(packageDirectory)` succeeds. Port
`RootedPath.RelativeTo` (the case-sensitive `trimContainedPath`,
`rooted_path.go:575`) as `relative_to_directory` and use it in
`get_package_id`.

With the wrong sub-module name, two different packages could get the same
package ID, so tsrs redirected one file to the other as a duplicate
package and dropped a TS2322 that tsgo reports.

Tests: the regression cases `package-id-outside-package-dedup` and
`package-id-outside-package-utf8`, with expected output from tsgo. Their
`node_modules` directories are added with `git add -f`, because the root
`.gitignore` ignores `node_modules/`.

AI assistance: written with Claude Code.
@codspeed

codspeed Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 3 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

βœ… 7 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing magurotuna:fix/package-id-outside-package (3c8d3ee) with main (4b60aba)2

Open in CodSpeed

Footnotes

  1. 9 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. ↩

  2. No successful run was found on main (b84ddb4) during the generation of this report, so 4b60aba was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@camc314
camc314 enabled auto-merge November 19, 2026 11:35
@camc314
camc314 added this pull request to the merge queue Nov 19, 2026
Merged via the queue into oxc-project:main with commit 1cf4808 Nov 19, 2026
20 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