@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa
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 +12 -23
- package/api/build/_adapter.d.mts +5 -0
- package/api/build/_adapter.mjs +49 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +2 -1
- package/api/build/kit/rank.mjs +47 -9
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +238 -31
- 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 +32 -0
- package/api/build/kit/words.mjs +49 -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 -5
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +217 -5
- 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 +77 -6
- package/api/doctor/built-checks.mjs +38 -13
- 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/render/_adapter.mjs +491 -186
- package/api/render/render.doc.mjs +10 -3
- package/api/render/render.type.d.mts +30 -0
- package/api/render/render.type.mjs +19 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_result.d.mts +5 -5
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +10 -0
- package/api/theme/build/build.d.mts +38 -0
- package/api/theme/build/build.mjs +144 -24
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +35 -0
- package/api/theme-edit/_adapter.mjs +477 -41
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1077 -200
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +932 -82
- package/api/theme-edit/_how-commands.d.mts +49 -0
- package/api/theme-edit/_how-commands.mjs +386 -1
- package/api/theme-edit/_how-question.d.mts +56 -0
- package/api/theme-edit/_how-question.mjs +3509 -168
- package/api/theme-edit/_how.mjs +104 -4
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +137 -0
- package/api/theme-edit/_normal.mjs +612 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +4 -0
- package/api/theme-edit/_parts.mjs +28 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +191 -15
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +401 -83
- package/api/theme-edit/_settings.d.mts +139 -5
- package/api/theme-edit/_settings.mjs +1659 -112
- package/api/theme-edit/_tables.mjs +17 -1
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +2 -2
- package/assets/codemods/run-codemod.mjs +73 -6
- 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/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/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +43 -2
- 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/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/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 +8 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -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 +1 -7
- 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/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 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -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/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -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 +20 -2
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +22 -14
- package/clients/cli/commands/experimental/render.mjs +32 -1
- package/clients/cli/commands/experimental/theme.mjs +27 -2
- 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-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- 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/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 +138 -3
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- 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/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +27 -2
- package/foundation/discovery/component-replacement.mjs +130 -1
- 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 +20 -7
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +169 -0
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/doc-compiler/import.mjs +7 -1
- 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/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +138 -52
- 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/module-loader.d.mts +18 -2
- package/foundation/fs/module-loader.mjs +92 -20
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- 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 +79 -10
- package/foundation/render/render-page.d.mts +34 -2
- package/foundation/render/render-page.mjs +210 -29
- package/foundation/render/source-block.d.mts +73 -6
- package/foundation/render/source-block.mjs +170 -19
- package/foundation/render/ts-paths.d.mts +4 -1
- package/foundation/render/ts-paths.mjs +7 -3
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.doc.mjs +7 -1
- package/foundation/response/error-codes.mjs +7 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +16 -3
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +13 -0
- package/package.json +6 -6
|
@@ -64,6 +64,7 @@ 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
66
|
import {createJiti} from 'jiti';
|
|
67
|
+
import {jitiCacheOptions} from '../../../foundation/fs/jiti-cache.mjs';
|
|
67
68
|
import {
|
|
68
69
|
formatCliCommand,
|
|
69
70
|
getCliInvocation,
|
|
@@ -92,6 +93,7 @@ import {applyWrites} from '../../integration/add-helpers.mjs';
|
|
|
92
93
|
import {logger} from '../../logger.mjs';
|
|
93
94
|
import {loadComponentDoc} from '../../../foundation/discovery/component-loader.mjs';
|
|
94
95
|
import {THEME_SOURCE_EXTENSIONS} from '../../../foundation/discovery/theme-module-extensions.mjs';
|
|
96
|
+
import {withEmptyStylesheets} from '../../../foundation/fs/module-loader.mjs';
|
|
95
97
|
import {
|
|
96
98
|
collectThemingTargets,
|
|
97
99
|
targetsByKey,
|
|
@@ -108,6 +110,7 @@ import {
|
|
|
108
110
|
} from '../../../foundation/discovery/template-needs.mjs';
|
|
109
111
|
import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
|
|
110
112
|
import {resolveIconImports} from './icon-imports.mjs';
|
|
113
|
+
import {generatedMark} from '../../theme-edit/_marks.mjs';
|
|
111
114
|
|
|
112
115
|
// Import shared theme processing from core. `astryx theme build` MUST produce the
|
|
113
116
|
// exact same CSS as the `<Theme>` runtime, so it has exactly one generation
|
|
@@ -925,6 +928,82 @@ function isDirectorySync(file) {
|
|
|
925
928
|
}
|
|
926
929
|
}
|
|
927
930
|
|
|
931
|
+
/**
|
|
932
|
+
* The marks a file's leading comment carries (see `generatedMark`): a theme
|
|
933
|
+
* build's output, or a file the theme editor writes, with the command it
|
|
934
|
+
* names. The one reader build and doctor share.
|
|
935
|
+
* @param {string} source the start of the file
|
|
936
|
+
* @param {string} [file] its path, for a mark that names no exact command
|
|
937
|
+
*/
|
|
938
|
+
export function fileMark(source, file) {
|
|
939
|
+
return generatedMark(source, GENERATED_MARKER, file);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* The command a file's leading comment says writes it, when another CLI
|
|
944
|
+
* command generates it (the theme editor's settings module or app copy):
|
|
945
|
+
* the exact command its mark names. Null for a theme build's own output and
|
|
946
|
+
* a file without a mark, such as a theme source of one's own.
|
|
947
|
+
* @param {string} file
|
|
948
|
+
* @returns {string | null}
|
|
949
|
+
*/
|
|
950
|
+
export function generatedFileCommand(file) {
|
|
951
|
+
const mark = fileMark(fileHead(file), file);
|
|
952
|
+
return mark?.kind === 'editor' ? mark.command : null;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* The command that writes a missing `file`: a file beside it carries
|
|
957
|
+
* another command's mark, and a file there names `file` (a build output's
|
|
958
|
+
* header names its source), so it is one that command writes. Null for any
|
|
959
|
+
* other name, such as a typo.
|
|
960
|
+
* @param {string} file
|
|
961
|
+
* @returns {string | null}
|
|
962
|
+
*/
|
|
963
|
+
function missingGeneratedCommand(file) {
|
|
964
|
+
const dir = path.dirname(file);
|
|
965
|
+
const base = path.basename(file);
|
|
966
|
+
let names;
|
|
967
|
+
try {
|
|
968
|
+
names = fs.readdirSync(dir).sort();
|
|
969
|
+
} catch {
|
|
970
|
+
return null;
|
|
971
|
+
}
|
|
972
|
+
/** @type {string | null} */
|
|
973
|
+
let by = null;
|
|
974
|
+
let named = false;
|
|
975
|
+
for (const n of names) {
|
|
976
|
+
const f = path.join(dir, n);
|
|
977
|
+
try {
|
|
978
|
+
if (!fs.statSync(f).isFile()) continue;
|
|
979
|
+
} catch {
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
by ??= generatedFileCommand(f);
|
|
983
|
+
if (!named)
|
|
984
|
+
try {
|
|
985
|
+
named = fs.readFileSync(f, 'utf8').slice(0, 4000).includes(base);
|
|
986
|
+
} catch {
|
|
987
|
+
// A file that does not read names nothing.
|
|
988
|
+
}
|
|
989
|
+
if (by && named) return by;
|
|
990
|
+
}
|
|
991
|
+
return null;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* The command that writes `file`: from its own mark, or, when it is
|
|
996
|
+
* missing, from the files beside it (see `missingGeneratedCommand`); null
|
|
997
|
+
* otherwise.
|
|
998
|
+
* @param {string} file
|
|
999
|
+
* @returns {string | null}
|
|
1000
|
+
*/
|
|
1001
|
+
export function generatedSourceCommand(file) {
|
|
1002
|
+
return fs.existsSync(file)
|
|
1003
|
+
? generatedFileCommand(file)
|
|
1004
|
+
: missingGeneratedCommand(file);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
928
1007
|
/** @param {string} file @returns {string} the start of a file, or '' when it cannot be read */
|
|
929
1008
|
function fileHead(file) {
|
|
930
1009
|
try {
|
|
@@ -1121,7 +1200,9 @@ function assertThemeSourceFile(filePath, cwd, mode = {}) {
|
|
|
1121
1200
|
* output must stay inside, for a scratch build; `commandWords` names the
|
|
1122
1201
|
* command in the rebuild hint; `prepareFamily`, `familyLoader`, and
|
|
1123
1202
|
* `familyInterception` make the build a family member's plan.
|
|
1124
|
-
*
|
|
1203
|
+
* `colorModes` is the one color mode a calling command knows the theme has
|
|
1204
|
+
* (the theme editor, from its settings), written into the built module.
|
|
1205
|
+
* @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}} ThemeBuildHandOff
|
|
1125
1206
|
*/
|
|
1126
1207
|
|
|
1127
1208
|
/**
|
|
@@ -2630,9 +2711,13 @@ function isSyncLoaderLimitation(error) {
|
|
|
2630
2711
|
* source export and old-Core adaptation checks keep treating that path as
|
|
2631
2712
|
* degraded/fail-closed.
|
|
2632
2713
|
*
|
|
2714
|
+
* On Node 22.15 and later, on every path, a stylesheet that a module in the
|
|
2715
|
+
* theme's graph imports loads as an empty module (`withEmptyStylesheets`): a
|
|
2716
|
+
* base theme's module can import its own stylesheet for the app's bundler.
|
|
2717
|
+
*
|
|
2633
2718
|
* @param {string} filePath
|
|
2634
2719
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
2635
|
-
* @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
|
|
2720
|
+
* @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes: ["light"] | ["dark"] | null}>}
|
|
2636
2721
|
*/
|
|
2637
2722
|
// prettier-ignore
|
|
2638
2723
|
async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
@@ -2640,9 +2725,9 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2640
2725
|
loader ??
|
|
2641
2726
|
createJiti(import.meta.url, {
|
|
2642
2727
|
moduleCache: false,
|
|
2643
|
-
//
|
|
2644
|
-
//
|
|
2645
|
-
|
|
2728
|
+
// The per-user transpile cache: an edited theme is transpiled again,
|
|
2729
|
+
// and the folder stays within its size limit.
|
|
2730
|
+
...jitiCacheOptions(),
|
|
2646
2731
|
jsx: true,
|
|
2647
2732
|
extensions: THEME_MODULE_EXTENSIONS,
|
|
2648
2733
|
...(interception ? {virtualModules: interception.modules} : {}),
|
|
@@ -2659,7 +2744,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2659
2744
|
const commonJsPatch = interception.patchCommonJs(filePath);
|
|
2660
2745
|
try {
|
|
2661
2746
|
try {
|
|
2662
|
-
mod = jiti(filePath);
|
|
2747
|
+
mod = await withEmptyStylesheets(async () => jiti(filePath));
|
|
2663
2748
|
} catch (error) {
|
|
2664
2749
|
// Only a sync-loader limitation may fall back. Anything else is the
|
|
2665
2750
|
// theme's own failure and belongs to the caller unchanged.
|
|
@@ -2668,14 +2753,16 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2668
2753
|
// Force asynchronous transformation instead of native import: this
|
|
2669
2754
|
// keeps virtual Core interception active even when the module uses
|
|
2670
2755
|
// top-level await.
|
|
2671
|
-
mod = await
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2756
|
+
mod = await withEmptyStylesheets(() =>
|
|
2757
|
+
jiti.evalModule(fs.readFileSync(filePath, 'utf8'), {
|
|
2758
|
+
id: filePath,
|
|
2759
|
+
filename: filePath,
|
|
2760
|
+
ext: path.extname(filePath),
|
|
2761
|
+
cache: jiti.cache,
|
|
2762
|
+
async: true,
|
|
2763
|
+
forceTranspile: true,
|
|
2764
|
+
}),
|
|
2765
|
+
);
|
|
2679
2766
|
}
|
|
2680
2767
|
} finally {
|
|
2681
2768
|
// Read after the load: the root is wrapped when the load requires it.
|
|
@@ -2683,7 +2770,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2683
2770
|
commonJsPatch.undo();
|
|
2684
2771
|
}
|
|
2685
2772
|
} else {
|
|
2686
|
-
mod = await jiti.import(filePath);
|
|
2773
|
+
mod = await withEmptyStylesheets(() => jiti.import(filePath));
|
|
2687
2774
|
}
|
|
2688
2775
|
|
|
2689
2776
|
// Both loads hand back the module. The theme is read from the module's own
|
|
@@ -2692,15 +2779,22 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2692
2779
|
// `default` with the module), so the module can pass for the theme while
|
|
2693
2780
|
// its own keys hide the theme's fields.
|
|
2694
2781
|
const isModule = mod != null && typeof mod === 'object';
|
|
2782
|
+
// A theme with one color mode says so with a `colorModes` export beside
|
|
2783
|
+
// the theme (`['light']` or `['dark']`); the build carries it into the
|
|
2784
|
+
// built module.
|
|
2785
|
+
const colorModes = oneColorMode(
|
|
2786
|
+
isModule && Object.hasOwn(mod, 'colorModes') ? mod.colorModes : undefined,
|
|
2787
|
+
);
|
|
2695
2788
|
const hasDefault = isModule && Object.hasOwn(mod, 'default');
|
|
2696
2789
|
const defaultExport = hasDefault ? mod.default : undefined;
|
|
2697
2790
|
if (isThemeObject(defaultExport)) {
|
|
2698
|
-
return {theme: defaultExport, exportName: 'default', degraded};
|
|
2791
|
+
return {theme: defaultExport, exportName: 'default', degraded, colorModes};
|
|
2699
2792
|
}
|
|
2700
2793
|
if (isModule) {
|
|
2701
2794
|
for (const [exportName, value] of Object.entries(mod)) {
|
|
2702
2795
|
if (exportName === 'default' || exportName === 'module.exports') continue;
|
|
2703
|
-
if (isThemeObject(value))
|
|
2796
|
+
if (isThemeObject(value))
|
|
2797
|
+
return {theme: value, exportName, degraded, colorModes};
|
|
2704
2798
|
}
|
|
2705
2799
|
}
|
|
2706
2800
|
// The loader's interop answers a null default with the module itself, so
|
|
@@ -2722,7 +2816,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2722
2816
|
// be all it defines), or no name: the build's validation says what it
|
|
2723
2817
|
// lacks.
|
|
2724
2818
|
if (isPlainObject(defaultExport)) {
|
|
2725
|
-
return {theme: defaultExport, exportName: 'default', degraded};
|
|
2819
|
+
return {theme: defaultExport, exportName: 'default', degraded, colorModes};
|
|
2726
2820
|
}
|
|
2727
2821
|
// A CommonJS module whose exports are the theme (`module.exports =
|
|
2728
2822
|
// theme`) has no default of its own: interop answers `default` with
|
|
@@ -2731,7 +2825,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2731
2825
|
if (isModule && !hasDefault) {
|
|
2732
2826
|
const exportsObject = mod.default ?? mod;
|
|
2733
2827
|
if (isThemeObject(exportsObject)) {
|
|
2734
|
-
return {theme: exportsObject, exportName: 'default', degraded};
|
|
2828
|
+
return {theme: exportsObject, exportName: 'default', degraded, colorModes};
|
|
2735
2829
|
}
|
|
2736
2830
|
}
|
|
2737
2831
|
|
|
@@ -2800,7 +2894,7 @@ function isThemeObject(value) {
|
|
|
2800
2894
|
*
|
|
2801
2895
|
* @param {string} filePath
|
|
2802
2896
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
2803
|
-
* @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
|
|
2897
|
+
* @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes?: ['light'] | ['dark'] | null}>}
|
|
2804
2898
|
*/
|
|
2805
2899
|
// prettier-ignore
|
|
2806
2900
|
async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
@@ -2815,6 +2909,20 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
|
|
|
2815
2909
|
}
|
|
2816
2910
|
}
|
|
2817
2911
|
|
|
2912
|
+
/**
|
|
2913
|
+
* A one-mode `colorModes` value (`['light']` or `['dark']`), or null for
|
|
2914
|
+
* anything else: a theme with both modes needs no export.
|
|
2915
|
+
* @param {unknown} value
|
|
2916
|
+
* @returns {['light'] | ['dark'] | null}
|
|
2917
|
+
*/
|
|
2918
|
+
export function oneColorMode(value) {
|
|
2919
|
+
return Array.isArray(value) &&
|
|
2920
|
+
value.length === 1 &&
|
|
2921
|
+
(value[0] === 'light' || value[0] === 'dark')
|
|
2922
|
+
? /** @type {['light'] | ['dark']} */ ([value[0]])
|
|
2923
|
+
: null;
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2818
2926
|
/** Names a theme module's exports must take; ends a shape failure. */
|
|
2819
2927
|
const THEME_EXPORT_FIX =
|
|
2820
2928
|
"Export the theme object: `export default defineTheme({name: 'my-theme', tokens: {...}})`, or a plain `export default {name: 'my-theme', tokens: {...}}`.";
|
|
@@ -3825,6 +3933,9 @@ async function themeBuildInternal(
|
|
|
3825
3933
|
let themeExportName;
|
|
3826
3934
|
/** Paths through the load that interception could not fully observe. */
|
|
3827
3935
|
let loadDegradation;
|
|
3936
|
+
/** The one color mode the theme module exports, or null for both. */
|
|
3937
|
+
/** @type {['light'] | ['dark'] | null} */
|
|
3938
|
+
let colorModes;
|
|
3828
3939
|
/**
|
|
3829
3940
|
* The theme file's bytes as loaded: read before and after the load, and the
|
|
3830
3941
|
* registry scan below reads these rather than the file again. An editor's
|
|
@@ -3851,6 +3962,7 @@ async function themeBuildInternal(
|
|
|
3851
3962
|
themeDef = loaded.theme;
|
|
3852
3963
|
themeExportName = loaded.exportName;
|
|
3853
3964
|
loadDegradation = loaded.degraded;
|
|
3965
|
+
colorModes = handOff.colorModes ?? loaded.colorModes ?? null;
|
|
3854
3966
|
} catch (e) {
|
|
3855
3967
|
const err = /** @type {Error} */ (e);
|
|
3856
3968
|
const shown = path.relative(cwd, filePath) || filePath;
|
|
@@ -4482,10 +4594,18 @@ async function themeBuildInternal(
|
|
|
4482
4594
|
? {}
|
|
4483
4595
|
: {cssFileName: path.basename(outPath)}),
|
|
4484
4596
|
},
|
|
4485
|
-
)
|
|
4597
|
+
) +
|
|
4598
|
+
// The one color mode, beside the theme export (a two-mode theme
|
|
4599
|
+
// exports none, so its module is unchanged).
|
|
4600
|
+
(colorModes
|
|
4601
|
+
? `export const colorModes = [${JSON.stringify(colorModes[0])}];\n`
|
|
4602
|
+
: '');
|
|
4486
4603
|
const dtsContent =
|
|
4487
4604
|
generatedHeader(headerSource, 'ts', buildCommand, versions) +
|
|
4488
|
-
generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName)
|
|
4605
|
+
generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName) +
|
|
4606
|
+
(colorModes
|
|
4607
|
+
? `export declare const colorModes: readonly [${JSON.stringify(colorModes[0])}];\n`
|
|
4608
|
+
: '');
|
|
4489
4609
|
|
|
4490
4610
|
const unloadedFonts = [
|
|
4491
4611
|
...new Set([
|
|
@@ -4998,7 +5118,7 @@ function planFamilySources(files, cwd) {
|
|
|
4998
5118
|
// prettier-ignore
|
|
4999
5119
|
async function preloadFamilySource(filePath, loader, interception) {
|
|
5000
5120
|
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}); } }
|
|
5121
|
+
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
5122
|
finally { patch.undo(); }
|
|
5003
5123
|
}
|
|
5004
5124
|
|
|
@@ -5026,7 +5146,7 @@ export async function themeBuildFamily(
|
|
|
5026
5146
|
await selectCore(cwd);
|
|
5027
5147
|
const familyInterception = interceptCore(_coreThemeModule, _coreRootModule);
|
|
5028
5148
|
// prettier-ignore
|
|
5029
|
-
const familyLoader = createJiti(import.meta.url, {moduleCache: true,
|
|
5149
|
+
const familyLoader = createJiti(import.meta.url, {moduleCache: true, ...jitiCacheOptions(), interopDefault: false, jsx: true, extensions: THEME_MODULE_EXTENSIONS, virtualModules: familyInterception.modules});
|
|
5030
5150
|
/** @type {any[]} */
|
|
5031
5151
|
const prepared = [];
|
|
5032
5152
|
for (const source of planFamilySources(files, cwd)) {
|
|
@@ -137,6 +137,12 @@ export type ThemeAppEntry = {
|
|
|
137
137
|
*/
|
|
138
138
|
fontStylesheet?: string | undefined;
|
|
139
139
|
source: "bundled" | "package" | "local";
|
|
140
|
+
/**
|
|
141
|
+
* the one color mode the theme has, when its
|
|
142
|
+
* built module exports one (`colorModes`); the generated module then lists
|
|
143
|
+
* it in `themeModes`. Absent for a theme with both modes.
|
|
144
|
+
*/
|
|
145
|
+
mode?: "light" | "dark" | undefined;
|
|
140
146
|
};
|
|
141
147
|
/**
|
|
142
148
|
* astryx --json theme add <slug> [--import] / remove / use
|
|
@@ -149,6 +155,9 @@ export type ThemeAppResponse = {
|
|
|
149
155
|
* `notes` is present only when the command did more than its change says:
|
|
150
156
|
* it chose between a local and a package theme with one slug, replaced a
|
|
151
157
|
* recorded owner, or dropped a recorded theme whose source is gone.
|
|
158
|
+
* `change.wireModes` is present when the module lists a theme's one color
|
|
159
|
+
* mode (`themeModes`) for the first time after the app was wired: the app's
|
|
160
|
+
* `Theme` then takes `mode={themeModes[defaultThemeSlug] ?? 'system'}`.
|
|
152
161
|
*/
|
|
153
162
|
package?: string | undefined;
|
|
154
163
|
data: {
|
|
@@ -160,6 +169,7 @@ export type ThemeAppResponse = {
|
|
|
160
169
|
slug: string;
|
|
161
170
|
changed: boolean;
|
|
162
171
|
firstAdd: boolean;
|
|
172
|
+
wireModes?: true;
|
|
163
173
|
};
|
|
164
174
|
notes?: string[];
|
|
165
175
|
};
|
package/api/theme/theme.type.mjs
CHANGED
|
@@ -92,6 +92,9 @@
|
|
|
92
92
|
* @property {string} stylesheet production stylesheet import
|
|
93
93
|
* @property {string} [fontStylesheet] package-owned font stylesheet import
|
|
94
94
|
* @property {'bundled'|'package'|'local'} source
|
|
95
|
+
* @property {'light'|'dark'} [mode] the one color mode the theme has, when its
|
|
96
|
+
* built module exports one (`colorModes`); the generated module then lists
|
|
97
|
+
* it in `themeModes`. Absent for a theme with both modes.
|
|
95
98
|
*/
|
|
96
99
|
|
|
97
100
|
/**
|
|
@@ -103,7 +106,10 @@
|
|
|
103
106
|
* `notes` is present only when the command did more than its change says:
|
|
104
107
|
* it chose between a local and a package theme with one slug, replaced a
|
|
105
108
|
* recorded owner, or dropped a recorded theme whose source is gone.
|
|
106
|
-
*
|
|
109
|
+
* `change.wireModes` is present when the module lists a theme's one color
|
|
110
|
+
* mode (`themeModes`) for the first time after the app was wired: the app's
|
|
111
|
+
* `Theme` then takes `mode={themeModes[defaultThemeSlug] ?? 'system'}`.
|
|
112
|
+
* @property {{themes: ThemeAppEntry[], default: string, modulePath: string, change: {action: 'add'|'remove'|'use', slug: string, changed: boolean, firstAdd: boolean, wireModes?: true}, notes?: string[]}} data
|
|
107
113
|
*/
|
|
108
114
|
|
|
109
115
|
/**
|
|
@@ -59,6 +59,41 @@ export function editorCompileProblem(files: string[], { cwd, check, family, icon
|
|
|
59
59
|
export function editorThemeHold(files: string[], { cwd }: {
|
|
60
60
|
cwd: string;
|
|
61
61
|
}): Promise<() => Promise<void>>;
|
|
62
|
+
/**
|
|
63
|
+
* For `compile` of an editor theme: `appCopyStale` for its result data when
|
|
64
|
+
* the app copy is behind (the same line set and show give); null for any
|
|
65
|
+
* other file or a current copy.
|
|
66
|
+
* @param {string} file the path as given
|
|
67
|
+
* @param {string} cwd
|
|
68
|
+
* @param {{check: boolean, upToDate?: boolean}} opts `upToDate`: the
|
|
69
|
+
* check's own verdict on the theme's outputs
|
|
70
|
+
* @returns {Promise<Record<string, unknown> | null>}
|
|
71
|
+
*/
|
|
72
|
+
export function editorBuildExtra(file: string, cwd: string, opts: {
|
|
73
|
+
check: boolean;
|
|
74
|
+
upToDate?: boolean;
|
|
75
|
+
}): Promise<Record<string, unknown> | null>;
|
|
76
|
+
/**
|
|
77
|
+
* For `compile` of an editor theme's own source (themes/<t>/<t>.theme.ts):
|
|
78
|
+
* the one color mode a light-only or dark-only theme has, which its source
|
|
79
|
+
* cannot say, for the build to write into the built module. Null for any
|
|
80
|
+
* other file (the app copy's source re-exports it from its build).
|
|
81
|
+
* @param {string} file the path as given
|
|
82
|
+
* @param {string} cwd
|
|
83
|
+
* @returns {['light'] | ['dark'] | null}
|
|
84
|
+
*/
|
|
85
|
+
export function editorColorModes(file: string, cwd: string): ["light"] | ["dark"] | null;
|
|
86
|
+
/**
|
|
87
|
+
* For `compile` of an editor theme (themes/<t>/ or its app copy's source):
|
|
88
|
+
* whether a font family is loaded by the app copy's font stylesheet
|
|
89
|
+
* (src/themes/<t>/<t>.fonts.css: an @fontsource package by its name, a
|
|
90
|
+
* stylesheet by the `family=` it requests), so the build's "named but not
|
|
91
|
+
* loaded" notice leaves it out. Null for any other file.
|
|
92
|
+
* @param {string} file the path as given
|
|
93
|
+
* @param {string} cwd
|
|
94
|
+
* @returns {((family: string) => boolean) | null}
|
|
95
|
+
*/
|
|
96
|
+
export function editorLoadedFonts(file: string, cwd: string): ((family: string) => boolean) | null;
|
|
62
97
|
/**
|
|
63
98
|
* For `compile` of a file that is not there: when it is an editor theme's
|
|
64
99
|
* own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
|