@astryxdesign/cli 0.6.5 → 0.6.6-canary.11a80dd
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 +91 -88
- package/api/build/_adapter.d.mts +70 -2
- package/api/build/_adapter.mjs +122 -10
- package/api/build/build.doc.mjs +3 -3
- package/api/build/build.test.mjs +111 -2
- package/api/build/build.type.d.mts +12 -0
- package/api/build/build.type.mjs +3 -0
- package/api/build/help/help.mjs +1 -1
- package/api/build/kit/kit.mjs +110 -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 +50 -0
- package/api/doctor/_adapter.mjs +190 -0
- package/api/doctor/doctor.d.mts +0 -10
- package/api/doctor/doctor.doc.mjs +1 -3
- package/api/doctor/doctor.mjs +8 -123
- package/api/doctor/theme-checks.d.mts +24 -0
- package/api/doctor/theme-checks.mjs +1231 -0
- package/api/doctor/theme-checks.test.mjs +667 -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 +11 -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/check/check.d.mts +1 -0
- package/api/layout/check/check.mjs +1 -0
- package/api/layout/expand/expand.d.mts +1 -0
- package/api/layout/expand/expand.mjs +13 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/grammar/grammar.d.mts +1 -0
- package/api/layout/grammar/grammar.mjs +1 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutCheck.doc.mjs +1 -1
- package/api/layout/layoutExpand.doc.mjs +2 -2
- package/api/layout/layoutGrammar.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 +27 -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 +17 -0
- package/api/template/template.type.mjs +8 -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 +120 -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 +667 -195
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +220 -1
- package/api/theme/build/font-warning.d.mts +11 -0
- package/api/theme/build/font-warning.mjs +28 -3
- 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 +166 -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-overview.doc.mjs +211 -0
- 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 +52 -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 +212 -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/page.tsx +1 -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 +11 -0
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/commands/blog.mjs +3 -3
- package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
- package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
- package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
- package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
- package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
- package/clients/cli/commands/build-theme.mjs +346 -47
- package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
- package/clients/cli/commands/build.mjs +8 -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 +383 -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 +26 -52
- 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 +28 -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 +2 -0
- package/clients/cli/commands/layout-expand.doc.mjs +5 -1
- package/clients/cli/commands/layout-grammar.doc.mjs +2 -0
- package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +140 -0
- package/clients/cli/commands/layout.doc.mjs +2 -0
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +56 -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 +69 -19
- package/clients/cli/commands/swizzle.doc.mjs +12 -3
- package/clients/cli/commands/swizzle.mjs +2 -1
- package/clients/cli/commands/swizzle.routing.test.mjs +2 -1
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +71 -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 +135 -0
- package/clients/cli/commands/theme-add.doc.mjs +19 -19
- package/clients/cli/commands/theme-build.doc.mjs +3 -1
- 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.config-ordering.test.mjs +2 -1
- package/clients/cli/commands/upgrade.mjs +1 -1
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/index.mjs +5 -2
- package/clients/cli/lib/component-format.mjs +19 -2
- package/clients/cli/lib/component-format.test.mjs +1 -1
- package/clients/cli/lib/define-command.mjs +4 -0
- 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 +34 -28
- package/foundation/agent-docs/agent-docs.test.mjs +1181 -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/template-needs.d.mts +31 -0
- package/foundation/discovery/template-needs.mjs +156 -0
- package/foundation/discovery/template-needs.test.mjs +203 -0
- 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/env/package-manager.d.mts +28 -8
- package/foundation/env/package-manager.mjs +49 -10
- package/foundation/env/package-manager.test.mjs +93 -1
- 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 +52 -37
- 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,417 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file App-theme state stored in the generated theme module.
|
|
5
|
+
*
|
|
6
|
+
* The module is both the app import surface and the only record of added themes.
|
|
7
|
+
* Its generated header records owners and the default without adding another public
|
|
8
|
+
* export. Commands parse that header without running project code, regenerate the
|
|
9
|
+
* whole marked file instead of editing it, and never replace an authored file.
|
|
10
|
+
*
|
|
11
|
+
* @input A project directory and resolved built-theme imports
|
|
12
|
+
* @output Parsed state plus deterministic generated-module write plans
|
|
13
|
+
* @position packages/cli/foundation/config — shared app-theme state
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as path from 'node:path';
|
|
18
|
+
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
19
|
+
|
|
20
|
+
export const LOCAL_THEME_ROOT = './src/themes';
|
|
21
|
+
export const THEME_MODULE_BASENAME = 'astryx-themes';
|
|
22
|
+
export const THEME_MODULE_MARKER =
|
|
23
|
+
'@generated by `astryx theme` — do not edit manually.';
|
|
24
|
+
export const THEME_RECORD_MARKER = '@astryx-theme-record';
|
|
25
|
+
|
|
26
|
+
const THEME_SLUG_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
27
|
+
|
|
28
|
+
export class ThemeStateError extends Error {}
|
|
29
|
+
|
|
30
|
+
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
31
|
+
function isRecord(value) {
|
|
32
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @param {string} value */
|
|
36
|
+
export function projectPath(value) {
|
|
37
|
+
return value.split(path.sep).join('/');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Find the nearest package.json from a working directory.
|
|
42
|
+
* @param {string} cwd
|
|
43
|
+
*/
|
|
44
|
+
export function findThemeProject(cwd) {
|
|
45
|
+
let projectDir = path.resolve(cwd);
|
|
46
|
+
for (let depth = 0; depth < 50; depth++) {
|
|
47
|
+
const packageFile = path.join(projectDir, 'package.json');
|
|
48
|
+
if (fs.existsSync(packageFile)) return {projectDir, packageFile};
|
|
49
|
+
const parent = path.dirname(projectDir);
|
|
50
|
+
if (parent === projectDir) break;
|
|
51
|
+
projectDir = parent;
|
|
52
|
+
}
|
|
53
|
+
throw new ThemeStateError(
|
|
54
|
+
'No package.json found. Run this command inside an app project.',
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether an owner value names a project-relative local theme root instead of
|
|
60
|
+
* an installed package.
|
|
61
|
+
* @param {string} owner
|
|
62
|
+
*/
|
|
63
|
+
export function isLocalThemeOwner(owner) {
|
|
64
|
+
return owner.startsWith('./') || owner.startsWith('../') || path.isAbsolute(owner);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {string} projectDir */
|
|
68
|
+
export function projectUsesTypeScript(projectDir) {
|
|
69
|
+
try {
|
|
70
|
+
return fs
|
|
71
|
+
.readdirSync(projectDir, {withFileTypes: true})
|
|
72
|
+
.some(
|
|
73
|
+
entry =>
|
|
74
|
+
entry.isFile() &&
|
|
75
|
+
/^tsconfig(?:\.[^.]+)*\.json$/u.test(entry.name),
|
|
76
|
+
);
|
|
77
|
+
} catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* All conventional module locations. The preferred new location is first.
|
|
84
|
+
* @param {string} projectDir
|
|
85
|
+
*/
|
|
86
|
+
export function themeModuleCandidates(projectDir) {
|
|
87
|
+
const src = path.join(projectDir, 'src');
|
|
88
|
+
const hasSrc = fs.existsSync(src) && fs.statSync(src).isDirectory();
|
|
89
|
+
const typescript = projectUsesTypeScript(projectDir);
|
|
90
|
+
const preferredDir = hasSrc ? src : projectDir;
|
|
91
|
+
const otherDir = hasSrc ? projectDir : src;
|
|
92
|
+
const preferredExtension = typescript ? '.ts' : '.js';
|
|
93
|
+
const otherExtension = typescript ? '.js' : '.ts';
|
|
94
|
+
return [
|
|
95
|
+
path.join(preferredDir, `${THEME_MODULE_BASENAME}${preferredExtension}`),
|
|
96
|
+
path.join(preferredDir, `${THEME_MODULE_BASENAME}${otherExtension}`),
|
|
97
|
+
path.join(otherDir, `${THEME_MODULE_BASENAME}${preferredExtension}`),
|
|
98
|
+
path.join(otherDir, `${THEME_MODULE_BASENAME}${otherExtension}`),
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {unknown} value
|
|
104
|
+
* @param {string} label
|
|
105
|
+
*/
|
|
106
|
+
function validThemeRecord(value, label) {
|
|
107
|
+
if (!isRecord(value) || !isRecord(value.themes)) {
|
|
108
|
+
throw new ThemeStateError(
|
|
109
|
+
`${label} must carry a static ${THEME_RECORD_MARKER} header. Regenerate it with \`astryx theme add <slug> --import\`.`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const keys = Object.keys(value);
|
|
113
|
+
if (
|
|
114
|
+
keys.length !== 2 ||
|
|
115
|
+
!keys.includes('themes') ||
|
|
116
|
+
!keys.includes('defaultThemeSlug')
|
|
117
|
+
) {
|
|
118
|
+
throw new ThemeStateError(
|
|
119
|
+
`${label} ${THEME_RECORD_MARKER} header must contain only themes and defaultThemeSlug.`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** @type {Record<string, string>} */
|
|
124
|
+
const themes = {};
|
|
125
|
+
for (const [slug, owner] of Object.entries(value.themes)) {
|
|
126
|
+
if (
|
|
127
|
+
!THEME_SLUG_RE.test(slug) ||
|
|
128
|
+
typeof owner !== 'string' ||
|
|
129
|
+
owner.trim() === ''
|
|
130
|
+
) {
|
|
131
|
+
throw new ThemeStateError(
|
|
132
|
+
`${label} theme record must map lowercase kebab-case slugs to package names or local theme roots.`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
themes[slug] = owner;
|
|
136
|
+
}
|
|
137
|
+
if (
|
|
138
|
+
typeof value.defaultThemeSlug !== 'string' ||
|
|
139
|
+
!THEME_SLUG_RE.test(value.defaultThemeSlug)
|
|
140
|
+
) {
|
|
141
|
+
throw new ThemeStateError(
|
|
142
|
+
`${label} defaultThemeSlug must be a lowercase kebab-case slug. Regenerate it with \`astryx theme use <slug>\`.`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return {themes, defaultSlug: value.defaultThemeSlug};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Parse the generated module's record without executing the module.
|
|
150
|
+
* @param {string} source
|
|
151
|
+
* @param {string} label
|
|
152
|
+
*/
|
|
153
|
+
export function parseThemeModuleRecord(source, label = 'theme module') {
|
|
154
|
+
if (!source.includes(THEME_MODULE_MARKER)) {
|
|
155
|
+
throw new ThemeStateError(`${label} does not carry the Astryx generated marker.`);
|
|
156
|
+
}
|
|
157
|
+
const recordLines = source
|
|
158
|
+
.split(/\r?\n/u)
|
|
159
|
+
.filter(line => /^\s*\*\s*@astryx-theme-record\s+/u.test(line));
|
|
160
|
+
if (recordLines.length !== 1) {
|
|
161
|
+
throw new ThemeStateError(
|
|
162
|
+
`${label} must carry exactly one static ${THEME_RECORD_MARKER} header. Regenerate it with \`astryx theme add <slug> --import\`.`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const payload = recordLines[0].replace(
|
|
166
|
+
/^\s*\*\s*@astryx-theme-record\s+/u,
|
|
167
|
+
'',
|
|
168
|
+
);
|
|
169
|
+
let record;
|
|
170
|
+
try {
|
|
171
|
+
record = JSON.parse(payload);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
throw new ThemeStateError(
|
|
174
|
+
`${label} has an invalid ${THEME_RECORD_MARKER} header: ${error instanceof Error ? error.message : String(error)}`,
|
|
175
|
+
{cause: error},
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return validThemeRecord(record, label);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Preserve the one existing generated module. With none, choose the first
|
|
183
|
+
* conventional location. Two generated copies are ambiguous and fail closed.
|
|
184
|
+
* @param {string} projectDir
|
|
185
|
+
* @param {{forWrite?: boolean}} [options]
|
|
186
|
+
*/
|
|
187
|
+
export function resolveThemeModule(projectDir, {forWrite = false} = {}) {
|
|
188
|
+
const candidates = themeModuleCandidates(projectDir);
|
|
189
|
+
const generated = candidates.filter(file => {
|
|
190
|
+
try {
|
|
191
|
+
return fs.readFileSync(file, 'utf-8').includes(THEME_MODULE_MARKER);
|
|
192
|
+
} catch {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
if (generated.length > 1) {
|
|
197
|
+
throw new ThemeStateError(
|
|
198
|
+
`More than one generated theme module exists: ${generated
|
|
199
|
+
.map(file => projectPath(path.relative(projectDir, file)))
|
|
200
|
+
.join(', ')}. Keep one and remove the others before running the command again.`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
const file = generated[0] ?? candidates[0];
|
|
204
|
+
if (forWrite) {
|
|
205
|
+
try {
|
|
206
|
+
assertWithin(path.relative(projectDir, file), projectDir, {
|
|
207
|
+
label: 'generated theme module',
|
|
208
|
+
});
|
|
209
|
+
} catch (error) {
|
|
210
|
+
if (error instanceof PathSafetyError) {
|
|
211
|
+
throw new ThemeStateError(error.message, {cause: error});
|
|
212
|
+
}
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
let expectedOriginal;
|
|
217
|
+
if (fs.existsSync(file)) {
|
|
218
|
+
expectedOriginal = fs.readFileSync(file);
|
|
219
|
+
if (!expectedOriginal.toString('utf-8').includes(THEME_MODULE_MARKER)) {
|
|
220
|
+
if (forWrite) {
|
|
221
|
+
throw new ThemeStateError(
|
|
222
|
+
`Refusing to replace ${projectPath(path.relative(projectDir, file))}: it is not an Astryx-generated theme module. Move that file before adding themes.`,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
expectedOriginal = undefined;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
file,
|
|
230
|
+
path: projectPath(path.relative(projectDir, file)),
|
|
231
|
+
typescript: file.endsWith('.ts'),
|
|
232
|
+
expectedOriginal,
|
|
233
|
+
exists: generated.length === 1,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @typedef {object} ThemeState
|
|
239
|
+
* @property {string} projectDir
|
|
240
|
+
* @property {string} packageFile
|
|
241
|
+
* @property {Record<string, string>} themes
|
|
242
|
+
* @property {string|null} defaultSlug
|
|
243
|
+
* @property {string|null} legacyTheme
|
|
244
|
+
* @property {boolean} configured
|
|
245
|
+
* @property {ReturnType<typeof resolveThemeModule>} module
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Read app-theme state from the generated module. Only when no module exists is
|
|
250
|
+
* the released `package.json#astryx.theme` meaning returned as legacy input.
|
|
251
|
+
* @param {string} [cwd]
|
|
252
|
+
* @returns {ThemeState}
|
|
253
|
+
*/
|
|
254
|
+
export function readThemeState(cwd = process.cwd()) {
|
|
255
|
+
const {projectDir, packageFile} = findThemeProject(cwd);
|
|
256
|
+
const module = resolveThemeModule(projectDir);
|
|
257
|
+
if (module.exists && module.expectedOriginal) {
|
|
258
|
+
const record = parseThemeModuleRecord(
|
|
259
|
+
module.expectedOriginal.toString('utf-8'),
|
|
260
|
+
module.path,
|
|
261
|
+
);
|
|
262
|
+
return {
|
|
263
|
+
projectDir,
|
|
264
|
+
packageFile,
|
|
265
|
+
themes: record.themes,
|
|
266
|
+
defaultSlug: record.defaultSlug,
|
|
267
|
+
legacyTheme: null,
|
|
268
|
+
configured: true,
|
|
269
|
+
module,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
let legacyTheme = null;
|
|
274
|
+
try {
|
|
275
|
+
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf-8'));
|
|
276
|
+
if (
|
|
277
|
+
isRecord(pkg) &&
|
|
278
|
+
isRecord(pkg.astryx) &&
|
|
279
|
+
typeof pkg.astryx.theme === 'string'
|
|
280
|
+
) {
|
|
281
|
+
legacyTheme = pkg.astryx.theme;
|
|
282
|
+
}
|
|
283
|
+
} catch {
|
|
284
|
+
// Theme commands surface package problems at their own write boundary. A
|
|
285
|
+
// legacy lookup with no readable package field simply has no configured theme.
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
projectDir,
|
|
289
|
+
packageFile,
|
|
290
|
+
themes: {},
|
|
291
|
+
defaultSlug: null,
|
|
292
|
+
legacyTheme,
|
|
293
|
+
configured: false,
|
|
294
|
+
module,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @typedef {object} ResolvedAppTheme
|
|
300
|
+
* @property {string} slug
|
|
301
|
+
* @property {string} owner
|
|
302
|
+
* @property {string} exportName
|
|
303
|
+
* @property {string} module
|
|
304
|
+
* @property {string} stylesheet
|
|
305
|
+
* @property {string} [fontStylesheet]
|
|
306
|
+
* @property {string} moduleFile
|
|
307
|
+
* @property {string} stylesheetFile
|
|
308
|
+
* @property {string} [fontStylesheetFile]
|
|
309
|
+
* @property {'bundled'|'package'|'local'} source
|
|
310
|
+
*/
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Render one generated module from final resolved state.
|
|
314
|
+
* @param {ResolvedAppTheme[]} themes
|
|
315
|
+
* @param {string} defaultSlug
|
|
316
|
+
* @param {boolean} typescript
|
|
317
|
+
*/
|
|
318
|
+
export function renderThemeModule(themes, defaultSlug, typescript) {
|
|
319
|
+
if (!themes.some(theme => theme.slug === defaultSlug)) {
|
|
320
|
+
throw new ThemeStateError(
|
|
321
|
+
`Default theme "${defaultSlug}" is not added. Run \`astryx theme add ${defaultSlug} --import\` first.`,
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
/** @type {string[]} */
|
|
325
|
+
const imports = [];
|
|
326
|
+
/** @type {string[]} */
|
|
327
|
+
const entries = [];
|
|
328
|
+
/** @type {Record<string, string>} */
|
|
329
|
+
const owners = {};
|
|
330
|
+
themes.forEach((theme, index) => {
|
|
331
|
+
const local = `_astryxTheme${index}`;
|
|
332
|
+
imports.push(
|
|
333
|
+
`import {${theme.exportName} as ${local}} from ${JSON.stringify(theme.module)};`,
|
|
334
|
+
`import ${JSON.stringify(theme.stylesheet)};`,
|
|
335
|
+
);
|
|
336
|
+
if (theme.fontStylesheet) {
|
|
337
|
+
imports.push(`import ${JSON.stringify(theme.fontStylesheet)};`);
|
|
338
|
+
}
|
|
339
|
+
entries.push(` ${JSON.stringify(theme.slug)}: ${local},`);
|
|
340
|
+
owners[theme.slug] = theme.owner;
|
|
341
|
+
});
|
|
342
|
+
const record = JSON.stringify({themes: owners, defaultThemeSlug: defaultSlug});
|
|
343
|
+
return `/**\n * ${THEME_MODULE_MARKER}\n * ${THEME_RECORD_MARKER} ${record}\n */\n\n${imports.join(
|
|
344
|
+
'\n',
|
|
345
|
+
)}\n\nexport const themes = {\n${entries.join('\n')}\n}${
|
|
346
|
+
typescript ? ' as const' : ''
|
|
347
|
+
};\n${
|
|
348
|
+
typescript ? 'export type ThemeSlug = keyof typeof themes;\n' : ''
|
|
349
|
+
}\nexport const defaultThemeSlug${
|
|
350
|
+
typescript ? ': keyof typeof themes' : ''
|
|
351
|
+
} = ${JSON.stringify(defaultSlug)};\n`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Resolve a project-relative import from the generated module to a local file.
|
|
356
|
+
* @param {string} moduleFile
|
|
357
|
+
* @param {string} target
|
|
358
|
+
*/
|
|
359
|
+
export function localImportSpecifier(moduleFile, target) {
|
|
360
|
+
let relative = projectPath(path.relative(path.dirname(moduleFile), target));
|
|
361
|
+
if (!relative.startsWith('.')) relative = `./${relative}`;
|
|
362
|
+
return relative;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Plan the generated-module write. The caller applies it through the shared
|
|
367
|
+
* atomic transaction.
|
|
368
|
+
* @param {ThemeState} state
|
|
369
|
+
* @param {Record<string, string>} themes
|
|
370
|
+
* @param {string} defaultSlug
|
|
371
|
+
* @param {ResolvedAppTheme[]} resolvedThemes
|
|
372
|
+
*/
|
|
373
|
+
export function planThemeAppWrite(state, themes, defaultSlug, resolvedThemes) {
|
|
374
|
+
const module = resolveThemeModule(state.projectDir, {forWrite: true});
|
|
375
|
+
const entries = resolvedThemes.map(theme =>
|
|
376
|
+
theme.source === 'local'
|
|
377
|
+
? {
|
|
378
|
+
...theme,
|
|
379
|
+
module: localImportSpecifier(module.file, theme.moduleFile),
|
|
380
|
+
stylesheet: localImportSpecifier(module.file, theme.stylesheetFile),
|
|
381
|
+
...(theme.fontStylesheetFile
|
|
382
|
+
? {
|
|
383
|
+
fontStylesheet: localImportSpecifier(
|
|
384
|
+
module.file,
|
|
385
|
+
theme.fontStylesheetFile,
|
|
386
|
+
),
|
|
387
|
+
}
|
|
388
|
+
: {}),
|
|
389
|
+
}
|
|
390
|
+
: theme,
|
|
391
|
+
);
|
|
392
|
+
for (const theme of entries) {
|
|
393
|
+
if (themes[theme.slug] !== theme.owner) {
|
|
394
|
+
throw new ThemeStateError(
|
|
395
|
+
`Theme record for "${theme.slug}" does not match its resolved owner.`,
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const moduleContents = renderThemeModule(
|
|
400
|
+
entries,
|
|
401
|
+
defaultSlug,
|
|
402
|
+
module.typescript,
|
|
403
|
+
);
|
|
404
|
+
return {
|
|
405
|
+
module,
|
|
406
|
+
entries,
|
|
407
|
+
plan: {
|
|
408
|
+
path: module.file,
|
|
409
|
+
contents: moduleContents,
|
|
410
|
+
createOnly: module.expectedOriginal == null,
|
|
411
|
+
...(module.expectedOriginal != null
|
|
412
|
+
? {expectedOriginal: module.expectedOriginal}
|
|
413
|
+
: {}),
|
|
414
|
+
},
|
|
415
|
+
moduleContents,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
LOCAL_THEME_ROOT,
|
|
8
|
+
THEME_MODULE_MARKER,
|
|
9
|
+
parseThemeModuleRecord,
|
|
10
|
+
planThemeAppWrite,
|
|
11
|
+
readThemeState,
|
|
12
|
+
renderThemeModule,
|
|
13
|
+
resolveThemeModule,
|
|
14
|
+
} from './theme-state.mjs';
|
|
15
|
+
|
|
16
|
+
/** @type {string[]} */
|
|
17
|
+
const dirs = [];
|
|
18
|
+
|
|
19
|
+
function project(pkg = {name: 'app'}) {
|
|
20
|
+
const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-theme-state-'));
|
|
21
|
+
dirs.push(dir);
|
|
22
|
+
fs.writeFileSync(path.join(dir, 'package.json'), `${JSON.stringify(pkg)}\n`);
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
while (dirs.length > 0) {
|
|
28
|
+
fs.rmSync(dirs.pop(), {recursive: true, force: true});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function packageEntry(slug = 'ocean') {
|
|
33
|
+
return {
|
|
34
|
+
slug,
|
|
35
|
+
owner: '@acme/themes',
|
|
36
|
+
exportName: `${slug}Theme`,
|
|
37
|
+
module: `@acme/themes/themes/${slug}`,
|
|
38
|
+
stylesheet: `@acme/themes/themes/${slug}.css`,
|
|
39
|
+
moduleFile: `/node_modules/@acme/themes/themes/${slug}.js`,
|
|
40
|
+
stylesheetFile: `/node_modules/@acme/themes/themes/${slug}.css`,
|
|
41
|
+
source: /** @type {const} */ ('package'),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('generated theme-module state', () => {
|
|
46
|
+
it('keeps released package.json astryx.theme meaning only without a module', () => {
|
|
47
|
+
const dir = project({name: 'app', astryx: {theme: '@acme/legacy'}});
|
|
48
|
+
expect(readThemeState(dir)).toMatchObject({
|
|
49
|
+
themes: {},
|
|
50
|
+
defaultSlug: null,
|
|
51
|
+
legacyTheme: '@acme/legacy',
|
|
52
|
+
configured: false,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('renders and statically reads the complete record without executing it', () => {
|
|
57
|
+
const source = renderThemeModule([packageEntry()], 'ocean', true);
|
|
58
|
+
expect(source).toContain(THEME_MODULE_MARKER);
|
|
59
|
+
expect(source).toContain('export type ThemeSlug = keyof typeof themes');
|
|
60
|
+
expect(
|
|
61
|
+
[...source.matchAll(/^export (?:const|type) (\w+)/gmu)].map(
|
|
62
|
+
match => match[1],
|
|
63
|
+
),
|
|
64
|
+
).toEqual(['themes', 'ThemeSlug', 'defaultThemeSlug']);
|
|
65
|
+
expect(source).not.toContain('export const themeOwners');
|
|
66
|
+
expect(parseThemeModuleRecord(source)).toEqual({
|
|
67
|
+
themes: {ocean: '@acme/themes'},
|
|
68
|
+
defaultSlug: 'ocean',
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('emits JavaScript without TypeScript syntax', () => {
|
|
73
|
+
const source = renderThemeModule([packageEntry()], 'ocean', false);
|
|
74
|
+
expect(source).not.toContain('export type');
|
|
75
|
+
expect(source).not.toContain(' as const');
|
|
76
|
+
expect(
|
|
77
|
+
[...source.matchAll(/^export const (\w+)/gmu)].map(match => match[1]),
|
|
78
|
+
).toEqual(['themes', 'defaultThemeSlug']);
|
|
79
|
+
expect(parseThemeModuleRecord(source)).toEqual({
|
|
80
|
+
themes: {ocean: '@acme/themes'},
|
|
81
|
+
defaultSlug: 'ocean',
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('uses src for a TypeScript project and the project root without src', () => {
|
|
86
|
+
const typed = project();
|
|
87
|
+
fs.mkdirSync(path.join(typed, 'src'));
|
|
88
|
+
fs.writeFileSync(path.join(typed, 'tsconfig.json'), '{}\n');
|
|
89
|
+
expect(resolveThemeModule(typed).path).toBe('src/astryx-themes.ts');
|
|
90
|
+
|
|
91
|
+
const plain = project();
|
|
92
|
+
expect(resolveThemeModule(plain).path).toBe('astryx-themes.js');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('preserves an existing marked module when project shape changes', () => {
|
|
96
|
+
const dir = project();
|
|
97
|
+
const existing = path.join(dir, 'astryx-themes.js');
|
|
98
|
+
fs.writeFileSync(
|
|
99
|
+
existing,
|
|
100
|
+
renderThemeModule([packageEntry()], 'ocean', false),
|
|
101
|
+
);
|
|
102
|
+
fs.mkdirSync(path.join(dir, 'src'));
|
|
103
|
+
fs.writeFileSync(path.join(dir, 'tsconfig.json'), '{}\n');
|
|
104
|
+
expect(resolveThemeModule(dir).file).toBe(existing);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('fails closed when two generated modules exist', () => {
|
|
108
|
+
const dir = project();
|
|
109
|
+
fs.mkdirSync(path.join(dir, 'src'));
|
|
110
|
+
const source = renderThemeModule([packageEntry()], 'ocean', false);
|
|
111
|
+
fs.writeFileSync(path.join(dir, 'astryx-themes.js'), source);
|
|
112
|
+
fs.writeFileSync(path.join(dir, 'src', 'astryx-themes.js'), source);
|
|
113
|
+
expect(() => readThemeState(dir)).toThrow(
|
|
114
|
+
/more than one generated theme module/i,
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('refuses to replace an authored file at the selected path', () => {
|
|
119
|
+
const dir = project();
|
|
120
|
+
fs.writeFileSync(
|
|
121
|
+
path.join(dir, 'astryx-themes.js'),
|
|
122
|
+
'export const mine = true;\n',
|
|
123
|
+
);
|
|
124
|
+
const state = readThemeState(dir);
|
|
125
|
+
expect(() =>
|
|
126
|
+
planThemeAppWrite(state, {ocean: '@acme/themes'}, 'ocean', [
|
|
127
|
+
packageEntry(),
|
|
128
|
+
]),
|
|
129
|
+
).toThrow(/refusing to replace/i);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('rejects a generated-module write through a symlink outside the project', () => {
|
|
133
|
+
const dir = project();
|
|
134
|
+
const outside = fs.mkdtempSync(
|
|
135
|
+
path.join(process.cwd(), '.astryx-theme-state-outside-'),
|
|
136
|
+
);
|
|
137
|
+
dirs.push(outside);
|
|
138
|
+
fs.symlinkSync(outside, path.join(dir, 'src'));
|
|
139
|
+
fs.writeFileSync(path.join(dir, 'tsconfig.json'), '{}\n');
|
|
140
|
+
const state = readThemeState(dir);
|
|
141
|
+
|
|
142
|
+
expect(() =>
|
|
143
|
+
planThemeAppWrite(state, {ocean: '@acme/themes'}, 'ocean', [
|
|
144
|
+
packageEntry(),
|
|
145
|
+
]),
|
|
146
|
+
).toThrow(/outside the project root.*symlink/i);
|
|
147
|
+
expect(fs.existsSync(path.join(outside, 'astryx-themes.ts'))).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('records a local owner and renders local paths relative to the module', () => {
|
|
151
|
+
const dir = project();
|
|
152
|
+
fs.mkdirSync(path.join(dir, 'src'));
|
|
153
|
+
fs.writeFileSync(path.join(dir, 'tsconfig.json'), '{}\n');
|
|
154
|
+
const state = readThemeState(dir);
|
|
155
|
+
const sourceDir = path.join(dir, 'src', 'themes', 'ocean');
|
|
156
|
+
const prepared = planThemeAppWrite(
|
|
157
|
+
state,
|
|
158
|
+
{ocean: LOCAL_THEME_ROOT},
|
|
159
|
+
'ocean',
|
|
160
|
+
[
|
|
161
|
+
{
|
|
162
|
+
slug: 'ocean',
|
|
163
|
+
owner: LOCAL_THEME_ROOT,
|
|
164
|
+
exportName: 'oceanTheme',
|
|
165
|
+
module: '',
|
|
166
|
+
stylesheet: '',
|
|
167
|
+
moduleFile: path.join(sourceDir, 'ocean.js'),
|
|
168
|
+
stylesheetFile: path.join(sourceDir, 'ocean.css'),
|
|
169
|
+
source: 'local',
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
);
|
|
173
|
+
expect(prepared.moduleContents).toContain('from "./themes/ocean/ocean.js"');
|
|
174
|
+
expect(prepared.moduleContents).toContain(
|
|
175
|
+
'import "./themes/ocean/ocean.css"',
|
|
176
|
+
);
|
|
177
|
+
expect(parseThemeModuleRecord(prepared.moduleContents)).toEqual({
|
|
178
|
+
themes: {ocean: LOCAL_THEME_ROOT},
|
|
179
|
+
defaultSlug: 'ocean',
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -127,11 +127,13 @@ export function discoverIntegrationComponents(integration: {
|
|
|
127
127
|
/**
|
|
128
128
|
* Load and validate every discovered integration component independently.
|
|
129
129
|
* Invalid metadata or a missing same-stem source removes only that component;
|
|
130
|
-
* callers can report the returned errors while retaining valid siblings.
|
|
130
|
+
* callers can report the returned errors while retaining valid siblings. A
|
|
131
|
+
* component whose doc sets `replaces` carries the value as written; the
|
|
132
|
+
* component replacement resolver decides what it means.
|
|
131
133
|
*
|
|
132
134
|
* @param {{name: string, components?: string, issuesUrl?: string}} integration
|
|
133
135
|
* @returns {Promise<{
|
|
134
|
-
* components: Array<{name: string, package: string, docPath: string, sourcePath: string, issuesUrl: string|undefined, group: string|null}>,
|
|
136
|
+
* components: Array<{name: string, package: string, docPath: string, sourcePath: string, issuesUrl: string|undefined, group: string|null, replaces?: unknown}>,
|
|
135
137
|
* discovered: Array<{name: string, package: string, docPath: string, sourcePath: string|null, issuesUrl: string|undefined, group: string|null}>,
|
|
136
138
|
* errors: Array<{name: string, message: string}>,
|
|
137
139
|
* }>}
|
|
@@ -148,6 +150,7 @@ export function discoverValidIntegrationComponents(integration: {
|
|
|
148
150
|
sourcePath: string;
|
|
149
151
|
issuesUrl: string | undefined;
|
|
150
152
|
group: string | null;
|
|
153
|
+
replaces?: unknown;
|
|
151
154
|
}>;
|
|
152
155
|
discovered: Array<{
|
|
153
156
|
name: string;
|
|
@@ -696,18 +696,20 @@ export function discoverIntegrationComponents(integration) {
|
|
|
696
696
|
/**
|
|
697
697
|
* Load and validate every discovered integration component independently.
|
|
698
698
|
* Invalid metadata or a missing same-stem source removes only that component;
|
|
699
|
-
* callers can report the returned errors while retaining valid siblings.
|
|
699
|
+
* callers can report the returned errors while retaining valid siblings. A
|
|
700
|
+
* component whose doc sets `replaces` carries the value as written; the
|
|
701
|
+
* component replacement resolver decides what it means.
|
|
700
702
|
*
|
|
701
703
|
* @param {{name: string, components?: string, issuesUrl?: string}} integration
|
|
702
704
|
* @returns {Promise<{
|
|
703
|
-
* components: Array<{name: string, package: string, docPath: string, sourcePath: string, issuesUrl: string|undefined, group: string|null}>,
|
|
705
|
+
* components: Array<{name: string, package: string, docPath: string, sourcePath: string, issuesUrl: string|undefined, group: string|null, replaces?: unknown}>,
|
|
704
706
|
* discovered: Array<{name: string, package: string, docPath: string, sourcePath: string|null, issuesUrl: string|undefined, group: string|null}>,
|
|
705
707
|
* errors: Array<{name: string, message: string}>,
|
|
706
708
|
* }>}
|
|
707
709
|
*/
|
|
708
710
|
export async function discoverValidIntegrationComponents(integration) {
|
|
709
711
|
const discovered = discoverIntegrationComponents(integration);
|
|
710
|
-
/** @type {Array<{name: string, package: string, docPath: string, sourcePath: string, issuesUrl: string|undefined, group: string|null}>} */
|
|
712
|
+
/** @type {Array<{name: string, package: string, docPath: string, sourcePath: string, issuesUrl: string|undefined, group: string|null, replaces?: unknown}>} */
|
|
711
713
|
const components = [];
|
|
712
714
|
/** @type {Array<{name: string, message: string}>} */
|
|
713
715
|
const errors = [];
|
|
@@ -721,11 +723,15 @@ export async function discoverValidIntegrationComponents(integration) {
|
|
|
721
723
|
continue;
|
|
722
724
|
}
|
|
723
725
|
try {
|
|
724
|
-
await loadComponentDoc(record.docPath);
|
|
725
|
-
|
|
726
|
+
const doc = await loadComponentDoc(record.docPath);
|
|
727
|
+
const valid =
|
|
726
728
|
/** @type {{name: string, package: string, docPath: string, sourcePath: string, issuesUrl: string|undefined, group: string|null}} */ (
|
|
727
729
|
record
|
|
728
|
-
)
|
|
730
|
+
);
|
|
731
|
+
components.push(
|
|
732
|
+
doc != null && typeof doc === 'object' && doc.replaces !== undefined
|
|
733
|
+
? {...valid, replaces: doc.replaces}
|
|
734
|
+
: valid,
|
|
729
735
|
);
|
|
730
736
|
} catch (err) {
|
|
731
737
|
errors.push({
|