Skip to content

fix(cli): swizzle copies the module graph a component reaches - #10197

Merged
cixzhang merged 6 commits into
mainfrom
fix/swizzle-module-graph
Nov 7, 2026
Merged

cixzhang merged 6 commits into
mainfrom
fix/swizzle-module-graph

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A product engineer runs astryx swizzle <Name> to own a component's source. Today about two thirds of the copies do not build. The copy sends every import that leaves the component folder to the package's folder entry (../InputGroup/InputGroupInternalContext becomes @astryxdesign/core/InputGroup), and that entry does not export the internal helpers the component uses. So Button, Dialog, Table, TextInput and most other copies stop at "has no exported member" or "Missing specifier" before the engineer has changed a line. Copies also leave out nested folders (Table/plugins, Markdown/plugins, Calendar/hooks) and bring along files that do not run (Badge.test-violations.tsx, a Field test harness that imports vitest).

After this change the copy imports what the package exports from the package, and carries every internal module it needs beside it, in the package's folder layout. Measured on every target swizzle offers (Core's list plus every Lab, Charts, RichText and Vega component through --package, 162 in all), ejected into a fresh Vite + StyleX app with only the published packages:

main this PR
imports that point at no file or at a path the package does not export 57 targets 0
files copied that do not run 2 targets 0
copies that type-check 51 96

Problem and solution fit

  • Why does the copy fail? The rewrite collapses ../X/anything to the public X entry, assuming every folder entry re-exports everything in the folder. Folder entries export only public API, by design.
  • Why does that harm the task? Swizzle's only value is a copy the engineer can edit; one that does not build sends them back to reconstruct Core's internals by hand.
  • Why does that matter? Making the helpers public to fix this would turn internal modules into public API. The record that governs swizzle already decided the copy carries them instead.

The fix follows the component's module graph from its entry. For each name taken from outside the folder it asks whether the package exports that same definition from a public path (following the package's exports map and its barrels), as a value when the import takes a value (a type-only re-export is erased at runtime). If yes, the copy imports it from there; StyleX modules only by their own exported path, because the StyleX compiler resolves styles from the real module. If not, the copy carries the module that defines the name and imports it by relative path. Tests, stories and docs are never reached, so they are never copied.

Expected behavior and authority

spec:AST-110 FR1 and FR2 (docs/specs/AST-110-swizzle-output/spec.md, approved): the output type-checks and bundles with no edits, imports only paths the owner's exports lists and never ./internal/*, carries every module not reachable through a public export in its folder layout, copies nested folders, holds only source the component runs, reuses an identical existing helper and never overwrites a different one (even with --overwrite), writing the new one under a version-suffixed name that only the new copy imports. FR4's owner-module rules are unchanged: a changed owner module, or a style module it imports, is refused without --overwrite and replaced with it.

This also delivers the nested-folder copy asked for in #3506 and proposed in #5101 by @jiunshinn, whose work this supersedes; credited in the changeset and the commit.

Smallest restoration

  • api/swizzle/_moduleGraph.mjs (new, an adapter helper per architecture:cli-surface INV21): plans the copy. It reads the owner's exports with sourceExportTarget and subpathDeclaration, and where each name is declared with the discovery module's export reader. Every read is cached for one copy only.
  • foundation/discovery/module-exports.mjs: moduleExportOrigin and followedExportNames take {types: true} to follow type-only exports too, and moduleExportOrigins gives every origin of a module in one pass (tested to agree with moduleExportOrigin name by name). Existing callers are unchanged.
  • api/swizzle/copy/copy.mjs: plans through src/ when the package has one around the component, else through the whole package (an integration whose components/ folder imports ../../lib/x); writes the planned files, a carried module above the component layout going under the output folder by its path in the package (under a folder named after the package when that path is already a layout destination); an asset the package exports by its own path is imported from the package wherever it sits; the public surface reads source, plain-string, import and default targets and expands ./* patterns; component files first, then helpers; identical helpers reused; a helper that must move tries the next version-suffixed name until no existing file differs, re-checking every helper whose import moved; owner modules keep their FR4 refusal.
  • rewriteImports (internal, not exported from @astryxdesign/cli/api) is removed with its unit tests; the behavior tests replace them.
  • Not in this PR, each its own PR: shared state across copy and package (FR3), theme layer placement (FR5), reporting npm dependencies and Node/private types (FR1), and the non-components in swizzle --list. The receipt field that says whether each helper was written, reused or suffixed is left to the CLI owner, as the spec records.

Evidence

  • Reproduction before the change: the new tests in copy.test.mjs fail on main (4 of 5; see the first commit): Button's copy has no InputGroupInternalContext and TypeScript reports the missing export; Table's copy has no plugins/; Badge's copy has Badge.test-violations.tsx; the reuse case has no helper to reuse. The three-copy helper test (Button, Card, Dialog with edited helpers) fails on the previous head of this PR: Dialog rewrote Card's utils/a.v1.0.0.ts.
  • Result after the change: all pass. TypeScript, resolving @astryxdesign/core through its exports, reports no unresolved module or missing export in the Button and Dialog copies.
  • Representative unchanged path: the FR4 owner-module tests, path safety, overwrite refusal, rollback on a failed write, and integration routing all pass; a component with no internal imports (IconButton) copies exactly its own files.
  • Regression test or other mutation-sensitive proof: the TypeScript check is independent of the copy logic; collapsing an import back to the folder entry fails it.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm exec vitest run --project node packages/cli/api/swizzle packages/cli/foundation/discovery packages/cli/clients/cli/commands/swizzle.routing.test.mjs packages/cli/clients/cli/commands/write-failure.test.mjs packages/cli/clients/cli/commands/swizzle.path-safety.test.mjs packages/cli/clients/cli/commands/text-json-parity.test.mjs
  • pnpm -F @astryxdesign/cli typecheck:strict, node scripts/check-cli-structure.mjs
  • Packed-consumer sweep: every offered target ejected into a fresh Vite 8 + @astryxdesign/build app from the main canary packages, then tsc --noEmit, vite build, and a headless Chrome render beside the package component.

CLI owner review requested.

@vercel

vercel Bot commented Nov 6, 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 7, 2026 8:27am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 6, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 6, 2026
@astracat-bot

astracat-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 7, 2026, 9:36 AM UTC

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · d1b5f75

Storybook · Sandbox · built from this PR's head

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

API changes: none in this pull request

Committed API report behind this build: cli 19 rows, core 25 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

@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.

Approval waits on an engineering owner's spec decision, and four fixes are needed either way.

The new swizzle output (public-path imports, carried helpers, nested folders, and version-suffixed helpers that --overwrite no longer replaces) is governed only by spec:AST-110 FR1 and FR2, which is still authority: draft on main. An engineering owner records approval of these output rules for this head by commenting /approve-spec a07ac80fd00c15ec925cab87efe6603f695a4d54 on this pull request, or makes the record current first; the author may do this as an engineering owner.

Blocking findings:

  • A third swizzle overwrites a version-suffixed helper that an earlier copy imports (packages/cli/api/swizzle/copy/copy.mjs:410-418): with edited helpers, swizzling Button, Card and then Dialog rewrites utils/a.v1.0.0.ts to import h.v1.0.0-2, so Card's copy silently drops the edit.
  • _moduleGraph.mjs caches file contents and resolutions at module scope with no invalidation, so a process that calls swizzle() again after Core changes copies the old source.
  • _moduleGraph.mjs re-implements the package's export readers (moduleExportOrigin and followedExportNames, sourceExportTarget, subpathDeclaration) instead of extending them, for example with type-only exports, so the two readers can drift.
  • The changeset and both swizzle docs say every copy builds with no edits, but the description's own sweep has 96 of 162 copies type-checking; say instead that every import names a file the copy holds or a path the owner package exports.

[Automated review]

Comment thread packages/cli/api/swizzle/copy/copy.mjs Resolved

@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.

Approval waits on an engineering owner's spec decision, and two fixes are needed either way.

The new swizzle output (public-path imports, carried helpers, nested folders, and version-suffixed helpers that --overwrite no longer replaces) is governed only by spec:AST-110 FR1 and FR2, which is still authority: draft on main. An engineering owner records that decision by commenting /approve-spec b2605a02f443468b0a3770fabbc107d2b660a009 on this pull request (the author may do so as an engineering owner), or by making spec:AST-110 current first.

Blocking findings:

  • Miss: a value import can be rewritten onto a public subpath that exports the name only as a type, so the copy imports an erased export (packages/cli/api/swizzle/_moduleGraph.mjs:265 and :509, and subpathCoveringModule for namespace imports); choose public paths for value specifiers from the value-only read and add the case to copy.test.mjs.
  • Miss: the changeset, both swizzle docs and the overwrite JSDoc say a helper an earlier swizzle wrote is never replaced, but a changed private attribute owner module is refused without --overwrite and replaced with it (copy.test.mjs:246-258); add that exception, as spec:AST-110 FR2 states.

The four earlier findings are fixed on this head: the repeated suffix choice, per-copy caches, the shared export readers, and the changeset wording.

[Automated review]

@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.

Approval waits on an engineering owner's spec decision; no blocking code finding remains.

The new swizzle output (public-path imports, carried helpers, nested folders, and version-suffixed helpers that --overwrite no longer replaces) is governed only by spec:AST-110 FR1 and FR2, which is still authority: draft on main. An engineering owner records that decision by commenting /approve-spec 101d9c31646c834a8595b7252205a1869d3c2678 on this pull request (the author may do so as an engineering owner), or by making spec:AST-110 current first.

Both earlier findings are fixed on this head: a value import now takes only a subpath that exports the name as a value, with a test that covers it, and the changeset and docs now state the owner-module exception to --overwrite.

  • Non-blocking: the header comments in packages/cli/api/swizzle/swizzle.mjs (lines 12-15) and packages/cli/api/swizzle/copy/copy.mjs (lines 4-6 and 218) still describe the removed rewriteImports behavior.

[Automated review]

@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.

Approval waits on an engineering owner's spec decision, and one fix is needed either way.

The new swizzle output (public-path imports, carried helpers, nested folders, and version-suffixed helpers that --overwrite no longer replaces) is governed only by spec:AST-110 FR1 and FR2, which is still authority: draft on main. An engineering owner records that decision by commenting /approve-spec 525e36c1be043aba9dc256e9a42013babe09868c on this pull request (the author may do so as an engineering owner), or by making spec:AST-110 current first.

  • Miss: after every copy, packages/cli/clients/cli/commands/swizzle.mjs:88 still prints "Relative imports have been rewritten to use @astryxdesign/core." although the copy now keeps relative imports of the internal modules it carries (nine in Button alone), so that text, the "Shared modules" line below it, the file's header comment and the expected string in swizzle.routing.test.mjs:417 need to describe the new copy.

The header comments flagged last time are fixed.

[Automated review]

@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.

Approval waits on an engineering owner's spec decision; no code fix is needed.

The new swizzle output (public-path imports, carried helpers, nested folders, and version-suffixed helpers that --overwrite no longer replaces) is governed only by spec:AST-110 FR1 and FR2, which is still authority: draft on main. An engineering owner records that decision by commenting /approve-spec b2f9eea4e4b3cbc35f66704aa4f676e05c6a1b52 on this pull request (the author may do so as an engineering owner), or by making spec:AST-110 current first.

The printed result flagged last time now describes the new copy.

[Automated review]

@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec b2f9eea

(Posted by Cindy's agent under her standing approval for AST-110 swizzle PRs.)

@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec b2f9eea
Decision: D-20261106-257

@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 for one wording fix. The new swizzle output is spec-approved for this head, and every Core, Lab, Charts, RichText and Vega copy now resolves every import.

  • Miss: the changeset and the --overwrite docs (both swizzle.doc.mjs files and swizzle.type.mjs) say a helper an earlier swizzle wrote is never replaced, even with --overwrite, but astryx swizzle InputGroup -f after astryx swizzle Button replaces an edited InputGroup/groupStyles.ts that Button's copy still imports, so narrow those sentences to copies that carry the helper or keep edited helpers in that case too.

[Automated review]

@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.

Approval waits on an engineering owner's spec decision for this head; the --overwrite wording flagged last time now matches what the command does.

The swizzle output (public-path imports, carried helpers, nested folders, and version-suffixed helpers, including that swizzling a helper's own component replaces it with --overwrite) is governed only by spec:AST-110 FR1 and FR2, which is still authority: draft on main, and the earlier /approve-spec named the previous commit. An engineering owner records the decision by commenting /approve-spec 1230e9912b7f2f15d0878783bbcb96aebdc3bd46 on this pull request (the author may do so as an engineering owner), or by making spec:AST-110 current first.

[Automated review]

@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 1230e99
Decision: D-20261106-301

@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 for one fix. The swizzle output is spec-approved for this head, and every Core copy now resolves every import.

  • Miss: an integration whose component folders sit under a root components/ directory gets a copy whose imports of modules beside that directory stay as written, so ../../lib/helper points at components/lib/ in the product and nothing is carried, because copy.mjs:333-335 takes the folder above the component as the source root and _moduleGraph.mjs:474-484 leaves every module outside it alone; plan those modules the way in-source ones are planned (public subpath or carried) and add a routing case for that layout.

[Automated review]

Comment thread packages/cli/api/swizzle/copy/copy.mjs Resolved

@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.

Approval waits on an engineering owner's spec decision for this head; no code change is required.

The swizzle output rules come from spec:AST-110 FR1 and FR2, which are still draft on main, and the earlier /approve-spec named an earlier head. An engineering owner records the decision by commenting /approve-spec 072c2ec6e0a15b3d4d22d4e0515cf52d75fd9e96 on this pull request (the author may do so as an engineering owner), or by making the record current on main. What needs settling: names the owner package exports are imported from its public subpaths, every other module the component reaches is copied in the package's folder layout (nested folders included, tests, stories and docs left out), and an existing helper is reused when identical or left in place beside a version-suffixed copy.

The size and the two duplicated helpers from the last review are fixed, and every Core copy now resolves every import.

Smaller: two root modules can still land on one file when an integration has a top-level folder named after itself; see the inline comment on copy.mjs.

[Automated review]

Comment thread packages/cli/api/swizzle/copy/copy.mjs Resolved
@cixzhang

cixzhang commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 072c2ec
Decision: D-20261107-072

@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 for one fix. The swizzle output is spec-approved for this head, every Core copy now resolves each import inside the copy or to a path Core exports, and CI is green.

Blocking

  • Miss: when an integration's exports uses a ./* pattern or a plain-string target (for example {"./*": {"source": "./components/*/index.ts"}}), publicSurfaceOf in _moduleGraph.mjs ignores those entries, so swizzling one of its components copies the integration's other public components (../Bar/Bar.tsx) instead of importing them from the package as main did, against spec:AST-110 FR2's "A symbol the owner package exports publicly is imported from that public path".

Non-blocking

  • Two root modules can still land on one file under a folder named after the package (see the earlier inline comment on copy.mjs).

Reading wildcard and plain-string entries into the public surface, with a routing test for each shape, resolves the blocking item.

[Automated review]

@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.

Approval waits on an engineering owner's spec decision for this head; the ./* and plain-string fix from the last review is in, and two new fixes are needed either way.

The swizzle output rules come from spec:AST-110 FR1 and FR2, which are still draft on main, and the latest /approve-spec named the previous head. An engineering owner records the decision by commenting /approve-spec 3ed6a592495746f97392ae78ab51996bbd383670 on this pull request (the author may do so as an engineering owner), or by making the record current on main. What needs settling: names the owner package exports are imported from its public subpaths (now including ./* patterns and plain-string, import and default targets), every other module the component reaches is copied in the package's folder layout, and an existing helper is reused when identical or left in place beside a version-suffixed copy.

Blocking

  • When an integration's exports is a single condition object ({"source": "./components/index.ts", "default": "./dist/index.js"}) or blocks a subpath with null beside a ./* pattern, exportedSourceFiles in _moduleGraph.mjs still reads those keys as public subpaths, so the copy writes imports the package refuses, such as @test/meta/urce or @test/meta/Secret, where the previous revision copied those modules.
  • exportTargetOf and the subpath handling in exportedSourceFiles repeat the exports readers in foundation/discovery/package-exports.mjs and foundation/integrations/exports-subpaths.mjs with different rules, so a target with * twice ({"./*": "./components/*/*.tsx"}) or a fallback array still gets the integration's public component copied instead of imported; confirm each candidate subpath through those shared readers, add routing cases for these shapes, and delete the local reader.

[Automated review]

@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.

Approval waits on an engineering owner's spec decision for this head; both exports fixes from the last review are in, and one small fix is needed either way.

The swizzle output rules come from spec:AST-110 FR1 and FR2, which are still draft on main, so an engineering owner records the decision by commenting /approve-spec 20ee33e191a5cb2c1277a0d6a2b6a994b2bf124a on this pull request (the author may do so as an engineering owner) or by making the record current on main. What needs settling: names the owner package exports are imported from its public subpaths as the shared exports readers confirm them, every other module the component reaches is copied in the package's folder layout, and an existing helper is reused when identical or left in place beside a version-suffixed copy.

Blocking

  • wildcardSubpaths in packages/cli/api/swizzle/_moduleGraph.mjs collects a * key's targets with its own collect walk, which repeats allTargets from foundation/integrations/exports-subpaths.mjs (already imported there for subpathDeclaration), so call allTargets(value) and delete the copy.

Non-blocking: the "single condition object" routing case catches the @test/meta/urce regression only if its fixture root exports Bar (expecting from '@test/meta').

[Automated review]

@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.

Approval waits on an engineering owner's spec decision for this head, and one fix is needed either way.

The copy rules this pull request implements come from spec:AST-110 FR1 and FR2, which are still draft on main, and the latest /approve-spec names an earlier head. An engineering owner records the decision by commenting /approve-spec 0f56dfee1df37fab91a86a9fef28af3cefdd60dc on this pull request (the author may do so as an engineering owner), or spec:AST-110 is made current on main.

Blocking:

  • Miss: 62 Core copies (Button, Dialog, Table, DateInput, PowerSearch and others) carry their own i18n/InternationalizationContext.ts because @astryxdesign/core/i18n exports that same context through the alias at packages/core/src/i18n/publicContext.ts:29, which the declaration match in packages/cli/api/swizzle/_moduleGraph.mjs:432-437 does not follow, so a copied Button shows "Loading" under the app's fr-FR provider where the package shows "Chargement"; resolve an export const X = Y alias of an imported binding to Y's origin when building the public surface, and add a copy test that a Button copy holds no i18n/InternationalizationContext.ts.

Non-blocking: exportedSourceFiles (_moduleGraph.mjs:248-251) can use isRecord from exports-subpaths.mjs instead of its own record check.

[Automated review]

cixzhang added a commit that referenced this pull request Nov 7, 2026
…10471)

* test(cli): the export reader follows an alias of an imported binding (red)

* fix(cli): the export reader follows `export const X = Y` to Y's origin

An exported const whose value is another binding is that binding: an
alias of an imported value (Core's public i18n context re-exports the
provider's context this way) now has the imported value's origin in
moduleExportOrigin and moduleExportOrigins alike.

* docs(changeset): name the icon-set effects of following export aliases

* docs(changeset): drop the swizzle sentence; #10197 describes that effect
cixzhang and others added 5 commits November 7, 2026 00:11
A swizzled component imports what its owner package exports from the
package's public paths (values only from value exports; a StyleX module
by its own exported path), and carries every other module it reaches
beside it in the package's folder layout, nested folders included, with
no tests, stories or docs. An identical existing helper is reused; a
different one is never overwritten, and the copy writes its own under a
version-suffixed name. Private attribute owner modules keep their
refuse-or-replace rule. For an integration without src/, modules beside
its components folder are planned too, and never share a file with a
module in the layout; an asset the package exports stays a package
import.

Co-authored-by: jiunshinn <[email protected]>
… public surface

An owner whose exports map components through a `./*` pattern, or names
a subpath with a plain string, import or default target, now has those
subpaths in the public surface, so a copy imports the owner's other
public components from the package instead of copying them. Root
modules of an integration also take distinct destinations among
themselves.
…ort readers

The public surface is built from candidate subpaths (each key, and each
file a `*` key's target patterns match) that the shared package-exports
readers confirm: a single condition object exports only `.`, a `null`
entry blocks its subpath, fallback arrays and repeated `*` resolve as
Node resolves them. The local exports reader is gone.
@cixzhang
cixzhang force-pushed the fix/swizzle-module-graph branch from 0f56dfe to 01c73ab Compare November 7, 2026 08:14

@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.

Approval waits on an engineering owner's spec decision for this head; no code fix is required.

The copy rules this pull request implements come from spec:AST-110 FR1 and FR2, which are still draft on main, and the latest /approve-spec names an earlier head. An engineering owner records the decision by commenting /approve-spec d1b5f7535e6525c5436f9c8000e3bef920733d61 on this pull request (the author may do so as an engineering owner), or spec:AST-110 is made current on main.

The earlier blocker is fixed (no Core copy carries its own i18n/InternationalizationContext.ts any more), and two non-blocking suggestions are inline.

[Automated review]

Comment on lines +633 to +635
const exported = /** @type {{name: string}} */ (
publicOptions.find(o => o.subpath === chosen)
).name;

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.

Non-blocking. Miss: this takes the first public export of the chosen subpath, whatever its name. @astryxdesign/core/utils exports plainDateFromISO and also parseISO (utils/dateParser.ts:18), so the Calendar, DateInput, DateRangeInput, DateTimeInput and PowerSearch copies write import {parseISO as plainDateFromISO} from '@astryxdesign/core/utils' where the source wrote plainDateFromISO; with the export reader following export const X = Y, every public alias of one binding can stand in the same way. Prefer the entry with the imported name:

publicOptions.find(o => o.subpath === chosen && o.name === spec.imported) ??
  publicOptions.find(o => o.subpath === chosen)

With that change only those five copies differ, each keeping its source's name, and the swizzle tests pass.

origin &&
origin.file !== target &&
inSource(origin.file) &&
!parseModule(target).declares.has(spec.imported)

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.

Non-blocking: this guard has to match the rule in foundation/discovery/module-exports.mjs, where exportOrigin applies declaredOrigin only to a name declarationExports finds (:1216-1228). The planner reads declarations on its own (:94-98) and parses the target again for each name. They agree today, but if the shared reader starts following another alias shape, this guard falls out of step. An exported declaresExport(file, name) beside declaredOrigin, called here, keeps one definition and drops the second parse (moduleExportSource is not that predicate: it also counts an imported-then-exported name, and swapping it in changes 27 Core copies).

@cixzhang

cixzhang commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec d1b5f75

@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. The swizzle copy rules are approved for this head by an engineering owner, every Core component's copy now resolves each import inside the copy or to a path @astryxdesign/core exports, and CI is green.

Two optional follow-ups, neither blocking:

  • When one public subpath exports a binding under two names, the copy can import the other name: the Calendar, DateInput, DateRangeInput, DateTimeInput and PowerSearch copies write parseISO as plainDateFromISO where the source wrote plainDateFromISO (packages/cli/api/swizzle/_moduleGraph.mjs:633-635), so preferring the entry whose name matches the import keeps the source's names.
  • The alias guard at _moduleGraph.mjs:646 reads export declarations itself and parses the target again, so an exported predicate beside the shared export reader's alias rule would keep one definition.

[Automated review]

@cixzhang
cixzhang merged commit 3c69236 into main Nov 7, 2026
108 of 111 checks passed
@github-actions
github-actions Bot deleted the fix/swizzle-module-graph branch November 8, 2026 06:03

This branch was successfully deployed

1 active deployment
Preview — d1b5f753 Deployed Nov 7, 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