-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix: make '@types' package resolution more consistent #31512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdded a new Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
libs/node_resolver/resolution.rs (1)
1631-1671: Confirm intent of broad @types fallback on any Types errorIn both
resolve_package_subpath_for_packageandresolve_package_dir_subpath, the@typesfallback is triggered wheneverresolution_kind.is_types()and the primary resolution result is anyErr(...), without inspecting the underlyingNodeJsErrorCode. That means we’ll also try@types/<name>for cases like misconfigured exports or invalid targets, not just for “module/types not found”.If the goal is “whenever types resolution fails, see if an @types package can satisfy it”, this is fine as‑is. If you only meant to cover strict “not found” scenarios, you may want to gate the fallback on a specific code (for example
ERR_TYPES_NOT_FOUNDand/orERR_MODULE_NOT_FOUND) before trying@types.Right now it’s a behavioral choice rather than a correctness bug, but worth double‑checking that this broader fallback is what you want.
Also applies to: 1689-1718
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
cli/tsc/mod.rs(4 hunks)libs/node_resolver/errors.rs(1 hunks)libs/node_resolver/resolution.rs(5 hunks)libs/resolver/npm/mod.rs(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- libs/node_resolver/errors.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.rs: For debugging Rust code, set breakpoints in IDE debuggers (VS Code with rust-analyzer, IntelliJ IDEA) or uselldbdirectly
Useeprintln!()ordbg!()macros for debug prints in Rust code
Files:
libs/node_resolver/resolution.rscli/tsc/mod.rslibs/resolver/npm/mod.rs
⚙️ CodeRabbit configuration file
Don't worry about coverage of Rust docstrings. Don't be nitpicky about it. Leave it to the author's judgement if such a documentation is necessary.
Files:
libs/node_resolver/resolution.rscli/tsc/mod.rslibs/resolver/npm/mod.rs
🧠 Learnings (1)
📚 Learning: 2025-11-24T16:19:37.808Z
Learnt from: CR
Repo: denoland/deno PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T16:19:37.808Z
Learning: Applies to cli/module_loader.rs : Module loading and resolution is handled in `cli/module_loader.rs`
Applied to files:
cli/tsc/mod.rs
🧬 Code graph analysis (2)
cli/tsc/mod.rs (2)
libs/node_resolver/errors.rs (1)
from(63-65)ext/node/polyfills/internal/errors.ts (1)
ERR_MODULE_NOT_FOUND(2544-2551)
libs/resolver/npm/mod.rs (8)
libs/node_resolver/npm.rs (1)
resolve_types_package_folder(25-30)libs/resolver/npm/managed/global.rs (1)
resolve_types_package_folder(184-197)libs/resolver/npm/managed/common.rs (1)
resolve_types_package_folder(81-99)libs/resolver/npm/managed/local.rs (1)
resolve_types_package_folder(207-228)libs/resolver/npm/byonm.rs (1)
resolve_types_package_folder(441-450)libs/resolver/npm/managed/mod.rs (1)
resolve_types_package_folder(269-280)libs/resolver/workspace.rs (1)
resolve_types_package_folder(1839-1846)libs/node_resolver/resolution.rs (1)
types_package_name(2510-2531)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: test debug linux-aarch64
- GitHub Check: test debug linux-x86_64
- GitHub Check: test debug windows-x86_64
- GitHub Check: test release linux-x86_64
- GitHub Check: test debug macos-aarch64
- GitHub Check: test debug macos-x86_64
- GitHub Check: lint debug windows-x86_64
- GitHub Check: build libs
- GitHub Check: lint debug linux-x86_64
- GitHub Check: lint debug macos-x86_64
🔇 Additional comments (4)
cli/tsc/mod.rs (1)
580-603: Npm types error wiring and resolution path look consistentAdding
ResolveError::ResolvePkgFolderFromDenoReqand switching both graph and non-graph npm types resolution to useresolve_pkg_folder_from_deno_module_req—while treatingERR_MODULE_NOT_FOUNDandERR_TYPES_NOT_FOUNDuniformly as “no types found” (returningNone)—is coherent with the new resolver API and keeps the CLI’s behavior straightforward. I don’t see correctness or propagation issues here.Also applies to: 663-687, 769-775
libs/resolver/npm/mod.rs (1)
13-13: resolve_types_package_folder delegation matches trait and backendsThe new
Versionimport andNpmPackageFolderResolver for NpmResolver<TSys>::resolve_types_package_folderimplementation are straightforward: they just forward(types_package_name, maybe_package_version, maybe_referrer)to the underlying Byonm/Managed resolvers, which is exactly what the trait expects. The behavior will mainly be shaped by those backend impls; at this layer, the wiring looks correct.Also applies to: 327-363
libs/node_resolver/resolution.rs (2)
2079-2117: Helpers for resolving @types package folders are consistent
resolve_types_package_folder_from_package_jsonandresolve_types_package_folder_with_name_and_versioncorrectly:
- Derive
(name, version?)fromPackageJsonwhen available, parsing the version viaVersion::parse_from_npmbest‑effort.- Compute the corresponding
@typespackage name withtypes_package_name, bailing out for already‑@types packages.- Delegate to
npm_pkg_folder_resolver.resolve_types_package_folderand emit a debug log with the effectivename@version(or*).The logic is tight and keeps all @types lookup specifics encapsulated.
2508-2531: types_package_name Option-returning helper and tests look goodMaking
types_package_nameprivate and returnOption<String>(None for inputs already under@types/) matches how it’s used by the new helpers and prevents double‑wrapping@types/@types/*. The implementation correctly handles scoped packages by mapping/to__, and the updated tests cover:
- Unscoped:
"name" -> Some("@types/name")- Scoped:
"@scoped/package" -> Some("@types/scoped__package")- Already-typed:
"@types/node" -> NoneThis behavior lines up with DefinitelyTyped conventions and the new resolver logic.
Also applies to: 2842-2848
nathanwhit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Shifts
@typespackage resolution down into node_resolver so it's always done. We were being inconsistent.