Skip to content

🐛 fix: rewrite flattened import paths after component install#89

Merged
renardeinside merged 1 commit intomainfrom
fix/flatten-import-rewriting
Feb 18, 2026
Merged

🐛 fix: rewrite flattened import paths after component install#89
renardeinside merged 1 commit intomainfrom
fix/flatten-import-rewriting

Conversation

@renardeinside
Copy link
Copy Markdown
Collaborator

Summary

  • Fixes 🐛 [BUG] mcp add_component: internal imports not rewritten to match flattened file paths #88: cross-file imports inside installed components were left pointing at the original nested registry paths (e.g. @/components/animate-ui/icons/icon) after file flattening flipped the saved name to icons-icon.tsx
  • Adds build_path_map to compare each file's original registry path against its saved (flattened) path and collect the differences
  • Adds rewrite_flattened_paths to apply that map to file content, anchored on the trailing quote to prevent partial-prefix matches; longest paths win

How it works

When plan_add resolves a component closure it now:

  1. Builds an original → saved path map across all resolved files
  2. Chains rewrite_flattened_paths after rewrite_registry_imports when writing each file

Helper functions added:

Function Purpose
determine_output_root Replaces the inline match file_type in the loop
compute_saved_import_path @/components/{registry}/{resolved.name} etc.
original_registry_import_path Strips extension, prepends @/ to file.path
build_path_map Collects original→saved pairs where they differ
rewrite_flattened_paths Quote-anchored, longest-first string replacement

Test plan

  • 9 new unit tests added in components::tests (component rewrite, hook rewrite, deeply-nested rewrite, no partial-match, empty map, path stripping, map building, integration scenario)
  • All 137 apx-core lib tests pass
  • cargo fmt --check passes
  • cargo check passes

🤖 Generated with Claude Code

@renardeinside renardeinside merged commit be5ae08 into main Feb 18, 2026
3 checks passed
@renardeinside renardeinside deleted the fix/flatten-import-rewriting branch February 18, 2026 10:13
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.

🐛 [BUG] mcp add_component: internal imports not rewritten to match flattened file paths

1 participant