-
-
Notifications
You must be signed in to change notification settings - Fork 722
feat(resolver): resolve extension alias #7158
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
Conversation
🦋 Changeset detectedLatest commit: 3253a1b The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThis update adds extension aliasing to the module resolution process. The resolver now tries alternative file extensions, such as falling back from Possibly related PRs
Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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). (24)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
fa72866
to
c5a7679
Compare
CodSpeed Performance ReportMerging #7158 will improve performances by 6.1%Comparing Summary
Benchmarks breakdown
|
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: 1
🧹 Nitpick comments (5)
crates/biome_resolver/src/lib.rs (2)
65-95
: Robustness: still try the original extension as a final fallback.Current semantics skip the original extension entirely if an alias entry exists that omits it. Many resolvers always try the original last to avoid surprising failures. Safe to add and keeps your tests passing.
Apply after the alias loop:
- Err(last_error.unwrap_or(ResolveError::NotFound)) + // As a safety net, try the original as the last resort if not already included. + if !aliases.contains(&extension) { + if let Ok(ok) = resolve_absolute_path(path.clone(), fs, options) { + return Ok(ok); + } + } + Err(last_error.unwrap_or(ResolveError::NotFound))
763-769
: Docs: clarify scope and precedence ofextension_alias
.
- It also applies to absolute paths (not just “relative paths”).
- Consider noting that alias order defines precedence, and the original extension is only tried if included (or if you adopt the suggested fallback above).
Suggested wording:
-/// List of extension aliases to search for in relative paths. -/// Typically used to resolve `.ts` files by `.js` extension. +/// List of extension aliases to search when a specifier has an explicit extension. +/// Applies to both absolute and relative paths. +/// Commonly used to resolve `.ts` files when `.js` is imported. +/// +/// Aliases are tried in the given order. The original extension is only tried if +/// it is included in the alias list (or as an implementation detail if the resolver +/// falls back to it after exhausting aliases)..changeset/petite-waves-love.md (1)
5-5
: Polish the changeset for clarity and style.Use past tense for what you did, present tense for behaviour, and tidy the grammar.
-The resolver can now correctly resolve `.ts` files by `.js` extension if exists. +Added support for extension aliasing in the resolver. Biome now resolves `.ts` files when they are imported with the `.js` extension, if the `.ts` file exists. + +See https://github.com/biomejs/biome/pull/7158 for details.crates/biome_module_graph/src/js_module_info/visitor.rs (1)
447-451
: Avoid drift: centralise default alias mapping.The
"js" -> ["ts", "js"]
and"mjs" -> ["mts", "mjs"]
mapping is likely useful elsewhere. Consider exposing a constant inbiome_resolver
(e.g.,DEFAULT_EXTENSION_ALIAS
) or a helper likewith_node_style_extension_alias()
to prevent duplication and divergence.crates/biome_resolver/tests/spec_tests.rs (1)
537-572
: Great coverage for fully specified aliasing.Minor nit: the assertion message “without an array” is misleading, since the option is an array with a single element.
- "should support alias option without an array", + "should support a single-alias alternative",
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.changeset/petite-waves-love.md
(1 hunks)crates/biome_module_graph/src/js_module_info/visitor.rs
(1 hunks)crates/biome_resolver/src/lib.rs
(8 hunks)crates/biome_resolver/tests/spec_tests.rs
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
.changeset/*.md
📄 CodeRabbit Inference Engine (CONTRIBUTING.md)
.changeset/*.md
: Changeset descriptions should be about user-facing changes, use past tense for what you did, present tense for Biome behavior, reference issues/rules/assists with links, include code blocks when applicable, and end every sentence with a full stop.
Headers in changesets should use####
or#####
only; other headers may break the changelog.
Files:
.changeset/petite-waves-love.md
**/*.{rs,toml}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Format code (Rust + TOML) using
just format
Format Rust and TOML files using
just f
(alias forjust format
).
Files:
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/tests/spec_tests.rs
crates/biome_resolver/src/lib.rs
crates/biome_*/**/*
📄 CodeRabbit Inference Engine (CLAUDE.md)
Core crates must be located in
/crates/biome_*/
Files:
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/tests/spec_tests.rs
crates/biome_resolver/src/lib.rs
**/*.rs
📄 CodeRabbit Inference Engine (CONTRIBUTING.md)
Update documentation for new features or changes, using inline rustdoc for rules, assists, and their options.
Files:
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/tests/spec_tests.rs
crates/biome_resolver/src/lib.rs
🧠 Learnings (30)
📓 Common learnings
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/resolver.rs : Implement and maintain the `TypeResolver` trait in `src/resolver.rs`, with separate implementations for hardcoded symbols, globals, module info collection, and full module resolution.
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/../biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference should resolve all remaining `TypeReference::Import` variants to `TypeReference::Resolved` using the complete module graph. Implemented in `../biome_module_graph/src/js_module_info/scoped_resolver.rs`.
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
PR: biomejs/biome#7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: Applies to .changeset/*.md : Changeset descriptions should be about user-facing changes, use past tense for what you did, present tense for Biome behavior, reference issues/rules/assists with links, include code blocks when applicable, and end every sentence with a full stop.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: Create changesets for user-facing bugfixes or features using `just new-changeset`.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: Update generated documentation in the `next` branch of the website after a release using `BIOME_VERSION=<version> pnpm run codegen:all`.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/biome_*/lib/src/lint/nursery/*.rs : Update the `language` field in `declare_lint_rule!` to match the language the rule applies to (e.g., `js`, `jsx`, `ts`, `tsx`).
Applied to files:
.changeset/petite-waves-love.md
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: For Node.js development, use the `packages/biomejs/biome` module and follow the specified build and test steps.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/resolver.rs : Implement and maintain the `TypeResolver` trait in `src/resolver.rs`, with separate implementations for hardcoded symbols, globals, module info collection, and full module resolution.
Applied to files:
.changeset/petite-waves-love.md
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/tests/spec_tests.rs
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/../biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference should resolve all remaining `TypeReference::Import` variants to `TypeReference::Resolved` using the complete module graph. Implemented in `../biome_module_graph/src/js_module_info/scoped_resolver.rs`.
Applied to files:
.changeset/petite-waves-love.md
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/tests/spec_tests.rs
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/../biome_module_graph/src/js_module_info/collector.rs : Module-level (thin) inference should resolve `TypeReference::Qualifier` variants to `TypeReference::Resolved` or `TypeReference::Import` as appropriate, but cannot resolve imports across modules. Implemented in `../biome_module_graph/src/js_module_info/collector.rs`.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/biome_*/lib/src/lint/nursery/*.rs : When implementing custom syntax tree visitors, define a `Visitor` struct and implement the `Visitor` trait for efficient traversal.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/local_inference.rs : Local type inference should only create type references and not resolve them to concrete types. Local inference is implemented in `src/local_inference.rs`.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/*.rs : Use boxed slices (`Box<[Box<str>]>`) instead of `Vec<String>` for string arrays in rule options to save memory.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/flattening.rs : Flattening of type expressions (e.g., reducing `TypeData::TypeofExpression` to a concrete type) should be implemented in `src/flattening.rs`.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : The `TypeData` enum, defined in `src/type_info.rs`, is the central data structure for type information and should be extended to cover all relevant TypeScript types.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:51:05.640Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:05.640Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : For tokens that are not mandatory, use the provided helper functions when formatting AST nodes.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:51:51.355Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:51.355Z
Learning: Applies to crates/biome_parser/crates/biome_*/**/*.rs : Use conditional syntax handling to add diagnostics if a syntax is not supported in the current file or context, and wrap invalid syntax in a `BOGUS` node if necessary.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:50:56.365Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:56.365Z
Learning: Applies to crates/biome_formatter/tests/spec_tests.rs : Update the `spec_tests.rs` file to generate a test function for each `.html` file found inside `tests/specs/html` using the `tests_macros::gen_tests!` macro.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:51:59.193Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:59.193Z
Learning: Applies to crates/biome_service/src/workspace/watcher.tests.rs : Add tests for watcher workspace methods in watcher.tests.rs (src/workspace/watcher.tests.rs)
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:50:56.365Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:56.365Z
Learning: Applies to crates/biome_formatter/tests/{spec_test.rs,spec_tests.rs,language.rs} : Inside the `biome_html_formatter` crate, create a `tests` folder containing a `specs` folder and the files `spec_test.rs`, `spec_tests.rs`, and `language.rs` for test infrastructure.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:51:59.193Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:59.193Z
Learning: Applies to crates/biome_service/../biome_lsp/src/server.tests.rs : Add end-to-end tests for watcher functionality in LSP tests (../biome_lsp/src/server.tests.rs)
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Test rules using quick tests in the appropriate test file (e.g., `biome_js_analyze/tests/quick_test.rs`) and snapshot tests in `tests/specs/`.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:50:56.365Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:56.365Z
Learning: Applies to crates/biome_formatter/tests/language.rs : Implement the `HtmlTestFormatLanguage` struct and the `TestFormatLanguage` trait in `language.rs` for test language support.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:50:56.365Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:56.365Z
Learning: Applies to crates/biome_formatter/tests/spec_test.rs : Implement the `run` function in `spec_test.rs` to execute formatting tests using the provided test infrastructure.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/tests/specs/*/*/{invalid*,valid*}* : Snapshot tests for rules should be placed in `tests/specs/<group>/<rule_name>/` with files prefixed by `invalid` or `valid`.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/*.rs : Rule options must be placed inside the `biome_rule_options` crate, with a file named after the rule (e.g., `use_this_convention.rs`).
Applied to files:
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : When using `ResolvedTypeData`, always use the correct `ResolverId` when resolving `TypeReference`s that are part of the type data; mistakes can lead to panics.
Applied to files:
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:51:59.193Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:59.193Z
Learning: Applies to crates/biome_service/src/workspace_watcher.rs : Keep the workspace state in sync with the filesystem using WorkspaceWatcher (src/workspace_watcher.rs)
Applied to files:
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: Applies to **/Cargo.toml : Use path dependencies for dev-dependencies in Cargo.toml to avoid requiring published versions.
Applied to files:
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:50:35.163Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_diagnostics/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:35.163Z
Learning: Applies to crates/biome_diagnostics/**/*.rs : Diagnostics should not simply state that something went wrong; they should explain why it went wrong. Add explanations in log advices, and show hyperlinks to relevant documentation pages if the user wants to know more.
Applied to files:
crates/biome_resolver/src/lib.rs
🔇 Additional comments (7)
crates/biome_resolver/src/lib.rs (6)
44-48
: Good call: route absolute paths through alias-aware resolver.This hooks fully specified absolute specifiers into the new alias flow as intended.
149-150
: Nice: aliasing now also applies to relative specifiers.Keeps behaviour consistent between absolute and relative flows.
838-838
: Sane default.
extension_alias
defaulting to an empty slice is correct and non-invasive.
877-885
: Builder API looks good.
const fn
here is handy and matches the rest of the options API.
925-926
: Good: preserve alias config when adjusting type roots.Avoids accidental drops of the feature mid-resolution.
940-941
: Correct: disable aliases when following manifest targets.Keeps
exports
/main
resolution strict and predictable.crates/biome_resolver/tests/spec_tests.rs (1)
575-597
: Good: verifies aliasing does not affect directory/main resolution.Consider adding one case where aliases are non-empty to confirm they still don’t affect directory/main lookups.
Would you like me to add a follow-up test that sets
extension_alias
for"js"
(non-empty) and asserts that resolving"./dir2"
and"./dir2/index"
still lands onindex.js
?
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: 1
🧹 Nitpick comments (7)
crates/biome_resolver/src/lib.rs (3)
84-91
: Minor: avoid redundant extension probing after aliasing.resolve_absolute_path may append options.extensions even when the candidate already has an extension, causing extra filesystem probes like "foo.ts.js". Not a correctness bug, but wasteful under aliasing.
Would you like a small PR to skip extension probing when the input already has an extension?
763-768
: Clarify docs: scope and ordering of aliases.This applies to absolute and relative paths with an explicit extension. If you want to keep the original extension as a fallback, include it in the alias list in the desired order.
-/// List of extension aliases to search for in relative paths. -/// Typically used to resolve `.ts` files by `.js` extension. -/// -/// Extensions should be provided without a leading dot. +/// Extension aliases to consider when a specifier contains an explicit extension +/// (absolute and relative paths). +/// Typically used to resolve `.js` imports to existing `.ts` sources. +/// +/// Provide extensions without a leading dot. The search order follows the slice order. +/// Include the original extension if you want it to be considered as a fallback. pub extension_alias: &'a [(&'a str, &'a [&'a str])],
877-885
: Nice builder.Const builder keeps config ergonomic. Consider adding a brief example in the field docs to show typical mapping ("js" -> ["ts","js"]).
crates/biome_module_graph/src/js_module_info/visitor.rs (1)
447-451
: Consider widening aliases for common ESM/TS patterns.Current mapping covers js→ts and mjs→mts. Many codebases also rely on:
- jsx → tsx
- cjs → cts
If aligned with project goals, extend the mapping (order matters):
- extension_alias: &[("js", &["ts", "js"]), ("mjs", &["mts", "mjs"])], + extension_alias: &[ + ("js", &["ts", "js"]), + ("mjs", &["mts", "mjs"]), + ("jsx", &["tsx", "jsx"]), + ("cjs", &["cts", "cjs"]), + ],Please verify SUPPORTED_EXTENSIONS already includes these extensions.
.changeset/petite-waves-love.md (1)
1-5
: Polish the changeset per guidelines (past tense + clearer behaviour).Short, user-facing, and precise:
--- "@biomejs/biome": patch --- -The resolver can now correctly resolve `.ts` files by `.js` extension if exists. +Added support for extension aliasing in the resolver. + +Biome now resolves imports that use the `.js` extension to corresponding `.ts` files when present. For example, `import "./foo.js"` resolves to `./foo.ts` if it exists; otherwise it resolves to `./foo.js`.crates/biome_resolver/tests/spec_tests.rs (2)
567-571
: Tweak the assertion message.It mentions “without an array”, but the option uses a slice with one element. Suggest rewording to avoid confusion.
- "should support alias option without an array", + "should support alias option with a single alternative",
537-572
: Add a couple more cases for completeness.
- Absolute path with alias (e.g.
${base_dir}/index.js
→${base_dir}/index.ts
).- Relative alias with query/fragment to prove strip_query_and_fragment plays nicely.
Happy to draft these tests if you want them added here.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.changeset/petite-waves-love.md
(1 hunks)crates/biome_module_graph/src/js_module_info/visitor.rs
(1 hunks)crates/biome_resolver/src/lib.rs
(8 hunks)crates/biome_resolver/tests/spec_tests.rs
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{rs,toml}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Format code (Rust + TOML) using
just format
Format Rust and TOML files using
just f
(alias forjust format
).
Files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/src/lib.rs
crates/biome_*/**/*
📄 CodeRabbit Inference Engine (CLAUDE.md)
Core crates must be located in
/crates/biome_*/
Files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/src/lib.rs
**/*.rs
📄 CodeRabbit Inference Engine (CONTRIBUTING.md)
Update documentation for new features or changes, using inline rustdoc for rules, assists, and their options.
Files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/src/lib.rs
.changeset/*.md
📄 CodeRabbit Inference Engine (CONTRIBUTING.md)
.changeset/*.md
: Changeset descriptions should be about user-facing changes, use past tense for what you did, present tense for Biome behavior, reference issues/rules/assists with links, include code blocks when applicable, and end every sentence with a full stop.
Headers in changesets should use####
or#####
only; other headers may break the changelog.
Files:
.changeset/petite-waves-love.md
🧠 Learnings (29)
📓 Common learnings
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/resolver.rs : Implement and maintain the `TypeResolver` trait in `src/resolver.rs`, with separate implementations for hardcoded symbols, globals, module info collection, and full module resolution.
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/../biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference should resolve all remaining `TypeReference::Import` variants to `TypeReference::Resolved` using the complete module graph. Implemented in `../biome_module_graph/src/js_module_info/scoped_resolver.rs`.
📚 Learning: 2025-08-05T14:50:56.365Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:56.365Z
Learning: Applies to crates/biome_formatter/tests/{spec_test.rs,spec_tests.rs,language.rs} : Inside the `biome_html_formatter` crate, create a `tests` folder containing a `specs` folder and the files `spec_test.rs`, `spec_tests.rs`, and `language.rs` for test infrastructure.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:51:59.193Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:59.193Z
Learning: Applies to crates/biome_service/src/workspace/watcher.tests.rs : Add tests for watcher workspace methods in watcher.tests.rs (src/workspace/watcher.tests.rs)
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:50:56.365Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:56.365Z
Learning: Applies to crates/biome_formatter/tests/spec_tests.rs : Update the `spec_tests.rs` file to generate a test function for each `.html` file found inside `tests/specs/html` using the `tests_macros::gen_tests!` macro.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:51:59.193Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:59.193Z
Learning: Applies to crates/biome_service/../biome_lsp/src/server.tests.rs : Add end-to-end tests for watcher functionality in LSP tests (../biome_lsp/src/server.tests.rs)
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/resolver.rs : Implement and maintain the `TypeResolver` trait in `src/resolver.rs`, with separate implementations for hardcoded symbols, globals, module info collection, and full module resolution.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_module_graph/src/js_module_info/visitor.rs
.changeset/petite-waves-love.md
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Test rules using quick tests in the appropriate test file (e.g., `biome_js_analyze/tests/quick_test.rs`) and snapshot tests in `tests/specs/`.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:50:56.365Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:56.365Z
Learning: Applies to crates/biome_formatter/tests/language.rs : Implement the `HtmlTestFormatLanguage` struct and the `TestFormatLanguage` trait in `language.rs` for test language support.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/../biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference should resolve all remaining `TypeReference::Import` variants to `TypeReference::Resolved` using the complete module graph. Implemented in `../biome_module_graph/src/js_module_info/scoped_resolver.rs`.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_module_graph/src/js_module_info/visitor.rs
.changeset/petite-waves-love.md
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:50:56.365Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:56.365Z
Learning: Applies to crates/biome_formatter/tests/spec_test.rs : Implement the `run` function in `spec_test.rs` to execute formatting tests using the provided test infrastructure.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/biome_*/lib/src/lint/nursery/*.rs : Update the `language` field in `declare_lint_rule!` to match the language the rule applies to (e.g., `js`, `jsx`, `ts`, `tsx`).
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_module_graph/src/js_module_info/visitor.rs
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/../biome_module_graph/src/js_module_info/collector.rs : Module-level (thin) inference should resolve `TypeReference::Qualifier` variants to `TypeReference::Resolved` or `TypeReference::Import` as appropriate, but cannot resolve imports across modules. Implemented in `../biome_module_graph/src/js_module_info/collector.rs`.
Applied to files:
crates/biome_resolver/tests/spec_tests.rs
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/local_inference.rs : Local type inference should only create type references and not resolve them to concrete types. Local inference is implemented in `src/local_inference.rs`.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/biome_*/lib/src/lint/nursery/*.rs : When implementing custom syntax tree visitors, define a `Visitor` struct and implement the `Visitor` trait for efficient traversal.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/*.rs : Use boxed slices (`Box<[Box<str>]>`) instead of `Vec<String>` for string arrays in rule options to save memory.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/flattening.rs : Flattening of type expressions (e.g., reducing `TypeData::TypeofExpression` to a concrete type) should be implemented in `src/flattening.rs`.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : The `TypeData` enum, defined in `src/type_info.rs`, is the central data structure for type information and should be extended to cover all relevant TypeScript types.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:51:05.640Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:05.640Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : For tokens that are not mandatory, use the provided helper functions when formatting AST nodes.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
📚 Learning: 2025-08-05T14:51:51.355Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:51.355Z
Learning: Applies to crates/biome_parser/crates/biome_*/**/*.rs : Use conditional syntax handling to add diagnostics if a syntax is not supported in the current file or context, and wrap invalid syntax in a `BOGUS` node if necessary.
Applied to files:
crates/biome_module_graph/src/js_module_info/visitor.rs
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
PR: biomejs/biome#7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: Applies to .changeset/*.md : Changeset descriptions should be about user-facing changes, use past tense for what you did, present tense for Biome behavior, reference issues/rules/assists with links, include code blocks when applicable, and end every sentence with a full stop.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: Create changesets for user-facing bugfixes or features using `just new-changeset`.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: For Node.js development, use the `packages/biomejs/biome` module and follow the specified build and test steps.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: Update generated documentation in the `next` branch of the website after a release using `BIOME_VERSION=<version> pnpm run codegen:all`.
Applied to files:
.changeset/petite-waves-love.md
📚 Learning: 2025-08-05T14:50:18.454Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:18.454Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/*.rs : Rule options must be placed inside the `biome_rule_options` crate, with a file named after the rule (e.g., `use_this_convention.rs`).
Applied to files:
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:51:59.193Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:59.193Z
Learning: Applies to crates/biome_service/src/workspace_watcher.rs : Keep the workspace state in sync with the filesystem using WorkspaceWatcher (src/workspace_watcher.rs)
Applied to files:
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:51:23.437Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:51:23.437Z
Learning: Applies to crates/biome_js_type_info/src/type_info.rs : When using `ResolvedTypeData`, always use the correct `ResolverId` when resolving `TypeReference`s that are part of the type data; mistakes can lead to panics.
Applied to files:
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:49:35.574Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:49:35.574Z
Learning: Applies to **/Cargo.toml : Use path dependencies for dev-dependencies in Cargo.toml to avoid requiring published versions.
Applied to files:
crates/biome_resolver/src/lib.rs
📚 Learning: 2025-08-05T14:50:35.163Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_diagnostics/CONTRIBUTING.md:0-0
Timestamp: 2025-08-05T14:50:35.163Z
Learning: Applies to crates/biome_diagnostics/**/*.rs : Diagnostics should not simply state that something went wrong; they should explain why it went wrong. Add explanations in log advices, and show hyperlinks to relevant documentation pages if the user wants to know more.
Applied to files:
crates/biome_resolver/src/lib.rs
🔇 Additional comments (5)
crates/biome_resolver/src/lib.rs (5)
44-48
: Good call: apply aliasing to absolute specifiers too.Routing absolute specifiers through the alias-aware path keeps behaviour consistent across relative/absolute imports.
149-149
: LGTM: alias-aware relative paths.Forwarding relative resolution through the alias helper keeps semantics uniform.
838-838
: Default is sensible.Defaulting extension_alias to an empty slice is safe and keeps existing behaviour intact.
925-925
: Correct: preserve alias config when removing manifests.Carrying extension_alias here maintains expected behaviour for tsconfig-driven flows.
940-940
: Good: disable aliasing in manifest-less resolution.This prevents aliasing from affecting package.json main/types and similar cases.
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.
I have a few questions
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.
Looks good. The error handling part could be improved, but we can follow up later
.changeset/petite-waves-love.md
Outdated
"@biomejs/biome": patch | ||
--- | ||
|
||
The resolver can now correctly resolve `.ts` files by `.js` extension if exists. |
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.
I believe a code snippet would help show what this means.
Summary
Add support for the
extension_alias
option in our own resolver.Now Biome can resolve
.ts
files imported by.js
extension, which is the common pattern in TypeScript with ESM module resolution.Test Plan
Added spec tests.
Test cases are copied from oxc-resolver: https://github.com/oxc-project/oxc-resolver/blob/3759487f28ee05e3deb1c60f193735d180d23bbe/src/tests/extension_alias.rs.
Docs
N/A