Skip to content

fix(cli): swizzle copies the private attribute owner modules a component imports - #10085

Merged
cixzhang merged 1 commit into
mainfrom
fix/swizzle-owner-modules
Nov 5, 2026
Merged

cixzhang merged 1 commit into
mainfrom
fix/swizzle-owner-modules

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

User impact

This affects people who run astryx swizzle on a component that imports a private data attribute's owner module, such as Item, CheckboxList, RadioList or TreeList today, and Button once its touch press layer lands.

  • Today: the copy rewrites ../privateAttributes/press.stylex to @astryxdesign/core/privateAttributes/press.stylex. @astryxdesign/core doesn't export that subpath (it is private by architecture:public-component-api INV23), so the swizzled component fails to compile.
  • After this change: swizzle copies the owner module whole beside the component, in the package's layout (<output>/privateAttributes/press.stylex.ts), with the unexported style modules it imports (<output>/motion/reducedMotion.stylex.ts). The component's import stays relative and resolves. The receipt's files lists them (relative to the component's folder, e.g. ../privateAttributes/press.stylex.ts) and filesCopied counts them, including an identical copy already in place. The text output adds one line, Shared modules: …, naming them.
  • Unchanged: a component that imports no owner module (Button on main) copies exactly as before.

Expected behavior and authority

spec:AST-110 FR4: an owner module the component imports travels with the copy, whole. This pull request implements it and records the rule Specs & Decisions gave for it:

Swizzle copies an imported owner module, and any unexported style module it imports, whole: the copy is unedited except that imports of modules the package exports are rewritten to their package subpaths, as the component's own files are; unexported dependencies keep their relative imports in the same layout. Re-swizzling skips an identical existing copy and refuses a changed one without --overwrite.

It also removes FR4's known gap ("No private data-attribute owner module exists yet"): nine owner modules exist on main. FR2, its Verification row and the Current-state impact bullet gain FR4's exception, as Specs & Decisions ruled: a differing helper is still never replaced, except an owner module and its unexported style modules, which FR4 governs. A version-suffixed second owner module would break INV23's single-owner guarantee. architecture:interaction-modality INV3 drops its sentence "Swizzle does not yet carry an unexported owner module into an ejected copy", which this makes false. A new known gap records that the result doesn't yet say whether each shared module was written, reused or replaced; adding that receipt field is the CLI owner's call. Exporting the owner modules, or re-exporting their styles from a public module, would publish internals INV23 keeps private.

Problem and solution fit

  • sharedModulesOf walks the component's relative imports. It carries each privateAttributes/*.stylex module, then each carried module's imports of unexported .stylex modules, transitively. Anything else keeps today's rewrite.
  • rewriteImports takes a keep predicate, so imports of carried modules stay relative. Its default keeps every existing call unchanged.
  • Overwrite: before any write, a shared module that already exists is compared with what this run would write. An identical copy (from another component's swizzle) is reused. A changed one is refused without --overwrite, like the component's own files, and nothing is written. A failed write undoes the run's writes, shared modules included, and removes the folders the run created.

Verification

  • Red first: the two new copy.test.mjs cases fail on main and pass here.
    • Swizzling Item copies privateAttributes/press.stylex.ts and motion/reducedMotion.stylex.ts, and keeps Item's import relative. Every @astryxdesign/core/* import in every copied file resolves in core's exports, and the owner module equals the package's except for its import specifiers.
    • A second swizzle (CheckboxList) reuses the identical owner module; an edited one is refused without --overwrite, with nothing written, and replaced with it.
  • The Button import contract (swizzle.test.mjs): it now swizzles Button and checks that every import in the copy resolves, either in core's exports or to a file the copy wrote. Before, it rewrote the source in memory, so a carried owner module counted as unresolved. It passes on main's Button, and on Button with fix(core): a button's touch press release runs on the compositor #9783's touch press layer, which imports privateAttributes/press.stylex.
  • Cleanup, red first: with a folder where the owner module goes, --overwrite fails with ERR_WRITE_FAILED and leaves no Item/ or motion/ folder behind. This fails on the previous head.
  • CLI text: swizzle.routing.test.mjs swizzles a fixture component with an owner module and an unexported style module, and checks the Shared modules: line.
  • Descriptions: swizzle()'s doc, the swizzle.copy receipt description and the README table now call files the copied file names, relative to the component folder, with owner modules beside it starting with ../. The Shared modules: line notes that their imports between each other stay relative.
  • Suites: the swizzle API, copy and CLI command tests pass (50/50). So do the json-api type check, strict lint and check:changesets. The receipt's shape and api-report.md are unchanged.

Scope

  • One spec gap closed (spec:AST-110 FR4), in the CLI only.
  • No new public API: the receipt keeps its shape, and the copied modules join files.
  • Public text contains no internal Meta context.

@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 5, 2026 3:07pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 5, 2026
@astracat-bot

astracat-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 5, 2026, 3:15 PM UTC

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · c035bc9

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 3.37 MB packed (+2.7 kB); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 9 rows, core 4 rows; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@cixzhang
cixzhang force-pushed the fix/swizzle-owner-modules branch 2 times, most recently from a5b1b4f to 58cd85d Compare November 5, 2026 13:32
@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 58cd85d

@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 905cfc3

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested. The owner-module copy works, and the swizzle tests pass. The spec record, the changeset and the CLI output still need to match what the copy now does.

  • spec:AST-110 FR2, its Verification row and the Current-state impact bullet still say a helper that differs is never replaced, even with --overwrite, and that the result marks each helper as written, reused or version-suffixed; both contradict the new FR4 and the code for owner modules, so amend them to agree.
  • The changeset says swizzled RadioList and TreeList compile, but their copies still import @astryxdesign/core/utils/touchHitArea.stylex and @astryxdesign/core/motion, which core does not export, so drop "so it compiles".
  • The CLI prints Copied N files to <component folder>/ while some of those files land in sibling privateAttributes/ and motion/ folders, and --overwrite replaces a shared module another copy uses without saying so; name the shared modules written or replaced outside the component folder.
  • Minor: a failed shared-module write leaves the empty component folder and privateAttributes/ folder behind, unlike a failed component-file write, so remove the folders the run created.

The FR4 rule itself is approved for this head, so no spec decision is pending.

[Automated review]

imports of modules the package exports are rewritten to their package
subpaths, as the component's own files are; unexported dependencies keep
their relative imports in the same layout. Re-swizzling skips an identical
existing copy and refuses a changed one without `--overwrite`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FR4 now refuses a changed shared copy without --overwrite and replaces it with it, as the code does. FR2 (lines 77-81), its Verification row and the Current-state impact bullet (lines 165-170) still say a helper that differs is never overwritten, even with --overwrite, and that the result marks each helper as written, reused or version-suffixed. Owner modules are such helpers, so please amend those lines to agree, for example by exempting owner modules from FR2's rule.

Comment thread .changeset/swizzle-owner-modules.md Outdated
'@astryxdesign/cli': patch
---

[fix] `astryx swizzle` now copies the private attribute owner modules a component imports, and the unexported style modules they need, beside the copy in the package's layout. A swizzled `Item`, `CheckboxList`, `RadioList` or `TreeList` no longer imports a `privateAttributes/*.stylex` subpath that `@astryxdesign/core` does not export, so it compiles. A second swizzle reuses an identical copy and refuses a changed one without `--overwrite`. The receipt's `files` and `filesCopied` include the modules it copied.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"so it compiles" overstates this for two of the four: a swizzled RadioList still imports @astryxdesign/core/utils/touchHitArea.stylex (from RadioListItem.tsx:37) and TreeList imports @astryxdesign/core/motion (from TreeList.tsx:40), and core exports neither. Suggest ending the sentence at "…that @astryxdesign/core does not export."

// carries beside the component (spec:AST-110 FR4) are its files too.
files: [
...copiedFiles.map(f => f),
...shared.map(m => path.relative(outputDir, m.dest).split(path.sep).join('/')),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These entries sit outside outputDir, and filesCopied counts them. The CLI renderer still prints [ok] Copied ${filesCopied} files to ${outputDir}/ (clients/cli/commands/swizzle.mjs:85). Swizzling Item reports 10 files in Item/ when two are in privateAttributes/ and motion/, and --overwrite replaces a shared module another copy uses without saying so. Please name the shared modules written or replaced in the human output.

Comment on lines +590 to +593
} catch (err) {
const unrestored = undoCopy(written);
throw writeFailed(module.dest, cwd, err, unrestored);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: unlike the component loop above (lines 563-571), this failure path does not remove the component folder this run created, nor the privateAttributes/ folder it just made. A failed shared write leaves both behind, empty.

@cixzhang
cixzhang force-pushed the fix/swizzle-owner-modules branch from 905cfc3 to 46009de Compare November 5, 2026 14:21
@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 46009de

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested. The owner-module copy works: the swizzle tests pass, every owner-module import in the nine affected copies now resolves to a file the run wrote, and an engineering owner approved the spec:AST-110 changes for this head.

  • Miss: architecture:interaction-modality INV3 still says "Swizzle does not yet carry an unexported owner module into an ejected copy" (docs/architecture/interaction-modality.md:150-151), which this change makes false, so please delete that sentence as you did for the FR4 gap in spec:AST-110.

Optional: swizzle()'s doc and both receipt descriptions still call files the written file names and say escaping imports are rewritten, and the text output still says relative imports were rewritten right above shared modules whose imports stay relative. A new commit needs a fresh /approve-spec for its head.

[Automated review]

imports is copied whole and unedited, so callers, the copy included, still
never write the attribute by hand.
imports travels with the copy, so callers, the copy included, still never
write the attribute by hand. Swizzle copies an imported owner module, and any

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss: with this rule in place, architecture:interaction-modality INV3 still says "Swizzle does not yet carry an unexported owner module into an ejected copy." (docs/architecture/interaction-modality.md:150-151). Please delete that sentence in this pull request, as you removed FR4's gap here.

…ent imports

A swizzled Item, CheckboxList, RadioList or TreeList imported
`@astryxdesign/core/privateAttributes/press.stylex`, which core does not
export, so it failed to compile. Swizzle now copies each owner module the
component imports, and the unexported style modules it imports, whole
beside the copy in the package's layout, keeping those imports relative
(spec:AST-110 FR4). A second swizzle reuses an identical copy and refuses
a changed one without --overwrite.
@cixzhang
cixzhang force-pushed the fix/swizzle-owner-modules branch from 46009de to c035bc9 Compare November 5, 2026 14:59
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 5, 2026
@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec c035bc9

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 5, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet because the pull request is a draft, and it runs once the pull request is marked ready for review.

The owner-module copy matches the spec:AST-110 changes an engineering owner approved for this head: the new tests fail on main and pass here, and every owner-module import in the nine affected copies resolves to a file the run wrote.

  • Optional: swizzle()'s doc (packages/cli/api/swizzle/swizzle.doc.mjs) still says escaping imports are rewritten to package subpaths; one clause on the carried owner modules would match the updated receipt description.

A new commit needs a fresh /approve-spec for its head.

[Automated review]

@cixzhang
cixzhang marked this pull request as ready for review November 5, 2026 15:22
@cixzhang
cixzhang merged commit 87ed8d0 into main Nov 5, 2026
107 checks passed
cixzhang added a commit to jiunshinn/astryx that referenced this pull request Nov 6, 2026
Rebuilds the recursive copy on main's swizzle, which since meta#10085 also
carries the private attribute owner modules a component imports.

- A Core component's nested folders are copied (Table's plugins/), and an
  integration's folder stays flat. One sorted file list drives the
  pre-flight, the copy and the receipt; the owner-module walk reads each
  nested file from its own folder.
- Imports that stay inside the component (../types from plugins/) stay
  relative; imports that leave it are rewritten to the owner package.
- __tests__ and __snapshots__ folders and *.spec.ts(x) browser harnesses
  are left out at every depth (Markdown's headingLinks chromium spec).
- Destination symlinks follow spec:AST-017 FR1/FR5: a folder linked
  elsewhere inside the project is written through, as released; a link out
  of the project is still refused by the existing confinement check. The
  blanket refusal of every destination symlink is dropped.
- A destination held by the wrong kind of entry is refused before any
  write, even with --overwrite; a failed copy removes the folders it made.
- The rewriteImports depth parameter is not carried: main's keep predicate
  covers it, and the copy tests check the depth behaviour end to end.
@github-actions
github-actions Bot deleted the fix/swizzle-owner-modules branch November 6, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — c035bc94 Deployed Nov 5, 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant