Skip to content

fix(module): port the directory-only candidate checks outside the type roots - #1049

Merged
camc314 merged 1 commit into
oxc-project:mainfrom
magurotuna:fix/module-directory-only-candidates
Nov 20, 2026
Merged

camc314 merged 1 commit into
oxc-project:mainfrom
magurotuna:fix/module-directory-only-candidates

Conversation

@magurotuna

Copy link
Copy Markdown
Member

A module name or target that ends with / resolved differently from tsgo:

  • typesVersions "*": ["ts/*/"] with ts/sub.d.ts and ts/sub/index.d.ts: tsgo resolves pkg/sub to ts/sub.d.ts, and tsrs resolved it to ts/sub/index.d.ts.
  • The imports target "./dist.js/" resolved to dist.d.js/.ts, where tsgo reports TS2307.
  • import "x//" did not find node_modules/x.d.ts.

Go's resolutionCandidate keeps a directoryOnly flag and a path without the trailing /. #1008 ported its checks at the type root call sites. This PR ports the others: try_load_input_file_for_path, load_file_name_from_package_json_field, load_module_from_file, and the node_modules lookup.

Tests: the types-versions-directory-substitution, imports-directory-only-target, and node-modules-double-trailing-slash regressions. All three fail without the fix.

AI assistance: written with Claude Code.

…e roots

Go's `resolutionCandidate` has a `directoryOnly` flag for a candidate that
was written with a trailing `/`, and its `path` has no trailing separator.
oxc-project#1008 ported the checks at the two type root call sites. Five other
functions still worked on the string with the trailing `/`:

- `try_load_input_file_for_path` and `load_file_name_from_package_json_field`
  now return `continue_searching()` for a directory-only candidate, as Go
  does. Before, an `imports` target `./dist.js/` resolved to
  `dist.d.js/.ts` (TS6263 instead of TS2307), and `./dist/` reported
  TS2210 without a config file.
- `load_module_from_file` and `load_module_from_file_no_implicit_extensions`
  add extensions to the path without the trailing `/` (Go's
  `candidate.path`), and pass the directory of that path to
  `try_adding_extensions` (Go's `candidate.Directory()`). Before, a
  `typesVersions` substitution `ts/*/` probed `ts/sub/.d.ts` and missed
  `ts/sub.d.ts`, so tsrs read `ts/sub/index.d.ts`.
- `load_module_from_specific_node_modules_directory` builds its candidate
  with `resolution_candidate_from_directory_path`, as Go does, instead of
  removing one trailing separator. So `x//` resolves to
  `node_modules/x.d.ts`, and the trace prints the candidate with its `/`.

The new `resolution_candidate_from_normalized` (Go
`resolutionCandidateFromNormalized`) reads the flag and the path back from
a candidate string.

Tests: the regression cases `types-versions-directory-substitution`,
`imports-directory-only-target`, and `node-modules-double-trailing-slash`.
Expected output is from tsgo at the pinned commit. All three fail without
the fix. Two of them have a `node_modules` directory, which `.gitignore`
ignores, so the files are added with `git add -f`.

AI assistance: written with Claude Code.
@camc314
camc314 added this pull request to the merge queue Nov 20, 2026
@codspeed

codspeed Bot commented Nov 20, 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-directory-only-candidates (2d348fc) with main (9f74013)

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

Merged via the queue into oxc-project:main with commit 3b3bf43 Nov 20, 2026
70 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