@astryxdesign/cli 0.6.5 → 0.6.6-canary.e1dda17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/README.md +58 -55
- package/api/build/_adapter.d.mts +55 -2
- package/api/build/_adapter.mjs +100 -10
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +111 -2
- package/api/build/build.type.d.mts +8 -0
- package/api/build/build.type.mjs +2 -0
- package/api/build/kit/kit.mjs +99 -22
- package/api/build/kit/rank.d.mts +32 -8
- package/api/build/kit/rank.mjs +291 -97
- package/api/build/kit/rank.test.mjs +231 -48
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/component/_adapter.d.mts +19 -0
- package/api/component/_adapter.mjs +33 -0
- package/api/component/component-replacement.test.mjs +603 -0
- package/api/component/component.mjs +49 -15
- package/api/component/component.test.mjs +32 -0
- package/api/component/component.type.d.mts +33 -3
- package/api/component/component.type.mjs +10 -3
- package/api/component/detail/blocks/blocks.d.mts +2 -1
- package/api/component/detail/blocks/blocks.mjs +5 -2
- package/api/component/detail/detail.mjs +5 -1
- package/api/component/detail/props/props.d.mts +2 -1
- package/api/component/detail/props/props.mjs +3 -2
- package/api/component/detail/showcase/showcase.d.mts +3 -1
- package/api/component/detail/showcase/showcase.mjs +3 -1
- package/api/component/detail/source/source.d.mts +3 -2
- package/api/component/detail/source/source.mjs +7 -3
- package/api/component/list/list.mjs +128 -10
- package/api/docs/_adapter.d.mts +11 -0
- package/api/docs/_adapter.mjs +25 -0
- package/api/docs/detail/detail.mjs +19 -3
- package/api/docs/detail/section/section.mjs +7 -1
- package/api/docs/docOverlays.test.mjs +10 -6
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +134 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +46 -1
- package/api/docs/docs.test.mjs +279 -0
- package/api/docs/docs.type.d.mts +81 -4
- package/api/docs/docs.type.mjs +41 -4
- package/api/docs/index/index.mjs +11 -2
- package/api/docs/index/index.test.mjs +7 -2
- package/api/docs/integration-tree.test.mjs +572 -0
- package/api/docs/integrationDocs.test.mjs +337 -0
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +149 -23
- package/api/doctor/_adapter.d.mts +43 -0
- package/api/doctor/_adapter.mjs +142 -0
- package/api/doctor/doctor.d.mts +0 -10
- package/api/doctor/doctor.doc.mjs +1 -3
- package/api/doctor/doctor.mjs +6 -123
- package/api/doctor/theme-checks.d.mts +12 -0
- package/api/doctor/theme-checks.mjs +1117 -0
- package/api/doctor/theme-checks.test.mjs +526 -0
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/gap-report/gap-report.d.mts +3 -1
- package/api/gap-report/gap-report.mjs +27 -3
- package/api/gap-report/gap-report.test.mjs +106 -0
- package/api/hook/_adapter.d.mts +1 -0
- package/api/hook/_adapter.mjs +3 -0
- package/api/hook/detail/detail.mjs +2 -2
- package/api/hook/detail/params/params.mjs +2 -2
- package/api/hook/hook.type.d.mts +12 -0
- package/api/hook/hook.type.mjs +3 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/hook/list/list.mjs +8 -8
- package/api/index.d.mts +1 -1
- package/api/index.mjs +4 -0
- package/api/init/run/run.d.mts +3 -5
- package/api/init/run/run.mjs +10 -11
- package/api/integration/__fixtures__/released-0.6.5-ocean.d.mts +14 -0
- package/api/integration/__fixtures__/released-0.6.5-ocean.mjs +15 -0
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-helpers.d.mts +26 -5
- package/api/integration/add-helpers.mjs +50 -5
- package/api/integration/add-theme.mjs +354 -28
- package/api/integration/add-theme.test.mjs +380 -16
- package/api/integration/authoring-checks.mjs +31 -8
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +6 -3
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.component-replaces.test.mjs +126 -0
- package/api/integration/pack-check.d.mts +10 -0
- package/api/integration/pack-check.lifecycle-output.test.mjs +21 -2
- package/api/integration/pack-check.mjs +495 -4
- package/api/integration/pack-check.test.mjs +619 -10
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +39 -8
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +248 -66
- package/api/search/search.test.mjs +829 -0
- package/api/search/search.type.d.mts +6 -6
- package/api/search/search.type.mjs +5 -5
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +23 -0
- package/api/swizzle/copy/copy.d.mts +5 -6
- package/api/swizzle/copy/copy.mjs +95 -13
- package/api/swizzle/list/list.mjs +2 -2
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/swizzle/swizzle.test.mjs +55 -5
- package/api/swizzle/swizzle.type.d.mts +8 -0
- package/api/swizzle/swizzle.type.mjs +2 -0
- package/api/template/copy/copy.mjs +15 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +17 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/skeleton/skeleton.mjs +2 -1
- package/api/template/template-integration.test.mjs +14 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +2 -0
- package/api/template/template.type.d.mts +14 -0
- package/api/template/template.type.mjs +5 -0
- package/api/theme/_adapter.d.mts +106 -6
- package/api/theme/_adapter.mjs +687 -18
- package/api/theme/add/add.binary.test.mjs +76 -3
- package/api/theme/add/add.d.mts +5 -9
- package/api/theme/add/add.mjs +87 -64
- package/api/theme/add/add.rollback.test.mjs +9 -9
- package/api/theme/add/add.staging.test.mjs +9 -9
- package/api/theme/add/add.test.mjs +461 -55
- package/api/theme/add/add.types.test.mjs +151 -0
- package/api/theme/build/build.d.mts +50 -2
- package/api/theme/build/build.family.test.mjs +13 -4
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +463 -155
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +220 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/eject/eject.binary.test.mjs +90 -0
- package/api/theme/eject/eject.d.mts +17 -0
- package/api/theme/eject/eject.mjs +65 -0
- package/api/theme/eject/eject.rollback.test.mjs +158 -0
- package/api/theme/eject/eject.staging.test.mjs +83 -0
- package/api/theme/eject/eject.test.mjs +160 -0
- package/api/theme/integration-themes.test.mjs +30 -6
- package/api/theme/list/list.d.mts +10 -0
- package/api/theme/list/list.mjs +75 -7
- package/api/theme/list/list.test.mjs +155 -4
- package/api/theme/remove/remove.d.mts +12 -0
- package/api/theme/remove/remove.mjs +15 -0
- package/api/theme/remove/remove.test.mjs +94 -0
- package/api/theme/template/template.mjs +3 -4
- package/api/theme/theme.d.mts +5 -2
- package/api/theme/theme.mjs +13 -8
- package/api/theme/theme.type.d.mts +106 -2
- package/api/theme/theme.type.mjs +54 -5
- package/api/theme/themeAdd.doc.d.mts +1 -3
- package/api/theme/themeAdd.doc.mjs +35 -22
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +15 -4
- package/api/theme/themeEject.doc.d.mts +8 -0
- package/api/theme/themeEject.doc.mjs +89 -0
- package/api/theme/themeListAvailable.doc.mjs +4 -4
- package/api/theme/themeListCopySources.doc.d.mts +8 -0
- package/api/theme/themeListCopySources.doc.mjs +60 -0
- package/api/theme/themeRemove.doc.d.mts +6 -0
- package/api/theme/themeRemove.doc.mjs +50 -0
- package/api/theme/themeTemplate.doc.mjs +4 -3
- package/api/theme/themeUse.doc.d.mts +6 -0
- package/api/theme/themeUse.doc.mjs +47 -0
- package/api/theme/use/use.d.mts +12 -0
- package/api/theme/use/use.mjs +15 -0
- package/api/theme/use/use.test.mjs +98 -0
- package/api/upgrade/_adapter.d.mts +1 -0
- package/api/upgrade/_adapter.mjs +3 -0
- package/api/upgrade/list/list.mjs +9 -3
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +5 -0
- package/api/upgrade/upgrade.type.mjs +2 -0
- package/assets/codemods/integration-discovery.mjs +1 -1
- package/assets/codemods/integration-discovery.test.mjs +64 -0
- package/assets/codemods/transforms/next/__tests__/migrate-copied-themes-to-descriptors.test.mjs +129 -0
- package/assets/codemods/transforms/next/index.mjs +14 -1
- package/assets/codemods/transforms/next/migrate-copied-themes-to-descriptors.mjs +54 -0
- package/assets/docs/author-a-theme.doc.mjs +161 -0
- package/assets/docs/getting-started.doc.mjs +59 -15
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/docs/principles.doc.dense.mjs +2 -2
- package/assets/docs/principles.doc.mjs +2 -2
- package/assets/docs/principles.doc.zh.mjs +2 -2
- package/assets/docs/styling-libraries.doc.mjs +1 -1
- package/assets/docs/styling.doc.mjs +2 -2
- package/assets/docs/theme.doc.dense.mjs +10 -198
- package/assets/docs/theme.doc.mjs +13 -770
- package/assets/docs/theme.doc.zh.mjs +31 -12
- package/assets/docs/tokens.doc.mjs +4 -4
- package/assets/docs/tree/add-a-theme.doc.mjs +6 -2
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +6 -5
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +2 -2
- package/assets/docs/tree/document-the-theme.doc.mjs +4 -4
- package/assets/docs/tree/fonts-and-assets.doc.mjs +25 -20
- package/assets/docs/tree/headers-and-footers.doc.mjs +68 -0
- package/assets/docs/tree/layout-spacing.doc.mjs +168 -0
- package/assets/docs/tree/layout.doc.mjs +32 -0
- package/assets/docs/tree/replace-a-core-component.doc.mjs +21 -4
- package/assets/docs/tree/responsive.doc.mjs +102 -0
- package/assets/docs/tree/scaffold.doc.mjs +145 -0
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/side-panels.doc.mjs +82 -0
- package/assets/docs/tree/structure.doc.mjs +144 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
- package/assets/docs/tree/themes.doc.mjs +2 -2
- package/assets/docs/tree/troubleshooting.doc.mjs +13 -5
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +22 -5
- package/assets/docs/tree/versioning.doc.mjs +11 -7
- package/assets/docs/use-a-theme.doc.mjs +97 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
- package/assets/templates/pages/blank/template.doc.mjs +3 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
- package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
- package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
- package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
- package/assets/templates/pages/documentation/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
- package/assets/templates/pages/editor/template.doc.mjs +9 -1
- package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
- package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
- package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
- package/assets/templates/pages/ide/template.doc.mjs +9 -1
- package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
- package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
- package/assets/templates/pages/library/template.doc.mjs +15 -1
- package/assets/templates/pages/login/template.doc.mjs +10 -1
- package/assets/templates/pages/login-card/template.doc.mjs +11 -1
- package/assets/templates/pages/login-split/template.doc.mjs +10 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
- package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
- package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/settings/template.doc.mjs +3 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/table/template.doc.mjs +11 -1
- package/assets/templates/pages/table-collapsible/page.tsx +1474 -0
- package/assets/templates/pages/table-collapsible/template.doc.mjs +12 -0
- package/assets/templates/pages/table-comparison/page.tsx +1449 -0
- package/assets/templates/pages/table-comparison/template.doc.mjs +12 -0
- package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
- package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
- package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
- package/assets/templates/pages/table-page/template.doc.mjs +20 -1
- package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
- package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/command/command.doc.mjs +5 -0
- package/authoring/doctypes/command/type.ts +2 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/component/type.ts +8 -4
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +1 -0
- package/authoring/doctypes/template/parse.test.mjs +21 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +10 -0
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.mjs +279 -30
- package/clients/cli/commands/build.mjs +7 -6
- package/clients/cli/commands/build.text-fields.test.mjs +1 -1
- package/clients/cli/commands/component/index.mjs +88 -12
- package/clients/cli/commands/component-replacement.text.test.mjs +271 -0
- package/clients/cli/commands/component.doc.mjs +9 -2
- package/clients/cli/commands/discover.mjs +29 -1
- package/clients/cli/commands/discover.no-source.test.mjs +75 -0
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +273 -16
- package/clients/cli/commands/docs.test.mjs +382 -0
- package/clients/cli/commands/doctor-integration-components.doc.mjs +15 -4
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/doctor.test.mjs +9 -51
- package/clients/cli/commands/gap-report.doc.mjs +2 -2
- package/clients/cli/commands/gap-report.mjs +12 -0
- package/clients/cli/commands/gap-report.test.mjs +63 -0
- package/clients/cli/commands/hook/index.mjs +7 -2
- package/clients/cli/commands/import-hint-correctness.test.mjs +5 -5
- package/clients/cli/commands/init.next-steps.test.mjs +18 -23
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration-real-world.test.mjs +61 -12
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-check.doc.mjs +1 -0
- package/clients/cli/commands/layout-expand.doc.mjs +4 -1
- package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
- package/clients/cli/commands/layout.doc.mjs +1 -0
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +61 -4
- package/clients/cli/commands/no-prompt-wording.test.mjs +4 -4
- package/clients/cli/commands/search.doc.mjs +5 -4
- package/clients/cli/commands/search.mjs +30 -6
- package/clients/cli/commands/search.test.mjs +63 -17
- package/clients/cli/commands/swizzle.doc.mjs +12 -3
- package/clients/cli/commands/swizzle.mjs +2 -1
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +70 -6
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/text-json-parity.test.mjs +40 -0
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +132 -0
- package/clients/cli/commands/theme-add.doc.mjs +19 -19
- package/clients/cli/commands/theme-eject.doc.mjs +47 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +44 -0
- package/clients/cli/commands/theme-list.doc.mjs +2 -2
- package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -2
- package/clients/cli/commands/theme-remove.doc.mjs +22 -0
- package/clients/cli/commands/theme-template.doc.mjs +4 -3
- package/clients/cli/commands/theme-use.doc.mjs +22 -0
- package/clients/cli/commands/theme.doc.mjs +21 -16
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/upgrade.mjs +1 -1
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/index.mjs +4 -1
- package/clients/cli/lib/component-format.mjs +19 -2
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/clients/cli/lib/resolve-theme.mjs +80 -78
- package/clients/cli/lib/resolve-theme.test.mjs +523 -27
- package/foundation/agent-docs/agent-docs.mjs +31 -28
- package/foundation/agent-docs/agent-docs.test.mjs +1163 -0
- package/foundation/agent-docs/app-theme-workflow.test.mjs +13 -0
- package/foundation/config/project.d.mts +20 -5
- package/foundation/config/project.mjs +43 -6
- package/foundation/config/theme-private-vars.d.mts +12 -0
- package/foundation/config/theme-private-vars.mjs +107 -0
- package/foundation/config/theme-private-vars.test.mjs +55 -0
- package/foundation/config/theme-state.d.mts +145 -0
- package/foundation/config/theme-state.mjs +417 -0
- package/foundation/config/theme-state.test.mjs +182 -0
- package/foundation/discovery/component-discovery.d.mts +5 -2
- package/foundation/discovery/component-discovery.mjs +12 -6
- package/foundation/discovery/component-replacement.d.mts +91 -0
- package/foundation/discovery/component-replacement.mjs +417 -0
- package/foundation/discovery/component-replacement.test.mjs +480 -0
- package/foundation/discovery/docs-output-budget.d.mts +6 -2
- package/foundation/discovery/docs-output-budget.mjs +2 -1
- package/foundation/discovery/docs-section-key.d.mts +4 -2
- package/foundation/discovery/docs-section-key.mjs +1 -1
- package/foundation/discovery/module-exports.d.mts +10 -0
- package/foundation/discovery/module-exports.mjs +146 -0
- package/foundation/discovery/package-exports.d.mts +29 -0
- package/foundation/discovery/package-exports.mjs +200 -0
- package/foundation/discovery/template-adapter.d.mts +14 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +21 -1
- package/foundation/discovery/theme-discovery.d.mts +78 -5
- package/foundation/discovery/theme-discovery.mjs +143 -18
- package/foundation/discovery/theme-discovery.test.mjs +9 -3
- package/foundation/discovery/theme-imports.d.mts +15 -0
- package/foundation/discovery/theme-imports.mjs +217 -0
- package/foundation/discovery/theme-imports.test.mjs +173 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +18 -8
- package/foundation/doc-compiler/inputs.mjs +2 -1
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/lenses.d.mts +4 -2
- package/foundation/doc-compiler/lenses.mjs +1 -1
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/foundation/fs/module-loader.d.mts +9 -0
- package/foundation/fs/module-loader.mjs +71 -2
- package/foundation/integrations/cli-requirement.d.mts +79 -13
- package/foundation/integrations/cli-requirement.mjs +115 -22
- package/foundation/integrations/cli-requirement.test.mjs +205 -8
- package/foundation/integrations/contribution-inventory.mjs +3 -3
- package/foundation/response/base.d.ts +9 -3
- package/foundation/response/json.d.mts +7 -4
- package/foundation/response/json.mjs +10 -6
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +50 -35
- package/foundation/response/response.doc.mjs +18 -4
- package/foundation/text/copyright-header.mjs +1 -1
- package/foundation/text/copyright-header.test.mjs +1 -1
- package/package.json +9 -9
- package/assets/docs/layout.doc.dense.mjs +0 -388
- package/assets/docs/layout.doc.mjs +0 -550
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve importable icon registries for the selected theme export.
|
|
5
|
+
*
|
|
6
|
+
* @input Loaded theme export identity, plus the caller's source reader and the
|
|
7
|
+
* theme loader's resolver (this module performs no environment access).
|
|
8
|
+
* @output Import bindings and an expression preserving inherited icon registries.
|
|
9
|
+
* @position Private theme-build packaging helper; never evaluates authored source.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import {fileURLToPath} from 'node:url';
|
|
14
|
+
import {AstryxError} from '../../error.mjs';
|
|
15
|
+
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {object} IconImports
|
|
19
|
+
* @property {{importPath: string, importedName: string, localName: string}[]} imports
|
|
20
|
+
* @property {string} expression
|
|
21
|
+
* @property {string} exportName
|
|
22
|
+
* @property {string} [iconsSpecifierImportPath]
|
|
23
|
+
* @property {string} [iconsSpecifierLocalName]
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** @typedef {{kind: 'reference', module: any, binding: any, members: string[]}} RegistryReference */
|
|
27
|
+
/** @typedef {{kind: 'registry', ref: RegistryReference, preferredName: string, override?: boolean} | {kind: 'merge', base: RegistryPlan, own: RegistryPlan}} RegistryPlan */
|
|
28
|
+
|
|
29
|
+
/** @param {any} node */
|
|
30
|
+
function unwrap(node) {
|
|
31
|
+
while (
|
|
32
|
+
node &&
|
|
33
|
+
[
|
|
34
|
+
'TSAsExpression',
|
|
35
|
+
'TSSatisfiesExpression',
|
|
36
|
+
'TSNonNullExpression',
|
|
37
|
+
'TSTypeAssertion',
|
|
38
|
+
'TypeCastExpression',
|
|
39
|
+
'ParenthesizedExpression',
|
|
40
|
+
].includes(node.type)
|
|
41
|
+
) {
|
|
42
|
+
node = node.expression;
|
|
43
|
+
}
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {any} node */
|
|
48
|
+
function propertyName(node) {
|
|
49
|
+
if (!node) return null;
|
|
50
|
+
if (node.type === 'Identifier') return node.name;
|
|
51
|
+
if (typeof node.value === 'string') return node.value;
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @param {any} node */
|
|
56
|
+
function rootIdentifier(node) {
|
|
57
|
+
node = unwrap(node);
|
|
58
|
+
while (
|
|
59
|
+
node?.type === 'MemberExpression' ||
|
|
60
|
+
node?.type === 'OptionalMemberExpression'
|
|
61
|
+
) {
|
|
62
|
+
node = unwrap(node.object);
|
|
63
|
+
}
|
|
64
|
+
return node?.type === 'Identifier' ? node.name : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {any} pattern @returns {string[]} */
|
|
68
|
+
function bindingNames(pattern) {
|
|
69
|
+
if (!pattern) return [];
|
|
70
|
+
if (pattern.type === 'Identifier') return [pattern.name];
|
|
71
|
+
if (pattern.type === 'AssignmentPattern') return bindingNames(pattern.left);
|
|
72
|
+
if (pattern.type === 'RestElement') return bindingNames(pattern.argument);
|
|
73
|
+
if (pattern.type === 'ObjectPattern')
|
|
74
|
+
return pattern.properties.flatMap((/** @type {any} */ item) =>
|
|
75
|
+
bindingNames(item.type === 'RestElement' ? item.argument : item.value),
|
|
76
|
+
);
|
|
77
|
+
if (pattern.type === 'ArrayPattern')
|
|
78
|
+
return pattern.elements.flatMap(bindingNames);
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @param {string} [name] @param {string} [reason] @returns {never} */
|
|
83
|
+
function invalidRegistry(name, reason = '') {
|
|
84
|
+
const registry = name ? `\`icons: ${name}\`` : 'an icon registry';
|
|
85
|
+
throw new AstryxError(
|
|
86
|
+
`Theme sets ${registry} but no import for the registry was found. ` +
|
|
87
|
+
'The generated module cannot preserve inline registries because they ' +
|
|
88
|
+
'may contain React elements, which cannot be serialized. ' +
|
|
89
|
+
(reason ? `${reason} ` : '') +
|
|
90
|
+
'Move the registry to its own module and import it into the theme file.',
|
|
91
|
+
undefined,
|
|
92
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Parse only real module declarations and follow the export chosen by the loader.
|
|
98
|
+
* Local base themes are traced to their registry imports. Package bases remain
|
|
99
|
+
* public theme imports, so their implementation and private files stay private.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} filePath
|
|
102
|
+
* @param {string | undefined} exportName
|
|
103
|
+
* @param {{hasIcons: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
|
|
104
|
+
* @returns {Promise<IconImports | null>}
|
|
105
|
+
*/
|
|
106
|
+
export async function resolveIconImports(
|
|
107
|
+
filePath,
|
|
108
|
+
exportName,
|
|
109
|
+
{hasIcons, readSource, resolveModule, reservedNames = [], rawInput = false},
|
|
110
|
+
) {
|
|
111
|
+
if (exportName === undefined) {
|
|
112
|
+
if (!hasIcons) return null;
|
|
113
|
+
invalidRegistry(
|
|
114
|
+
undefined,
|
|
115
|
+
'The selected theme export could not be identified.',
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
120
|
+
const entryDirectory = path.dirname(filePath);
|
|
121
|
+
/** @type {Map<string, any>} */
|
|
122
|
+
const modules = new Map();
|
|
123
|
+
const active = new Set();
|
|
124
|
+
let inspectedRegistry = false;
|
|
125
|
+
|
|
126
|
+
/** @param {string} key @param {() => Promise<any>} visit */
|
|
127
|
+
async function guarded(key, visit) {
|
|
128
|
+
if (active.has(key))
|
|
129
|
+
invalidRegistry(undefined, 'The icon reference contains a cycle.');
|
|
130
|
+
active.add(key);
|
|
131
|
+
try {
|
|
132
|
+
return await visit();
|
|
133
|
+
} finally {
|
|
134
|
+
active.delete(key);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** @param {any} module @param {any} node @param {Set<string>} [seen] */
|
|
139
|
+
function isDefineTheme(module, node, seen = new Set()) {
|
|
140
|
+
node = unwrap(node);
|
|
141
|
+
if (node?.type === 'Identifier') {
|
|
142
|
+
if (seen.has(node.name)) return false;
|
|
143
|
+
seen.add(node.name);
|
|
144
|
+
const binding = module.bindings.get(node.name);
|
|
145
|
+
if (binding?.kind === 'const')
|
|
146
|
+
return isDefineTheme(module, binding.node, seen);
|
|
147
|
+
return (
|
|
148
|
+
binding?.kind === 'import' &&
|
|
149
|
+
['@astryxdesign/core', '@astryxdesign/core/theme'].includes(
|
|
150
|
+
binding.source,
|
|
151
|
+
) &&
|
|
152
|
+
binding.importedName === 'defineTheme'
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (
|
|
156
|
+
node?.type === 'MemberExpression' &&
|
|
157
|
+
!node.computed &&
|
|
158
|
+
node.property.name === 'defineTheme'
|
|
159
|
+
) {
|
|
160
|
+
const binding = module.bindings.get(node.object?.name);
|
|
161
|
+
return (
|
|
162
|
+
binding?.kind === 'import' &&
|
|
163
|
+
binding.importedName === '*' &&
|
|
164
|
+
['@astryxdesign/core', '@astryxdesign/core/theme'].includes(
|
|
165
|
+
binding.source,
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** @param {string} filename */
|
|
173
|
+
function readModule(filename) {
|
|
174
|
+
if (modules.has(filename)) return modules.get(filename);
|
|
175
|
+
const parser = /\.[cm]?ts$/u.test(filename) ? 'ts' : 'tsx';
|
|
176
|
+
const j = jscodeshift.withParser(parser);
|
|
177
|
+
let root;
|
|
178
|
+
try {
|
|
179
|
+
root = j(readSource(filename));
|
|
180
|
+
} catch {
|
|
181
|
+
invalidRegistry(
|
|
182
|
+
undefined,
|
|
183
|
+
'The selected theme module could not be parsed.',
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
const first = root.nodes()[0];
|
|
187
|
+
const statements = (first.program ?? first).body;
|
|
188
|
+
/** @type {{filename: string, bindings: Map<string, any>, exports: Map<string, any>, stars: string[], mutated: Set<string>, aliases: Map<string, string>}} */
|
|
189
|
+
const module = {
|
|
190
|
+
filename,
|
|
191
|
+
bindings: new Map(),
|
|
192
|
+
exports: new Map(),
|
|
193
|
+
stars: [],
|
|
194
|
+
mutated: new Set(),
|
|
195
|
+
aliases: new Map(),
|
|
196
|
+
};
|
|
197
|
+
modules.set(filename, module);
|
|
198
|
+
|
|
199
|
+
for (const statement of statements) {
|
|
200
|
+
if (
|
|
201
|
+
statement.type === 'ImportDeclaration' &&
|
|
202
|
+
statement.importKind !== 'type'
|
|
203
|
+
) {
|
|
204
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
205
|
+
if (specifier.importKind === 'type') continue;
|
|
206
|
+
module.bindings.set(specifier.local.name, {
|
|
207
|
+
kind: 'import',
|
|
208
|
+
source: statement.source.value,
|
|
209
|
+
importedName:
|
|
210
|
+
specifier.type === 'ImportDefaultSpecifier'
|
|
211
|
+
? 'default'
|
|
212
|
+
: specifier.type === 'ImportNamespaceSpecifier'
|
|
213
|
+
? '*'
|
|
214
|
+
: propertyName(specifier.imported),
|
|
215
|
+
localName: specifier.local.name,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const declaration =
|
|
220
|
+
statement.type === 'ExportNamedDeclaration'
|
|
221
|
+
? statement.declaration
|
|
222
|
+
: statement;
|
|
223
|
+
if (declaration?.type === 'VariableDeclaration') {
|
|
224
|
+
for (const item of declaration.declarations) {
|
|
225
|
+
const original = rootIdentifier(item.init);
|
|
226
|
+
if (original) {
|
|
227
|
+
for (const name of bindingNames(item.id))
|
|
228
|
+
module.aliases.set(name, original);
|
|
229
|
+
}
|
|
230
|
+
if (item.id.type !== 'Identifier') continue;
|
|
231
|
+
module.bindings.set(item.id.name, {
|
|
232
|
+
kind: declaration.kind === 'const' ? 'const' : 'unsupported',
|
|
233
|
+
node: item.init,
|
|
234
|
+
});
|
|
235
|
+
if (statement.type === 'ExportNamedDeclaration') {
|
|
236
|
+
module.exports.set(item.id.name, {node: item.id});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (statement.type === 'ExportDefaultDeclaration') {
|
|
241
|
+
module.exports.set('default', {node: statement.declaration});
|
|
242
|
+
}
|
|
243
|
+
if (
|
|
244
|
+
statement.type === 'ExportNamedDeclaration' &&
|
|
245
|
+
statement.exportKind !== 'type'
|
|
246
|
+
) {
|
|
247
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
248
|
+
if (specifier.exportKind === 'type') continue;
|
|
249
|
+
const exportedName = propertyName(specifier.exported);
|
|
250
|
+
module.exports.set(
|
|
251
|
+
exportedName,
|
|
252
|
+
statement.source
|
|
253
|
+
? {
|
|
254
|
+
binding: {
|
|
255
|
+
kind: 'import',
|
|
256
|
+
source: statement.source.value,
|
|
257
|
+
importedName:
|
|
258
|
+
specifier.type === 'ExportNamespaceSpecifier'
|
|
259
|
+
? '*'
|
|
260
|
+
: propertyName(specifier.local),
|
|
261
|
+
localName: propertyName(specifier.local) ?? exportedName,
|
|
262
|
+
},
|
|
263
|
+
}
|
|
264
|
+
: {node: specifier.local},
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (
|
|
269
|
+
statement.type === 'ExportAllDeclaration' &&
|
|
270
|
+
statement.exportKind !== 'type'
|
|
271
|
+
) {
|
|
272
|
+
module.stars.push(statement.source.value);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** @param {any} node @param {any} nodePath */
|
|
277
|
+
const markMutation = (node, nodePath) => {
|
|
278
|
+
const name = rootIdentifier(node);
|
|
279
|
+
if (name && nodePath.scope.lookup(name)?.path.node.type === 'Program')
|
|
280
|
+
module.mutated.add(name);
|
|
281
|
+
};
|
|
282
|
+
root
|
|
283
|
+
.find(j.AssignmentExpression)
|
|
284
|
+
.forEach((/** @type {any} */ p) => markMutation(p.node.left, p));
|
|
285
|
+
root
|
|
286
|
+
.find(j.UpdateExpression)
|
|
287
|
+
.forEach((/** @type {any} */ p) => markMutation(p.node.argument, p));
|
|
288
|
+
root
|
|
289
|
+
.find(j.UnaryExpression, {operator: 'delete'})
|
|
290
|
+
.forEach((/** @type {any} */ p) => markMutation(p.node.argument, p));
|
|
291
|
+
root.find(j.CallExpression).forEach((/** @type {any} */ p) => {
|
|
292
|
+
if (isDefineTheme(module, p.node.callee)) return;
|
|
293
|
+
if (p.node.callee.type === 'MemberExpression')
|
|
294
|
+
markMutation(p.node.callee.object, p);
|
|
295
|
+
for (const argument of p.node.arguments) markMutation(argument, p);
|
|
296
|
+
});
|
|
297
|
+
// Mutating an alias also mutates the object that supplied its value.
|
|
298
|
+
for (const name of module.mutated) {
|
|
299
|
+
const original = module.aliases.get(name);
|
|
300
|
+
if (original) module.mutated.add(original);
|
|
301
|
+
}
|
|
302
|
+
return module;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** @param {any} module @param {string} name */
|
|
306
|
+
function checkedBinding(module, name) {
|
|
307
|
+
if (module.mutated.has(name))
|
|
308
|
+
invalidRegistry(
|
|
309
|
+
name,
|
|
310
|
+
'The referenced binding is mutated or passed to unsupported code.',
|
|
311
|
+
);
|
|
312
|
+
const binding = module.bindings.get(name);
|
|
313
|
+
if (!binding || binding.kind === 'unsupported') invalidRegistry(name);
|
|
314
|
+
return binding;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** @param {any} module @param {any} binding @param {string[]} [members] @returns {RegistryReference} */
|
|
318
|
+
function importedReference(module, binding, members = []) {
|
|
319
|
+
return {kind: 'reference', module, binding, members};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** @param {any} module @param {any} node @returns {Promise<RegistryReference | null>} */
|
|
323
|
+
async function reference(module, node) {
|
|
324
|
+
node = unwrap(node);
|
|
325
|
+
if (node?.type === 'Identifier') {
|
|
326
|
+
return guarded(`${module.filename}:reference:${node.name}`, async () => {
|
|
327
|
+
const binding = checkedBinding(module, node.name);
|
|
328
|
+
if (binding.kind === 'import')
|
|
329
|
+
return importedReference(module, binding);
|
|
330
|
+
return reference(module, binding.node);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
if (node?.type === 'MemberExpression' && !node.optional) {
|
|
334
|
+
const name = node.computed
|
|
335
|
+
? typeof node.property.value === 'string'
|
|
336
|
+
? node.property.value
|
|
337
|
+
: null
|
|
338
|
+
: propertyName(node.property);
|
|
339
|
+
if (name === null) invalidRegistry();
|
|
340
|
+
const object = await reference(module, node.object);
|
|
341
|
+
if (!object) return null;
|
|
342
|
+
return {...object, members: [...object.members, name]};
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** @param {RegistryReference} ref */
|
|
348
|
+
async function importedExport(ref) {
|
|
349
|
+
if (!ref.binding.source.startsWith('.')) return null;
|
|
350
|
+
let filename;
|
|
351
|
+
try {
|
|
352
|
+
filename = await resolveModule(ref.binding.source, ref.module.filename);
|
|
353
|
+
if (filename.startsWith('file:')) filename = fileURLToPath(filename);
|
|
354
|
+
} catch {
|
|
355
|
+
invalidRegistry(
|
|
356
|
+
ref.binding.localName,
|
|
357
|
+
'The inherited theme module could not be resolved.',
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
let name = ref.binding.importedName;
|
|
361
|
+
const members = [...ref.members];
|
|
362
|
+
if (name === '*') name = members.shift();
|
|
363
|
+
if (!name || members.length > 0)
|
|
364
|
+
invalidRegistry(
|
|
365
|
+
ref.binding.localName,
|
|
366
|
+
'The inherited theme must name a module export.',
|
|
367
|
+
);
|
|
368
|
+
return {module: readModule(filename), name};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** @param {any} module @param {string} name */
|
|
372
|
+
async function selectedExport(module, name) {
|
|
373
|
+
const selected = module.exports.get(name);
|
|
374
|
+
if (selected) return selected;
|
|
375
|
+
// Follow explicit local barrels without choosing another arbitrary theme.
|
|
376
|
+
for (const source of module.stars) {
|
|
377
|
+
if (name === 'default') continue;
|
|
378
|
+
const binding = {source, importedName: name, localName: name};
|
|
379
|
+
const target = await importedExport(importedReference(module, binding));
|
|
380
|
+
if (
|
|
381
|
+
target &&
|
|
382
|
+
(target.module.exports.has(name) || target.module.stars.length > 0)
|
|
383
|
+
)
|
|
384
|
+
return {binding};
|
|
385
|
+
}
|
|
386
|
+
invalidRegistry(
|
|
387
|
+
undefined,
|
|
388
|
+
`The selected export "${name}" has no statically resolved declaration.`,
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** @param {RegistryReference} ref @returns {RegistryPlan} */
|
|
393
|
+
function packageTheme(ref) {
|
|
394
|
+
return {
|
|
395
|
+
kind: 'registry',
|
|
396
|
+
ref: {...ref, members: [...ref.members, 'icons']},
|
|
397
|
+
preferredName: 'themeIcons',
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** @param {any} module @param {string} name @param {boolean} [rejectOpaque] @returns {Promise<RegistryPlan | null>} */
|
|
402
|
+
async function exportedTheme(module, name, rejectOpaque = false) {
|
|
403
|
+
return guarded(`${module.filename}:theme-export:${name}`, async () => {
|
|
404
|
+
const selected = await selectedExport(module, name);
|
|
405
|
+
return selected.binding
|
|
406
|
+
? themeReference(
|
|
407
|
+
importedReference(module, selected.binding),
|
|
408
|
+
rejectOpaque,
|
|
409
|
+
)
|
|
410
|
+
: theme(module, selected.node, rejectOpaque);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** @param {RegistryReference} ref @param {boolean} [rejectOpaque] @returns {Promise<RegistryPlan | null>} */
|
|
415
|
+
async function themeReference(ref, rejectOpaque = false) {
|
|
416
|
+
const target = await importedExport(ref);
|
|
417
|
+
if (target) return exportedTheme(target.module, target.name, rejectOpaque);
|
|
418
|
+
if (rejectOpaque)
|
|
419
|
+
invalidRegistry(
|
|
420
|
+
ref.binding.localName,
|
|
421
|
+
'A raw package configuration cannot supply a resolved theme registry.',
|
|
422
|
+
);
|
|
423
|
+
return packageTheme(ref);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** @param {any} module @param {any} node @param {string} [preferredName] @returns {Promise<RegistryPlan | null>} */
|
|
427
|
+
async function registry(module, node, preferredName) {
|
|
428
|
+
inspectedRegistry = true;
|
|
429
|
+
node = unwrap(node);
|
|
430
|
+
if (
|
|
431
|
+
node?.type === 'NullLiteral' ||
|
|
432
|
+
(node?.type === 'Literal' && node.value === null) ||
|
|
433
|
+
(node?.type === 'UnaryExpression' && node.operator === 'void')
|
|
434
|
+
)
|
|
435
|
+
return null;
|
|
436
|
+
if (node?.type === 'Identifier') {
|
|
437
|
+
if (node.name === 'undefined' && !module.bindings.has(node.name))
|
|
438
|
+
return null;
|
|
439
|
+
return guarded(`${module.filename}:registry:${node.name}`, async () => {
|
|
440
|
+
const binding = checkedBinding(module, node.name);
|
|
441
|
+
if (binding.kind === 'const')
|
|
442
|
+
return registry(module, binding.node, preferredName ?? node.name);
|
|
443
|
+
return {
|
|
444
|
+
kind: 'registry',
|
|
445
|
+
ref: importedReference(module, binding),
|
|
446
|
+
preferredName: preferredName ?? node.name,
|
|
447
|
+
override: true,
|
|
448
|
+
};
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
if (node?.type === 'MemberExpression') {
|
|
452
|
+
const ref = await reference(module, node);
|
|
453
|
+
if (ref)
|
|
454
|
+
return {
|
|
455
|
+
kind: 'registry',
|
|
456
|
+
ref,
|
|
457
|
+
preferredName: preferredName ?? 'themeIcons',
|
|
458
|
+
// A namespace's exported registry can be redirected to an icon module;
|
|
459
|
+
// a named theme's .icons cannot be imported from that sidecar.
|
|
460
|
+
override:
|
|
461
|
+
ref.binding.importedName === '*' && ref.members.length === 1,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
// Spreads merge in order. An object adding no entries, such as `{}`, is no
|
|
465
|
+
// local registry: a child keeps its inherited icons and a root emits none.
|
|
466
|
+
if (
|
|
467
|
+
node?.type === 'ObjectExpression' &&
|
|
468
|
+
node.properties.every((/** @type {any} */ item) =>
|
|
469
|
+
['SpreadElement', 'SpreadProperty'].includes(item.type),
|
|
470
|
+
)
|
|
471
|
+
) {
|
|
472
|
+
/** @type {RegistryPlan | null} */
|
|
473
|
+
let result = null;
|
|
474
|
+
for (const item of node.properties) {
|
|
475
|
+
const next = await registry(module, item.argument);
|
|
476
|
+
if (next)
|
|
477
|
+
result = result ? {kind: 'merge', base: result, own: next} : next;
|
|
478
|
+
}
|
|
479
|
+
return result;
|
|
480
|
+
}
|
|
481
|
+
invalidRegistry(preferredName ?? rootIdentifier(node) ?? undefined);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** @param {any} module @param {any} node @returns {Promise<Map<string, any>>} */
|
|
485
|
+
async function fields(module, node) {
|
|
486
|
+
node = unwrap(node);
|
|
487
|
+
if (node?.type === 'Identifier') {
|
|
488
|
+
return guarded(`${module.filename}:fields:${node.name}`, async () => {
|
|
489
|
+
const binding = checkedBinding(module, node.name);
|
|
490
|
+
if (binding.kind === 'const') return fields(module, binding.node);
|
|
491
|
+
return referenceFields(importedReference(module, binding));
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
if (node?.type === 'MemberExpression') {
|
|
495
|
+
const ref = await reference(module, node);
|
|
496
|
+
if (ref) return referenceFields(ref);
|
|
497
|
+
}
|
|
498
|
+
if (node?.type === 'CallExpression' && isDefineTheme(module, node.callee)) {
|
|
499
|
+
return new Map([['icons', {plan: await theme(module, node)}]]);
|
|
500
|
+
}
|
|
501
|
+
if (node?.type !== 'ObjectExpression') invalidRegistry();
|
|
502
|
+
const result = new Map();
|
|
503
|
+
for (const item of node.properties) {
|
|
504
|
+
if (item.type === 'SpreadElement' || item.type === 'SpreadProperty') {
|
|
505
|
+
for (const [key, value] of await fields(module, item.argument))
|
|
506
|
+
result.set(key, value);
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const key = item.computed
|
|
510
|
+
? typeof item.key?.value === 'string'
|
|
511
|
+
? item.key.value
|
|
512
|
+
: null
|
|
513
|
+
: propertyName(item.key);
|
|
514
|
+
if (key === null)
|
|
515
|
+
invalidRegistry(undefined, 'Computed theme keys cannot be resolved.');
|
|
516
|
+
if (!['icons', 'extends'].includes(key)) continue;
|
|
517
|
+
if (
|
|
518
|
+
!['ObjectProperty', 'Property'].includes(item.type) ||
|
|
519
|
+
item.method ||
|
|
520
|
+
(item.kind && item.kind !== 'init')
|
|
521
|
+
)
|
|
522
|
+
invalidRegistry();
|
|
523
|
+
result.set(key, {module, node: item.value});
|
|
524
|
+
}
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** @param {RegistryReference} ref @returns {Promise<Map<string, any>>} */
|
|
529
|
+
async function referenceFields(ref) {
|
|
530
|
+
const target = await importedExport(ref);
|
|
531
|
+
if (!target)
|
|
532
|
+
invalidRegistry(
|
|
533
|
+
ref.binding.localName,
|
|
534
|
+
'A package configuration cannot be inspected for inherited registries.',
|
|
535
|
+
);
|
|
536
|
+
return guarded(
|
|
537
|
+
`${target.module.filename}:fields-export:${target.name}`,
|
|
538
|
+
async () => {
|
|
539
|
+
const selected = await selectedExport(target.module, target.name);
|
|
540
|
+
return selected.binding
|
|
541
|
+
? referenceFields(importedReference(target.module, selected.binding))
|
|
542
|
+
: fields(target.module, selected.node);
|
|
543
|
+
},
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** @param {any} module @param {any} node @param {boolean} [rejectOpaque] @returns {Promise<RegistryPlan | null>} */
|
|
548
|
+
async function theme(module, node, rejectOpaque = false) {
|
|
549
|
+
node = unwrap(node);
|
|
550
|
+
if (node?.type === 'Identifier') {
|
|
551
|
+
return guarded(`${module.filename}:theme:${node.name}`, async () => {
|
|
552
|
+
const binding = checkedBinding(module, node.name);
|
|
553
|
+
return binding.kind === 'const'
|
|
554
|
+
? theme(module, binding.node, rejectOpaque)
|
|
555
|
+
: themeReference(importedReference(module, binding), rejectOpaque);
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
if (node?.type === 'MemberExpression') {
|
|
559
|
+
const ref = await reference(module, node);
|
|
560
|
+
if (ref) return themeReference(ref, rejectOpaque);
|
|
561
|
+
}
|
|
562
|
+
if (node?.type === 'CallExpression') {
|
|
563
|
+
if (!isDefineTheme(module, node.callee) || node.arguments.length !== 1)
|
|
564
|
+
invalidRegistry();
|
|
565
|
+
node = unwrap(node.arguments[0]);
|
|
566
|
+
}
|
|
567
|
+
const config = await fields(module, node);
|
|
568
|
+
const baseField = config.get('extends');
|
|
569
|
+
const iconField = config.get('icons');
|
|
570
|
+
const base = baseField
|
|
571
|
+
? await theme(baseField.module, baseField.node)
|
|
572
|
+
: null;
|
|
573
|
+
const own = iconField
|
|
574
|
+
? 'plan' in iconField
|
|
575
|
+
? iconField.plan
|
|
576
|
+
: await registry(iconField.module, iconField.node)
|
|
577
|
+
: null;
|
|
578
|
+
return base && own ? {kind: 'merge', base, own} : (own ?? base);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
let plan;
|
|
582
|
+
try {
|
|
583
|
+
plan = await exportedTheme(readModule(filePath), exportName, rawInput);
|
|
584
|
+
} catch (error) {
|
|
585
|
+
// No registry needs packaging when the loaded theme has none. This also
|
|
586
|
+
// keeps arbitrary icon-free authoring helpers outside this static resolver.
|
|
587
|
+
if (!hasIcons && !inspectedRegistry && error instanceof AstryxError)
|
|
588
|
+
return null;
|
|
589
|
+
throw error;
|
|
590
|
+
}
|
|
591
|
+
if (!plan) {
|
|
592
|
+
if (hasIcons) invalidRegistry();
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const used = new Set(reservedNames);
|
|
597
|
+
/** @type {IconImports['imports']} */
|
|
598
|
+
const imports = [];
|
|
599
|
+
const emitted = new Map();
|
|
600
|
+
|
|
601
|
+
/** @param {string} preferred */
|
|
602
|
+
function allocate(preferred) {
|
|
603
|
+
const stem =
|
|
604
|
+
/^[A-Za-z_$][\w$]*$/u.test(preferred) &&
|
|
605
|
+
!['default', 'await', 'yield'].includes(preferred)
|
|
606
|
+
? preferred
|
|
607
|
+
: 'themeIcons';
|
|
608
|
+
let name = stem;
|
|
609
|
+
let counter = 1;
|
|
610
|
+
while (used.has(name)) name = `${stem}${counter++}`;
|
|
611
|
+
used.add(name);
|
|
612
|
+
return name;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** @param {any} ref */
|
|
616
|
+
function importPath(ref) {
|
|
617
|
+
const source = ref.binding.source;
|
|
618
|
+
if (
|
|
619
|
+
!source.startsWith('.') ||
|
|
620
|
+
path.dirname(ref.module.filename) === entryDirectory
|
|
621
|
+
)
|
|
622
|
+
return source;
|
|
623
|
+
const relative = path
|
|
624
|
+
.relative(
|
|
625
|
+
entryDirectory,
|
|
626
|
+
path.resolve(path.dirname(ref.module.filename), source),
|
|
627
|
+
)
|
|
628
|
+
.split(path.sep)
|
|
629
|
+
.join('/');
|
|
630
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** @param {RegistryPlan} value @returns {{expression: string, preferredName: string, overridePath?: string, overrideLocalName?: string}} */
|
|
634
|
+
function render(value) {
|
|
635
|
+
if (value.kind === 'merge') {
|
|
636
|
+
const base = render(value.base);
|
|
637
|
+
const own = render(value.own);
|
|
638
|
+
return {
|
|
639
|
+
expression: `{...${base.expression}, ...${own.expression}}`,
|
|
640
|
+
preferredName: 'themeIcons',
|
|
641
|
+
overridePath: own.overridePath,
|
|
642
|
+
overrideLocalName: own.overrideLocalName,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
const {ref} = value;
|
|
646
|
+
const source = importPath(ref);
|
|
647
|
+
const identity = `${source}\0${ref.binding.importedName}\0${JSON.stringify(ref.members)}`;
|
|
648
|
+
let localName = emitted.get(identity);
|
|
649
|
+
if (!localName) {
|
|
650
|
+
localName = allocate(ref.binding.localName);
|
|
651
|
+
emitted.set(identity, localName);
|
|
652
|
+
imports.push({
|
|
653
|
+
importPath: source,
|
|
654
|
+
importedName: ref.binding.importedName,
|
|
655
|
+
localName,
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
const expression = ref.members.reduce(
|
|
659
|
+
(result, member) => `${result}[${JSON.stringify(member)}]`,
|
|
660
|
+
localName,
|
|
661
|
+
);
|
|
662
|
+
return {
|
|
663
|
+
expression,
|
|
664
|
+
preferredName:
|
|
665
|
+
ref.members.length === 0 &&
|
|
666
|
+
value.preferredName === ref.binding.localName
|
|
667
|
+
? localName
|
|
668
|
+
: value.preferredName,
|
|
669
|
+
overridePath: value.override ? source : undefined,
|
|
670
|
+
overrideLocalName: value.override ? localName : undefined,
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const rendered = render(plan);
|
|
675
|
+
const name =
|
|
676
|
+
rendered.preferredName === rendered.expression &&
|
|
677
|
+
imports.some(item => item.localName === rendered.expression)
|
|
678
|
+
? rendered.expression
|
|
679
|
+
: allocate(rendered.preferredName);
|
|
680
|
+
return {
|
|
681
|
+
imports,
|
|
682
|
+
expression: rendered.expression,
|
|
683
|
+
exportName: name,
|
|
684
|
+
...(rendered.overridePath
|
|
685
|
+
? {
|
|
686
|
+
iconsSpecifierImportPath: rendered.overridePath,
|
|
687
|
+
iconsSpecifierLocalName: rendered.overrideLocalName,
|
|
688
|
+
}
|
|
689
|
+
: {}),
|
|
690
|
+
};
|
|
691
|
+
}
|