Skip to content

fix(cli): swizzle copies nested component source recursively - #4347

Closed
cixzhang wants to merge 1 commit into
mainfrom
fix/swizzle-nested-subdirs
Closed

cixzhang wants to merge 1 commit into
mainfrom
fix/swizzle-nested-subdirs

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Summary

Fixes #3506.

astryx swizzle <Name> copied only a component's top-level files and silently skipped nested subdirectories. For components whose source spans folders (e.g. Table/plugins/*), that produced a broken partial eject: the copied entry file still export … from './plugins/…', but the subtree it pointed at was never copied — so the swizzled component fails module resolution while the CLI reports success.

Re-implements the fix originally proposed by @oneshot2001 in #3507, rebased onto the reorganized CLI pillar layout (the logic now lives in packages/cli/api/swizzle/swizzle.mjs, the API pillar, rather than the old src/commands/swizzle.mjs).

Changes

  • Recursive copy. A new collectSourceFiles() walks the component tree, preserving nested structure and excluding tests/docs/README at every level. It's the single source of truth for the pre-flight collision check, the copy loop, and the reported file list. Symlinks are not followed.
  • Location-aware import rewriting. rewriteImports gains an optional {fromDir, componentDir}. Each ../ import is resolved from the source file's own directory; only imports that actually escape the component are rewritten to the owner package's subpath. Intra-component imports from nested files (e.g. ../../types in Table/plugins/pagination/*) stay relative instead of becoming a broken @astryxdesign/core/... Without the location arg the legacy behavior is unchanged, so the existing rewriteImports(content) contract and its tests are preserved.
  • Path safety. Every destination is asserted within the output dir (assertWithin) before any mkdir/write.

Testing

  • Added location-aware unit tests (escaping intra-package/sibling imports → owner subpath; intra-component ../../types stays relative; nested-sibling stays relative; top-level legacy parity) and an end-to-end regression test that swizzles a component with a nested plugins/ subtree and asserts the full tree is copied with correct rewrites.
  • packages/cli swizzle suites (swizzle.test.mjs, swizzle.routing.test.mjs, swizzle.path-safety.test.mjs) — 27/27 pass.
  • CLI strict typecheck (typecheck:strict, checkJs) — clean.
  • Changeset added (@astryxdesign/cli patch).

Notes

Behavior change is additive: top-level-only components swizzle identically to before; multi-directory components now eject completely.

Walk the component tree recursively so nested subdirectories are ejected instead of silently dropped, and make import-rewriting location-aware so intra-component imports from nested files stay relative while only escaping imports map to the owner package's subpaths. Every destination is asserted within the output dir before writing.

Fixes #3506
@vercel

vercel Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 26, 2026 3:02am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 26, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

Closing this — on reflection we can't build on an unsigned contribution here. The underlying issue #3506 remains open and we'll address it independently.

@cixzhang cixzhang closed this Jul 26, 2026
@cixzhang
cixzhang deleted the fix/swizzle-nested-subdirs branch July 26, 2026 03:07
github-actions Bot added a commit that referenced this pull request Jul 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

This branch was successfully deployed

1 active deployment
Preview — 6e892e95 Deployed Jul 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

swizzle silently drops nested subdirectories, producing a broken partial eject (e.g. Table/plugins)

1 participant