@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0404a74
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/README.md +76 -86
- package/api/build/_adapter.d.mts +17 -0
- package/api/build/_adapter.mjs +53 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/blocks/blocks.weights.json +1 -1
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.d.mts +6 -4
- package/api/build/kit/rank.mjs +132 -28
- package/api/build/kit/signals.d.mts +7 -1
- package/api/build/kit/signals.mjs +21 -10
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +14 -9
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +351 -46
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +86 -0
- package/api/build/kit/words.mjs +241 -1
- package/api/build/tree.mjs +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -6
- package/api/component/_adapter.d.mts +26 -2
- package/api/component/_adapter.mjs +135 -8
- package/api/component/component.mjs +14 -1
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +11 -1
- package/api/discover/_adapter.mjs +95 -1
- package/api/discover/detail/item/item.mjs +5 -0
- package/api/discover/discover.mjs +12 -3
- package/api/discover/discover.type.d.mts +16 -3
- package/api/discover/discover.type.mjs +13 -3
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +57 -2
- package/api/docs/_adapter.mjs +266 -33
- package/api/docs/_entry-names-lazily.d.mts +22 -0
- package/api/docs/_entry-names-lazily.mjs +25 -0
- package/api/docs/_entry-names.d.mts +23 -0
- package/api/docs/_entry-names.mjs +105 -0
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +54 -5
- package/api/doctor/_adapter.mjs +162 -11
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +15 -3
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +31 -7
- package/api/doctor/theme-checks.d.mts +35 -3
- package/api/doctor/theme-checks.mjs +377 -29
- package/api/hook/_adapter.d.mts +10 -4
- package/api/hook/_adapter.mjs +41 -5
- package/api/hook/detail/detail.mjs +5 -2
- package/api/hook/detail/params/params.mjs +10 -3
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/add-helpers.mjs +10 -0
- package/api/integration/authoring-checks.mjs +11 -8
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/pack-check.mjs +16 -1
- package/api/integration/validate-integration.d.mts +18 -6
- package/api/integration/validate-integration.mjs +129 -15
- package/api/integration/validate-integration.type.d.mts +22 -0
- package/api/integration/validate-integration.type.mjs +2 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +53 -1
- package/api/render/render.type.mjs +32 -2
- package/api/search/ORDERING.md +2 -2
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.d.mts +9 -4
- package/api/search/_candidate-score.mjs +133 -46
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +14 -0
- package/api/search/_lexical.mjs +93 -11
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/template/_adapter.d.mts +16 -0
- package/api/template/_adapter.mjs +39 -2
- package/api/template/cdn/cdn.mjs +37 -8
- package/api/template/copy/copy.d.mts +6 -3
- package/api/template/copy/copy.mjs +40 -8
- package/api/template/template.doc.mjs +3 -3
- package/api/template/template.mjs +63 -11
- package/api/template/template.type.d.mts +1 -0
- package/api/template/template.type.mjs +1 -0
- package/api/theme/_adapter.d.mts +12 -1
- package/api/theme/_adapter.mjs +132 -13
- package/api/theme/_app-provider.d.mts +31 -0
- package/api/theme/_app-provider.mjs +135 -0
- package/api/theme/add/add.mjs +3 -1
- package/api/theme/build/build.d.mts +142 -1
- package/api/theme/build/build.mjs +692 -284
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +10 -0
- package/api/theme/build/font-warning.d.mts +80 -5
- package/api/theme/build/font-warning.mjs +323 -55
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/build/null-values.d.mts +28 -0
- package/api/theme/build/null-values.mjs +191 -0
- package/api/theme/list/list.mjs +17 -1
- package/api/theme/remove/remove.d.mts +2 -1
- package/api/theme/remove/remove.mjs +7 -3
- package/api/theme/theme.type.d.mts +78 -1
- package/api/theme/theme.type.mjs +38 -2
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +8 -5
- package/api/theme-edit/_adapter.d.mts +116 -4
- package/api/theme-edit/_adapter.mjs +1058 -93
- package/api/theme-edit/_catalog.d.mts +46 -2
- package/api/theme-edit/_catalog.mjs +115 -14
- package/api/theme-edit/_check.d.mts +133 -24
- package/api/theme-edit/_check.mjs +3392 -531
- package/api/theme-edit/_color.d.mts +26 -0
- package/api/theme-edit/_color.mjs +92 -2
- package/api/theme-edit/_compiler.d.mts +5 -1
- package/api/theme-edit/_compiler.mjs +141 -17
- package/api/theme-edit/_context.d.mts +74 -6
- package/api/theme-edit/_context.mjs +468 -76
- package/api/theme-edit/_css.d.mts +21 -0
- package/api/theme-edit/_css.mjs +87 -14
- package/api/theme-edit/_edit.d.mts +74 -7
- package/api/theme-edit/_edit.mjs +4426 -319
- package/api/theme-edit/_how-commands.d.mts +76 -1
- package/api/theme-edit/_how-commands.mjs +793 -9
- package/api/theme-edit/_how-question.d.mts +97 -6
- package/api/theme-edit/_how-question.mjs +9184 -747
- package/api/theme-edit/_how.d.mts +5 -2
- package/api/theme-edit/_how.mjs +255 -46
- package/api/theme-edit/_importers.d.mts +38 -0
- package/api/theme-edit/_importers.mjs +188 -0
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_name-rule.d.mts +11 -0
- package/api/theme-edit/_name-rule.mjs +12 -0
- package/api/theme-edit/_normal.d.mts +322 -0
- package/api/theme-edit/_normal.mjs +1630 -0
- package/api/theme-edit/_palette.d.mts +49 -0
- package/api/theme-edit/_palette.mjs +180 -38
- package/api/theme-edit/_part-words.d.mts +39 -0
- package/api/theme-edit/_part-words.mjs +152 -0
- package/api/theme-edit/_parts.d.mts +55 -3
- package/api/theme-edit/_parts.mjs +421 -36
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +1108 -599
- package/api/theme-edit/_preview.d.mts +156 -19
- package/api/theme-edit/_preview.mjs +809 -180
- package/api/theme-edit/_project.d.mts +61 -1
- package/api/theme-edit/_project.mjs +177 -6
- package/api/theme-edit/_settings.d.mts +619 -48
- package/api/theme-edit/_settings.mjs +4910 -617
- package/api/theme-edit/_tables.d.mts +41 -0
- package/api/theme-edit/_tables.mjs +261 -41
- package/api/theme-edit/_vet.d.mts +31 -0
- package/api/theme-edit/_vet.mjs +114 -8
- package/api/theme-edit/theme-edit.type.d.mts +34 -2
- package/api/theme-edit/theme-edit.type.mjs +18 -3
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
- package/api/theme-edit/themeEditNew.doc.mjs +7 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/api/upgrade/upgrade.mjs +16 -1
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/jscodeshift.d.ts +1 -1
- package/assets/codemods/run-codemod.mjs +151 -18
- package/assets/codemods/runner.mjs +1 -4
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +2 -0
- package/assets/docs/theme.doc.dense.mjs +76 -7
- package/assets/docs/theme.doc.mjs +66 -2
- package/assets/docs/theme.doc.zh.mjs +51 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +2 -2
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/font-setup.doc.mjs +1 -1
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/render-pages.doc.mjs +46 -5
- package/assets/docs/tree/share-a-page.doc.mjs +157 -0
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/docs-routes.generated.json +1 -0
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.tsx +43 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/page.tsx +31 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +1 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +1 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-comparison/page.tsx +2 -2
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/page.tsx +1 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/page.tsx +60 -7
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/page.tsx +13 -13
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/page.tsx +14 -2
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/page.tsx +9 -0
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/form-wizard-vertical/page.tsx +23 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +33 -2
- package/assets/templates/pages/kanban-board/page.tsx +12 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/page.tsx +16 -0
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/page.tsx +19 -6
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/messaging-shell/template.doc.mjs +6 -0
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/payment-form/page.tsx +30 -4
- package/assets/templates/pages/product-detail/page.tsx +26 -2
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/page.tsx +162 -12
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/page.tsx +11 -3
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/page.tsx +9 -0
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/page.tsx +161 -133
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/page.tsx +14 -1
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/page.tsx +47 -7
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +9 -2
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +9 -9
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +24 -1
- package/authoring/integration/schema.mjs +126 -4
- package/authoring/integration/type.ts +14 -0
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/discover.mjs +70 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +44 -6
- package/clients/cli/commands/doctor.mjs +84 -16
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +1032 -134
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +4 -4
- package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.doc.mjs +1 -1
- package/clients/cli/commands/template.mjs +15 -2
- package/clients/cli/commands/theme-add.doc.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +13 -5
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +849 -441
- package/clients/cli/commands/upgrade.mjs +46 -8
- package/clients/cli/index.mjs +9 -19
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +265 -29
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/lib/stray-option.mjs +478 -0
- package/clients/cli/lib/unknown-command.mjs +353 -0
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/project.d.mts +8 -0
- package/foundation/config/project.mjs +26 -29
- package/foundation/config/theme-state.d.mts +31 -2
- package/foundation/config/theme-state.mjs +140 -8
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/cli-self-doc-names.d.mts +13 -0
- package/foundation/discovery/cli-self-doc-names.mjs +51 -0
- package/foundation/discovery/cli-self-docs.d.mts +0 -2
- package/foundation/discovery/cli-self-docs.mjs +2 -15
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +59 -10
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/core-component-docs.d.mts +29 -0
- package/foundation/discovery/core-component-docs.mjs +83 -0
- package/foundation/discovery/core-theme-facts.d.mts +70 -0
- package/foundation/discovery/core-theme-facts.mjs +384 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/docs-discovery.d.mts +66 -9
- package/foundation/discovery/docs-discovery.mjs +126 -60
- package/foundation/discovery/entry-name-files.d.mts +106 -0
- package/foundation/discovery/entry-name-files.mjs +354 -0
- package/foundation/discovery/hook-discovery.d.mts +18 -2
- package/foundation/discovery/hook-discovery.mjs +93 -42
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-component-views.d.mts +15 -0
- package/foundation/discovery/integration-component-views.mjs +91 -0
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/module-exports.d.mts +26 -1
- package/foundation/discovery/module-exports.mjs +114 -40
- package/foundation/discovery/name-roots.d.mts +38 -0
- package/foundation/discovery/name-roots.mjs +108 -0
- package/foundation/discovery/next-routes.d.mts +48 -0
- package/foundation/discovery/next-routes.mjs +181 -0
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-search-catalog.d.mts +115 -0
- package/foundation/discovery/stored-search-catalog.mjs +297 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +40 -18
- package/foundation/discovery/template-adapter.d.mts +49 -29
- package/foundation/discovery/template-adapter.mjs +89 -99
- package/foundation/discovery/template-destination.d.mts +28 -0
- package/foundation/discovery/template-destination.mjs +104 -0
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/template-ids.d.mts +69 -0
- package/foundation/discovery/template-ids.mjs +199 -0
- package/foundation/discovery/theme-discovery.d.mts +12 -0
- package/foundation/discovery/theme-discovery.mjs +34 -4
- package/foundation/discovery/theme-imports.d.mts +24 -0
- package/foundation/discovery/theme-imports.mjs +61 -4
- package/foundation/discovery/theming-targets.d.mts +13 -5
- package/foundation/discovery/theming-targets.mjs +41 -47
- package/foundation/doc-compiler/generated-levels.d.mts +43 -0
- package/foundation/doc-compiler/generated-levels.mjs +72 -0
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/literal-doc.d.mts +12 -0
- package/foundation/doc-compiler/literal-doc.mjs +322 -0
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +29 -0
- package/foundation/doc-compiler/stored-docs.mjs +63 -1
- package/foundation/doc-compiler/tree.d.mts +4 -84
- package/foundation/doc-compiler/tree.mjs +4 -62
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +46 -0
- package/foundation/fonts/font-stylesheet.mjs +173 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/file-protection.mjs +16 -5
- package/foundation/fs/gather-cache.d.mts +94 -4
- package/foundation/fs/gather-cache.mjs +671 -106
- package/foundation/fs/glob.d.mts +16 -0
- package/foundation/fs/glob.mjs +105 -0
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +80 -0
- package/foundation/fs/kept-tree.mjs +240 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/path-safety.d.mts +11 -2
- package/foundation/fs/path-safety.mjs +108 -18
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +56 -7
- package/foundation/fs/read-record.mjs +280 -56
- package/foundation/fs/regular-file.d.mts +29 -0
- package/foundation/fs/regular-file.mjs +77 -0
- package/foundation/fs/stop-cleanup.d.mts +12 -0
- package/foundation/fs/stop-cleanup.mjs +66 -0
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/integrations.d.mts +23 -1
- package/foundation/integrations/integrations.mjs +18 -1
- package/foundation/integrations/pack-state.d.mts +75 -0
- package/foundation/integrations/pack-state.mjs +314 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/shipped-imports.d.mts +122 -0
- package/foundation/integrations/shipped-imports.mjs +497 -0
- package/foundation/integrations/validate-contributions.d.mts +0 -17
- package/foundation/integrations/validate-contributions.mjs +59 -333
- package/foundation/render/assets.mjs +52 -7
- package/foundation/render/charts.d.mts +78 -27
- package/foundation/render/charts.mjs +266 -90
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +70 -7
- package/foundation/render/embedded-imports.mjs +132 -41
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/layers.d.mts +30 -0
- package/foundation/render/layers.mjs +158 -0
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/offline.d.mts +32 -0
- package/foundation/render/offline.mjs +56 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +354 -21
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +192 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +46 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +79 -5
- package/foundation/render/render-page.mjs +735 -109
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +6 -6
- package/foundation/suggest/name-index.d.mts +148 -0
- package/foundation/suggest/name-index.mjs +317 -0
- package/foundation/suggest/other-command.d.mts +140 -0
- package/foundation/suggest/other-command.mjs +756 -0
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/css-escape.d.mts +18 -0
- package/foundation/text/css-escape.mjs +35 -0
- package/foundation/text/entry-names.d.mts +14 -0
- package/foundation/text/entry-names.mjs +14 -0
- package/foundation/text/string-utils.d.mts +46 -6
- package/foundation/text/string-utils.mjs +118 -20
- package/foundation/text/suggest-order.d.mts +47 -4
- package/foundation/text/suggest-order.mjs +174 -5
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -59,11 +59,12 @@
|
|
|
59
59
|
*/
|
|
60
60
|
|
|
61
61
|
import * as fs from 'node:fs';
|
|
62
|
+
import * as os from 'node:os';
|
|
62
63
|
import * as path from 'node:path';
|
|
63
64
|
import {createRequire, isBuiltin} from 'node:module';
|
|
64
65
|
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
65
66
|
import {babelParse as parse} from '../../../foundation/runtime/lazy-dependencies.mjs';
|
|
66
|
-
import {
|
|
67
|
+
import {jitiCacheOptions} from '../../../foundation/fs/jiti-cache.mjs';
|
|
67
68
|
import {
|
|
68
69
|
formatCliCommand,
|
|
69
70
|
getCliInvocation,
|
|
@@ -90,24 +91,32 @@ import {validatePrivateVars} from '../../../foundation/config/theme-private-vars
|
|
|
90
91
|
import {AstryxError} from '../../error.mjs';
|
|
91
92
|
import {applyWrites} from '../../integration/add-helpers.mjs';
|
|
92
93
|
import {logger} from '../../logger.mjs';
|
|
93
|
-
import {
|
|
94
|
+
import {
|
|
95
|
+
coreThemeTargets,
|
|
96
|
+
coreThemeValues,
|
|
97
|
+
keepCoreThemeFacts,
|
|
98
|
+
} from '../../../foundation/discovery/core-theme-facts.mjs';
|
|
94
99
|
import {THEME_SOURCE_EXTENSIONS} from '../../../foundation/discovery/theme-module-extensions.mjs';
|
|
95
100
|
import {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} from '../../../foundation/
|
|
101
|
+
createJiti,
|
|
102
|
+
withEmptyStylesheets,
|
|
103
|
+
} from '../../../foundation/fs/module-loader.mjs';
|
|
104
|
+
import {targetsByKey} from '../../../foundation/discovery/theming-targets.mjs';
|
|
99
105
|
import {
|
|
100
106
|
collectUnloadedFonts,
|
|
101
107
|
formatBatchFontLoadingHelp,
|
|
102
108
|
formatFontLoadingHelp,
|
|
103
109
|
} from './font-warning.mjs';
|
|
104
110
|
import {interceptCore} from './core-interception.mjs';
|
|
111
|
+
import {irregularFileKind} from '../../../foundation/fs/regular-file.mjs';
|
|
112
|
+
import {keyPathLine, nullThemeValues} from './null-values.mjs';
|
|
105
113
|
import {
|
|
106
114
|
installCommandFor,
|
|
107
115
|
parsedSpecifiers,
|
|
108
116
|
} from '../../../foundation/discovery/template-needs.mjs';
|
|
109
117
|
import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
|
|
110
118
|
import {resolveIconImports} from './icon-imports.mjs';
|
|
119
|
+
import {generatedMark} from '../../theme-edit/_marks.mjs';
|
|
111
120
|
|
|
112
121
|
// Import shared theme processing from core. `astryx theme build` MUST produce the
|
|
113
122
|
// exact same CSS as the `<Theme>` runtime, so it has exactly one generation
|
|
@@ -324,7 +333,9 @@ function importTarget(dir, subpath) {
|
|
|
324
333
|
/** @param {string} file @returns {string} its real path, or itself */
|
|
325
334
|
function realOrSelf(file) {
|
|
326
335
|
try {
|
|
327
|
-
|
|
336
|
+
// The native form spells a path as the disk does (its own case on a
|
|
337
|
+
// case-insensitive disk), so two spellings of one file compare equal.
|
|
338
|
+
return fs.realpathSync.native(file);
|
|
328
339
|
} catch {
|
|
329
340
|
return file;
|
|
330
341
|
}
|
|
@@ -333,10 +344,12 @@ function realOrSelf(file) {
|
|
|
333
344
|
/**
|
|
334
345
|
* `target` spelled through real directories: the deepest ancestor that exists
|
|
335
346
|
* is resolved through its symlinks, and the missing rest is appended as given.
|
|
347
|
+
* The build groups and locates its outputs by it, and the theme editor's
|
|
348
|
+
* compile guard reads paths through it too, so both read a path the same way.
|
|
336
349
|
* @param {string} target absolute path
|
|
337
350
|
* @returns {string}
|
|
338
351
|
*/
|
|
339
|
-
function realLocation(target) {
|
|
352
|
+
export function realLocation(target) {
|
|
340
353
|
/** @type {string[]} */
|
|
341
354
|
const missing = [];
|
|
342
355
|
let existing = target;
|
|
@@ -786,9 +799,9 @@ const FAMILY_REMEDY =
|
|
|
786
799
|
/**
|
|
787
800
|
* Refuse an output outside `root`: every write is confined, whether `out` names
|
|
788
801
|
* the path or it defaults to the theme file's directory (architecture:cli-surface
|
|
789
|
-
* INV10).
|
|
790
|
-
*
|
|
791
|
-
*
|
|
802
|
+
* INV10). assertWithin reads the absolute path, so a path that reaches the
|
|
803
|
+
* working directory through a symlink is inside it, and a symlink inside it
|
|
804
|
+
* that leads elsewhere is not.
|
|
792
805
|
* @param {string} dest absolute output path
|
|
793
806
|
* @param {string} root the directory writes stay inside: the working directory
|
|
794
807
|
* @param {string} remedy what to do instead; ends the error message
|
|
@@ -796,7 +809,7 @@ const FAMILY_REMEDY =
|
|
|
796
809
|
*/
|
|
797
810
|
function confineOutput(dest, root, remedy, shown = dest) {
|
|
798
811
|
try {
|
|
799
|
-
assertWithin(
|
|
812
|
+
assertWithin(dest, root, {
|
|
800
813
|
allowAbsolute: true,
|
|
801
814
|
label: 'output path',
|
|
802
815
|
});
|
|
@@ -818,7 +831,7 @@ function confineOutputs(writes, root, remedy) {
|
|
|
818
831
|
}
|
|
819
832
|
|
|
820
833
|
/** @param {string} dest absolute output path @param {string} root @returns {boolean} whether a build at `root` refuses to write `dest` */
|
|
821
|
-
function refusedOutput(dest, root) {
|
|
834
|
+
export function refusedOutput(dest, root) {
|
|
822
835
|
try {
|
|
823
836
|
confineOutput(dest, root, '');
|
|
824
837
|
return false;
|
|
@@ -925,8 +938,85 @@ function isDirectorySync(file) {
|
|
|
925
938
|
}
|
|
926
939
|
}
|
|
927
940
|
|
|
928
|
-
/**
|
|
941
|
+
/**
|
|
942
|
+
* The marks a file's leading comment carries (see `generatedMark`): a theme
|
|
943
|
+
* build's output, or a file the theme editor writes, with the command it
|
|
944
|
+
* names. The one reader build and doctor share.
|
|
945
|
+
* @param {string} source the start of the file
|
|
946
|
+
* @param {string} [file] its path, for a mark that names no exact command
|
|
947
|
+
*/
|
|
948
|
+
export function fileMark(source, file) {
|
|
949
|
+
return generatedMark(source, GENERATED_MARKER, file);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* The command a file's leading comment says writes it, when another CLI
|
|
954
|
+
* command generates it (the theme editor's settings module or app copy):
|
|
955
|
+
* the exact command its mark names. Null for a theme build's own output and
|
|
956
|
+
* a file without a mark, such as a theme source of one's own.
|
|
957
|
+
* @param {string} file
|
|
958
|
+
* @returns {string | null}
|
|
959
|
+
*/
|
|
960
|
+
export function generatedFileCommand(file) {
|
|
961
|
+
const mark = fileMark(fileHead(file), file);
|
|
962
|
+
return mark?.kind === 'editor' ? mark.command : null;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* The command that writes a missing `file`: a file beside it carries
|
|
967
|
+
* another command's mark, and a file there names `file` (a build output's
|
|
968
|
+
* header names its source), so it is one that command writes. Null for any
|
|
969
|
+
* other name, such as a typo.
|
|
970
|
+
* @param {string} file
|
|
971
|
+
* @returns {string | null}
|
|
972
|
+
*/
|
|
973
|
+
function missingGeneratedCommand(file) {
|
|
974
|
+
const dir = path.dirname(file);
|
|
975
|
+
const base = path.basename(file);
|
|
976
|
+
let names;
|
|
977
|
+
try {
|
|
978
|
+
names = fs.readdirSync(dir).sort();
|
|
979
|
+
} catch {
|
|
980
|
+
return null;
|
|
981
|
+
}
|
|
982
|
+
/** @type {string | null} */
|
|
983
|
+
let by = null;
|
|
984
|
+
let named = false;
|
|
985
|
+
for (const n of names) {
|
|
986
|
+
const f = path.join(dir, n);
|
|
987
|
+
try {
|
|
988
|
+
if (!fs.statSync(f).isFile()) continue;
|
|
989
|
+
} catch {
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
by ??= generatedFileCommand(f);
|
|
993
|
+
if (!named)
|
|
994
|
+
try {
|
|
995
|
+
named = fs.readFileSync(f, 'utf8').slice(0, 4000).includes(base);
|
|
996
|
+
} catch {
|
|
997
|
+
// A file that does not read names nothing.
|
|
998
|
+
}
|
|
999
|
+
if (by && named) return by;
|
|
1000
|
+
}
|
|
1001
|
+
return null;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* The command that writes `file`: from its own mark, or, when it is
|
|
1006
|
+
* missing, from the files beside it (see `missingGeneratedCommand`); null
|
|
1007
|
+
* otherwise.
|
|
1008
|
+
* @param {string} file
|
|
1009
|
+
* @returns {string | null}
|
|
1010
|
+
*/
|
|
1011
|
+
export function generatedSourceCommand(file) {
|
|
1012
|
+
return fs.existsSync(file)
|
|
1013
|
+
? generatedFileCommand(file)
|
|
1014
|
+
: missingGeneratedCommand(file);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/** @param {string} file @returns {string} the start of a file, or '' when it cannot be read (no regular file is opened) */
|
|
929
1018
|
function fileHead(file) {
|
|
1019
|
+
if (irregularFileKind(file)) return '';
|
|
930
1020
|
try {
|
|
931
1021
|
const fd = fs.openSync(file, 'r');
|
|
932
1022
|
try {
|
|
@@ -1121,7 +1211,16 @@ function assertThemeSourceFile(filePath, cwd, mode = {}) {
|
|
|
1121
1211
|
* output must stay inside, for a scratch build; `commandWords` names the
|
|
1122
1212
|
* command in the rebuild hint; `prepareFamily`, `familyLoader`, and
|
|
1123
1213
|
* `familyInterception` make the build a family member's plan.
|
|
1124
|
-
*
|
|
1214
|
+
* `colorModes` is the one color mode a calling command knows the theme has
|
|
1215
|
+
* (the theme editor, from its settings), written into the built module.
|
|
1216
|
+
* @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}, colorModes?: ['light'] | ['dark'] | null, fontHelp?: FontHelp | null, loadedFonts?: ((family: string) => boolean) | null, install?: string | null}} ThemeBuildHandOff
|
|
1217
|
+
*/
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* How a caller that loads a theme's fonts itself (the editor's app copy)
|
|
1221
|
+
* says to load a family: the notice per family and the recipe in place of
|
|
1222
|
+
* the generic one.
|
|
1223
|
+
* @typedef {{notice: (family: string) => string, recipe: (families: string[]) => string}} FontHelp
|
|
1125
1224
|
*/
|
|
1126
1225
|
|
|
1127
1226
|
/**
|
|
@@ -1157,6 +1256,45 @@ export function setEditorFolderListener(listener) {
|
|
|
1157
1256
|
* @typedef {{glob?: boolean, family?: boolean, familyKey?: string}} SuggestionShape
|
|
1158
1257
|
*/
|
|
1159
1258
|
|
|
1259
|
+
/**
|
|
1260
|
+
* The refusal a build gives the file it is given before it reads it, or
|
|
1261
|
+
* null: a file that is not there, and a folder. The build throws it, and a
|
|
1262
|
+
* suggested build is checked by it before it is offered.
|
|
1263
|
+
* @param {string} file as typed, from cwd
|
|
1264
|
+
* @param {BuildMode} options
|
|
1265
|
+
* @param {string} cwd
|
|
1266
|
+
* @returns {AstryxError | null}
|
|
1267
|
+
*/
|
|
1268
|
+
export function buildInputProblem(file, options, cwd) {
|
|
1269
|
+
const filePath = path.resolve(cwd, file);
|
|
1270
|
+
if (!fs.existsSync(filePath))
|
|
1271
|
+
return new AstryxError(
|
|
1272
|
+
`File not found: ${filePath}`,
|
|
1273
|
+
themeSourceGuesses(file, cwd).map(guess => ({
|
|
1274
|
+
name: buildSuggestion(guess, options, cwd),
|
|
1275
|
+
reason: 'a theme source that exists',
|
|
1276
|
+
})),
|
|
1277
|
+
ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
1278
|
+
);
|
|
1279
|
+
if (fs.statSync(filePath).isDirectory())
|
|
1280
|
+
return new AstryxError(
|
|
1281
|
+
`${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
|
|
1282
|
+
themeFilesIn(filePath).map(name => ({
|
|
1283
|
+
name: buildSuggestion(
|
|
1284
|
+
path
|
|
1285
|
+
.relative(cwd, path.join(filePath, name))
|
|
1286
|
+
.split(path.sep)
|
|
1287
|
+
.join('/'),
|
|
1288
|
+
options,
|
|
1289
|
+
cwd,
|
|
1290
|
+
),
|
|
1291
|
+
reason: 'a theme source in that folder',
|
|
1292
|
+
})),
|
|
1293
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1294
|
+
);
|
|
1295
|
+
return null;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1160
1298
|
/**
|
|
1161
1299
|
* The `theme build` command for `source` with the caller's mode flags, so a
|
|
1162
1300
|
* suggestion never turns a check into a write or moves the outputs.
|
|
@@ -1212,11 +1350,12 @@ export function buildSuggestion(source, mode, cwd, words, shape = {}) {
|
|
|
1212
1350
|
* @param {Array<{dest: string}>} writes
|
|
1213
1351
|
* @param {string} filePath the theme source
|
|
1214
1352
|
* @param {string} cwd
|
|
1215
|
-
* @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void}} [options]
|
|
1353
|
+
* @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void, onWarning?: (message: string) => void}} [options]
|
|
1216
1354
|
* `claimed`: outputs written earlier in this run, by the source that wrote
|
|
1217
1355
|
* them; `rerun`: this build's command with another --out, or without one;
|
|
1218
1356
|
* `elsewhere`: the option that moves the outputs; `onEditorFolder`: takes
|
|
1219
|
-
* the editor-folder warning instead of the logger (a watcher prints it
|
|
1357
|
+
* the editor-folder warning instead of the logger (a watcher prints it
|
|
1358
|
+
* once); `onWarning`: each warning's message too, for the result
|
|
1220
1359
|
*/
|
|
1221
1360
|
function assertOutputsReplaceable(
|
|
1222
1361
|
writes,
|
|
@@ -1228,6 +1367,7 @@ function assertOutputsReplaceable(
|
|
|
1228
1367
|
refuseUnmarked = false,
|
|
1229
1368
|
elsewhere = '--out',
|
|
1230
1369
|
onEditorFolder,
|
|
1370
|
+
onWarning,
|
|
1231
1371
|
} = {},
|
|
1232
1372
|
) {
|
|
1233
1373
|
const rel = (/** @type {string} */ file) => path.relative(cwd, file);
|
|
@@ -1309,7 +1449,7 @@ function assertOutputsReplaceable(
|
|
|
1309
1449
|
// It is printed after every output passes, so it names a replacement
|
|
1310
1450
|
// that happens.
|
|
1311
1451
|
if (warnedOtherSource) continue;
|
|
1312
|
-
warnedOtherSource =
|
|
1452
|
+
warnedOtherSource = `${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
|
|
1313
1453
|
} else if (otherSource) {
|
|
1314
1454
|
throw new AstryxError(
|
|
1315
1455
|
`${rel(write.dest)} is the build output of another theme source, ${otherSource}, so this build does not replace it. Pick another ${elsewhere}.`,
|
|
@@ -1346,12 +1486,16 @@ function assertOutputsReplaceable(
|
|
|
1346
1486
|
}
|
|
1347
1487
|
// Warned only once nothing refuses the build, so it names a write that
|
|
1348
1488
|
// happens.
|
|
1349
|
-
if (warnedOtherSource)
|
|
1489
|
+
if (warnedOtherSource) {
|
|
1490
|
+
logger.warn(`Warning: ${warnedOtherSource}`);
|
|
1491
|
+
onWarning?.(warnedOtherSource);
|
|
1492
|
+
}
|
|
1350
1493
|
if (editorFolder) {
|
|
1351
1494
|
const dir = path.dirname(writes[0].dest);
|
|
1352
|
-
const
|
|
1353
|
-
if (onEditorFolder) onEditorFolder(
|
|
1354
|
-
else logger.warn(
|
|
1495
|
+
const message = `${rel(dir) || '.'} is a folder the theme editor made, and ${rel(filePath)} is outside it; the build writes there anyway. Build beside the source, or pick another ${elsewhere}, to keep the editor's folder to its own theme.`;
|
|
1496
|
+
if (onEditorFolder) onEditorFolder(`Warning: ${message}`);
|
|
1497
|
+
else logger.warn(`Warning: ${message}`);
|
|
1498
|
+
onWarning?.(message);
|
|
1355
1499
|
}
|
|
1356
1500
|
}
|
|
1357
1501
|
|
|
@@ -1443,7 +1587,31 @@ function writeBuildOutputs(writes) {
|
|
|
1443
1587
|
})),
|
|
1444
1588
|
);
|
|
1445
1589
|
} catch (error) {
|
|
1446
|
-
const
|
|
1590
|
+
const e = /** @type {NodeJS.ErrnoException} */ (error);
|
|
1591
|
+
// A place the outputs cannot be written: name it and its fix (the
|
|
1592
|
+
// writes go through temporary files beside each output, whose names
|
|
1593
|
+
// help nobody).
|
|
1594
|
+
if (e.code === 'EACCES' || e.code === 'EPERM' || e.code === 'EROFS') {
|
|
1595
|
+
const failed = e.path ? path.resolve(e.path) : null;
|
|
1596
|
+
const output = writes.find(w => path.resolve(w.dest) === failed);
|
|
1597
|
+
const place = output
|
|
1598
|
+
? output.dest
|
|
1599
|
+
: failed
|
|
1600
|
+
? path.dirname(failed)
|
|
1601
|
+
: path.dirname(writes[0].dest);
|
|
1602
|
+
const shownPlace = path.relative(process.cwd(), place) || place;
|
|
1603
|
+
throw new AstryxError(
|
|
1604
|
+
`Could not write the theme's outputs: ${shownPlace} is not writable (${e.code}). Give yourself write permission on it (chmod u+w ${shellWord(shownPlace)}), then build again. Nothing was changed.`,
|
|
1605
|
+
[
|
|
1606
|
+
{
|
|
1607
|
+
name: `ls -ld ${shellWord(shownPlace)}`,
|
|
1608
|
+
reason: 'see its permissions',
|
|
1609
|
+
},
|
|
1610
|
+
],
|
|
1611
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
1612
|
+
);
|
|
1613
|
+
}
|
|
1614
|
+
const message = `Failed to write theme outputs: ${e.message}`;
|
|
1447
1615
|
throw new AstryxError(message, undefined, ERROR_CODES.ERR_WRITE_FAILED);
|
|
1448
1616
|
}
|
|
1449
1617
|
}
|
|
@@ -1530,126 +1698,9 @@ let _knownValuesIndexPromise = null;
|
|
|
1530
1698
|
* guessing is not a valid lookup strategy.
|
|
1531
1699
|
*/
|
|
1532
1700
|
async function loadKnownValuesIndex() {
|
|
1533
|
-
const
|
|
1534
|
-
const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
|
|
1701
|
+
const coreSrc = coreSrcPath();
|
|
1535
1702
|
if (!coreSrc || !fs.existsSync(coreSrc)) return {};
|
|
1536
|
-
|
|
1537
|
-
/** @type {any[]} */
|
|
1538
|
-
const docs = [];
|
|
1539
|
-
/** @param {string} dir */
|
|
1540
|
-
async function scan(dir) {
|
|
1541
|
-
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
1542
|
-
const full = path.join(dir, entry.name);
|
|
1543
|
-
if (entry.isDirectory()) {
|
|
1544
|
-
if (entry.name !== 'node_modules' && entry.name !== '__tests__') {
|
|
1545
|
-
await scan(full);
|
|
1546
|
-
}
|
|
1547
|
-
continue;
|
|
1548
|
-
}
|
|
1549
|
-
if (!entry.name.endsWith('.doc.mjs')) continue;
|
|
1550
|
-
try {
|
|
1551
|
-
docs.push(await loadComponentDoc(full));
|
|
1552
|
-
} catch {
|
|
1553
|
-
// One malformed or optional doc must not erase validation for the rest.
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
await scan(coreSrc);
|
|
1558
|
-
|
|
1559
|
-
/** @param {string} value */
|
|
1560
|
-
const targetName = value =>
|
|
1561
|
-
value
|
|
1562
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1563
|
-
.replace(/\s+/g, '-')
|
|
1564
|
-
.toLowerCase();
|
|
1565
|
-
/**
|
|
1566
|
-
* @param {any[]} props
|
|
1567
|
-
* @returns {Record<string, Set<string>>}
|
|
1568
|
-
*/
|
|
1569
|
-
const valuesFromProps = props => {
|
|
1570
|
-
/** @type {Record<string, Set<string>>} */
|
|
1571
|
-
const result = {};
|
|
1572
|
-
for (const prop of props ?? []) {
|
|
1573
|
-
if (typeof prop?.name !== 'string' || typeof prop?.type !== 'string') {
|
|
1574
|
-
continue;
|
|
1575
|
-
}
|
|
1576
|
-
/** @type {Set<string>} */
|
|
1577
|
-
const values = new Set();
|
|
1578
|
-
for (const match of prop.type.match(/'([^']+)'/g) ?? []) {
|
|
1579
|
-
values.add(match.slice(1, -1));
|
|
1580
|
-
}
|
|
1581
|
-
for (const part of prop.type
|
|
1582
|
-
.split('|')
|
|
1583
|
-
.map((/** @type {string} */ value) => value.trim())) {
|
|
1584
|
-
if (/^-?\d+(?:\.\d+)?$/.test(part)) values.add(part);
|
|
1585
|
-
}
|
|
1586
|
-
if (values.size > 0) result[prop.name] = values;
|
|
1587
|
-
}
|
|
1588
|
-
return result;
|
|
1589
|
-
};
|
|
1590
|
-
|
|
1591
|
-
// A component can appear in more than one doc: its own doc declares its
|
|
1592
|
-
// props, and a parent doc can list it by name only. Merge every entry, so
|
|
1593
|
-
// the result does not depend on the order the docs load in.
|
|
1594
|
-
/** @type {Record<string, Record<string, Set<string>>>} */
|
|
1595
|
-
const valuesByOwner = {};
|
|
1596
|
-
/**
|
|
1597
|
-
* @param {string} name
|
|
1598
|
-
* @param {any[]} props
|
|
1599
|
-
*/
|
|
1600
|
-
const addOwnerValues = (name, props) => {
|
|
1601
|
-
const owner = (valuesByOwner[targetName(name)] ??= {});
|
|
1602
|
-
for (const [prop, values] of Object.entries(valuesFromProps(props))) {
|
|
1603
|
-
owner[prop] = new Set([...(owner[prop] ?? []), ...values]);
|
|
1604
|
-
}
|
|
1605
|
-
};
|
|
1606
|
-
for (const doc of docs) {
|
|
1607
|
-
if (typeof doc?.name === 'string') {
|
|
1608
|
-
addOwnerValues(doc.name, doc.props);
|
|
1609
|
-
}
|
|
1610
|
-
for (const component of /** @type {any[]} */ (doc?.components ?? [])) {
|
|
1611
|
-
if (typeof component?.name === 'string') {
|
|
1612
|
-
addOwnerValues(component.name, component.props);
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
/** @type {Record<string, Record<string, Set<string>>>} */
|
|
1618
|
-
const collected = {};
|
|
1619
|
-
for (const doc of docs) {
|
|
1620
|
-
const localValues = valuesFromProps([
|
|
1621
|
-
...(doc?.props ?? []),
|
|
1622
|
-
...(doc?.components ?? []).flatMap(
|
|
1623
|
-
(/** @type {any} */ component) => component?.props ?? [],
|
|
1624
|
-
),
|
|
1625
|
-
]);
|
|
1626
|
-
for (const target of doc?.theming?.targets ?? []) {
|
|
1627
|
-
if (typeof target?.className !== 'string') continue;
|
|
1628
|
-
const componentName = target.className.replace(/^astryx-/, '');
|
|
1629
|
-
const ownerValues = valuesByOwner[componentName] ?? {};
|
|
1630
|
-
if (!collected[componentName]) collected[componentName] = {};
|
|
1631
|
-
for (const prop of target.visualProps ?? []) {
|
|
1632
|
-
if (!collected[componentName][prop]) {
|
|
1633
|
-
collected[componentName][prop] = new Set();
|
|
1634
|
-
}
|
|
1635
|
-
for (const value of [
|
|
1636
|
-
...(localValues[prop] ?? []),
|
|
1637
|
-
...(ownerValues[prop] ?? []),
|
|
1638
|
-
]) {
|
|
1639
|
-
collected[componentName][prop].add(value);
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
return Object.fromEntries(
|
|
1646
|
-
Object.entries(collected).map(([component, props]) => [
|
|
1647
|
-
component,
|
|
1648
|
-
Object.fromEntries(
|
|
1649
|
-
Object.entries(props).map(([prop, values]) => [prop, [...values]]),
|
|
1650
|
-
),
|
|
1651
|
-
]),
|
|
1652
|
-
);
|
|
1703
|
+
return (await coreThemeValues(coreSrc)).knownValues;
|
|
1653
1704
|
}
|
|
1654
1705
|
|
|
1655
1706
|
/**
|
|
@@ -1674,6 +1725,16 @@ function resolveCoreRoot() {
|
|
|
1674
1725
|
return fs.existsSync(coreRoot) ? coreRoot : null;
|
|
1675
1726
|
}
|
|
1676
1727
|
|
|
1728
|
+
/**
|
|
1729
|
+
* The `src` folder of the Core beside the CLI ({@link resolveCoreRoot}), or
|
|
1730
|
+
* null when there is none.
|
|
1731
|
+
* @returns {string | null}
|
|
1732
|
+
*/
|
|
1733
|
+
function coreSrcPath() {
|
|
1734
|
+
const coreRoot = resolveCoreRoot();
|
|
1735
|
+
return coreRoot ? path.join(coreRoot, 'src') : null;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1677
1738
|
/**
|
|
1678
1739
|
* Read the type declarations `@astryxdesign/core/<Component>` exposes so we can
|
|
1679
1740
|
* check whether a given augmentation-target interface actually exists before
|
|
@@ -1755,8 +1816,7 @@ async function resolveAugmentationTargetCandidates(componentName) {
|
|
|
1755
1816
|
},
|
|
1756
1817
|
];
|
|
1757
1818
|
|
|
1758
|
-
const
|
|
1759
|
-
const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
|
|
1819
|
+
const coreSrc = coreSrcPath();
|
|
1760
1820
|
if (!coreSrc || !fs.existsSync(coreSrc)) {
|
|
1761
1821
|
_augmentationTargetCache.set(componentName, fallback);
|
|
1762
1822
|
return fallback;
|
|
@@ -1778,55 +1838,17 @@ async function resolveAugmentationTargetCandidates(componentName) {
|
|
|
1778
1838
|
matches.push({moduleName, interfacePrefix});
|
|
1779
1839
|
}
|
|
1780
1840
|
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
}
|
|
1792
|
-
if (!entry.name.endsWith('.doc.mjs')) continue;
|
|
1793
|
-
|
|
1794
|
-
/** @type {any} */
|
|
1795
|
-
let doc;
|
|
1796
|
-
try {
|
|
1797
|
-
doc = await loadComponentDoc(full);
|
|
1798
|
-
} catch {
|
|
1799
|
-
continue;
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
const matchesTarget = (doc?.theming?.targets || []).some(
|
|
1803
|
-
(/** @type {any} */ target) =>
|
|
1804
|
-
typeof target?.className === 'string' &&
|
|
1805
|
-
target.className.replace(/^astryx-/, '') === componentName,
|
|
1806
|
-
);
|
|
1807
|
-
if (!matchesTarget) continue;
|
|
1808
|
-
|
|
1809
|
-
const moduleName =
|
|
1810
|
-
typeof doc?.name === 'string' && doc.name
|
|
1811
|
-
? doc.name
|
|
1812
|
-
: path.basename(path.dirname(full));
|
|
1813
|
-
|
|
1814
|
-
// Try the exact rendered token first for documented subtargets such as
|
|
1815
|
-
// avatar-status-dot → AvatarStatusDotVariantMap, then the owning public
|
|
1816
|
-
// component name (for example, ProgressBar for progress-bar-fill).
|
|
1817
|
-
addCandidate(moduleName, toPascalCase(componentName));
|
|
1818
|
-
addCandidate(moduleName, moduleName);
|
|
1819
|
-
if (Array.isArray(doc?.components)) {
|
|
1820
|
-
for (const comp of doc.components) {
|
|
1821
|
-
if (typeof comp?.name === 'string') {
|
|
1822
|
-
addCandidate(moduleName, comp.name);
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1841
|
+
const {owners} = await coreThemeValues(coreSrc);
|
|
1842
|
+
for (const {moduleName, components} of Object.hasOwn(owners, componentName)
|
|
1843
|
+
? owners[componentName]
|
|
1844
|
+
: []) {
|
|
1845
|
+
// Try the exact rendered token first for documented subtargets such as
|
|
1846
|
+
// avatar-status-dot → AvatarStatusDotVariantMap, then the owning public
|
|
1847
|
+
// component name (for example, ProgressBar for progress-bar-fill).
|
|
1848
|
+
addCandidate(moduleName, toPascalCase(componentName));
|
|
1849
|
+
addCandidate(moduleName, moduleName);
|
|
1850
|
+
for (const name of components) addCandidate(moduleName, name);
|
|
1827
1851
|
}
|
|
1828
|
-
|
|
1829
|
-
await scan(coreSrc);
|
|
1830
1852
|
// A target documented by a parent component may also have its own public
|
|
1831
1853
|
// subpath and augmentation interface (Heading is documented under Text but
|
|
1832
1854
|
// owns @astryxdesign/core/Heading). Keep the direct-name candidate after
|
|
@@ -2630,19 +2652,23 @@ function isSyncLoaderLimitation(error) {
|
|
|
2630
2652
|
* source export and old-Core adaptation checks keep treating that path as
|
|
2631
2653
|
* degraded/fail-closed.
|
|
2632
2654
|
*
|
|
2655
|
+
* On Node 22.15 and later, on every path, a stylesheet that a module in the
|
|
2656
|
+
* theme's graph imports loads as an empty module (`withEmptyStylesheets`): a
|
|
2657
|
+
* base theme's module can import its own stylesheet for the app's bundler.
|
|
2658
|
+
*
|
|
2633
2659
|
* @param {string} filePath
|
|
2634
2660
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
2635
|
-
* @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
|
|
2661
|
+
* @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes: ["light"] | ["dark"] | null}>}
|
|
2636
2662
|
*/
|
|
2637
2663
|
// prettier-ignore
|
|
2638
|
-
async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
2664
|
+
async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined, /** @type {string | undefined} */ pick = undefined) {
|
|
2639
2665
|
const jiti =
|
|
2640
2666
|
loader ??
|
|
2641
2667
|
createJiti(import.meta.url, {
|
|
2642
2668
|
moduleCache: false,
|
|
2643
|
-
//
|
|
2644
|
-
//
|
|
2645
|
-
|
|
2669
|
+
// The per-user transpile cache: an edited theme is transpiled again,
|
|
2670
|
+
// and the folder stays within its size limit.
|
|
2671
|
+
...jitiCacheOptions(),
|
|
2646
2672
|
jsx: true,
|
|
2647
2673
|
extensions: THEME_MODULE_EXTENSIONS,
|
|
2648
2674
|
...(interception ? {virtualModules: interception.modules} : {}),
|
|
@@ -2659,7 +2685,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2659
2685
|
const commonJsPatch = interception.patchCommonJs(filePath);
|
|
2660
2686
|
try {
|
|
2661
2687
|
try {
|
|
2662
|
-
mod = jiti(filePath);
|
|
2688
|
+
mod = await withEmptyStylesheets(async () => jiti(filePath));
|
|
2663
2689
|
} catch (error) {
|
|
2664
2690
|
// Only a sync-loader limitation may fall back. Anything else is the
|
|
2665
2691
|
// theme's own failure and belongs to the caller unchanged.
|
|
@@ -2668,14 +2694,16 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2668
2694
|
// Force asynchronous transformation instead of native import: this
|
|
2669
2695
|
// keeps virtual Core interception active even when the module uses
|
|
2670
2696
|
// top-level await.
|
|
2671
|
-
mod = await
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2697
|
+
mod = await withEmptyStylesheets(() =>
|
|
2698
|
+
jiti.evalModule(fs.readFileSync(filePath, 'utf8'), {
|
|
2699
|
+
id: filePath,
|
|
2700
|
+
filename: filePath,
|
|
2701
|
+
ext: path.extname(filePath),
|
|
2702
|
+
cache: jiti.cache,
|
|
2703
|
+
async: true,
|
|
2704
|
+
forceTranspile: true,
|
|
2705
|
+
}),
|
|
2706
|
+
);
|
|
2679
2707
|
}
|
|
2680
2708
|
} finally {
|
|
2681
2709
|
// Read after the load: the root is wrapped when the load requires it.
|
|
@@ -2683,7 +2711,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2683
2711
|
commonJsPatch.undo();
|
|
2684
2712
|
}
|
|
2685
2713
|
} else {
|
|
2686
|
-
mod = await jiti.import(filePath);
|
|
2714
|
+
mod = await withEmptyStylesheets(() => jiti.import(filePath));
|
|
2687
2715
|
}
|
|
2688
2716
|
|
|
2689
2717
|
// Both loads hand back the module. The theme is read from the module's own
|
|
@@ -2692,15 +2720,28 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2692
2720
|
// `default` with the module), so the module can pass for the theme while
|
|
2693
2721
|
// its own keys hide the theme's fields.
|
|
2694
2722
|
const isModule = mod != null && typeof mod === 'object';
|
|
2723
|
+
// A theme with one color mode says so with a `colorModes` export beside
|
|
2724
|
+
// the theme (`['light']` or `['dark']`); the build carries it into the
|
|
2725
|
+
// built module.
|
|
2726
|
+
const colorModes = oneColorMode(
|
|
2727
|
+
isModule && Object.hasOwn(mod, 'colorModes') ? mod.colorModes : undefined,
|
|
2728
|
+
);
|
|
2695
2729
|
const hasDefault = isModule && Object.hasOwn(mod, 'default');
|
|
2696
2730
|
const defaultExport = hasDefault ? mod.default : undefined;
|
|
2731
|
+
// A caller that already knows which export a build reads (from a load
|
|
2732
|
+
// as the build loads it) reads that one.
|
|
2733
|
+
if (pick !== undefined && isModule && Object.hasOwn(mod, pick)) {
|
|
2734
|
+
if (isThemeObject(mod[pick]))
|
|
2735
|
+
return {theme: mod[pick], exportName: pick, degraded, colorModes};
|
|
2736
|
+
}
|
|
2697
2737
|
if (isThemeObject(defaultExport)) {
|
|
2698
|
-
return {theme: defaultExport, exportName: 'default', degraded};
|
|
2738
|
+
return {theme: defaultExport, exportName: 'default', degraded, colorModes};
|
|
2699
2739
|
}
|
|
2700
2740
|
if (isModule) {
|
|
2701
2741
|
for (const [exportName, value] of Object.entries(mod)) {
|
|
2702
2742
|
if (exportName === 'default' || exportName === 'module.exports') continue;
|
|
2703
|
-
if (isThemeObject(value))
|
|
2743
|
+
if (isThemeObject(value))
|
|
2744
|
+
return {theme: value, exportName, degraded, colorModes};
|
|
2704
2745
|
}
|
|
2705
2746
|
}
|
|
2706
2747
|
// The loader's interop answers a null default with the module itself, so
|
|
@@ -2722,7 +2763,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2722
2763
|
// be all it defines), or no name: the build's validation says what it
|
|
2723
2764
|
// lacks.
|
|
2724
2765
|
if (isPlainObject(defaultExport)) {
|
|
2725
|
-
return {theme: defaultExport, exportName: 'default', degraded};
|
|
2766
|
+
return {theme: defaultExport, exportName: 'default', degraded, colorModes};
|
|
2726
2767
|
}
|
|
2727
2768
|
// A CommonJS module whose exports are the theme (`module.exports =
|
|
2728
2769
|
// theme`) has no default of its own: interop answers `default` with
|
|
@@ -2731,10 +2772,46 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2731
2772
|
if (isModule && !hasDefault) {
|
|
2732
2773
|
const exportsObject = mod.default ?? mod;
|
|
2733
2774
|
if (isThemeObject(exportsObject)) {
|
|
2734
|
-
return {theme: exportsObject, exportName: 'default', degraded};
|
|
2775
|
+
return {theme: exportsObject, exportName: 'default', degraded, colorModes};
|
|
2735
2776
|
}
|
|
2736
2777
|
}
|
|
2737
2778
|
|
|
2779
|
+
// A theme object (tokens of its own) whose name is missing or no text is
|
|
2780
|
+
// that theme without its name, not a module without a theme.
|
|
2781
|
+
const unnamed = isModule
|
|
2782
|
+
? [
|
|
2783
|
+
...(hasDefault ? [['default', defaultExport]] : []),
|
|
2784
|
+
...Object.entries(mod).filter(
|
|
2785
|
+
([k]) => k !== 'default' && k !== 'module.exports',
|
|
2786
|
+
),
|
|
2787
|
+
].find(
|
|
2788
|
+
([, v]) =>
|
|
2789
|
+
v &&
|
|
2790
|
+
typeof v === 'object' &&
|
|
2791
|
+
v.tokens &&
|
|
2792
|
+
typeof v.tokens === 'object' &&
|
|
2793
|
+
typeof v.name !== 'string',
|
|
2794
|
+
)
|
|
2795
|
+
: undefined;
|
|
2796
|
+
if (unnamed) {
|
|
2797
|
+
const [exportName, value] = unnamed;
|
|
2798
|
+
let text = '';
|
|
2799
|
+
try {
|
|
2800
|
+
text = fs.readFileSync(filePath, 'utf8');
|
|
2801
|
+
} catch {
|
|
2802
|
+
// The line is left out.
|
|
2803
|
+
}
|
|
2804
|
+
const call = /\bdefineTheme\s*\(/.exec(text);
|
|
2805
|
+
const line =
|
|
2806
|
+
keyPathLine(text, ['name']) ??
|
|
2807
|
+
(call ? text.slice(0, call.index).split('\n').length : null);
|
|
2808
|
+
const stem = path
|
|
2809
|
+
.basename(filePath)
|
|
2810
|
+
.replace(/(?:\.theme)?\.[cm]?[jt]sx?$/, '');
|
|
2811
|
+
throw new ThemeNameError(
|
|
2812
|
+
`${exportName === 'default' ? 'The default export' : `The export ${exportName}`} is a theme with no name${value.name === undefined ? '' : ` (its name is ${value.name === null ? 'null' : `a ${typeof value.name}`}, not text)`}${line ? ` (line ${line})` : ''}, and the build names the theme's files after it. Give defineTheme a name, such as name: '${stem}'.`,
|
|
2813
|
+
);
|
|
2814
|
+
}
|
|
2738
2815
|
throw new ThemeShapeError(
|
|
2739
2816
|
`Could not find a defineTheme() result in ${filePath}.`,
|
|
2740
2817
|
);
|
|
@@ -2800,12 +2877,12 @@ function isThemeObject(value) {
|
|
|
2800
2877
|
*
|
|
2801
2878
|
* @param {string} filePath
|
|
2802
2879
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
2803
|
-
* @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
|
|
2880
|
+
* @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes?: ['light'] | ['dark'] | null}>}
|
|
2804
2881
|
*/
|
|
2805
2882
|
// prettier-ignore
|
|
2806
|
-
async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
2883
|
+
async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined, /** @type {string | undefined} */ pick = undefined) {
|
|
2807
2884
|
try {
|
|
2808
|
-
return await importThemeModule(filePath, interception, loader);
|
|
2885
|
+
return await importThemeModule(filePath, interception, loader, pick);
|
|
2809
2886
|
} catch (jitiError) {
|
|
2810
2887
|
const je = /** @type {Error} */ (jitiError);
|
|
2811
2888
|
throw new Error(
|
|
@@ -2815,6 +2892,143 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
|
|
|
2815
2892
|
}
|
|
2816
2893
|
}
|
|
2817
2894
|
|
|
2895
|
+
/**
|
|
2896
|
+
* The Core interception a standalone build loads a theme module with: none
|
|
2897
|
+
* when the selected Core generates adaptations itself and the theme's folder
|
|
2898
|
+
* resolves a Core of its own; else imports of Core are handed the selected
|
|
2899
|
+
* Core.
|
|
2900
|
+
* @param {string} filePath
|
|
2901
|
+
*/
|
|
2902
|
+
function standaloneInterception(filePath) {
|
|
2903
|
+
return _generateAdaptationCSS && themeFolderResolvesCore(filePath)
|
|
2904
|
+
? undefined
|
|
2905
|
+
: interceptCore(_coreThemeModule, _coreRootModule);
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2908
|
+
/**
|
|
2909
|
+
* Load a theme module as a standalone build of it loads it (the Core the
|
|
2910
|
+
* build selects, the same loader and interception) and name the export the
|
|
2911
|
+
* build reads. Callers that must agree with the build on which theme a
|
|
2912
|
+
* module defines read it here, never from the module's text.
|
|
2913
|
+
*
|
|
2914
|
+
* With `base`, also whether the theme extends that module's export, by
|
|
2915
|
+
* identity, anywhere up its `extends` chain (`extendsBase`): the module is
|
|
2916
|
+
* loaded once, and the theme module's imports of it (by any of
|
|
2917
|
+
* `base.specifiers`) are handed that one load, so the answer is about the
|
|
2918
|
+
* very object, not one that only looks like it.
|
|
2919
|
+
* @param {string} file
|
|
2920
|
+
* @param {{cwd?: string, base?: {file: string, exportName: string, specifiers: string[]}}} [ctx]
|
|
2921
|
+
* @returns {Promise<{theme: any, exportName: string, extendsBase?: boolean}>}
|
|
2922
|
+
*/
|
|
2923
|
+
export async function loadThemeExport(file, {cwd = process.cwd(), base} = {}) {
|
|
2924
|
+
const filePath = path.resolve(cwd, file);
|
|
2925
|
+
await selectCore(cwd, {projectOnly: false});
|
|
2926
|
+
const {theme, exportName = 'default'} = await extractThemeDefinition(
|
|
2927
|
+
filePath,
|
|
2928
|
+
standaloneInterception(filePath),
|
|
2929
|
+
);
|
|
2930
|
+
if (!base) return {theme, exportName};
|
|
2931
|
+
const recorder = interceptCore(_coreThemeModule, _coreRootModule);
|
|
2932
|
+
const shared = (
|
|
2933
|
+
await extractThemeDefinition(
|
|
2934
|
+
path.resolve(cwd, base.file),
|
|
2935
|
+
recorder,
|
|
2936
|
+
undefined,
|
|
2937
|
+
base.exportName,
|
|
2938
|
+
)
|
|
2939
|
+
).theme;
|
|
2940
|
+
const withBase = {
|
|
2941
|
+
...recorder,
|
|
2942
|
+
modules: {
|
|
2943
|
+
...recorder.modules,
|
|
2944
|
+
...Object.fromEntries(
|
|
2945
|
+
base.specifiers.map(s => [s, {[base.exportName]: shared}]),
|
|
2946
|
+
),
|
|
2947
|
+
},
|
|
2948
|
+
};
|
|
2949
|
+
const again = await extractThemeDefinition(
|
|
2950
|
+
filePath,
|
|
2951
|
+
withBase,
|
|
2952
|
+
undefined,
|
|
2953
|
+
exportName,
|
|
2954
|
+
);
|
|
2955
|
+
let extendsBase = false;
|
|
2956
|
+
for (
|
|
2957
|
+
let at = recorder.parentOf(again.theme), depth = 0;
|
|
2958
|
+
at && depth < 64;
|
|
2959
|
+
at = recorder.parentOf(at), depth++
|
|
2960
|
+
)
|
|
2961
|
+
if (at === shared) {
|
|
2962
|
+
extendsBase = true;
|
|
2963
|
+
break;
|
|
2964
|
+
}
|
|
2965
|
+
return {theme, exportName, extendsBase};
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
/**
|
|
2969
|
+
* The input a theme module gives `defineTheme()` for the theme a build of
|
|
2970
|
+
* it reads, evaluated as the build evaluates the module (an import, an
|
|
2971
|
+
* expression, a spread or a computed key is its value), with the theme Core
|
|
2972
|
+
* made of it. When Core refuses the input, the input the module gave for
|
|
2973
|
+
* the named theme (else its last) and Core's error; null when the module
|
|
2974
|
+
* does not load at all.
|
|
2975
|
+
* `chain` holds the inputs of the themes it extends, nearest first, as far
|
|
2976
|
+
* as each was made by a `defineTheme()` call this load saw.
|
|
2977
|
+
* @param {string} file
|
|
2978
|
+
* @param {{cwd?: string, name?: string}} [ctx]
|
|
2979
|
+
* @returns {Promise<{input: any, theme: any, error: Error | null, chain: any[]} | null>}
|
|
2980
|
+
*/
|
|
2981
|
+
export async function loadThemeInput(file, {cwd = process.cwd(), name} = {}) {
|
|
2982
|
+
const filePath = path.resolve(cwd, file);
|
|
2983
|
+
await selectCore(cwd, {projectOnly: false});
|
|
2984
|
+
const interception = interceptCore(_coreThemeModule, _coreRootModule);
|
|
2985
|
+
/** @param {any} input */
|
|
2986
|
+
const chainOf = input => {
|
|
2987
|
+
const chain = [];
|
|
2988
|
+
/** @type {Set<any>} */
|
|
2989
|
+
const seen = new Set([input]);
|
|
2990
|
+
let parent = interception.inputOf(input?.extends);
|
|
2991
|
+
while (parent && typeof parent === 'object' && !seen.has(parent)) {
|
|
2992
|
+
seen.add(parent);
|
|
2993
|
+
chain.push(parent);
|
|
2994
|
+
parent = interception.inputOf(parent.extends);
|
|
2995
|
+
}
|
|
2996
|
+
return chain;
|
|
2997
|
+
};
|
|
2998
|
+
try {
|
|
2999
|
+
const {theme} = await extractThemeDefinition(filePath, interception);
|
|
3000
|
+
const input = interception.inputOf(theme) ?? null;
|
|
3001
|
+
return {input, theme, error: null, chain: chainOf(input)};
|
|
3002
|
+
} catch (e) {
|
|
3003
|
+
const given = interception.inputs;
|
|
3004
|
+
const input =
|
|
3005
|
+
given.filter(x => x && typeof x === 'object' && x.name === name).at(-1) ??
|
|
3006
|
+
given.at(-1);
|
|
3007
|
+
return input
|
|
3008
|
+
? {
|
|
3009
|
+
input,
|
|
3010
|
+
theme: null,
|
|
3011
|
+
error: /** @type {Error} */ (e),
|
|
3012
|
+
chain: chainOf(input),
|
|
3013
|
+
}
|
|
3014
|
+
: null;
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3018
|
+
/**
|
|
3019
|
+
* A one-mode `colorModes` value (`['light']` or `['dark']`), or null for
|
|
3020
|
+
* anything else: a theme with both modes needs no export.
|
|
3021
|
+
* @param {unknown} value
|
|
3022
|
+
* @returns {['light'] | ['dark'] | null}
|
|
3023
|
+
*/
|
|
3024
|
+
export function oneColorMode(value) {
|
|
3025
|
+
return Array.isArray(value) &&
|
|
3026
|
+
value.length === 1 &&
|
|
3027
|
+
(value[0] === 'light' || value[0] === 'dark')
|
|
3028
|
+
? /** @type {['light'] | ['dark']} */ ([value[0]])
|
|
3029
|
+
: null;
|
|
3030
|
+
}
|
|
3031
|
+
|
|
2818
3032
|
/** Names a theme module's exports must take; ends a shape failure. */
|
|
2819
3033
|
const THEME_EXPORT_FIX =
|
|
2820
3034
|
"Export the theme object: `export default defineTheme({name: 'my-theme', tokens: {...}})`, or a plain `export default {name: 'my-theme', tokens: {...}}`.";
|
|
@@ -2830,6 +3044,7 @@ function themeLoadReason(error) {
|
|
|
2830
3044
|
const message = error.message;
|
|
2831
3045
|
if (error instanceof ThemeShapeError)
|
|
2832
3046
|
return `${message}\n${THEME_EXPORT_FIX}`;
|
|
3047
|
+
if (error instanceof ThemeNameError) return message;
|
|
2833
3048
|
if (
|
|
2834
3049
|
error instanceof TypeError &&
|
|
2835
3050
|
/^Cannot read properties of (?:null|undefined)/.test(message) &&
|
|
@@ -2842,12 +3057,26 @@ function themeLoadReason(error) {
|
|
|
2842
3057
|
// Node's "Require stack" names absolute paths; the package is the fact.
|
|
2843
3058
|
return `Cannot find module '${missing}'.\nThe theme imports ${missing}, which is not installed. Install it, then build again.`;
|
|
2844
3059
|
}
|
|
2845
|
-
|
|
3060
|
+
const alias = unresolvedAlias(error);
|
|
3061
|
+
if (alias)
|
|
3062
|
+
return `Cannot find module '${alias}'.\nThe theme imports ${alias}, which names no package: a path alias (tsconfig paths, a bundler alias) or a # subpath import with no "imports" entry, which the theme loader does not map. Import it by a path relative to the theme file (such as '../lib/c'), then build again.`;
|
|
3063
|
+
// A module that did not resolve: the import hint. Any other failure (the
|
|
3064
|
+
// theme's own code, or Core refusing its input) is told as it is.
|
|
3065
|
+
const unresolved =
|
|
3066
|
+
/^(?:ERR_MODULE_NOT_FOUND|MODULE_NOT_FOUND)$/.test(
|
|
3067
|
+
String(/** @type {any} */ (error).code ?? ''),
|
|
3068
|
+
) || /Cannot (?:find|resolve) (?:module|package)/.test(message);
|
|
3069
|
+
return unresolved
|
|
3070
|
+
? `${message}\nMake sure all imports in the theme file are resolvable.`
|
|
3071
|
+
: message;
|
|
2846
3072
|
}
|
|
2847
3073
|
|
|
2848
3074
|
/** A theme module that loaded but exports no theme object. */
|
|
2849
3075
|
class ThemeShapeError extends Error {}
|
|
2850
3076
|
|
|
3077
|
+
/** A theme module whose theme object has no name. */
|
|
3078
|
+
class ThemeNameError extends Error {}
|
|
3079
|
+
|
|
2851
3080
|
/**
|
|
2852
3081
|
* The command that moves a failed theme load forward: the install for a
|
|
2853
3082
|
* package the theme imports and the app lacks, the same build for a file that
|
|
@@ -2897,11 +3126,46 @@ function themeLoadSuggestions(error, shown, cwd, mode = {}) {
|
|
|
2897
3126
|
*/
|
|
2898
3127
|
export function missingThemePackage(error) {
|
|
2899
3128
|
const message = error instanceof Error ? error.message : String(error);
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
3129
|
+
const specifier = /Cannot find (?:module|package) '([^']+)'/.exec(
|
|
3130
|
+
message,
|
|
3131
|
+
)?.[1];
|
|
3132
|
+
return specifier ? (packageNameOf(specifier) ?? null) : null;
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
/**
|
|
3136
|
+
* The package an import specifier names, or undefined when it names none:
|
|
3137
|
+
* a relative or absolute path, a `#` subpath import, or a path alias such
|
|
3138
|
+
* as `@/lib/c` or `~/lib/c`, which a bundler or tsconfig maps and the
|
|
3139
|
+
* theme loader does not. A package name is `name` or `@scope/name`, of
|
|
3140
|
+
* the characters npm takes, never starting with `.` or `_`.
|
|
3141
|
+
* @param {string} specifier
|
|
3142
|
+
* @returns {string | undefined}
|
|
3143
|
+
*/
|
|
3144
|
+
export function packageNameOf(specifier) {
|
|
3145
|
+
const m =
|
|
3146
|
+
/^((?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*)(?:\/|$)/i.exec(
|
|
3147
|
+
specifier,
|
|
3148
|
+
);
|
|
3149
|
+
return m ? m[1] : undefined;
|
|
3150
|
+
}
|
|
3151
|
+
|
|
3152
|
+
/**
|
|
3153
|
+
* The import a theme load failed on that names no package (a path alias,
|
|
3154
|
+
* a `#` subpath import with no entry), or null.
|
|
3155
|
+
* @param {unknown} error
|
|
3156
|
+
* @returns {string | null}
|
|
3157
|
+
*/
|
|
3158
|
+
function unresolvedAlias(error) {
|
|
3159
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3160
|
+
const specifier = /Cannot find (?:module|package) '([^']+)'/.exec(
|
|
3161
|
+
message,
|
|
3162
|
+
)?.[1];
|
|
3163
|
+
return specifier &&
|
|
3164
|
+
!/^\.{0,2}\//.test(specifier) &&
|
|
3165
|
+
!path.isAbsolute(specifier) &&
|
|
3166
|
+
!packageNameOf(specifier)
|
|
3167
|
+
? specifier
|
|
3168
|
+
: null;
|
|
2905
3169
|
}
|
|
2906
3170
|
|
|
2907
3171
|
/**
|
|
@@ -3399,11 +3663,10 @@ function builtThemeType(themeDef) {
|
|
|
3399
3663
|
* @returns {Promise<{propsByKey: Record<string, string[]>} | null>}
|
|
3400
3664
|
*/
|
|
3401
3665
|
async function loadKnownComponents() {
|
|
3402
|
-
const
|
|
3403
|
-
const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
|
|
3666
|
+
const coreSrc = coreSrcPath();
|
|
3404
3667
|
if (!coreSrc || !fs.existsSync(coreSrc)) return null;
|
|
3405
3668
|
|
|
3406
|
-
const propsByKey = targetsByKey(await
|
|
3669
|
+
const propsByKey = targetsByKey(await coreThemeTargets(coreSrc));
|
|
3407
3670
|
return Object.keys(propsByKey).length > 0 ? {propsByKey} : null;
|
|
3408
3671
|
}
|
|
3409
3672
|
|
|
@@ -3510,9 +3773,46 @@ export function validateComponentOverridesAgainstRegistry(
|
|
|
3510
3773
|
*/
|
|
3511
3774
|
async function validateComponentOverrides(themeDef) {
|
|
3512
3775
|
const knownComponents = await getKnownComponents();
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3776
|
+
if (knownComponents == null) return [];
|
|
3777
|
+
const warnings = validateComponentOverridesAgainstRegistry(
|
|
3778
|
+
themeDef,
|
|
3779
|
+
knownComponents,
|
|
3780
|
+
);
|
|
3781
|
+
// Style keys no element can carry: a pseudo-class or pseudo-element
|
|
3782
|
+
// written as a style key (`':hover'` builds `[data-="hover"]`), and a
|
|
3783
|
+
// value a closed prop never takes (Button's size has no `xxl`, and no
|
|
3784
|
+
// theme can add one). Either builds a selector nothing matches.
|
|
3785
|
+
const layers = [
|
|
3786
|
+
...getThemeComponentLayers(themeDef).map(l => l.components),
|
|
3787
|
+
...adaptationRuleValues(themeDef)
|
|
3788
|
+
.map((/** @type {any} */ v) => v?.components)
|
|
3789
|
+
.filter(isRecord),
|
|
3790
|
+
];
|
|
3791
|
+
for (const components of layers)
|
|
3792
|
+
for (const [component, rules] of Object.entries(components)) {
|
|
3793
|
+
const knownProps = knownComponents.propsByKey[component];
|
|
3794
|
+
if (!knownProps || !isRecord(rules)) continue;
|
|
3795
|
+
for (const key of Object.keys(rules))
|
|
3796
|
+
for (const {prop, value} of componentValuePairs(key)) {
|
|
3797
|
+
if (!prop) {
|
|
3798
|
+
warnings.push(
|
|
3799
|
+
`Style key "${key}" on component "${component}" is no prop or state: a pseudo-class or pseudo-element goes inside a style key, such as base: {'${key}': {…}}. As written it builds a selector nothing matches.`,
|
|
3800
|
+
);
|
|
3801
|
+
continue;
|
|
3802
|
+
}
|
|
3803
|
+
if (!knownProps.includes(prop)) continue;
|
|
3804
|
+
const values = (await getKnownValues(component))[prop] ?? [];
|
|
3805
|
+
if (
|
|
3806
|
+
values.length > 0 &&
|
|
3807
|
+
(await classifyComponentValue(component, prop, value)) ===
|
|
3808
|
+
'unresolved'
|
|
3809
|
+
)
|
|
3810
|
+
warnings.push(
|
|
3811
|
+
`Style key "${key}" on component "${component}": ${prop} takes ${values.join(', ')}, and a theme cannot add a value to it, so "${value}" builds a selector nothing matches.`,
|
|
3812
|
+
);
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
return [...new Set(warnings)];
|
|
3516
3816
|
}
|
|
3517
3817
|
|
|
3518
3818
|
const BUILTIN_HEADING_TYPES = new Set(['display-1', 'display-2', 'display-3']);
|
|
@@ -3739,21 +4039,36 @@ async function themeBuildInternal(
|
|
|
3739
4039
|
report = {},
|
|
3740
4040
|
handOff = {},
|
|
3741
4041
|
) {
|
|
4042
|
+
// A blank --out names no file: the build would write files named by the
|
|
4043
|
+
// spaces alone.
|
|
4044
|
+
if (
|
|
4045
|
+
typeof options.out === 'string' &&
|
|
4046
|
+
options.out !== '' &&
|
|
4047
|
+
!options.out.trim()
|
|
4048
|
+
)
|
|
4049
|
+
throw new AstryxError(
|
|
4050
|
+
'--out is blank; name a file or folder, or leave out --out to write beside the source.',
|
|
4051
|
+
[
|
|
4052
|
+
{
|
|
4053
|
+
name: buildSuggestion(file, {...options, out: undefined}, cwd),
|
|
4054
|
+
reason: 'do this instead',
|
|
4055
|
+
},
|
|
4056
|
+
],
|
|
4057
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
4058
|
+
);
|
|
3742
4059
|
// A backslash in --out separates folders on every platform, as it does in
|
|
3743
4060
|
// the other theme paths (a Windows path copied into a POSIX shell).
|
|
3744
4061
|
if (typeof options.out === 'string' && options.out.includes('\\'))
|
|
3745
4062
|
options = {...options, out: options.out.replace(/\\/g, '/')};
|
|
3746
4063
|
const filePath = path.resolve(cwd, file);
|
|
3747
4064
|
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
3756
|
-
);
|
|
4065
|
+
// Core's facts first, before the build reads the theme: kept facts then do
|
|
4066
|
+
// not depend on it, and a build after an edit to the theme reads them back.
|
|
4067
|
+
await keepCoreThemeFacts(coreSrcPath());
|
|
4068
|
+
|
|
4069
|
+
{
|
|
4070
|
+
const problem = buildInputProblem(file, options, cwd);
|
|
4071
|
+
if (problem) throw problem;
|
|
3757
4072
|
}
|
|
3758
4073
|
|
|
3759
4074
|
// A theme the theme editor made is built from its settings by the editor;
|
|
@@ -3772,24 +4087,6 @@ async function themeBuildInternal(
|
|
|
3772
4087
|
);
|
|
3773
4088
|
}
|
|
3774
4089
|
|
|
3775
|
-
if (fs.statSync(filePath).isDirectory()) {
|
|
3776
|
-
throw new AstryxError(
|
|
3777
|
-
`${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
|
|
3778
|
-
themeFilesIn(filePath).map(name => ({
|
|
3779
|
-
name: buildSuggestion(
|
|
3780
|
-
path
|
|
3781
|
-
.relative(cwd, path.join(filePath, name))
|
|
3782
|
-
.split(path.sep)
|
|
3783
|
-
.join('/'),
|
|
3784
|
-
options,
|
|
3785
|
-
cwd,
|
|
3786
|
-
),
|
|
3787
|
-
reason: 'a theme source in that folder',
|
|
3788
|
-
})),
|
|
3789
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
3790
|
-
);
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
4090
|
assertThemeSourceFile(filePath, cwd, options);
|
|
3794
4091
|
|
|
3795
4092
|
if (!report.compact) {
|
|
@@ -3814,10 +4111,7 @@ async function themeBuildInternal(
|
|
|
3814
4111
|
// shared loader so exact authored parent identity stays CLI-private instead
|
|
3815
4112
|
// of becoming a public DefinedTheme field.
|
|
3816
4113
|
const interception =
|
|
3817
|
-
handOff.familyInterception ??
|
|
3818
|
-
(_generateAdaptationCSS && themeFolderResolvesCore(filePath)
|
|
3819
|
-
? undefined
|
|
3820
|
-
: interceptCore(_coreThemeModule, _coreRootModule));
|
|
4114
|
+
handOff.familyInterception ?? standaloneInterception(filePath);
|
|
3821
4115
|
|
|
3822
4116
|
// Extract theme definition
|
|
3823
4117
|
let themeDef;
|
|
@@ -3825,6 +4119,9 @@ async function themeBuildInternal(
|
|
|
3825
4119
|
let themeExportName;
|
|
3826
4120
|
/** Paths through the load that interception could not fully observe. */
|
|
3827
4121
|
let loadDegradation;
|
|
4122
|
+
/** The one color mode the theme module exports, or null for both. */
|
|
4123
|
+
/** @type {['light'] | ['dark'] | null} */
|
|
4124
|
+
let colorModes;
|
|
3828
4125
|
/**
|
|
3829
4126
|
* The theme file's bytes as loaded: read before and after the load, and the
|
|
3830
4127
|
* registry scan below reads these rather than the file again. An editor's
|
|
@@ -3851,6 +4148,7 @@ async function themeBuildInternal(
|
|
|
3851
4148
|
themeDef = loaded.theme;
|
|
3852
4149
|
themeExportName = loaded.exportName;
|
|
3853
4150
|
loadDegradation = loaded.degraded;
|
|
4151
|
+
colorModes = handOff.colorModes ?? loaded.colorModes ?? null;
|
|
3854
4152
|
} catch (e) {
|
|
3855
4153
|
const err = /** @type {Error} */ (e);
|
|
3856
4154
|
const shown = path.relative(cwd, filePath) || filePath;
|
|
@@ -4026,12 +4324,43 @@ async function themeBuildInternal(
|
|
|
4026
4324
|
/** @type {import('./icon-imports.mjs').IconImports | null} */
|
|
4027
4325
|
let componentIconInfo = null;
|
|
4028
4326
|
|
|
4327
|
+
// A null part or style key: Core throws on it, so it is refused before
|
|
4328
|
+
// anything is written, at the line that gives it. A null value keeps its
|
|
4329
|
+
// meaning (Core writes it as it is), so it is warned at its line.
|
|
4330
|
+
const shownSource = path.relative(cwd, filePath) || filePath;
|
|
4331
|
+
const nulls = nullThemeValues(themeDef).map(n => ({
|
|
4332
|
+
...n,
|
|
4333
|
+
line: keyPathLine(themeSource, n.path),
|
|
4334
|
+
}));
|
|
4335
|
+
/** @param {{path: string[], why: string, line: number | null}} n */
|
|
4336
|
+
const nullLine = n =>
|
|
4337
|
+
`${n.path.join('.')}${n.line != null ? ` (line ${n.line})` : ''}: ${n.why}`;
|
|
4338
|
+
const unbuildable = nulls.filter(n => n.unbuildable);
|
|
4339
|
+
if (unbuildable.length > 0) {
|
|
4340
|
+
const first = unbuildable.find(n => n.line != null);
|
|
4341
|
+
throw new AstryxError(
|
|
4342
|
+
`${shownSource} gives null where the build reads a block: ${unbuildable.map(nullLine).join('; ')}. Nothing was written.`,
|
|
4343
|
+
first
|
|
4344
|
+
? [
|
|
4345
|
+
{
|
|
4346
|
+
name: `sed -n ${first.line}p ${quoteCommandArgument(shownSource)}`,
|
|
4347
|
+
reason: 'see the line that gives it',
|
|
4348
|
+
},
|
|
4349
|
+
]
|
|
4350
|
+
: undefined,
|
|
4351
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
4352
|
+
);
|
|
4353
|
+
}
|
|
4354
|
+
|
|
4029
4355
|
// Validate component overrides
|
|
4030
4356
|
const warnings = await validateComponentOverrides(themeDef);
|
|
4031
4357
|
const warningMessages = [];
|
|
4032
4358
|
/** Advisories about a correct theme — see the `notices` note on the receipt. */
|
|
4033
4359
|
const noticeMessages = [];
|
|
4034
|
-
for (const w of
|
|
4360
|
+
for (const w of [
|
|
4361
|
+
...warnings,
|
|
4362
|
+
...nulls.filter(n => !n.unbuildable).map(nullLine),
|
|
4363
|
+
]) {
|
|
4035
4364
|
warningMessages.push(w);
|
|
4036
4365
|
logger.warn(` [warn] ${source}${w}`);
|
|
4037
4366
|
}
|
|
@@ -4389,6 +4718,16 @@ async function themeBuildInternal(
|
|
|
4389
4718
|
const writeRoot = handOff.writeRoot ?? cwd;
|
|
4390
4719
|
let outPath;
|
|
4391
4720
|
if (options.out) {
|
|
4721
|
+
// A leading ~ reaches the build only when the shell did not expand it
|
|
4722
|
+
// (quoted, or from a script or a config): it names a folder called ~
|
|
4723
|
+
// in the project, never the home folder. The build writes there, as it
|
|
4724
|
+
// always has, and says so.
|
|
4725
|
+
if (/^~(?:[\\/]|$)/.test(options.out)) {
|
|
4726
|
+
const rest = options.out.replace(/^~[\\/]*/, '');
|
|
4727
|
+
const w = `--out ${options.out} starts with "~", which is not your home folder here: a shell expands ~ only when it is not quoted, so the build writes in a folder named ~ in the project (${path.join(cwd, '~', rest)}). To write in the home folder, give it in full (${path.join(os.homedir(), rest)}).`;
|
|
4728
|
+
warningMessages.push(w);
|
|
4729
|
+
logger.warn(`Warning: ${w}`);
|
|
4730
|
+
}
|
|
4392
4731
|
outPath = path.resolve(cwd, options.out);
|
|
4393
4732
|
// A folder, or a path that ends in a separator, names where the outputs
|
|
4394
4733
|
// go: write `<folder>/<name>.css`, never a file named like the folder.
|
|
@@ -4397,15 +4736,23 @@ async function themeBuildInternal(
|
|
|
4397
4736
|
}
|
|
4398
4737
|
// The stylesheet is CSS whatever its name; a name that does not end in
|
|
4399
4738
|
// .css still builds, and the module's import names the file as written.
|
|
4400
|
-
|
|
4401
|
-
|
|
4739
|
+
// The name's extension is what follows its last dot, a leading one too:
|
|
4740
|
+
// `.css` is a name with no stem, which writes hidden files.
|
|
4741
|
+
const file = path.basename(outPath);
|
|
4742
|
+
const dot = file.lastIndexOf('.');
|
|
4743
|
+
const ext = dot < 0 ? '' : file.slice(dot).toLowerCase();
|
|
4744
|
+
const stem = (dot < 0 ? file : file.slice(0, dot)).replace(/\.d$/, '');
|
|
4745
|
+
if (ext !== '.css' || !stem) {
|
|
4402
4746
|
const fixed = path
|
|
4403
|
-
.join(path.dirname(options.out), `${stem}.css`)
|
|
4747
|
+
.join(path.dirname(options.out), `${stem || baseName}.css`)
|
|
4404
4748
|
.split(path.sep)
|
|
4405
4749
|
.join('/');
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4750
|
+
// The result's warnings say it too, as text does.
|
|
4751
|
+
const w = stem
|
|
4752
|
+
? `--out names the stylesheet, which is CSS; give it a .css name such as ${fixed}.`
|
|
4753
|
+
: `--out names a stylesheet with no name before .css, which writes hidden files; give it a name such as ${fixed}.`;
|
|
4754
|
+
warningMessages.push(w);
|
|
4755
|
+
logger.warn(`Warning: ${w}`);
|
|
4409
4756
|
}
|
|
4410
4757
|
// A build keeps the explicit output inside the write root, relative or
|
|
4411
4758
|
// absolute. Check mode writes nothing, so it refuses only a relative path
|
|
@@ -4482,19 +4829,30 @@ async function themeBuildInternal(
|
|
|
4482
4829
|
? {}
|
|
4483
4830
|
: {cssFileName: path.basename(outPath)}),
|
|
4484
4831
|
},
|
|
4485
|
-
)
|
|
4832
|
+
) +
|
|
4833
|
+
// The one color mode, beside the theme export (a two-mode theme
|
|
4834
|
+
// exports none, so its module is unchanged).
|
|
4835
|
+
(colorModes
|
|
4836
|
+
? `export const colorModes = [${JSON.stringify(colorModes[0])}];\n`
|
|
4837
|
+
: '');
|
|
4486
4838
|
const dtsContent =
|
|
4487
4839
|
generatedHeader(headerSource, 'ts', buildCommand, versions) +
|
|
4488
|
-
generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName)
|
|
4840
|
+
generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName) +
|
|
4841
|
+
(colorModes
|
|
4842
|
+
? `export declare const colorModes: readonly [${JSON.stringify(colorModes[0])}];\n`
|
|
4843
|
+
: '');
|
|
4489
4844
|
|
|
4845
|
+
// A family the caller knows the app loads (a font stylesheet it writes
|
|
4846
|
+
// for the theme) is not named as unloaded.
|
|
4490
4847
|
const unloadedFonts = [
|
|
4491
4848
|
...new Set([
|
|
4492
4849
|
...collectUnloadedFonts(resolvedTheme),
|
|
4493
4850
|
...adaptationRuleValues(resolvedTheme).flatMap(
|
|
4494
|
-
(/** @type {any} */ value) =>
|
|
4851
|
+
(/** @type {any} */ value) =>
|
|
4852
|
+
collectUnloadedFonts(value, resolvedTheme),
|
|
4495
4853
|
),
|
|
4496
4854
|
]),
|
|
4497
|
-
];
|
|
4855
|
+
].filter(family => !handOff.loadedFonts?.(family));
|
|
4498
4856
|
|
|
4499
4857
|
if (handOff.prepareFamily) {
|
|
4500
4858
|
return {
|
|
@@ -4526,6 +4884,18 @@ async function themeBuildInternal(
|
|
|
4526
4884
|
writes.push({dest: variantDtsPath, content: variantContent});
|
|
4527
4885
|
}
|
|
4528
4886
|
|
|
4887
|
+
// A named pipe, a device or a socket where an output goes is never read
|
|
4888
|
+
// or replaced: an open of one can wait for good. A check refuses it too.
|
|
4889
|
+
for (const write of writes) {
|
|
4890
|
+
const kind = irregularFileKind(write.dest);
|
|
4891
|
+
if (kind && kind !== 'a folder')
|
|
4892
|
+
throw new AstryxError(
|
|
4893
|
+
`${path.relative(cwd, write.dest) || write.dest} is ${kind}, not a file, so the build neither reads nor replaces it: remove it, then build again. Nothing was written.`,
|
|
4894
|
+
undefined,
|
|
4895
|
+
ERROR_CODES.ERR_FILE_EXISTS,
|
|
4896
|
+
);
|
|
4897
|
+
}
|
|
4898
|
+
|
|
4529
4899
|
// Every output a build writes stays inside cwd, including the defaults
|
|
4530
4900
|
// beside the theme file. Check mode writes nothing, so it compares outputs
|
|
4531
4901
|
// outside cwd read-only.
|
|
@@ -4547,6 +4917,8 @@ async function themeBuildInternal(
|
|
|
4547
4917
|
rerun,
|
|
4548
4918
|
refuseUnmarked: Boolean(options.out),
|
|
4549
4919
|
onEditorFolder: editorFolderListener ?? undefined,
|
|
4920
|
+
// The result's warnings carry what text prints.
|
|
4921
|
+
onWarning: message => warningMessages.push(message),
|
|
4550
4922
|
});
|
|
4551
4923
|
}
|
|
4552
4924
|
|
|
@@ -4637,12 +5009,19 @@ async function themeBuildInternal(
|
|
|
4637
5009
|
// permanently in violation of its own "compiles with no warnings" guard).
|
|
4638
5010
|
// Adaptation rules are resolved theme writes in their own right, so a family
|
|
4639
5011
|
// named only inside one needs the same notice as one named at the root.
|
|
5012
|
+
// The result names the recipe's command bare, as every machine-read
|
|
5013
|
+
// command is; the printed note starts it the way this project runs the CLI.
|
|
5014
|
+
/** @param {string} family @param {string} recipe */
|
|
5015
|
+
const fontNotice = (family, recipe) =>
|
|
5016
|
+
handOff.fontHelp?.notice(family) ??
|
|
5017
|
+
`Font "${family}" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: ${recipe})`;
|
|
4640
5018
|
/** @type {string[]} */
|
|
4641
5019
|
const fontNotices = [];
|
|
4642
5020
|
for (const family of unloadedFonts) {
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
5021
|
+
noticeMessages.push(fontNotice(family, 'astryx docs typography'));
|
|
5022
|
+
fontNotices.push(
|
|
5023
|
+
fontNotice(family, formatCliCommand('docs typography', cwd)),
|
|
5024
|
+
);
|
|
4646
5025
|
}
|
|
4647
5026
|
|
|
4648
5027
|
/** @type {ThemeBuildTrailer} */
|
|
@@ -4653,6 +5032,8 @@ async function themeBuildInternal(
|
|
|
4653
5032
|
cssImport,
|
|
4654
5033
|
unloadedFonts,
|
|
4655
5034
|
fontNotices,
|
|
5035
|
+
fontHelp: handOff.fontHelp ?? null,
|
|
5036
|
+
install: handOff.install ?? null,
|
|
4656
5037
|
};
|
|
4657
5038
|
// A batch or compact report prints this once for the whole run instead.
|
|
4658
5039
|
if (report.trailers) report.trailers.push(trailer);
|
|
@@ -4689,7 +5070,11 @@ async function themeBuildInternal(
|
|
|
4689
5070
|
* @property {string} jsImport Import specifier of the built JS module.
|
|
4690
5071
|
* @property {string} cssImport Import specifier of the built CSS.
|
|
4691
5072
|
* @property {string[]} unloadedFonts Font families the theme names but does not load.
|
|
4692
|
-
* @property {string[]} fontNotices One notice per unloaded font family.
|
|
5073
|
+
* @property {string[]} fontNotices One notice per unloaded font family, as printed.
|
|
5074
|
+
* @property {FontHelp | null} [fontHelp] How the caller loads fonts, when it does.
|
|
5075
|
+
* @property {string | null} [install] How the app takes the theme, when the
|
|
5076
|
+
* caller wires it another way than importing these outputs (the editor's
|
|
5077
|
+
* app copy).
|
|
4693
5078
|
*/
|
|
4694
5079
|
|
|
4695
5080
|
/**
|
|
@@ -4697,7 +5082,9 @@ async function themeBuildInternal(
|
|
|
4697
5082
|
* @param {ThemeBuildTrailer} trailer
|
|
4698
5083
|
*/
|
|
4699
5084
|
function printBuildTrailer(trailer) {
|
|
4700
|
-
logger.log(`
|
|
5085
|
+
if (trailer.install) logger.log(`\n${trailer.install}\n`);
|
|
5086
|
+
else
|
|
5087
|
+
logger.log(`
|
|
4701
5088
|
Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
|
|
4702
5089
|
|
|
4703
5090
|
import { Theme } from '@astryxdesign/core/theme';
|
|
@@ -4720,7 +5107,13 @@ Or with a <link> tag:
|
|
|
4720
5107
|
`);
|
|
4721
5108
|
for (const msg of trailer.fontNotices) logger.log(` note: ${msg}`);
|
|
4722
5109
|
if (trailer.unloadedFonts.length > 0) {
|
|
4723
|
-
logger.log(
|
|
5110
|
+
logger.log(
|
|
5111
|
+
formatFontLoadingHelp(
|
|
5112
|
+
trailer.themeName,
|
|
5113
|
+
trailer.unloadedFonts,
|
|
5114
|
+
trailer.fontHelp?.recipe,
|
|
5115
|
+
),
|
|
5116
|
+
);
|
|
4724
5117
|
}
|
|
4725
5118
|
}
|
|
4726
5119
|
|
|
@@ -4732,8 +5125,13 @@ Or with a <link> tag:
|
|
|
4732
5125
|
*/
|
|
4733
5126
|
export function printBatchTrailer(trailers) {
|
|
4734
5127
|
if (trailers.length === 0) return;
|
|
4735
|
-
|
|
4736
|
-
|
|
5128
|
+
// A theme the caller wires another way says how, once each.
|
|
5129
|
+
for (const trailer of trailers)
|
|
5130
|
+
if (trailer.install) logger.log(`\n${trailer.install}\n`);
|
|
5131
|
+
const imported = trailers.filter(trailer => !trailer.install);
|
|
5132
|
+
const [first] = imported;
|
|
5133
|
+
if (first)
|
|
5134
|
+
logger.log(`
|
|
4737
5135
|
Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
|
|
4738
5136
|
|
|
4739
5137
|
import { Theme } from '@astryxdesign/core/theme';
|
|
@@ -4754,16 +5152,19 @@ Or with a <link> tag:
|
|
|
4754
5152
|
<App />
|
|
4755
5153
|
</Theme>
|
|
4756
5154
|
`);
|
|
4757
|
-
if (
|
|
5155
|
+
if (imported.length > 1) {
|
|
4758
5156
|
logger.log('Each built theme imports the same way:');
|
|
4759
|
-
for (const trailer of
|
|
5157
|
+
for (const trailer of imported) {
|
|
4760
5158
|
logger.log(
|
|
4761
5159
|
` import { ${trailer.exportName} } from '${trailer.jsImport}'; import '${trailer.cssImport}';`,
|
|
4762
5160
|
);
|
|
4763
5161
|
}
|
|
4764
5162
|
}
|
|
4765
5163
|
const fonts = groupUnloadedFonts(trailers);
|
|
4766
|
-
|
|
5164
|
+
// One caller's recipe serves the batch only when every theme takes it.
|
|
5165
|
+
const help = trailers.every(t => t.fontHelp) ? trailers[0].fontHelp : null;
|
|
5166
|
+
if (fonts.length > 0)
|
|
5167
|
+
logger.log(formatBatchFontLoadingHelp(fonts, help?.recipe));
|
|
4767
5168
|
}
|
|
4768
5169
|
|
|
4769
5170
|
/**
|
|
@@ -4998,7 +5399,7 @@ function planFamilySources(files, cwd) {
|
|
|
4998
5399
|
// prettier-ignore
|
|
4999
5400
|
async function preloadFamilySource(filePath, loader, interception) {
|
|
5000
5401
|
const patch = interception.patchCommonJs(filePath);
|
|
5001
|
-
try { try { loader(filePath); } catch (error) { if (!isSyncLoaderLimitation(error)) throw error; await loader.evalModule(fs.readFileSync(filePath, 'utf8'), {id: filePath, filename: filePath, ext: path.extname(filePath), cache: loader.cache, async: true, forceTranspile: true}); } }
|
|
5402
|
+
try { try { await withEmptyStylesheets(async () => loader(filePath)); } catch (error) { if (!isSyncLoaderLimitation(error)) throw error; await withEmptyStylesheets(() => loader.evalModule(fs.readFileSync(filePath, 'utf8'), {id: filePath, filename: filePath, ext: path.extname(filePath), cache: loader.cache, async: true, forceTranspile: true})); } }
|
|
5002
5403
|
finally { patch.undo(); }
|
|
5003
5404
|
}
|
|
5004
5405
|
|
|
@@ -5026,7 +5427,7 @@ export async function themeBuildFamily(
|
|
|
5026
5427
|
await selectCore(cwd);
|
|
5027
5428
|
const familyInterception = interceptCore(_coreThemeModule, _coreRootModule);
|
|
5028
5429
|
// prettier-ignore
|
|
5029
|
-
const familyLoader = createJiti(import.meta.url, {moduleCache: true,
|
|
5430
|
+
const familyLoader = createJiti(import.meta.url, {moduleCache: true, ...jitiCacheOptions(), interopDefault: false, jsx: true, extensions: THEME_MODULE_EXTENSIONS, virtualModules: familyInterception.modules});
|
|
5030
5431
|
/** @type {any[]} */
|
|
5031
5432
|
const prepared = [];
|
|
5032
5433
|
for (const source of planFamilySources(files, cwd)) {
|
|
@@ -5318,11 +5719,18 @@ Or load the same stylesheet natively:
|
|
|
5318
5719
|
const unloadedFonts = [
|
|
5319
5720
|
...new Set(members.flatMap(member => member.unloadedFonts)),
|
|
5320
5721
|
];
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5722
|
+
/** @param {string} family @param {string} recipe */
|
|
5723
|
+
const familyNotice = (family, recipe) =>
|
|
5724
|
+
`Font "${family}" is named by this theme family but not loaded; add a <link> or @font-face in your app (recipe: ${recipe})`;
|
|
5725
|
+
// The result names the command bare; the printed note as this project
|
|
5726
|
+
// runs the CLI.
|
|
5727
|
+
const notices = unloadedFonts.map(family =>
|
|
5728
|
+
familyNotice(family, 'astryx docs typography'),
|
|
5324
5729
|
);
|
|
5325
|
-
for (const
|
|
5730
|
+
for (const family of unloadedFonts)
|
|
5731
|
+
logger.log(
|
|
5732
|
+
` note: ${familyNotice(family, formatCliCommand('docs typography', cwd))}`,
|
|
5733
|
+
);
|
|
5326
5734
|
return {
|
|
5327
5735
|
type: 'theme.build',
|
|
5328
5736
|
data: {
|