Skip to content

feat: collision detection and opt-in auto-namespace by crate name#5

Merged
4dawit merged 2 commits into4dawit:mainfrom
jcrugzz:collision-and-namespace-for-4dawit
Mar 5, 2026
Merged

feat: collision detection and opt-in auto-namespace by crate name#5
4dawit merged 2 commits into4dawit:mainfrom
jcrugzz:collision-and-namespace-for-4dawit

Conversation

@jcrugzz
Copy link

@jcrugzz jcrugzz commented Mar 5, 2026

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 TS with the same TypeScript name and export to the same file, export_and_merge now returns ExportError::Collision instead 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

  • TS trait: adds crate_name() method (default None, derive macro generates Some(env!("CARGO_PKG_NAME")))
  • export.rs: adds maybe_namespace helper, auto_namespace_enabled(), collision detection in export_and_merge
  • error.rs: adds ExportError::Collision variant with suggestion to use TS_RS_AUTO_NAMESPACE
  • Dependency::from_ty: applies namespace prefix to output paths
  • Hyphens in crate names converted to underscores for directory names

Test plan

  • cargo test --all-features --test integration auto_namespace — new namespace tests pass
  • cargo test --all-features --test integration collision — new collision tests pass
  • cargo test --all-features — full suite (524 tests) passes, zero regressions

🤖 Generated with Claude Code

jcrugzz and others added 2 commits March 5, 2026 15:48
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>
@jcrugzz jcrugzz force-pushed the collision-and-namespace-for-4dawit branch from 1af9cdf to a75982a Compare March 5, 2026 20:49
@4dawit 4dawit merged commit 79cfb44 into 4dawit:main Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants