feat: collision detection and opt-in auto-namespace by crate name#5
Merged
4dawit merged 2 commits into4dawit:mainfrom Mar 5, 2026
Merged
Conversation
When two different Rust types derive TS with the same TypeScript name, they write to the same output file. Previously this was silent last-writer-wins. Now `export_and_merge` compares file content and returns an actionable `ExportError::Collision` when the generated output differs, while still allowing idempotent re-exports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When TS_RS_AUTO_NAMESPACE=true (or Config::with_auto_namespace(true)),
all exported types are organized into {crate_name}/ subdirectories.
This prevents collisions entirely — different crates get different
directories with correct relative import paths between them.
Follow-up to Aleph-Alpha#483 which added collision detection.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1af9cdf to
a75982a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Combines both features from upstream PRs #483 and #484, ported to work with the current codebase API.
1. Collision detection: When two different Rust types derive
TSwith the same TypeScript name and export to the same file,export_and_mergenow returnsExportError::Collisioninstead of silently dropping the second type. Idempotent re-exports of the same type still succeed.2. Auto-namespace by crate: When
TS_RS_AUTO_NAMESPACE=true, all exported types are organized into{crate_name}/subdirectories based on the crate that defined them. This prevents collisions entirely — different crates get different directories with correct relative import paths between them.Changes
TStrait: addscrate_name()method (defaultNone, derive macro generatesSome(env!("CARGO_PKG_NAME")))export.rs: addsmaybe_namespacehelper,auto_namespace_enabled(), collision detection inexport_and_mergeerror.rs: addsExportError::Collisionvariant with suggestion to useTS_RS_AUTO_NAMESPACEDependency::from_ty: applies namespace prefix to output pathsTest plan
cargo test --all-features --test integration auto_namespace— new namespace tests passcargo test --all-features --test integration collision— new collision tests passcargo test --all-features— full suite (524 tests) passes, zero regressions🤖 Generated with Claude Code