Repository navigation
fix(cli): mark icon-set generated calls pure so apps drop unused icons - #12441
josephfarina wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
The generated icons module writes each adapter call and theme-map element with /* @__PURE__ */, and reads modules with or without the mark the same.
8732528 to
eebd5a7
Compare
There was a problem hiding this comment.
Changes requested. The pure marks work and shrink app bundles, but two fixes are needed before approval.
- The changeset says an earlier CLI only fails
integration checkon a marked set, but an earlier CLI'sexperimental icon addandmapwrite a generated module without its adapter import (importing the set then throwsadaptIcon is not defined) and itsnew-set --fromrefuses withERR_FILE_EXISTS, so the changeset and description should tell set authors to author, not only check, with this release or later. normalizedStatementstrips every pure mark butwrittenStatementrestores it only on adapter exports, so a statement added by hand, such asexport const BrandIcon = /* @__PURE__ */ makeBrand('brand');, loses its mark on the nextadd,mapor refresh, where it kept it before; keep each statement's mark when it is written back and add that case to the new test.
Consider warning when the set package's @astryxdesign/cli range admits an earlier CLI, as experimental icon use already does for experimental.iconVariant. The guide could also say that an adapter must only build the component, since the mark lets a bundler drop its call.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Claim: the generated module marks each adapter call and theme-map element. Verified (
icon-set-writer.mjs:1816,:1845; new writer test). - Claim: a bundler then drops the icons an app does not use; before, it kept the theme map and every adapted icon. Verified: a bundle of an app that imports one icon keeps both adapted icons before the change and drops them after.
- Claim: modules without marks, or with the
/*#__PURE__*/spelling, read the same. Verified (icon-set-writer.mjs:1404; newit.eachcases). - Claim: the next
add,mapor refresh adds the marks and changes nothing else. False for a statement added by hand that carries a mark. - Claim: apps on an earlier CLI are unaffected (template copies, search, doctor). Not contradicted: those paths read modules as syntax trees.
- Claim: only an earlier CLI's
integration checkfails. False: itsaddandmapwrite a module that throws on import, and its refresh refuses. - Claim: the declaration file is unchanged and has no marks. Verified (new writer test;
integration checkpasses on a set this release wrote). - Claim: spreading
themeIconsdraws every entry with identical markup. Verified: the mark is a comment. - Claim: bundles are about two and about ten times smaller. Not re-measured; the mechanism is verified.
- Claim: no new public API and no spec change, under the icon-set spec's rule that a module is read however it is formatted. Verified.
- File
.changeset/icon-set-pure-calls.md: both findings above. - File
packages/cli/foundation/discovery/icon-set-writer.mjs: the hand-added mark finding. - File
packages/cli/foundation/discovery/icon-set-writer.test.mjs: clear; add the hand-statement case. - File
packages/cli/assets/docs/tree/icon-sets.doc.mjs: clear; it matches whataddwrites (see the adapter note above). - File
packages/cli/api/icon/look-theme-maps.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-authoring.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-library-looks.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-look-packages.test.mjs: clear.
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Changes requested. The code is ready: hand-written pure marks now survive a rewrite, the changeset warns set authors about earlier CLIs, and the guide states the adapter contract. One fix is left, in the pull request description:
- The Testing section still says that only an earlier CLI's
integration checkfails on a marked set and that set authors need only check with this release, but an earlier CLI'sexperimental icon addandmapwrite the module without its adapter import (so importing the set throwsadaptIcon is not defined) and itsnew-set --fromrefuses, as the changeset now says; please replace those two sentences with the changeset's wording.
Claims and files checked
Review mode: incremental; reason: none
- changed rules (0): none
- Changeset: each adapter call and theme-map element is marked. Verified (
icon-set-writer.mjs:1588-1589,:1862; writer test). - Changeset: a bundler then drops unused icons, where before it kept the theme map and every adapted icon. Verified (a minified bundle of an app that imports one icon: 284 bytes before, 92 after).
- Changeset: modules without marks or with the other spelling read the same, and the next
add,mapor refresh adds the marks and changes nothing else. Verified (writer tests; the declaration file is unchanged). - Changeset: a mark written by hand is kept. Verified (the new tests fail on the previous revision and pass here).
- Changeset: an earlier CLI's
addandmapdrop the adapter import, itsnew-set --fromrefuses, and itsintegration checkreports a types mismatch. Verified (the earlier writer's code and an end-to-end run). - Changeset: apps that only use a marked set with an earlier CLI are unaffected. Verified (template copies, icon search and doctor read only import and re-export lines, which carry no mark).
- Description: unmarked top-level calls keep every adapted icon and the theme map in an app bundle. Verified (same bundle run).
- Description: bundles about two and ten times smaller on real libraries. Not re-measured; the mechanism is verified.
- Description: the result costs the same as importing the icons directly. Verified up to the external React import the bundler keeps, which a React icon library carries too.
- Description: the marks are true because the calls only build elements and components. Verified for
createElement; for the adapter it holds when the adapter has no other effect, which the guide now requires. - Description: marks are dropped when a statement is read and added back when the module is written, under the icon-set spec's formatter rule, with no record change. Verified.
- Description: the guide's sample line and the pinned test text show the mark. Verified.
- Description: spreading the theme map draws every entry with identical markup. Verified: the mark is a comment.
- Description: the regression tests cover marked calls, three restyled modules and an unmarked declaration file. Verified (the tests pass).
- Description: template copies are unchanged with four real sets, and a second refresh changes nothing. Not re-run (the sets are not in the repository); idempotence is verified by tests.
- Description: the full CLI suite and four regenerated sets pass. Not re-run as stated; the 61 icon-related CLI test files pass.
- Description: in an app on CLI 0.7.14 or 0.7.16, doctor, template copies and icon search work as before. Not re-run on those versions; consistent with the earlier code.
- Description: no new public API and no internal context. Verified.
- Description: only an earlier CLI's
integration checkfails in the set's own package. False (see above). - Description: set authors need only check with this release, as the changeset says. False: the changeset says author and check.
- File
.changeset/icon-set-pure-calls.md: clear. - File
packages/cli/foundation/discovery/icon-set-writer.mjs: clear. - File
packages/cli/foundation/discovery/icon-set-writer.test.mjs: clear. - File
packages/cli/assets/docs/tree/icon-sets.doc.mjs: clear. - File
packages/cli/api/icon/look-theme-maps.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-authoring.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-library-looks.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-look-packages.test.mjs: clear.
There was a problem hiding this comment.
Changes requested. The code is ready, and the description now lists every earlier-CLI failure a set author meets. One claim about apps is still wrong:
- Miss: the changeset and the description say that apps using a marked set with an earlier CLI are unaffected and pass doctor, but that CLI's
astryx doctor integration validate <set package>exits 1 withicon_generated_types_mismatchfor an installed marked set that passes with this release (and its fix asks the app team to rewrite a file inside the installed package), so please say that an app running that check needs this release or later, and keep template copies, icon search and plainastryx doctoras the unaffected list.
Claims and files checked
Review mode: incremental; reason: none
- changed rules (0): none
- Changeset: each adapter call and theme-map element is marked. Verified (
icon-set-writer.mjs:1588-1589,:1862; writer test). - Changeset: a bundler then drops unused icons, where before one icon pulled in the theme map and every adapted icon. Verified (a minified bundle of an app that imports one icon: 284 bytes before, 92 after).
- Changeset: modules without marks or with the other spelling read the same. Verified (writer test).
- Changeset: the next
add,mapor refresh adds the marks, keeps hand-written ones and changes nothing else. Verified (writer tests and a rewrite run; a second rewrite changes nothing). - Changeset: set authors author and check with this release or later. Consistent with the earlier-CLI behaviour below.
- Changeset: an earlier CLI's
addandmapdrop the adapter import, itsnew-set --fromrefuses, and itsintegration checkreports a types mismatch. Verified for a set built with an adapter; an earlieraddof an adapted icon keeps the import, and in a component-library set an earlier refresh succeeds, so the list errs broad, never narrow. - Changeset: apps that only use a marked set with an earlier CLI are unaffected (template copies, icon search, doctor). False for
doctor integration validate <set package>; verified for template copies, icon search and plainastryx doctor. - Description: unmarked top-level calls keep every adapted icon and the theme map in an app bundle. Verified (same bundle run).
- Description: bundles about two and ten times larger on real libraries. Not re-measured; the mechanism is verified.
- Description: after the change, the cost matches importing the icons directly. Verified up to the external React import the bundler keeps.
- Description: the marks are true because the calls only build elements and components. Verified for
createElement; for the adapter when it has no other effect, which the guide now requires. - Description: marks are dropped when a statement is read and added back when the module is written, under the icon-set spec's formatter rule, with no record change. Verified.
- Description: the reader drops either spelling before it compares or types a statement, so older modules read the same and hand-written marks survive. Verified.
- Description: the guide's sample line shows the mark and states the adapter contract. Verified (
icon-sets.doc.mjs:244). - Description: tests that pinned the written text now expect the mark. Verified (five test files).
- Description: before the change a bundle holds every theme-map element and adapted icon; after it holds only the imported icons, and spreading the theme map still draws every entry. Verified (bundle runs; the mark is a comment).
- Description: a module written by the current CLI reads the same and rewrites with only the marks; the declaration file is unchanged. Verified (writer tests).
- Description: the regression tests cover marked calls, three restyled modules, hand-written marks and an unmarked declaration file. Verified (they pass).
- Description: template copies are unchanged with four real sets, and a second refresh changes nothing. Not re-run (the sets are not in the repository); idempotence is verified by tests.
- Description: the full CLI suite passes, the hand-mark tests fail without the fix, and four regenerated sets pass the strict check. Not re-run as stated; the 56 icon-related CLI test files pass.
- Description: older CLIs fail
add,map,new-set --fromandintegration checkin a marked set's package. Verified for a set built with an adapter, as above. - Description: apps on an earlier CLI pass doctor, copy templates and answer icon search as before. False for
doctor integration validate <set package>; the rest verified from the earlier code. - Description: no new public API and no internal context. Verified.
- File
.changeset/icon-set-pure-calls.md: the app claim above. - File
packages/cli/foundation/discovery/icon-set-writer.mjs: clear. - File
packages/cli/foundation/discovery/icon-set-writer.test.mjs: clear. - File
packages/cli/assets/docs/tree/icon-sets.doc.mjs: clear. - File
packages/cli/api/icon/look-theme-maps.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-authoring.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-library-looks.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-look-packages.test.mjs: clear.
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, because the CI run stopped at admission with "CI is full", so it needs a re-run before merge.
The changeset and the description now name every earlier-CLI command that misreads a marked set, including doctor integration validate <set package>, so the one finding from the last review is fixed. The marks work as described: on real heroicons artwork, an app drawing 25 icons through a set now bundles what importing them directly costs.
Claims and files checked
Review mode: incremental; reason: none
- changed rules (0): none
- Changeset: each adapter call and theme-map element is marked. Verified (
icon-set-writer.mjs:1586-1592,:1862; writer test). - Changeset: a bundler then drops unused icons, where before one icon pulled in the theme map and every adapted icon. Verified (bundles of the base and head modules).
- Changeset: modules without marks or with the other spelling read the same. Verified (writer test).
- Changeset: the next
add,mapor refresh adds the marks, keeps hand-written ones and changes nothing else. Verified (writer tests; a refresh of an older set changes only the marks, and a second refresh changes nothing). - Changeset: set authors author and check with this release or later. Consistent with the earlier-CLI behavior below.
- Changeset: an earlier CLI's
addandmapdrop the adapter import, itsnew-set --fromrefuses, and itsintegration checkanddoctor integration validatereport a types mismatch. Verified for a set built with an adapter; the list errs broad, never narrow. - Changeset: in an app on an earlier CLI, template copies, icon search and plain
doctorread a marked set as before, and validating the set package fails until the app upgrades. Verified (doctorexits 0 anddoctor integration validateexits 1 on the earlier CLI, both exit 0 on this release; template copies and icon search read only import and re-export lines). - Description: importing a few icons from a set bundled its theme map and, for an adapter set, every adapted icon. Verified.
- Description: that cost about twice the direct cost through a component-library set and about ten times through an adapter data set. Verified on heroicons artwork: 2.1 times, and 13 times minified (9 times gzip).
- Description: after the change both cost the same as importing directly. Verified, up to the React import the bundler keeps.
- Description: the cause is top-level calls a bundler cannot prove free of side effects. Verified.
- Description: the mark is true because the calls only build elements and components. Verified for
createElement; for the adapter when it only builds the component, which the guide now requires. - Description: the icon-set spec's formatter rule covers the change, the marks are dropped on read and added on write, and no record changes. Verified.
- Description: the reader drops either spelling before it compares or types a statement, so older modules read the same and the next write only adds the marks. Verified.
- Description: a hand-written mark is written back. Verified.
- Description: the guide's sample line shows the mark and the adapter contract. Verified (
icon-sets.doc.mjs:244). - Description: tests that pinned the written text expect the mark. Verified (five test files).
- Description: before the change a bundle holds every theme-map element and adapted icon. Verified.
- Description: after it the bundle holds only the imported icons at the direct size, and spreading the theme map still draws every entry. Verified.
- Description: a module the current CLI wrote reads the same and rewrites with only the marks; the declaration file is unchanged. Verified.
- Description: the regression tests cover marked calls, three restyled modules, hand-written marks and an unmarked declaration file. Verified (they pass).
- Description: template copies are unchanged with and without sets, a refresh adds only the marks, and a second refresh changes nothing. Verified on a probe set (132 sampled templates byte-identical; refresh run).
- Description: one defect, no new public API, default or interaction, and no internal context. Verified.
- Description: the full CLI suite passes. Verified as far as this environment allows: 1,230 of 1,235 files pass, and the three that fail need a git checkout,
/procor the system temp folder and fail the same way without this change. - Description: the two hand-mark tests fail without the keep-the-mark change. Verified (red-first run).
- Description: real sets regenerate with only the marks changed, identical declaration and data files, an idempotent second round and a passing integration check. Verified on probe and heroicons sets; the author's own sets are not public.
- Description: older CLIs fail
add,map,new-set --from,integration checkanddoctor integration validateon a marked set. Verified for a set built with an adapter. - Description: in an app on an earlier CLI, template copies, icon search and plain
doctorwork, and validating the set package fails until the app upgrades. Verified with the CLI this change replaces; the two older releases named were not re-run. - Description: the marks change no runtime value. Verified.
- File
.changeset/icon-set-pure-calls.md: clear (the earlier app claim is fixed). - File
packages/cli/foundation/discovery/icon-set-writer.mjs: clear. - File
packages/cli/foundation/discovery/icon-set-writer.test.mjs: clear. - File
packages/cli/assets/docs/tree/icon-sets.doc.mjs: clear. - File
packages/cli/api/icon/look-theme-maps.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-authoring.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-library-looks.test.mjs: clear. - File
packages/cli/clients/cli/commands/icon-look-packages.test.mjs: clear.
- #12252 docs(cli): agent docs name the prop names that differ from other libraries Author: Joey Farina <[email protected]> - #12154 fix(core): a numeric typography weight builds through an extended base's adaptation rules Author: Joey <[email protected]> - #12092 fix(cli): theme build reads the Core it builds with for variant declarations, and names the build command alone Author: Joey Farina <[email protected]> - #12316 fix(core): a shorthand never follows its own longhand in one style merge Author: josephfarina <[email protected]> - #12357 fix(core): a Table stays the scroll region when a host scrolls every table's parent Author: Joey Farina <[email protected]> - #12349 fix(core): end a mouse drag a sandboxed frame never saw released Author: josephfarina <[email protected]> - #12425 fix(cli): use a stored doc parse only with the zod release that made it Author: Joey <[email protected]> - #12396 fix(AppShell): with the standard width points, a server-rendered shell hides its inline side nav on a phone before its script runs Author: Joey <[email protected]> - #12438 fix(charts): end dots draw whole and a thinned axis keeps its last label Author: Joey Farina <[email protected]> - #12448 fix(cli): upgrade outside a project names the project, not --from Author: Joey Farina <[email protected]> - #12459 fix(templates): the dashboard scorecard fits a phone screen Author: Joey Farina <[email protected]> - #12428 fix(core): Field labels draw in a bolder face than their description Author: Joey Farina <[email protected]> - #12435 fix(theme-matcha): dark menus, popovers and muted fills take the theme's deep gray neutral Author: Joey <[email protected]> - #12432 fix(templates): dashboard chart labels show whole instead of clipped by the chart edge Author: Joey Farina <[email protected]> - #12441 fix(cli): mark icon-set generated calls pure so apps drop unused icons Author: Joey Farina <[email protected]> - #12472 fix(MetadataListItem): a value breaks only a word longer than its line Author: Joey <[email protected]>
|
Landed in #12718. |
User impact
An app that imports a few icons from an icon set's package also bundles the set's whole theme map, and for a set built with an adapter, every adapted icon in the set. Importing a few dozen icons through a set built from a component library cost about twice what importing the same icons from the library directly costs; through a set built from a data library with an adapter, about ten times. After this change both cost the same as importing the icons directly.
Problem and solution fit
createElement(...)for each theme-map entry,adaptIcon(...)for each adapted icon). A bundler cannot tell those calls have no side effects, so it keeps every one of them, even when the app never reads the theme map or the icon.The writer now marks each of those calls
/* @__PURE__ */, the annotation bundlers (esbuild, Rollup, webpack's minifier) read as "drop this call when its result is unused". The calls are plain element and component construction, so the mark is true.Expected behavior and authority
AST-084 FR13: the generated module and its declaration file "are read statement by statement however a formatter left them". A module with the marks is read the same as one without; the marks are dropped when a statement is read, the way comments and formatting are, and added back when the module is written. No record changes.
Smallest restoration
foundation/discovery/icon-set-writer.mjs: the written module marks each adapter export and each theme-map element;normalizedStatementdrops a mark (/* @__PURE__ */or/*#__PURE__*/) before anything compares or types a statement, so a module an older CLI wrote reads the same and the nextadd,map, or refresh only adds the marks. A statement that carried its own mark (one written by hand) is written back with it.experimental icon addshows the mark, and says an adapter must only build the component.Evidence
--bundle --minify, React external): the output holds every theme-map element, and for an adapter set every adapted icon.themeIconsinto a theme still draws every entry, with identical markup.icon-set-writer.test.mjs"generatedModuleText marks its top-level calls pure": every top-level call is marked; a module without marks, with the/*#__PURE__*/spelling, or with the call moved to its own line by a formatter reads the same and rewrites to the marked text; a hand-written statement keeps its own mark in both spellings, and one without a mark stays unmarked; the declaration file carries no marks.Scope
Components: cli (icon sets)
Testing
CI=1 pnpm vitest run packages/cli(full CLI suite).icon-set-writer.test.mjsfail against the writer without the keep-the-mark change (the mark is dropped on rewrite) and pass with it.experimental icon mapround trip): the generated modules differ only by the marks, the declaration files and data files are byte-identical, a second round changes nothing, andastryx integration check --strictpasses.experimental icon addandmapdrop the adapter import, itsnew-set --fromrefuses, and itsintegration checkanddoctor integration validate <set package>fail loudly withicon_generated_types_mismatch. In an app on an earlier CLI (0.7.14 and 0.7.16 tried, as the app's own CLI), template copies with the set's icons, icon search and the defaultdoctorrun work as before; validating the set package itself fails until the app moves to this release. The marks change no runtime value. The changeset says so.