@astryxdesign/cli 0.7.16 → 0.7.17-canary.g16fe6a8
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 +12 -0
- package/api/build/_adapter.mjs +51 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- 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 +4 -2
- package/api/build/kit/rank.mjs +125 -24
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +340 -43
- 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 +48 -0
- package/api/build/kit/words.mjs +90 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +1 -1
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +28 -2
- package/api/docs/_adapter.mjs +249 -10
- 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 +27 -5
- package/api/doctor/_adapter.mjs +83 -10
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- 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/authoring-checks.mjs +6 -6
- 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/validate-integration.mjs +19 -1
- package/api/integration/validate-integration.type.d.mts +9 -0
- package/api/integration/validate-integration.type.mjs +1 -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 +52 -0
- package/api/render/render.type.mjs +31 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.mjs +51 -32
- 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 +5 -0
- package/api/search/_lexical.mjs +8 -2
- 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/theme/_adapter.mjs +12 -1
- package/api/theme/build/build.d.mts +132 -1
- package/api/theme/build/build.mjs +482 -157
- 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 +44 -5
- package/api/theme/build/font-warning.mjs +118 -10
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +115 -4
- package/api/theme-edit/_adapter.mjs +997 -83
- package/api/theme-edit/_catalog.d.mts +20 -2
- package/api/theme-edit/_catalog.mjs +50 -10
- package/api/theme-edit/_check.d.mts +75 -24
- package/api/theme-edit/_check.mjs +2672 -422
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +54 -1
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +133 -15
- package/api/theme-edit/_context.d.mts +14 -3
- package/api/theme-edit/_context.mjs +225 -65
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +54 -4
- package/api/theme-edit/_edit.mjs +2966 -286
- package/api/theme-edit/_how-commands.d.mts +72 -1
- package/api/theme-edit/_how-commands.mjs +770 -9
- package/api/theme-edit/_how-question.d.mts +82 -5
- package/api/theme-edit/_how-question.mjs +6983 -701
- package/api/theme-edit/_how.d.mts +2 -1
- package/api/theme-edit/_how.mjs +237 -41
- 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 +303 -0
- package/api/theme-edit/_normal.mjs +1517 -0
- package/api/theme-edit/_palette.d.mts +12 -0
- package/api/theme-edit/_palette.mjs +37 -4
- package/api/theme-edit/_part-words.d.mts +31 -0
- package/api/theme-edit/_part-words.mjs +126 -0
- package/api/theme-edit/_parts.d.mts +28 -2
- package/api/theme-edit/_parts.mjs +267 -31
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +814 -406
- package/api/theme-edit/_preview.d.mts +116 -16
- package/api/theme-edit/_preview.mjs +649 -152
- package/api/theme-edit/_project.d.mts +22 -1
- package/api/theme-edit/_project.mjs +83 -3
- package/api/theme-edit/_settings.d.mts +467 -42
- package/api/theme-edit/_settings.mjs +3527 -468
- package/api/theme-edit/_tables.d.mts +21 -0
- package/api/theme-edit/_tables.mjs +97 -3
- 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 +16 -2
- package/api/theme-edit/theme-edit.type.mjs +6 -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/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/run-codemod.mjs +87 -7
- 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 +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +44 -3
- 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/use-a-theme.doc.mjs +1 -1
- 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/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/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/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- 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/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- 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/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -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/template.doc.mjs +2 -1
- 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/mixed-gallery/template.doc.mjs +2 -1
- 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/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/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/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- 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/template.doc.mjs +1 -0
- package/assets/theme.template.ts +6 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- 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/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/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +32 -14
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +573 -119
- 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 +1 -1
- 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 +1 -1
- 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.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.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +718 -438
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- 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 +132 -24
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +56 -8
- 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/doc-types.mjs +4 -3
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +22 -8
- 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-doc-files.mjs +2 -1
- 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 +38 -18
- package/foundation/discovery/template-adapter.d.mts +53 -1
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +31 -4
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.d.mts +6 -5
- package/foundation/discovery/theming-targets.mjs +31 -47
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +38 -0
- package/foundation/fonts/font-stylesheet.mjs +141 -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 +4 -3
- package/foundation/fs/gather-cache.d.mts +62 -4
- package/foundation/fs/gather-cache.mjs +517 -91
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -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/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +9 -0
- package/foundation/fs/read-record.mjs +19 -11
- 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/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/validate-contributions.mjs +17 -45
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +39 -7
- package/foundation/render/embedded-imports.mjs +66 -27
- 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/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +121 -13
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +185 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +34 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +641 -96
- 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 +2 -2
- 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/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +18 -4
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +15 -1
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -63,7 +63,7 @@ import * as path from 'node:path';
|
|
|
63
63
|
import {createRequire, isBuiltin} from 'node:module';
|
|
64
64
|
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
65
65
|
import {babelParse as parse} from '../../../foundation/runtime/lazy-dependencies.mjs';
|
|
66
|
-
import {
|
|
66
|
+
import {jitiCacheOptions} from '../../../foundation/fs/jiti-cache.mjs';
|
|
67
67
|
import {
|
|
68
68
|
formatCliCommand,
|
|
69
69
|
getCliInvocation,
|
|
@@ -90,8 +90,12 @@ import {validatePrivateVars} from '../../../foundation/config/theme-private-vars
|
|
|
90
90
|
import {AstryxError} from '../../error.mjs';
|
|
91
91
|
import {applyWrites} from '../../integration/add-helpers.mjs';
|
|
92
92
|
import {logger} from '../../logger.mjs';
|
|
93
|
-
import {
|
|
93
|
+
import {coreComponentDocs} from '../../../foundation/discovery/core-component-docs.mjs';
|
|
94
94
|
import {THEME_SOURCE_EXTENSIONS} from '../../../foundation/discovery/theme-module-extensions.mjs';
|
|
95
|
+
import {
|
|
96
|
+
createJiti,
|
|
97
|
+
withEmptyStylesheets,
|
|
98
|
+
} from '../../../foundation/fs/module-loader.mjs';
|
|
95
99
|
import {
|
|
96
100
|
collectThemingTargets,
|
|
97
101
|
targetsByKey,
|
|
@@ -108,6 +112,7 @@ import {
|
|
|
108
112
|
} from '../../../foundation/discovery/template-needs.mjs';
|
|
109
113
|
import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
|
|
110
114
|
import {resolveIconImports} from './icon-imports.mjs';
|
|
115
|
+
import {generatedMark} from '../../theme-edit/_marks.mjs';
|
|
111
116
|
|
|
112
117
|
// Import shared theme processing from core. `astryx theme build` MUST produce the
|
|
113
118
|
// exact same CSS as the `<Theme>` runtime, so it has exactly one generation
|
|
@@ -324,7 +329,9 @@ function importTarget(dir, subpath) {
|
|
|
324
329
|
/** @param {string} file @returns {string} its real path, or itself */
|
|
325
330
|
function realOrSelf(file) {
|
|
326
331
|
try {
|
|
327
|
-
|
|
332
|
+
// The native form spells a path as the disk does (its own case on a
|
|
333
|
+
// case-insensitive disk), so two spellings of one file compare equal.
|
|
334
|
+
return fs.realpathSync.native(file);
|
|
328
335
|
} catch {
|
|
329
336
|
return file;
|
|
330
337
|
}
|
|
@@ -333,10 +340,12 @@ function realOrSelf(file) {
|
|
|
333
340
|
/**
|
|
334
341
|
* `target` spelled through real directories: the deepest ancestor that exists
|
|
335
342
|
* is resolved through its symlinks, and the missing rest is appended as given.
|
|
343
|
+
* The build confines its outputs by it, and the theme editor's compile guard
|
|
344
|
+
* reads paths through it too, so both read a path the same way.
|
|
336
345
|
* @param {string} target absolute path
|
|
337
346
|
* @returns {string}
|
|
338
347
|
*/
|
|
339
|
-
function realLocation(target) {
|
|
348
|
+
export function realLocation(target) {
|
|
340
349
|
/** @type {string[]} */
|
|
341
350
|
const missing = [];
|
|
342
351
|
let existing = target;
|
|
@@ -818,7 +827,7 @@ function confineOutputs(writes, root, remedy) {
|
|
|
818
827
|
}
|
|
819
828
|
|
|
820
829
|
/** @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) {
|
|
830
|
+
export function refusedOutput(dest, root) {
|
|
822
831
|
try {
|
|
823
832
|
confineOutput(dest, root, '');
|
|
824
833
|
return false;
|
|
@@ -925,6 +934,82 @@ function isDirectorySync(file) {
|
|
|
925
934
|
}
|
|
926
935
|
}
|
|
927
936
|
|
|
937
|
+
/**
|
|
938
|
+
* The marks a file's leading comment carries (see `generatedMark`): a theme
|
|
939
|
+
* build's output, or a file the theme editor writes, with the command it
|
|
940
|
+
* names. The one reader build and doctor share.
|
|
941
|
+
* @param {string} source the start of the file
|
|
942
|
+
* @param {string} [file] its path, for a mark that names no exact command
|
|
943
|
+
*/
|
|
944
|
+
export function fileMark(source, file) {
|
|
945
|
+
return generatedMark(source, GENERATED_MARKER, file);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* The command a file's leading comment says writes it, when another CLI
|
|
950
|
+
* command generates it (the theme editor's settings module or app copy):
|
|
951
|
+
* the exact command its mark names. Null for a theme build's own output and
|
|
952
|
+
* a file without a mark, such as a theme source of one's own.
|
|
953
|
+
* @param {string} file
|
|
954
|
+
* @returns {string | null}
|
|
955
|
+
*/
|
|
956
|
+
export function generatedFileCommand(file) {
|
|
957
|
+
const mark = fileMark(fileHead(file), file);
|
|
958
|
+
return mark?.kind === 'editor' ? mark.command : null;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* The command that writes a missing `file`: a file beside it carries
|
|
963
|
+
* another command's mark, and a file there names `file` (a build output's
|
|
964
|
+
* header names its source), so it is one that command writes. Null for any
|
|
965
|
+
* other name, such as a typo.
|
|
966
|
+
* @param {string} file
|
|
967
|
+
* @returns {string | null}
|
|
968
|
+
*/
|
|
969
|
+
function missingGeneratedCommand(file) {
|
|
970
|
+
const dir = path.dirname(file);
|
|
971
|
+
const base = path.basename(file);
|
|
972
|
+
let names;
|
|
973
|
+
try {
|
|
974
|
+
names = fs.readdirSync(dir).sort();
|
|
975
|
+
} catch {
|
|
976
|
+
return null;
|
|
977
|
+
}
|
|
978
|
+
/** @type {string | null} */
|
|
979
|
+
let by = null;
|
|
980
|
+
let named = false;
|
|
981
|
+
for (const n of names) {
|
|
982
|
+
const f = path.join(dir, n);
|
|
983
|
+
try {
|
|
984
|
+
if (!fs.statSync(f).isFile()) continue;
|
|
985
|
+
} catch {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
by ??= generatedFileCommand(f);
|
|
989
|
+
if (!named)
|
|
990
|
+
try {
|
|
991
|
+
named = fs.readFileSync(f, 'utf8').slice(0, 4000).includes(base);
|
|
992
|
+
} catch {
|
|
993
|
+
// A file that does not read names nothing.
|
|
994
|
+
}
|
|
995
|
+
if (by && named) return by;
|
|
996
|
+
}
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* The command that writes `file`: from its own mark, or, when it is
|
|
1002
|
+
* missing, from the files beside it (see `missingGeneratedCommand`); null
|
|
1003
|
+
* otherwise.
|
|
1004
|
+
* @param {string} file
|
|
1005
|
+
* @returns {string | null}
|
|
1006
|
+
*/
|
|
1007
|
+
export function generatedSourceCommand(file) {
|
|
1008
|
+
return fs.existsSync(file)
|
|
1009
|
+
? generatedFileCommand(file)
|
|
1010
|
+
: missingGeneratedCommand(file);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
928
1013
|
/** @param {string} file @returns {string} the start of a file, or '' when it cannot be read */
|
|
929
1014
|
function fileHead(file) {
|
|
930
1015
|
try {
|
|
@@ -1121,7 +1206,16 @@ function assertThemeSourceFile(filePath, cwd, mode = {}) {
|
|
|
1121
1206
|
* output must stay inside, for a scratch build; `commandWords` names the
|
|
1122
1207
|
* command in the rebuild hint; `prepareFamily`, `familyLoader`, and
|
|
1123
1208
|
* `familyInterception` make the build a family member's plan.
|
|
1124
|
-
*
|
|
1209
|
+
* `colorModes` is the one color mode a calling command knows the theme has
|
|
1210
|
+
* (the theme editor, from its settings), written into the built module.
|
|
1211
|
+
* @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
|
|
1212
|
+
*/
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* How a caller that loads a theme's fonts itself (the editor's app copy)
|
|
1216
|
+
* says to load a family: the notice per family and the recipe in place of
|
|
1217
|
+
* the generic one.
|
|
1218
|
+
* @typedef {{notice: (family: string) => string, recipe: (families: string[]) => string}} FontHelp
|
|
1125
1219
|
*/
|
|
1126
1220
|
|
|
1127
1221
|
/**
|
|
@@ -1157,6 +1251,45 @@ export function setEditorFolderListener(listener) {
|
|
|
1157
1251
|
* @typedef {{glob?: boolean, family?: boolean, familyKey?: string}} SuggestionShape
|
|
1158
1252
|
*/
|
|
1159
1253
|
|
|
1254
|
+
/**
|
|
1255
|
+
* The refusal a build gives the file it is given before it reads it, or
|
|
1256
|
+
* null: a file that is not there, and a folder. The build throws it, and a
|
|
1257
|
+
* suggested build is checked by it before it is offered.
|
|
1258
|
+
* @param {string} file as typed, from cwd
|
|
1259
|
+
* @param {BuildMode} options
|
|
1260
|
+
* @param {string} cwd
|
|
1261
|
+
* @returns {AstryxError | null}
|
|
1262
|
+
*/
|
|
1263
|
+
export function buildInputProblem(file, options, cwd) {
|
|
1264
|
+
const filePath = path.resolve(cwd, file);
|
|
1265
|
+
if (!fs.existsSync(filePath))
|
|
1266
|
+
return new AstryxError(
|
|
1267
|
+
`File not found: ${filePath}`,
|
|
1268
|
+
themeSourceGuesses(file, cwd).map(guess => ({
|
|
1269
|
+
name: buildSuggestion(guess, options, cwd),
|
|
1270
|
+
reason: 'a theme source that exists',
|
|
1271
|
+
})),
|
|
1272
|
+
ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
1273
|
+
);
|
|
1274
|
+
if (fs.statSync(filePath).isDirectory())
|
|
1275
|
+
return new AstryxError(
|
|
1276
|
+
`${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
|
|
1277
|
+
themeFilesIn(filePath).map(name => ({
|
|
1278
|
+
name: buildSuggestion(
|
|
1279
|
+
path
|
|
1280
|
+
.relative(cwd, path.join(filePath, name))
|
|
1281
|
+
.split(path.sep)
|
|
1282
|
+
.join('/'),
|
|
1283
|
+
options,
|
|
1284
|
+
cwd,
|
|
1285
|
+
),
|
|
1286
|
+
reason: 'a theme source in that folder',
|
|
1287
|
+
})),
|
|
1288
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1289
|
+
);
|
|
1290
|
+
return null;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1160
1293
|
/**
|
|
1161
1294
|
* The `theme build` command for `source` with the caller's mode flags, so a
|
|
1162
1295
|
* suggestion never turns a check into a write or moves the outputs.
|
|
@@ -1212,11 +1345,12 @@ export function buildSuggestion(source, mode, cwd, words, shape = {}) {
|
|
|
1212
1345
|
* @param {Array<{dest: string}>} writes
|
|
1213
1346
|
* @param {string} filePath the theme source
|
|
1214
1347
|
* @param {string} cwd
|
|
1215
|
-
* @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void}} [options]
|
|
1348
|
+
* @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void, onWarning?: (message: string) => void}} [options]
|
|
1216
1349
|
* `claimed`: outputs written earlier in this run, by the source that wrote
|
|
1217
1350
|
* them; `rerun`: this build's command with another --out, or without one;
|
|
1218
1351
|
* `elsewhere`: the option that moves the outputs; `onEditorFolder`: takes
|
|
1219
|
-
* the editor-folder warning instead of the logger (a watcher prints it
|
|
1352
|
+
* the editor-folder warning instead of the logger (a watcher prints it
|
|
1353
|
+
* once); `onWarning`: each warning's message too, for the result
|
|
1220
1354
|
*/
|
|
1221
1355
|
function assertOutputsReplaceable(
|
|
1222
1356
|
writes,
|
|
@@ -1228,6 +1362,7 @@ function assertOutputsReplaceable(
|
|
|
1228
1362
|
refuseUnmarked = false,
|
|
1229
1363
|
elsewhere = '--out',
|
|
1230
1364
|
onEditorFolder,
|
|
1365
|
+
onWarning,
|
|
1231
1366
|
} = {},
|
|
1232
1367
|
) {
|
|
1233
1368
|
const rel = (/** @type {string} */ file) => path.relative(cwd, file);
|
|
@@ -1309,7 +1444,7 @@ function assertOutputsReplaceable(
|
|
|
1309
1444
|
// It is printed after every output passes, so it names a replacement
|
|
1310
1445
|
// that happens.
|
|
1311
1446
|
if (warnedOtherSource) continue;
|
|
1312
|
-
warnedOtherSource =
|
|
1447
|
+
warnedOtherSource = `${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
|
|
1313
1448
|
} else if (otherSource) {
|
|
1314
1449
|
throw new AstryxError(
|
|
1315
1450
|
`${rel(write.dest)} is the build output of another theme source, ${otherSource}, so this build does not replace it. Pick another ${elsewhere}.`,
|
|
@@ -1346,12 +1481,16 @@ function assertOutputsReplaceable(
|
|
|
1346
1481
|
}
|
|
1347
1482
|
// Warned only once nothing refuses the build, so it names a write that
|
|
1348
1483
|
// happens.
|
|
1349
|
-
if (warnedOtherSource)
|
|
1484
|
+
if (warnedOtherSource) {
|
|
1485
|
+
logger.warn(`Warning: ${warnedOtherSource}`);
|
|
1486
|
+
onWarning?.(warnedOtherSource);
|
|
1487
|
+
}
|
|
1350
1488
|
if (editorFolder) {
|
|
1351
1489
|
const dir = path.dirname(writes[0].dest);
|
|
1352
|
-
const
|
|
1353
|
-
if (onEditorFolder) onEditorFolder(
|
|
1354
|
-
else logger.warn(
|
|
1490
|
+
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.`;
|
|
1491
|
+
if (onEditorFolder) onEditorFolder(`Warning: ${message}`);
|
|
1492
|
+
else logger.warn(`Warning: ${message}`);
|
|
1493
|
+
onWarning?.(message);
|
|
1355
1494
|
}
|
|
1356
1495
|
}
|
|
1357
1496
|
|
|
@@ -1443,7 +1582,31 @@ function writeBuildOutputs(writes) {
|
|
|
1443
1582
|
})),
|
|
1444
1583
|
);
|
|
1445
1584
|
} catch (error) {
|
|
1446
|
-
const
|
|
1585
|
+
const e = /** @type {NodeJS.ErrnoException} */ (error);
|
|
1586
|
+
// A place the outputs cannot be written: name it and its fix (the
|
|
1587
|
+
// writes go through temporary files beside each output, whose names
|
|
1588
|
+
// help nobody).
|
|
1589
|
+
if (e.code === 'EACCES' || e.code === 'EPERM' || e.code === 'EROFS') {
|
|
1590
|
+
const failed = e.path ? path.resolve(e.path) : null;
|
|
1591
|
+
const output = writes.find(w => path.resolve(w.dest) === failed);
|
|
1592
|
+
const place = output
|
|
1593
|
+
? output.dest
|
|
1594
|
+
: failed
|
|
1595
|
+
? path.dirname(failed)
|
|
1596
|
+
: path.dirname(writes[0].dest);
|
|
1597
|
+
const shownPlace = path.relative(process.cwd(), place) || place;
|
|
1598
|
+
throw new AstryxError(
|
|
1599
|
+
`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.`,
|
|
1600
|
+
[
|
|
1601
|
+
{
|
|
1602
|
+
name: `ls -ld ${shellWord(shownPlace)}`,
|
|
1603
|
+
reason: 'see its permissions',
|
|
1604
|
+
},
|
|
1605
|
+
],
|
|
1606
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
const message = `Failed to write theme outputs: ${e.message}`;
|
|
1447
1610
|
throw new AstryxError(message, undefined, ERROR_CODES.ERR_WRITE_FAILED);
|
|
1448
1611
|
}
|
|
1449
1612
|
}
|
|
@@ -1534,27 +1697,10 @@ async function loadKnownValuesIndex() {
|
|
|
1534
1697
|
const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
|
|
1535
1698
|
if (!coreSrc || !fs.existsSync(coreSrc)) return {};
|
|
1536
1699
|
|
|
1537
|
-
|
|
1538
|
-
const docs =
|
|
1539
|
-
|
|
1540
|
-
|
|
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);
|
|
1700
|
+
// One malformed or optional doc must not erase validation for the rest.
|
|
1701
|
+
const docs = (await coreComponentDocs(coreSrc)).flatMap(read =>
|
|
1702
|
+
'error' in read ? [] : [read.doc],
|
|
1703
|
+
);
|
|
1558
1704
|
|
|
1559
1705
|
/** @param {string} value */
|
|
1560
1706
|
const targetName = value =>
|
|
@@ -1778,55 +1924,34 @@ async function resolveAugmentationTargetCandidates(componentName) {
|
|
|
1778
1924
|
matches.push({moduleName, interfacePrefix});
|
|
1779
1925
|
}
|
|
1780
1926
|
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
const
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
const
|
|
1803
|
-
(
|
|
1804
|
-
|
|
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
|
-
}
|
|
1927
|
+
for (const read of await coreComponentDocs(coreSrc)) {
|
|
1928
|
+
if ('error' in read) continue;
|
|
1929
|
+
const {file, doc} = read;
|
|
1930
|
+
const matchesTarget = (doc?.theming?.targets || []).some(
|
|
1931
|
+
(/** @type {any} */ target) =>
|
|
1932
|
+
typeof target?.className === 'string' &&
|
|
1933
|
+
target.className.replace(/^astryx-/, '') === componentName,
|
|
1934
|
+
);
|
|
1935
|
+
if (!matchesTarget) continue;
|
|
1936
|
+
|
|
1937
|
+
const moduleName =
|
|
1938
|
+
typeof doc?.name === 'string' && doc.name
|
|
1939
|
+
? doc.name
|
|
1940
|
+
: path.basename(path.dirname(file));
|
|
1941
|
+
|
|
1942
|
+
// Try the exact rendered token first for documented subtargets such as
|
|
1943
|
+
// avatar-status-dot → AvatarStatusDotVariantMap, then the owning public
|
|
1944
|
+
// component name (for example, ProgressBar for progress-bar-fill).
|
|
1945
|
+
addCandidate(moduleName, toPascalCase(componentName));
|
|
1946
|
+
addCandidate(moduleName, moduleName);
|
|
1947
|
+
if (Array.isArray(doc?.components)) {
|
|
1948
|
+
for (const comp of doc.components) {
|
|
1949
|
+
if (typeof comp?.name === 'string') {
|
|
1950
|
+
addCandidate(moduleName, comp.name);
|
|
1824
1951
|
}
|
|
1825
1952
|
}
|
|
1826
1953
|
}
|
|
1827
1954
|
}
|
|
1828
|
-
|
|
1829
|
-
await scan(coreSrc);
|
|
1830
1955
|
// A target documented by a parent component may also have its own public
|
|
1831
1956
|
// subpath and augmentation interface (Heading is documented under Text but
|
|
1832
1957
|
// owns @astryxdesign/core/Heading). Keep the direct-name candidate after
|
|
@@ -2630,19 +2755,23 @@ function isSyncLoaderLimitation(error) {
|
|
|
2630
2755
|
* source export and old-Core adaptation checks keep treating that path as
|
|
2631
2756
|
* degraded/fail-closed.
|
|
2632
2757
|
*
|
|
2758
|
+
* On Node 22.15 and later, on every path, a stylesheet that a module in the
|
|
2759
|
+
* theme's graph imports loads as an empty module (`withEmptyStylesheets`): a
|
|
2760
|
+
* base theme's module can import its own stylesheet for the app's bundler.
|
|
2761
|
+
*
|
|
2633
2762
|
* @param {string} filePath
|
|
2634
2763
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
2635
|
-
* @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
|
|
2764
|
+
* @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes: ["light"] | ["dark"] | null}>}
|
|
2636
2765
|
*/
|
|
2637
2766
|
// prettier-ignore
|
|
2638
|
-
async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
2767
|
+
async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined, /** @type {string | undefined} */ pick = undefined) {
|
|
2639
2768
|
const jiti =
|
|
2640
2769
|
loader ??
|
|
2641
2770
|
createJiti(import.meta.url, {
|
|
2642
2771
|
moduleCache: false,
|
|
2643
|
-
//
|
|
2644
|
-
//
|
|
2645
|
-
|
|
2772
|
+
// The per-user transpile cache: an edited theme is transpiled again,
|
|
2773
|
+
// and the folder stays within its size limit.
|
|
2774
|
+
...jitiCacheOptions(),
|
|
2646
2775
|
jsx: true,
|
|
2647
2776
|
extensions: THEME_MODULE_EXTENSIONS,
|
|
2648
2777
|
...(interception ? {virtualModules: interception.modules} : {}),
|
|
@@ -2659,7 +2788,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2659
2788
|
const commonJsPatch = interception.patchCommonJs(filePath);
|
|
2660
2789
|
try {
|
|
2661
2790
|
try {
|
|
2662
|
-
mod = jiti(filePath);
|
|
2791
|
+
mod = await withEmptyStylesheets(async () => jiti(filePath));
|
|
2663
2792
|
} catch (error) {
|
|
2664
2793
|
// Only a sync-loader limitation may fall back. Anything else is the
|
|
2665
2794
|
// theme's own failure and belongs to the caller unchanged.
|
|
@@ -2668,14 +2797,16 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2668
2797
|
// Force asynchronous transformation instead of native import: this
|
|
2669
2798
|
// keeps virtual Core interception active even when the module uses
|
|
2670
2799
|
// top-level await.
|
|
2671
|
-
mod = await
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2800
|
+
mod = await withEmptyStylesheets(() =>
|
|
2801
|
+
jiti.evalModule(fs.readFileSync(filePath, 'utf8'), {
|
|
2802
|
+
id: filePath,
|
|
2803
|
+
filename: filePath,
|
|
2804
|
+
ext: path.extname(filePath),
|
|
2805
|
+
cache: jiti.cache,
|
|
2806
|
+
async: true,
|
|
2807
|
+
forceTranspile: true,
|
|
2808
|
+
}),
|
|
2809
|
+
);
|
|
2679
2810
|
}
|
|
2680
2811
|
} finally {
|
|
2681
2812
|
// Read after the load: the root is wrapped when the load requires it.
|
|
@@ -2683,7 +2814,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2683
2814
|
commonJsPatch.undo();
|
|
2684
2815
|
}
|
|
2685
2816
|
} else {
|
|
2686
|
-
mod = await jiti.import(filePath);
|
|
2817
|
+
mod = await withEmptyStylesheets(() => jiti.import(filePath));
|
|
2687
2818
|
}
|
|
2688
2819
|
|
|
2689
2820
|
// Both loads hand back the module. The theme is read from the module's own
|
|
@@ -2692,15 +2823,28 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2692
2823
|
// `default` with the module), so the module can pass for the theme while
|
|
2693
2824
|
// its own keys hide the theme's fields.
|
|
2694
2825
|
const isModule = mod != null && typeof mod === 'object';
|
|
2826
|
+
// A theme with one color mode says so with a `colorModes` export beside
|
|
2827
|
+
// the theme (`['light']` or `['dark']`); the build carries it into the
|
|
2828
|
+
// built module.
|
|
2829
|
+
const colorModes = oneColorMode(
|
|
2830
|
+
isModule && Object.hasOwn(mod, 'colorModes') ? mod.colorModes : undefined,
|
|
2831
|
+
);
|
|
2695
2832
|
const hasDefault = isModule && Object.hasOwn(mod, 'default');
|
|
2696
2833
|
const defaultExport = hasDefault ? mod.default : undefined;
|
|
2834
|
+
// A caller that already knows which export a build reads (from a load
|
|
2835
|
+
// as the build loads it) reads that one.
|
|
2836
|
+
if (pick !== undefined && isModule && Object.hasOwn(mod, pick)) {
|
|
2837
|
+
if (isThemeObject(mod[pick]))
|
|
2838
|
+
return {theme: mod[pick], exportName: pick, degraded, colorModes};
|
|
2839
|
+
}
|
|
2697
2840
|
if (isThemeObject(defaultExport)) {
|
|
2698
|
-
return {theme: defaultExport, exportName: 'default', degraded};
|
|
2841
|
+
return {theme: defaultExport, exportName: 'default', degraded, colorModes};
|
|
2699
2842
|
}
|
|
2700
2843
|
if (isModule) {
|
|
2701
2844
|
for (const [exportName, value] of Object.entries(mod)) {
|
|
2702
2845
|
if (exportName === 'default' || exportName === 'module.exports') continue;
|
|
2703
|
-
if (isThemeObject(value))
|
|
2846
|
+
if (isThemeObject(value))
|
|
2847
|
+
return {theme: value, exportName, degraded, colorModes};
|
|
2704
2848
|
}
|
|
2705
2849
|
}
|
|
2706
2850
|
// The loader's interop answers a null default with the module itself, so
|
|
@@ -2722,7 +2866,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2722
2866
|
// be all it defines), or no name: the build's validation says what it
|
|
2723
2867
|
// lacks.
|
|
2724
2868
|
if (isPlainObject(defaultExport)) {
|
|
2725
|
-
return {theme: defaultExport, exportName: 'default', degraded};
|
|
2869
|
+
return {theme: defaultExport, exportName: 'default', degraded, colorModes};
|
|
2726
2870
|
}
|
|
2727
2871
|
// A CommonJS module whose exports are the theme (`module.exports =
|
|
2728
2872
|
// theme`) has no default of its own: interop answers `default` with
|
|
@@ -2731,7 +2875,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2731
2875
|
if (isModule && !hasDefault) {
|
|
2732
2876
|
const exportsObject = mod.default ?? mod;
|
|
2733
2877
|
if (isThemeObject(exportsObject)) {
|
|
2734
|
-
return {theme: exportsObject, exportName: 'default', degraded};
|
|
2878
|
+
return {theme: exportsObject, exportName: 'default', degraded, colorModes};
|
|
2735
2879
|
}
|
|
2736
2880
|
}
|
|
2737
2881
|
|
|
@@ -2800,12 +2944,12 @@ function isThemeObject(value) {
|
|
|
2800
2944
|
*
|
|
2801
2945
|
* @param {string} filePath
|
|
2802
2946
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
2803
|
-
* @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
|
|
2947
|
+
* @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes?: ['light'] | ['dark'] | null}>}
|
|
2804
2948
|
*/
|
|
2805
2949
|
// prettier-ignore
|
|
2806
|
-
async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
2950
|
+
async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined, /** @type {string | undefined} */ pick = undefined) {
|
|
2807
2951
|
try {
|
|
2808
|
-
return await importThemeModule(filePath, interception, loader);
|
|
2952
|
+
return await importThemeModule(filePath, interception, loader, pick);
|
|
2809
2953
|
} catch (jitiError) {
|
|
2810
2954
|
const je = /** @type {Error} */ (jitiError);
|
|
2811
2955
|
throw new Error(
|
|
@@ -2815,6 +2959,143 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
|
|
|
2815
2959
|
}
|
|
2816
2960
|
}
|
|
2817
2961
|
|
|
2962
|
+
/**
|
|
2963
|
+
* The Core interception a standalone build loads a theme module with: none
|
|
2964
|
+
* when the selected Core generates adaptations itself and the theme's folder
|
|
2965
|
+
* resolves a Core of its own; else imports of Core are handed the selected
|
|
2966
|
+
* Core.
|
|
2967
|
+
* @param {string} filePath
|
|
2968
|
+
*/
|
|
2969
|
+
function standaloneInterception(filePath) {
|
|
2970
|
+
return _generateAdaptationCSS && themeFolderResolvesCore(filePath)
|
|
2971
|
+
? undefined
|
|
2972
|
+
: interceptCore(_coreThemeModule, _coreRootModule);
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
/**
|
|
2976
|
+
* Load a theme module as a standalone build of it loads it (the Core the
|
|
2977
|
+
* build selects, the same loader and interception) and name the export the
|
|
2978
|
+
* build reads. Callers that must agree with the build on which theme a
|
|
2979
|
+
* module defines read it here, never from the module's text.
|
|
2980
|
+
*
|
|
2981
|
+
* With `base`, also whether the theme extends that module's export, by
|
|
2982
|
+
* identity, anywhere up its `extends` chain (`extendsBase`): the module is
|
|
2983
|
+
* loaded once, and the theme module's imports of it (by any of
|
|
2984
|
+
* `base.specifiers`) are handed that one load, so the answer is about the
|
|
2985
|
+
* very object, not one that only looks like it.
|
|
2986
|
+
* @param {string} file
|
|
2987
|
+
* @param {{cwd?: string, base?: {file: string, exportName: string, specifiers: string[]}}} [ctx]
|
|
2988
|
+
* @returns {Promise<{theme: any, exportName: string, extendsBase?: boolean}>}
|
|
2989
|
+
*/
|
|
2990
|
+
export async function loadThemeExport(file, {cwd = process.cwd(), base} = {}) {
|
|
2991
|
+
const filePath = path.resolve(cwd, file);
|
|
2992
|
+
await selectCore(cwd, {projectOnly: false});
|
|
2993
|
+
const {theme, exportName = 'default'} = await extractThemeDefinition(
|
|
2994
|
+
filePath,
|
|
2995
|
+
standaloneInterception(filePath),
|
|
2996
|
+
);
|
|
2997
|
+
if (!base) return {theme, exportName};
|
|
2998
|
+
const recorder = interceptCore(_coreThemeModule, _coreRootModule);
|
|
2999
|
+
const shared = (
|
|
3000
|
+
await extractThemeDefinition(
|
|
3001
|
+
path.resolve(cwd, base.file),
|
|
3002
|
+
recorder,
|
|
3003
|
+
undefined,
|
|
3004
|
+
base.exportName,
|
|
3005
|
+
)
|
|
3006
|
+
).theme;
|
|
3007
|
+
const withBase = {
|
|
3008
|
+
...recorder,
|
|
3009
|
+
modules: {
|
|
3010
|
+
...recorder.modules,
|
|
3011
|
+
...Object.fromEntries(
|
|
3012
|
+
base.specifiers.map(s => [s, {[base.exportName]: shared}]),
|
|
3013
|
+
),
|
|
3014
|
+
},
|
|
3015
|
+
};
|
|
3016
|
+
const again = await extractThemeDefinition(
|
|
3017
|
+
filePath,
|
|
3018
|
+
withBase,
|
|
3019
|
+
undefined,
|
|
3020
|
+
exportName,
|
|
3021
|
+
);
|
|
3022
|
+
let extendsBase = false;
|
|
3023
|
+
for (
|
|
3024
|
+
let at = recorder.parentOf(again.theme), depth = 0;
|
|
3025
|
+
at && depth < 64;
|
|
3026
|
+
at = recorder.parentOf(at), depth++
|
|
3027
|
+
)
|
|
3028
|
+
if (at === shared) {
|
|
3029
|
+
extendsBase = true;
|
|
3030
|
+
break;
|
|
3031
|
+
}
|
|
3032
|
+
return {theme, exportName, extendsBase};
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
/**
|
|
3036
|
+
* The input a theme module gives `defineTheme()` for the theme a build of
|
|
3037
|
+
* it reads, evaluated as the build evaluates the module (an import, an
|
|
3038
|
+
* expression, a spread or a computed key is its value), with the theme Core
|
|
3039
|
+
* made of it. When Core refuses the input, the input the module gave for
|
|
3040
|
+
* the named theme (else its last) and Core's error; null when the module
|
|
3041
|
+
* does not load at all.
|
|
3042
|
+
* `chain` holds the inputs of the themes it extends, nearest first, as far
|
|
3043
|
+
* as each was made by a `defineTheme()` call this load saw.
|
|
3044
|
+
* @param {string} file
|
|
3045
|
+
* @param {{cwd?: string, name?: string}} [ctx]
|
|
3046
|
+
* @returns {Promise<{input: any, theme: any, error: Error | null, chain: any[]} | null>}
|
|
3047
|
+
*/
|
|
3048
|
+
export async function loadThemeInput(file, {cwd = process.cwd(), name} = {}) {
|
|
3049
|
+
const filePath = path.resolve(cwd, file);
|
|
3050
|
+
await selectCore(cwd, {projectOnly: false});
|
|
3051
|
+
const interception = interceptCore(_coreThemeModule, _coreRootModule);
|
|
3052
|
+
/** @param {any} input */
|
|
3053
|
+
const chainOf = input => {
|
|
3054
|
+
const chain = [];
|
|
3055
|
+
/** @type {Set<any>} */
|
|
3056
|
+
const seen = new Set([input]);
|
|
3057
|
+
let parent = interception.inputOf(input?.extends);
|
|
3058
|
+
while (parent && typeof parent === 'object' && !seen.has(parent)) {
|
|
3059
|
+
seen.add(parent);
|
|
3060
|
+
chain.push(parent);
|
|
3061
|
+
parent = interception.inputOf(parent.extends);
|
|
3062
|
+
}
|
|
3063
|
+
return chain;
|
|
3064
|
+
};
|
|
3065
|
+
try {
|
|
3066
|
+
const {theme} = await extractThemeDefinition(filePath, interception);
|
|
3067
|
+
const input = interception.inputOf(theme) ?? null;
|
|
3068
|
+
return {input, theme, error: null, chain: chainOf(input)};
|
|
3069
|
+
} catch (e) {
|
|
3070
|
+
const given = interception.inputs;
|
|
3071
|
+
const input =
|
|
3072
|
+
given.filter(x => x && typeof x === 'object' && x.name === name).at(-1) ??
|
|
3073
|
+
given.at(-1);
|
|
3074
|
+
return input
|
|
3075
|
+
? {
|
|
3076
|
+
input,
|
|
3077
|
+
theme: null,
|
|
3078
|
+
error: /** @type {Error} */ (e),
|
|
3079
|
+
chain: chainOf(input),
|
|
3080
|
+
}
|
|
3081
|
+
: null;
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
/**
|
|
3086
|
+
* A one-mode `colorModes` value (`['light']` or `['dark']`), or null for
|
|
3087
|
+
* anything else: a theme with both modes needs no export.
|
|
3088
|
+
* @param {unknown} value
|
|
3089
|
+
* @returns {['light'] | ['dark'] | null}
|
|
3090
|
+
*/
|
|
3091
|
+
export function oneColorMode(value) {
|
|
3092
|
+
return Array.isArray(value) &&
|
|
3093
|
+
value.length === 1 &&
|
|
3094
|
+
(value[0] === 'light' || value[0] === 'dark')
|
|
3095
|
+
? /** @type {['light'] | ['dark']} */ ([value[0]])
|
|
3096
|
+
: null;
|
|
3097
|
+
}
|
|
3098
|
+
|
|
2818
3099
|
/** Names a theme module's exports must take; ends a shape failure. */
|
|
2819
3100
|
const THEME_EXPORT_FIX =
|
|
2820
3101
|
"Export the theme object: `export default defineTheme({name: 'my-theme', tokens: {...}})`, or a plain `export default {name: 'my-theme', tokens: {...}}`.";
|
|
@@ -3739,21 +4020,32 @@ async function themeBuildInternal(
|
|
|
3739
4020
|
report = {},
|
|
3740
4021
|
handOff = {},
|
|
3741
4022
|
) {
|
|
4023
|
+
// A blank --out names no file: the build would write files named by the
|
|
4024
|
+
// spaces alone.
|
|
4025
|
+
if (
|
|
4026
|
+
typeof options.out === 'string' &&
|
|
4027
|
+
options.out !== '' &&
|
|
4028
|
+
!options.out.trim()
|
|
4029
|
+
)
|
|
4030
|
+
throw new AstryxError(
|
|
4031
|
+
'--out is blank; name a file or folder, or leave out --out to write beside the source.',
|
|
4032
|
+
[
|
|
4033
|
+
{
|
|
4034
|
+
name: buildSuggestion(file, {...options, out: undefined}, cwd),
|
|
4035
|
+
reason: 'do this instead',
|
|
4036
|
+
},
|
|
4037
|
+
],
|
|
4038
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
4039
|
+
);
|
|
3742
4040
|
// A backslash in --out separates folders on every platform, as it does in
|
|
3743
4041
|
// the other theme paths (a Windows path copied into a POSIX shell).
|
|
3744
4042
|
if (typeof options.out === 'string' && options.out.includes('\\'))
|
|
3745
4043
|
options = {...options, out: options.out.replace(/\\/g, '/')};
|
|
3746
4044
|
const filePath = path.resolve(cwd, file);
|
|
3747
4045
|
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
themeSourceGuesses(file, cwd).map(guess => ({
|
|
3752
|
-
name: buildSuggestion(guess, options, cwd),
|
|
3753
|
-
reason: 'a theme source that exists',
|
|
3754
|
-
})),
|
|
3755
|
-
ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
3756
|
-
);
|
|
4046
|
+
{
|
|
4047
|
+
const problem = buildInputProblem(file, options, cwd);
|
|
4048
|
+
if (problem) throw problem;
|
|
3757
4049
|
}
|
|
3758
4050
|
|
|
3759
4051
|
// A theme the theme editor made is built from its settings by the editor;
|
|
@@ -3772,24 +4064,6 @@ async function themeBuildInternal(
|
|
|
3772
4064
|
);
|
|
3773
4065
|
}
|
|
3774
4066
|
|
|
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
4067
|
assertThemeSourceFile(filePath, cwd, options);
|
|
3794
4068
|
|
|
3795
4069
|
if (!report.compact) {
|
|
@@ -3814,10 +4088,7 @@ async function themeBuildInternal(
|
|
|
3814
4088
|
// shared loader so exact authored parent identity stays CLI-private instead
|
|
3815
4089
|
// of becoming a public DefinedTheme field.
|
|
3816
4090
|
const interception =
|
|
3817
|
-
handOff.familyInterception ??
|
|
3818
|
-
(_generateAdaptationCSS && themeFolderResolvesCore(filePath)
|
|
3819
|
-
? undefined
|
|
3820
|
-
: interceptCore(_coreThemeModule, _coreRootModule));
|
|
4091
|
+
handOff.familyInterception ?? standaloneInterception(filePath);
|
|
3821
4092
|
|
|
3822
4093
|
// Extract theme definition
|
|
3823
4094
|
let themeDef;
|
|
@@ -3825,6 +4096,9 @@ async function themeBuildInternal(
|
|
|
3825
4096
|
let themeExportName;
|
|
3826
4097
|
/** Paths through the load that interception could not fully observe. */
|
|
3827
4098
|
let loadDegradation;
|
|
4099
|
+
/** The one color mode the theme module exports, or null for both. */
|
|
4100
|
+
/** @type {['light'] | ['dark'] | null} */
|
|
4101
|
+
let colorModes;
|
|
3828
4102
|
/**
|
|
3829
4103
|
* The theme file's bytes as loaded: read before and after the load, and the
|
|
3830
4104
|
* registry scan below reads these rather than the file again. An editor's
|
|
@@ -3851,6 +4125,7 @@ async function themeBuildInternal(
|
|
|
3851
4125
|
themeDef = loaded.theme;
|
|
3852
4126
|
themeExportName = loaded.exportName;
|
|
3853
4127
|
loadDegradation = loaded.degraded;
|
|
4128
|
+
colorModes = handOff.colorModes ?? loaded.colorModes ?? null;
|
|
3854
4129
|
} catch (e) {
|
|
3855
4130
|
const err = /** @type {Error} */ (e);
|
|
3856
4131
|
const shown = path.relative(cwd, filePath) || filePath;
|
|
@@ -4403,9 +4678,10 @@ async function themeBuildInternal(
|
|
|
4403
4678
|
.join(path.dirname(options.out), `${stem}.css`)
|
|
4404
4679
|
.split(path.sep)
|
|
4405
4680
|
.join('/');
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
);
|
|
4681
|
+
// The result's warnings say it too, as text does.
|
|
4682
|
+
const w = `--out names the stylesheet, which is CSS; give it a .css name such as ${fixed}.`;
|
|
4683
|
+
warningMessages.push(w);
|
|
4684
|
+
logger.warn(`Warning: ${w}`);
|
|
4409
4685
|
}
|
|
4410
4686
|
// A build keeps the explicit output inside the write root, relative or
|
|
4411
4687
|
// absolute. Check mode writes nothing, so it refuses only a relative path
|
|
@@ -4482,19 +4758,30 @@ async function themeBuildInternal(
|
|
|
4482
4758
|
? {}
|
|
4483
4759
|
: {cssFileName: path.basename(outPath)}),
|
|
4484
4760
|
},
|
|
4485
|
-
)
|
|
4761
|
+
) +
|
|
4762
|
+
// The one color mode, beside the theme export (a two-mode theme
|
|
4763
|
+
// exports none, so its module is unchanged).
|
|
4764
|
+
(colorModes
|
|
4765
|
+
? `export const colorModes = [${JSON.stringify(colorModes[0])}];\n`
|
|
4766
|
+
: '');
|
|
4486
4767
|
const dtsContent =
|
|
4487
4768
|
generatedHeader(headerSource, 'ts', buildCommand, versions) +
|
|
4488
|
-
generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName)
|
|
4769
|
+
generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName) +
|
|
4770
|
+
(colorModes
|
|
4771
|
+
? `export declare const colorModes: readonly [${JSON.stringify(colorModes[0])}];\n`
|
|
4772
|
+
: '');
|
|
4489
4773
|
|
|
4774
|
+
// A family the caller knows the app loads (a font stylesheet it writes
|
|
4775
|
+
// for the theme) is not named as unloaded.
|
|
4490
4776
|
const unloadedFonts = [
|
|
4491
4777
|
...new Set([
|
|
4492
4778
|
...collectUnloadedFonts(resolvedTheme),
|
|
4493
4779
|
...adaptationRuleValues(resolvedTheme).flatMap(
|
|
4494
|
-
(/** @type {any} */ value) =>
|
|
4780
|
+
(/** @type {any} */ value) =>
|
|
4781
|
+
collectUnloadedFonts(value, resolvedTheme),
|
|
4495
4782
|
),
|
|
4496
4783
|
]),
|
|
4497
|
-
];
|
|
4784
|
+
].filter(family => !handOff.loadedFonts?.(family));
|
|
4498
4785
|
|
|
4499
4786
|
if (handOff.prepareFamily) {
|
|
4500
4787
|
return {
|
|
@@ -4547,6 +4834,8 @@ async function themeBuildInternal(
|
|
|
4547
4834
|
rerun,
|
|
4548
4835
|
refuseUnmarked: Boolean(options.out),
|
|
4549
4836
|
onEditorFolder: editorFolderListener ?? undefined,
|
|
4837
|
+
// The result's warnings carry what text prints.
|
|
4838
|
+
onWarning: message => warningMessages.push(message),
|
|
4550
4839
|
});
|
|
4551
4840
|
}
|
|
4552
4841
|
|
|
@@ -4637,12 +4926,19 @@ async function themeBuildInternal(
|
|
|
4637
4926
|
// permanently in violation of its own "compiles with no warnings" guard).
|
|
4638
4927
|
// Adaptation rules are resolved theme writes in their own right, so a family
|
|
4639
4928
|
// named only inside one needs the same notice as one named at the root.
|
|
4929
|
+
// The result names the recipe's command bare, as every machine-read
|
|
4930
|
+
// command is; the printed note starts it the way this project runs the CLI.
|
|
4931
|
+
/** @param {string} family @param {string} recipe */
|
|
4932
|
+
const fontNotice = (family, recipe) =>
|
|
4933
|
+
handOff.fontHelp?.notice(family) ??
|
|
4934
|
+
`Font "${family}" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: ${recipe})`;
|
|
4640
4935
|
/** @type {string[]} */
|
|
4641
4936
|
const fontNotices = [];
|
|
4642
4937
|
for (const family of unloadedFonts) {
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4938
|
+
noticeMessages.push(fontNotice(family, 'astryx docs typography'));
|
|
4939
|
+
fontNotices.push(
|
|
4940
|
+
fontNotice(family, formatCliCommand('docs typography', cwd)),
|
|
4941
|
+
);
|
|
4646
4942
|
}
|
|
4647
4943
|
|
|
4648
4944
|
/** @type {ThemeBuildTrailer} */
|
|
@@ -4653,6 +4949,8 @@ async function themeBuildInternal(
|
|
|
4653
4949
|
cssImport,
|
|
4654
4950
|
unloadedFonts,
|
|
4655
4951
|
fontNotices,
|
|
4952
|
+
fontHelp: handOff.fontHelp ?? null,
|
|
4953
|
+
install: handOff.install ?? null,
|
|
4656
4954
|
};
|
|
4657
4955
|
// A batch or compact report prints this once for the whole run instead.
|
|
4658
4956
|
if (report.trailers) report.trailers.push(trailer);
|
|
@@ -4689,7 +4987,11 @@ async function themeBuildInternal(
|
|
|
4689
4987
|
* @property {string} jsImport Import specifier of the built JS module.
|
|
4690
4988
|
* @property {string} cssImport Import specifier of the built CSS.
|
|
4691
4989
|
* @property {string[]} unloadedFonts Font families the theme names but does not load.
|
|
4692
|
-
* @property {string[]} fontNotices One notice per unloaded font family.
|
|
4990
|
+
* @property {string[]} fontNotices One notice per unloaded font family, as printed.
|
|
4991
|
+
* @property {FontHelp | null} [fontHelp] How the caller loads fonts, when it does.
|
|
4992
|
+
* @property {string | null} [install] How the app takes the theme, when the
|
|
4993
|
+
* caller wires it another way than importing these outputs (the editor's
|
|
4994
|
+
* app copy).
|
|
4693
4995
|
*/
|
|
4694
4996
|
|
|
4695
4997
|
/**
|
|
@@ -4697,7 +4999,9 @@ async function themeBuildInternal(
|
|
|
4697
4999
|
* @param {ThemeBuildTrailer} trailer
|
|
4698
5000
|
*/
|
|
4699
5001
|
function printBuildTrailer(trailer) {
|
|
4700
|
-
logger.log(`
|
|
5002
|
+
if (trailer.install) logger.log(`\n${trailer.install}\n`);
|
|
5003
|
+
else
|
|
5004
|
+
logger.log(`
|
|
4701
5005
|
Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
|
|
4702
5006
|
|
|
4703
5007
|
import { Theme } from '@astryxdesign/core/theme';
|
|
@@ -4720,7 +5024,13 @@ Or with a <link> tag:
|
|
|
4720
5024
|
`);
|
|
4721
5025
|
for (const msg of trailer.fontNotices) logger.log(` note: ${msg}`);
|
|
4722
5026
|
if (trailer.unloadedFonts.length > 0) {
|
|
4723
|
-
logger.log(
|
|
5027
|
+
logger.log(
|
|
5028
|
+
formatFontLoadingHelp(
|
|
5029
|
+
trailer.themeName,
|
|
5030
|
+
trailer.unloadedFonts,
|
|
5031
|
+
trailer.fontHelp?.recipe,
|
|
5032
|
+
),
|
|
5033
|
+
);
|
|
4724
5034
|
}
|
|
4725
5035
|
}
|
|
4726
5036
|
|
|
@@ -4732,8 +5042,13 @@ Or with a <link> tag:
|
|
|
4732
5042
|
*/
|
|
4733
5043
|
export function printBatchTrailer(trailers) {
|
|
4734
5044
|
if (trailers.length === 0) return;
|
|
4735
|
-
|
|
4736
|
-
|
|
5045
|
+
// A theme the caller wires another way says how, once each.
|
|
5046
|
+
for (const trailer of trailers)
|
|
5047
|
+
if (trailer.install) logger.log(`\n${trailer.install}\n`);
|
|
5048
|
+
const imported = trailers.filter(trailer => !trailer.install);
|
|
5049
|
+
const [first] = imported;
|
|
5050
|
+
if (first)
|
|
5051
|
+
logger.log(`
|
|
4737
5052
|
Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
|
|
4738
5053
|
|
|
4739
5054
|
import { Theme } from '@astryxdesign/core/theme';
|
|
@@ -4754,16 +5069,19 @@ Or with a <link> tag:
|
|
|
4754
5069
|
<App />
|
|
4755
5070
|
</Theme>
|
|
4756
5071
|
`);
|
|
4757
|
-
if (
|
|
5072
|
+
if (imported.length > 1) {
|
|
4758
5073
|
logger.log('Each built theme imports the same way:');
|
|
4759
|
-
for (const trailer of
|
|
5074
|
+
for (const trailer of imported) {
|
|
4760
5075
|
logger.log(
|
|
4761
5076
|
` import { ${trailer.exportName} } from '${trailer.jsImport}'; import '${trailer.cssImport}';`,
|
|
4762
5077
|
);
|
|
4763
5078
|
}
|
|
4764
5079
|
}
|
|
4765
5080
|
const fonts = groupUnloadedFonts(trailers);
|
|
4766
|
-
|
|
5081
|
+
// One caller's recipe serves the batch only when every theme takes it.
|
|
5082
|
+
const help = trailers.every(t => t.fontHelp) ? trailers[0].fontHelp : null;
|
|
5083
|
+
if (fonts.length > 0)
|
|
5084
|
+
logger.log(formatBatchFontLoadingHelp(fonts, help?.recipe));
|
|
4767
5085
|
}
|
|
4768
5086
|
|
|
4769
5087
|
/**
|
|
@@ -4998,7 +5316,7 @@ function planFamilySources(files, cwd) {
|
|
|
4998
5316
|
// prettier-ignore
|
|
4999
5317
|
async function preloadFamilySource(filePath, loader, interception) {
|
|
5000
5318
|
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}); } }
|
|
5319
|
+
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
5320
|
finally { patch.undo(); }
|
|
5003
5321
|
}
|
|
5004
5322
|
|
|
@@ -5026,7 +5344,7 @@ export async function themeBuildFamily(
|
|
|
5026
5344
|
await selectCore(cwd);
|
|
5027
5345
|
const familyInterception = interceptCore(_coreThemeModule, _coreRootModule);
|
|
5028
5346
|
// prettier-ignore
|
|
5029
|
-
const familyLoader = createJiti(import.meta.url, {moduleCache: true,
|
|
5347
|
+
const familyLoader = createJiti(import.meta.url, {moduleCache: true, ...jitiCacheOptions(), interopDefault: false, jsx: true, extensions: THEME_MODULE_EXTENSIONS, virtualModules: familyInterception.modules});
|
|
5030
5348
|
/** @type {any[]} */
|
|
5031
5349
|
const prepared = [];
|
|
5032
5350
|
for (const source of planFamilySources(files, cwd)) {
|
|
@@ -5318,11 +5636,18 @@ Or load the same stylesheet natively:
|
|
|
5318
5636
|
const unloadedFonts = [
|
|
5319
5637
|
...new Set(members.flatMap(member => member.unloadedFonts)),
|
|
5320
5638
|
];
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5639
|
+
/** @param {string} family @param {string} recipe */
|
|
5640
|
+
const familyNotice = (family, recipe) =>
|
|
5641
|
+
`Font "${family}" is named by this theme family but not loaded; add a <link> or @font-face in your app (recipe: ${recipe})`;
|
|
5642
|
+
// The result names the command bare; the printed note as this project
|
|
5643
|
+
// runs the CLI.
|
|
5644
|
+
const notices = unloadedFonts.map(family =>
|
|
5645
|
+
familyNotice(family, 'astryx docs typography'),
|
|
5324
5646
|
);
|
|
5325
|
-
for (const
|
|
5647
|
+
for (const family of unloadedFonts)
|
|
5648
|
+
logger.log(
|
|
5649
|
+
` note: ${familyNotice(family, formatCliCommand('docs typography', cwd))}`,
|
|
5650
|
+
);
|
|
5326
5651
|
return {
|
|
5327
5652
|
type: 'theme.build',
|
|
5328
5653
|
data: {
|