feat: add DTS resolver matching TypeScript's bundler mode#997
Conversation
…ler"` Add `resolve_dts()` method to `ResolverGeneric` that implements TypeScript's `ts.resolveModuleName` algorithm for declaration file resolution. This replaces the need for JS workarounds that configure enhanced-resolve with DTS-friendly options but can't match TypeScript's actual resolution behavior. Key features: - Two-pass node_modules walk: TS/DTS + @types before JS - @types scoped name mangling (@babel/core -> @types/babel__core) - TypeScript extension substitution (.js -> .ts, .d.ts) - typesVersions package.json field support - exports field absolute priority (blocks types/typings/main) - NAPI bindings: resolveDtsSync / resolveDtsAsync Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #997 +/- ##
==========================================
- Coverage 94.02% 91.62% -2.41%
==========================================
Files 17 18 +1
Lines 3348 3880 +532
==========================================
+ Hits 3148 3555 +407
- Misses 200 325 +125 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR adds a DTS resolver that implements TypeScript's ts.resolveModuleName with moduleResolution: "bundler" algorithm. The implementation addresses a critical gap for tools like rolldown-plugin-dts that need to inline and bundle type declarations, and solves numerous edge cases that cannot be handled by workarounds using the existing JavaScript resolver.
Changes:
- Implements a new
resolve_dts()method with TypeScript-specific resolution logic including two-pass node_modules walk, @types scoped name mangling, TypeScript extension substitution, typesVersions support, and proper exports field handling - Adds package.json field accessors for
types,typings, andtypesVersionsfields in both simd and serde implementations - Exposes
resolveDtsSyncandresolveDtsAsyncmethods through NAPI bindings with comprehensive documentation
Reviewed changes
Copilot reviewed 18 out of 41 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/dts_resolver.rs | Core DTS resolution algorithm implementation with TypeScript-specific logic |
| src/tests/dts_resolver.rs | Comprehensive test suite with 20 test cases covering relative resolution, extension priority, @types, exports, typesVersions, and name mangling |
| src/package_json/simd.rs | Added types(), typings(), and types_versions() accessors for SIMD JSON parser |
| src/package_json/serde.rs | Added types(), typings(), and types_versions() accessors for serde JSON parser |
| napi/src/lib.rs | NAPI bindings for resolve_dts_sync and resolve_dts_async |
| napi/index.d.ts | TypeScript type definitions for DTS resolution methods |
| src/tests/mod.rs | Added dts_resolver test module |
| src/lib.rs | Added dts_resolver module |
| fixtures/dts_resolver/* | Test fixtures for DTS resolution scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
resolve_dts()method toResolverGenericimplementing TypeScript'sts.resolveModuleNamewithmoduleResolution: "bundler"algorithmnode_moduleswalk: all ancestors for TS/DTS +@typesbefore trying JS — fixes the fundamental algorithmic difference that JS workarounds can't address@typesscoped name mangling (@babel/core→@types/babel__core).js→.ts,.d.ts) following TS priority ordertypesVersionspackage.json field supportexportsfield absolute priority (blockstypes/typings/mainwhen present)resolveDtsSync/resolveDtsAsync@types, exports,typesVersions,typingsfield, and name manglingCloses #549
🤖 Generated with Claude Code