refactor: use NormalizedId to ensure consistent behavior for id#7688
refactor: use NormalizedId to ensure consistent behavior for id#7688
NormalizedId to ensure consistent behavior for id#7688Conversation
How to use the Graphite Merge QueueAdd the label graphite: merge-when-ready to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR introduces a new NormalizedId type to ensure consistent handling of module identifiers across the codebase. The key change is wrapping the id field in ResolvedId with NormalizedId, which automatically normalizes Windows paths by converting backslashes to forward slashes for absolute paths.
Key changes:
- New
NormalizedIdtype that wrapsArcStrand performs path normalization on Windows - Refactored
ResolvedId.idfromArcStrtoNormalizedId - Updated all usages throughout the codebase to work with the new type using
.as_str()and.as_arc_str()accessor methods
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/rolldown_common/src/types/normalized_id.rs |
New type definition for NormalizedId with Windows path normalization logic and trait implementations |
crates/rolldown_common/src/types/mod.rs |
Adds the new normalized_id module to exports |
crates/rolldown_common/src/lib.rs |
Exports NormalizedId for public use |
crates/rolldown_common/src/types/resolved_id.rs |
Changes id field type from ArcStr to NormalizedId, updates usages to call .as_str() |
crates/rolldown_resolver/src/resolver.rs |
Wraps resolved path with NormalizedId::new() when creating ResolvedId |
crates/rolldown_plugin/src/utils/resolve_id_with_plugins.rs |
Updates all ResolvedId constructions to use NormalizedId::new() |
crates/rolldown_plugin/src/utils/resolve_id_check_external.rs |
Wraps external IDs with NormalizedId::new() |
crates/rolldown_plugin/src/types/hook_resolve_id_output.rs |
Accesses id via .as_arc_str().clone() instead of direct field access |
crates/rolldown_plugin/src/plugin_context/native_plugin_context.rs |
Wraps specifier with NormalizedId::new() when creating ResolvedId |
crates/rolldown_plugin_vite_import_glob/src/utils.rs |
Converts resolved_id.id to string using .to_string() instead of .into() |
crates/rolldown_plugin_vite_import_glob/src/utils_2.rs |
Converts resolved_id.id to string using .to_string() instead of .into() |
crates/rolldown/src/module_loader/resolve_utils.rs |
Updates all ID accesses to use .as_str() or .as_arc_str().clone() |
crates/rolldown/src/module_loader/runtime_module_task.rs |
Wraps runtime module ID with NormalizedId::new() |
crates/rolldown/src/module_loader/module_task.rs |
Updates ID accesses to use .as_str() or .as_arc_str().clone() |
crates/rolldown/src/module_loader/module_loader.rs |
Updates all map lookups and insertions to use .as_str() or .as_arc_str().clone() |
crates/rolldown/src/module_loader/external_module_task.rs |
Adds explicit type annotation for ArcStr and uses accessor methods |
crates/rolldown/src/ecmascript/ecma_module_view_factory.rs |
Uses .as_str() when creating ModuleId |
crates/rolldown/tests/rolldown/plugin/plugin_context/custom_arg_in_resolve/mod.rs |
Uses .as_str() for string comparison in test |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,50 @@ | |||
| // This's a temporary abstraction to represent `normalized` resolved id, but if we call it `NormalizedResolvedId`, it may confuse with `ResolvedId`. | |||
There was a problem hiding this comment.
The comment contains a grammatical error. "This's" should be "This is".
| // This's a temporary abstraction to represent `normalized` resolved id, but if we call it `NormalizedResolvedId`, it may confuse with `ResolvedId`. | |
| // This is a temporary abstraction to represent `normalized` resolved id, but if we call it `NormalizedResolvedId`, it may confuse with `ResolvedId`. |
| #[derive(Debug, Default, Clone, PartialEq, Eq, Hash)] | ||
| pub struct NormalizedId(ArcStr); |
There was a problem hiding this comment.
According to Rust API Guidelines (C-COMMON-TRAITS), common traits should be implemented where applicable. Consider implementing the PartialOrd and Ord traits for NormalizedId since it wraps ArcStr which implements these traits. This would allow NormalizedId instances to be used in contexts that require ordering, such as BTreeMap keys or sorting collections.
Benchmarks Rust
|
df2b5a8 to
32127bd
Compare
3f00fd2 to
aaaea8d
Compare
aaaea8d to
a3db8c3
Compare
32127bd to
10262da
Compare
a3db8c3 to
cbe5fe8
Compare
✅ Deploy Preview for rolldown-rs canceled.
|
cbe5fe8 to
30cbc23
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
30cbc23 to
22353de
Compare

NormalizedIdis a temporary abstraction to representnormalizedresolved id, but if we call itNormalizedResolvedId, it may confuse withResolvedId.