Repository navigation
fix(cli): swizzle copies the module graph a component reaches - #10197
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
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 rewritesutils/a.v1.0.0.tsto importh.v1.0.0-2, so Card's copy silently drops the edit. _moduleGraph.mjscaches file contents and resolutions at module scope with no invalidation, so a process that callsswizzle()again after Core changes copies the old source._moduleGraph.mjsre-implements the package's export readers (moduleExportOriginandfollowedExportNames,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]
There was a problem hiding this comment.
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:265and:509, andsubpathCoveringModulefor namespace imports); choose public paths for value specifiers from the value-only read and add the case tocopy.test.mjs. - Miss: the changeset, both swizzle docs and the
overwriteJSDoc say a helper an earlier swizzle wrote is never replaced, but a changed private attribute owner module is refused without--overwriteand replaced with it (copy.test.mjs:246-258); add that exception, asspec:AST-110FR2 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]
There was a problem hiding this comment.
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) andpackages/cli/api/swizzle/copy/copy.mjs(lines 4-6 and 218) still describe the removedrewriteImportsbehavior.
[Automated review]
There was a problem hiding this comment.
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:88still 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 inswizzle.routing.test.mjs:417need to describe the new copy.
The header comments flagged last time are fixed.
[Automated review]
There was a problem hiding this comment.
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]
|
/approve-spec b2f9eea (Posted by Cindy's agent under her standing approval for AST-110 swizzle PRs.) |
|
/approve-spec b2f9eea |
There was a problem hiding this comment.
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
--overwritedocs (bothswizzle.doc.mjsfiles andswizzle.type.mjs) say a helper an earlier swizzle wrote is never replaced, even with--overwrite, butastryx swizzle InputGroup -fafterastryx swizzle Buttonreplaces an editedInputGroup/groupStyles.tsthat 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]
There was a problem hiding this comment.
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]
|
/approve-spec 1230e99 |
There was a problem hiding this comment.
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/helperpoints atcomponents/lib/in the product and nothing is carried, becausecopy.mjs:333-335takes the folder above the component as the source root and_moduleGraph.mjs:474-484leaves 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]
ea0a53c to
072c2ec
Compare
There was a problem hiding this comment.
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]
|
/approve-spec 072c2ec |
There was a problem hiding this comment.
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
exportsuses a./*pattern or a plain-string target (for example{"./*": {"source": "./components/*/index.ts"}}),publicSurfaceOfin_moduleGraph.mjsignores 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 asmaindid, againstspec:AST-110FR2'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]
There was a problem hiding this comment.
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
exportsis a single condition object ({"source": "./components/index.ts", "default": "./dist/index.js"}) or blocks a subpath withnullbeside a./*pattern,exportedSourceFilesin_moduleGraph.mjsstill reads those keys as public subpaths, so the copy writes imports the package refuses, such as@test/meta/urceor@test/meta/Secret, where the previous revision copied those modules. exportTargetOfand the subpath handling inexportedSourceFilesrepeat theexportsreaders infoundation/discovery/package-exports.mjsandfoundation/integrations/exports-subpaths.mjswith 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]
There was a problem hiding this comment.
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
wildcardSubpathsinpackages/cli/api/swizzle/_moduleGraph.mjscollects a*key's targets with its owncollectwalk, which repeatsallTargetsfromfoundation/integrations/exports-subpaths.mjs(already imported there forsubpathDeclaration), so callallTargets(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]
There was a problem hiding this comment.
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.tsbecause@astryxdesign/core/i18nexports that same context through the alias atpackages/core/src/i18n/publicContext.ts:29, which the declaration match inpackages/cli/api/swizzle/_moduleGraph.mjs:432-437does not follow, so a copied Button shows "Loading" under the app'sfr-FRprovider where the package shows "Chargement"; resolve anexport const X = Yalias of an imported binding toY's origin when building the public surface, and add a copy test that a Button copy holds noi18n/InternationalizationContext.ts.
Non-blocking: exportedSourceFiles (_moduleGraph.mjs:248-251) can use isRecord from exports-subpaths.mjs instead of its own record check.
[Automated review]
…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
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.
0f56dfe to
01c73ab
Compare
…nstead of skipping to the aliased module
There was a problem hiding this comment.
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]
| const exported = /** @type {{name: string}} */ ( | ||
| publicOptions.find(o => o.subpath === chosen) | ||
| ).name; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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).
|
/approve-spec d1b5f75 |
There was a problem hiding this comment.
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 plainDateFromISOwhere the source wroteplainDateFromISO(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:646reads 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]
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/InputGroupInternalContextbecomes@astryxdesign/core/InputGroup), and that entry does not export the internal helpers the component uses. SoButton,Dialog,Table,TextInputand 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 importsvitest).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
swizzleoffers (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:Problem and solution fit
../X/anythingto the publicXentry, assuming every folder entry re-exports everything in the folder. Folder entries export only public API, by design.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
exportsmap 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-110FR1 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'sexportslists 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--overwriteand 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 perarchitecture:cli-surfaceINV21): plans the copy. It reads the owner'sexportswithsourceExportTargetandsubpathDeclaration, 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:moduleExportOriginandfollowedExportNamestake{types: true}to follow type-only exports too, andmoduleExportOriginsgives every origin of a module in one pass (tested to agree withmoduleExportOriginname by name). Existing callers are unchanged.api/swizzle/copy/copy.mjs: plans throughsrc/when the package has one around the component, else through the whole package (an integration whosecomponents/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 readssource, plain-string,importanddefaulttargets 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.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
copy.test.mjsfail on main (4 of 5; see the first commit): Button's copy has noInputGroupInternalContextand TypeScript reports the missing export; Table's copy has noplugins/; Badge's copy hasBadge.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'sutils/a.v1.0.0.ts.@astryxdesign/corethrough itsexports, reports no unresolved module or missing export in the Button and Dialog copies.IconButton) copies exactly its own files.Scope
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.mjspnpm -F @astryxdesign/cli typecheck:strict,node scripts/check-cli-structure.mjs@astryxdesign/buildapp from the main canary packages, thentsc --noEmit,vite build, and a headless Chrome render beside the package component.CLI owner review requested.