Skip to content

fix(modulespecifiers): do not take lib.d.ts as the main file of "types": "lib/" - #1103

Merged
camc314 merged 2 commits into
oxc-project:mainfrom
magurotuna:fix/specifiers-package-main-directory
Nov 26, 2026
Merged

camc314 merged 2 commits into
oxc-project:mainfrom
magurotuna:fix/specifiers-package-main-directory

Conversation

@magurotuna

Copy link
Copy Markdown
Member

Declaration emit named a type from lib.d.ts with the package name when types ends with /:

// node_modules/pkg/package.json: { "name": "pkg", "types": "lib/" }
// node_modules/pkg/lib.d.ts:       export interface L { x: number }
// node_modules/pkg/lib/index.d.ts: export {};
tsgo: export declare const v: import("pkg/lib").L;
tsrs: export declare const v: import("pkg").L;     (this resolves to lib/index.d.ts, which has no L)

Go isPackageMainFile treats a main, types, or typings value that ends with / as a directory, so only its index file can be the main file. tsrs removed the / and compared the file stems, so lib matched lib.d.ts. This PR ports the mainIsDirectory check.

Tests: package_main_directory_stem_match in tsrs_cli.

AI assistance: written with Claude Code.

…s": "lib/"

Declaration emit named a type from `lib.d.ts` with the package name when
`types` ends with `/`:

```
// node_modules/pkg/package.json: { "name": "pkg", "types": "lib/" }
// node_modules/pkg/lib.d.ts:       export interface L { x: number }
// node_modules/pkg/lib/index.d.ts: export {};
tsgo: export declare const v: import("pkg/lib").L;
tsrs: export declare const v: import("pkg").L;     (this resolves to lib/index.d.ts, which has no L)
```

Go `isPackageMainFile` (`modulespecifiers/specifiers.go:984`) treats a
`main`, `types`, or `typings` value that ends with `/` as a directory, so
only its index file can be the main file. tsrs removed the `/` and compared
the file stems, so `lib` matched `lib.d.ts`. Port the `mainIsDirectory`
check.

Tests: `package_main_directory_stem_match` in `tsrs_cli`.

AI assistance: written with Claude Code.
@codspeed

codspeed Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

Warning

oxc-project has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

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/specifiers-package-main-directory (9913ac5) with main (9fb8d5a)

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 26, 2026
Merged via the queue into oxc-project:main with commit 96eead1 Nov 26, 2026
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