Skip to content

fix(cli): swizzle copies a component's nested source (#3506) - #4445

Closed
AKnassa wants to merge 2 commits into
meta:mainfrom
AKnassa:rocky/issue-3506-swizzle-recursive
Closed

AKnassa wants to merge 2 commits into
meta:mainfrom
AKnassa:rocky/issue-3506-swizzle-recursive

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3506.

astryx swizzle <Name> copied only a component's top-level files and silently skipped nested subdirectories. swizzle Table reported success after writing 17 files while dropping plugins/ entirely, so the ejected index.ts still re-exported ./plugins/selection, ./plugins/sortable and 15 more paths that were never created. The eject failed module resolution; the CLI called it a success.

After this change swizzle Table writes 47 files, all 12 plugin directories land, and all 138 relative specifiers in the output resolve on disk.

This is an independent implementation written against current main from the issue's root-cause description and the existing source. I did not read the diff of #4347 or #3507.

Changes

Recursive copy. A new collectSourceFiles() walks the component tree and returns posix-relative paths. It is the single source of truth for the pre-flight collision check, the copy loop and the reported file list, so those three can no longer disagree — previously all three applied the same top-level isFile() filter, which is why nested files were invisible even in the success count.

Location-aware import rewriting. rewriteImports gained an optional {componentDir, fromDir}. Each ../ specifier is resolved from the importing file's own directory rather than assumed to sit at the component root:

from specifier before after
Table/index.ts ../theme/tokens.stylex @astryxdesign/core/theme unchanged
Table/plugins/tree/x.ts ../../types @astryxdesign/core/.. untouched — resolves inside the eject
Table/plugins/tree/x.ts ../../../theme/tokens.stylex @astryxdesign/core/.. @astryxdesign/core/theme
Table/plugins/tree/x.ts ../.. (own entry) @astryxdesign/core/.. untouched
any escapes the package source root @astryxdesign/core/.. untouched

The old rule mapped every ../seg/… to <owner>/seg, so the 29 '../../types' imports inside Table/plugins would each have become @astryxdesign/core/.. — a specifier that resolves to nothing. Making the copy recursive without this would have swapped one broken eject for another.

Test scaffolding is skipped. __tests__, __snapshots__, __mocks__ and __fixtures__ are excluded as directories. The existing filename filter only catches .test., .doc. and README.md, so a .snap or a .spec.tsx would otherwise have been copied into a consumer's source once recursion was on. Symlinks are not followed.

Tests

packages/cli/api/swizzle/swizzle.recursive.test.mjs — 21 new tests over synthetic core fixtures under os.tmpdir(), so nothing is written inside process.cwd() and the existing suite's isolation is untouched. Coverage: structure preservation, posix path reporting, filesCopied matching disk, nested exclusions, the two directory-only exclusions, per-location rewriting, nested collision detection, --overwrite on nested files, usesStyleX from a nested file only, the flat-component path, symlink refusal, and a walk asserting every ./-relative specifier in the output resolves.

Full packages/cli suite: 120 files, 2100 tests, green. pnpm check:repo and eslint clean.

`astryx swizzle <Name>` copied only a component's top-level files and
silently skipped nested subdirectories. `swizzle Table` wrote 17 files and
dropped `plugins/`, so the ejected `index.ts` still re-exported
`./plugins/*` paths that were never created — the eject failed module
resolution while the CLI reported success.

The copy now walks the component tree recursively (47 files for `Table`).
One `collectSourceFiles()` walk backs the pre-flight collision check, the
copy loop and the reported file list, so the three cannot drift apart, and
paths are reported posix-separated.

`rewriteImports` resolves each `../` specifier from the importing file's own
directory instead of assuming the file sits at the component root:

- `../../types` from `plugins/tree/` stays untouched — structure is
  preserved, so it still resolves inside the eject.
- `../../../theme/tokens.stylex` still becomes `@astryxdesign/core/theme`.
- `../..`, the component's own entry reached from a nested file, stays
  untouched rather than becoming `@astryxdesign/core/<Name>`, which would
  point the eject back at the library it forked.
- A specifier reaching past the package source root is left alone rather
  than rewritten to `@astryxdesign/core/..`, which resolves to nothing.

Test scaffolding directories (`__tests__`, `__snapshots__`, `__mocks__`,
`__fixtures__`) are skipped — their contents carry no `.test.` marker for
the filename filter to catch — and symlinks are not followed.

Verified end to end: the ejected `Table` has all 12 plugin directories and
all 138 relative specifiers resolve on disk.

Fixes meta#3506
@vercel

vercel Bot commented Jul 28, 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 28, 2026 12:39pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 28, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 28, 2026
`packages/cli` typechecks its `.mjs` sources under `checkJs` via
`tsconfig.strict.json`, so an untyped parameter is an error, not a warning.
`isInside` and `isAtOrInside` shipped without JSDoc and tripped TS7006 four
times in CI.

Local `vitest` and `eslint` both pass without them — `pnpm -F
@astryxdesign/cli typecheck:strict` is the gate that catches this.
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

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 | View full report

This branch was successfully deployed

1 active deployment
Preview — 389bc170 Deployed Jul 28, 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. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

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