Repository navigation
fix(cli): swizzle copies nested component source recursively - #3507
oneshot2001 wants to merge 1 commit into
Conversation
`astryx swizzle <Name>` copied only the top-level files of a component directory and silently skipped nested subdirectories, producing a broken partial eject for components whose source spans folders (e.g. Table/plugins/*). The copied entry file still imported from the dropped subtree, so the swizzled component failed to resolve — while the CLI reported success. - Walk the component directory recursively, preserving nested structure (collectSourceFiles), and use that single list for the collision check, the copy loop, and the reported file list. - Make import rewriting location-aware: resolve each `../` import from the source file's own directory and only rewrite imports that escape the component. Intra-component imports from nested files (e.g. `../../types`) stay relative instead of becoming a broken `@astryxdesign/core/..`. Top-level behavior and the existing exported `rewriteImports(content)` contract are unchanged. - Assert each destination path stays within the output dir before writing. Adds unit tests for nested-file rewriting; verified end-to-end that `swizzle Table` now emits the full plugins/ tree with correct imports. Fixes meta#3506 Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@oneshot2001 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @oneshot2001! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Thanks, this is a good catch. |
cixzhang
left a comment
There was a problem hiding this comment.
Verified end-to-end: swizzle Table now ejects the full plugins/ subtree (36 files), every relative import resolves, and escaping imports rewrite correctly while intra-component ones stay relative — 21/21 tests pass. LGTM; please sign the Meta CLA so we can merge.
|
Thanks for spotting this and taking the time to write it up, @oneshot2001 — the non-recursive copy is a real bug. Unfortunately we can't merge this as-is: the Meta CLA hasn't been signed, and the PR has fallen well behind main since the CLI was reorganized, so it no longer applies cleanly. Closing for now — if you'd like to pursue it, please sign the CLA at https://code.facebook.com/cla and open a fresh PR against current main, and we'll gladly review it. The underlying issue #3506 stays open in the meantime. Appreciate the contribution! |
Summary
Fixes #3506.
astryx swizzle <Name>copied only the top-level files of a component directory and silently skipped nested subdirectories. For components whose source spans folders (e.g.Table/plugins/*), this produced a broken partial eject: the copied entry file stillexport … from './plugins/…', but that subtree was never copied, so the swizzled component fails module resolution — while the CLI reports success.Root cause in
packages/cli/src/commands/swizzle.mjs: the copy loop read the component dir non-recursively (if (!stat.isFile()) continue), andrewriteImportsonly handled top-level files (it mapped every../seg/...toowner/seg).Changes
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.rewriteImportsnow accepts an optional{fromDir, componentDir}. Each../import is resolved from the source file's own directory; only imports that escape the component are rewritten to the owner package's subpath. Intra-component imports from nested files (e.g.../../typesinTable/plugins/pagination/*) stay relative instead of becoming a broken@astryxdesign/core/... Without the location arg the legacy behavior is unchanged, so the existing exportedrewriteImports(content)contract and its tests are preserved.assertWithin) before anymkdir/write.Testing
pnpm exec vitest run packages/cli/src/commands/swizzle.*.test.mjs— 21/21 pass (added 5 unit tests for nested-file rewriting; existing routing + path-safety suites still green).astryx swizzle Tablenow emits the fullplugins/subtree; spot-checkedTable/plugins/pagination/useTablePagination.tsx— escaping imports resolve to@astryxdesign/core/theme/@astryxdesign/core/Paginationwhile the intra-component../../typesstays relative. Top-levelindex.ts's./plugins/*re-exports now resolve.pnpm check:repo(sync, package-boundaries, changesets, demo-media) passes; changeset added (@astryxdesign/clipatch,[fix]).Notes
Behavior change is additive — top-level-only components swizzle identically to before; multi-directory components now eject completely. Happy to adjust naming/placement to match maintainer preference.
I've read the CONTRIBUTING guide and will complete the Meta CLA.
🤖 Generated with Claude Code