@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61

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.
Files changed (203) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +63 -63
  3. package/api/build/_adapter.d.mts +4 -0
  4. package/api/build/_adapter.mjs +28 -2
  5. package/api/build/blocks/blocks.d.mts +10 -1
  6. package/api/build/blocks/blocks.mjs +84 -7
  7. package/api/build/build.mjs +6 -1
  8. package/api/build/tree.d.mts +4 -0
  9. package/api/build/tree.mjs +9 -2
  10. package/api/doctor/_adapter.d.mts +3 -1
  11. package/api/doctor/_adapter.mjs +14 -1
  12. package/api/doctor/_authoring-audit.d.mts +42 -0
  13. package/api/doctor/_authoring-audit.mjs +106 -0
  14. package/api/doctor/doctor.d.mts +7 -0
  15. package/api/doctor/doctor.mjs +24 -39
  16. package/api/doctor/theme-checks.mjs +56 -21
  17. package/api/integration/add-helpers.mjs +5 -0
  18. package/api/integration/add-theme.mjs +15 -110
  19. package/api/integration/validate-integration.mjs +17 -3
  20. package/api/integration/validateIntegration.doc.mjs +1 -1
  21. package/api/search/_adapter.mjs +124 -3
  22. package/api/search/_candidate-score.mjs +63 -9
  23. package/api/search/_entries.d.mts +10 -0
  24. package/api/search/_entries.mjs +68 -1
  25. package/api/search/_gather-templates.d.mts +11 -0
  26. package/api/search/_gather-templates.mjs +22 -2
  27. package/api/search/_words.mjs +26 -6
  28. package/api/swizzle/copy/copy.mjs +1 -1
  29. package/api/theme/_adapter.d.mts +37 -5
  30. package/api/theme/_adapter.mjs +381 -57
  31. package/api/theme/_fork.d.mts +90 -0
  32. package/api/theme/_fork.mjs +246 -0
  33. package/api/theme/build/build.d.mts +40 -2
  34. package/api/theme/build/build.mjs +477 -66
  35. package/api/theme/eject/eject.mjs +36 -15
  36. package/api/theme/list/list.mjs +3 -6
  37. package/api/theme/palette/generate/generator.d.mts +13 -0
  38. package/api/theme/palette/generate/generator.mjs +32 -2
  39. package/api/theme/targets/targets.d.mts +8 -0
  40. package/api/theme/targets/targets.mjs +24 -4
  41. package/api/theme/template/template.mjs +48 -2
  42. package/api/theme/theme.type.d.mts +8 -0
  43. package/api/theme/theme.type.mjs +5 -1
  44. package/api/theme/themeBuild.doc.mjs +7 -4
  45. package/api/theme/themeEject.doc.mjs +3 -3
  46. package/api/theme/themeRemove.doc.mjs +5 -2
  47. package/api/theme/themeTargets.doc.mjs +1 -1
  48. package/api/theme/themeTemplate.doc.mjs +2 -2
  49. package/api/theme/themeUse.doc.mjs +8 -2
  50. package/api/theme-edit/_adapter.d.mts +46 -3
  51. package/api/theme-edit/_adapter.mjs +496 -112
  52. package/api/theme-edit/_catalog.d.mts +1 -6
  53. package/api/theme-edit/_catalog.mjs +5 -268
  54. package/api/theme-edit/_check.d.mts +9 -4
  55. package/api/theme-edit/_check.mjs +1232 -229
  56. package/api/theme-edit/_color.d.mts +19 -0
  57. package/api/theme-edit/_color.mjs +280 -34
  58. package/api/theme-edit/_compiler.d.mts +3 -1
  59. package/api/theme-edit/_compiler.mjs +52 -13
  60. package/api/theme-edit/_context.d.mts +4 -1
  61. package/api/theme-edit/_context.mjs +126 -13
  62. package/api/theme-edit/_css.d.mts +84 -0
  63. package/api/theme-edit/_css.mjs +700 -0
  64. package/api/theme-edit/_edit.d.mts +9 -3
  65. package/api/theme-edit/_edit.mjs +806 -103
  66. package/api/theme-edit/_how-commands.d.mts +38 -7
  67. package/api/theme-edit/_how-commands.mjs +64 -45
  68. package/api/theme-edit/_how-question.d.mts +33 -0
  69. package/api/theme-edit/_how-question.mjs +2553 -381
  70. package/api/theme-edit/_how.mjs +402 -31
  71. package/api/theme-edit/_overview.mjs +2 -7
  72. package/api/theme-edit/_palette.d.mts +60 -13
  73. package/api/theme-edit/_palette.mjs +826 -295
  74. package/api/theme-edit/_parts.d.mts +42 -10
  75. package/api/theme-edit/_parts.mjs +280 -69
  76. package/api/theme-edit/_png.d.mts +4 -4
  77. package/api/theme-edit/_png.mjs +4 -2
  78. package/api/theme-edit/_preview-app.d.mts +14 -0
  79. package/api/theme-edit/_preview-app.mjs +1675 -235
  80. package/api/theme-edit/_preview.d.mts +7 -16
  81. package/api/theme-edit/_preview.mjs +79 -86
  82. package/api/theme-edit/_project.d.mts +32 -2
  83. package/api/theme-edit/_project.mjs +80 -19
  84. package/api/theme-edit/_settings.d.mts +199 -52
  85. package/api/theme-edit/_settings.mjs +1422 -217
  86. package/api/theme-edit/_tables.d.mts +19 -6
  87. package/api/theme-edit/_tables.mjs +150 -92
  88. package/api/theme-edit/theme-edit.type.d.mts +20 -1
  89. package/api/theme-edit/theme-edit.type.mjs +6 -3
  90. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  91. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  92. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  93. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  94. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  95. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  96. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  97. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  98. package/api/upgrade/_adapter.d.mts +1 -0
  99. package/assets/codemods/run-codemod.mjs +61 -0
  100. package/assets/codemods/runner.mjs +5 -4
  101. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  102. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  103. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  104. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  105. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  106. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  107. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  108. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  109. package/assets/docs/tree/calendars.doc.mjs +1 -3
  110. package/assets/docs/tree/checks.doc.mjs +22 -1
  111. package/assets/docs/tree/publishing.doc.mjs +1 -0
  112. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  113. package/assets/docs.generated.json +2 -1
  114. package/assets/preview-app/next.config.mjs +7 -1
  115. package/assets/self-audit.generated.json +1 -0
  116. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  117. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  118. package/assets/templates/components.generated.json +1 -1
  119. package/authoring/integration/integration.doc.mjs +8 -0
  120. package/authoring/integration/schema.d.mts +8 -0
  121. package/authoring/integration/schema.mjs +1 -0
  122. package/authoring/integration/type.ts +9 -0
  123. package/clients/cli/bin/astryx.mjs +19 -15
  124. package/clients/cli/build-id.generated.json +1 -0
  125. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  126. package/clients/cli/commands/experimental/index.mjs +10 -10
  127. package/clients/cli/commands/experimental/theme.mjs +200 -81
  128. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  129. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  130. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  131. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  132. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  133. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  134. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  135. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  136. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  137. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  138. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  139. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  140. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  142. package/clients/cli/commands/integration.mjs +8 -0
  143. package/clients/cli/commands/manifest.mjs +5 -2
  144. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  145. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  146. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  147. package/clients/cli/commands/theme.mjs +439 -66
  148. package/clients/cli/index.mjs +27 -6
  149. package/clients/cli/lib/cli-error.mjs +118 -3
  150. package/clients/cli/lib/manifest.mjs +37 -0
  151. package/clients/cli/lib/resolve-theme.mjs +2 -1
  152. package/clients/cli/manifest.generated.json +1 -0
  153. package/foundation/config/project.mjs +34 -8
  154. package/foundation/config/theme-state.d.mts +16 -0
  155. package/foundation/config/theme-state.mjs +84 -13
  156. package/foundation/discovery/module-exports.mjs +16 -2
  157. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  158. package/foundation/discovery/stored-self-audit.mjs +119 -0
  159. package/foundation/discovery/template-adapter.d.mts +48 -2
  160. package/foundation/discovery/template-adapter.mjs +51 -19
  161. package/foundation/discovery/template-needs.d.mts +19 -0
  162. package/foundation/discovery/template-needs.mjs +50 -16
  163. package/foundation/discovery/template-source-tree.d.mts +7 -0
  164. package/foundation/discovery/template-source-tree.mjs +15 -0
  165. package/foundation/discovery/theme-discovery.d.mts +2 -1
  166. package/foundation/discovery/theme-discovery.mjs +16 -10
  167. package/foundation/discovery/theme-imports.d.mts +16 -0
  168. package/foundation/discovery/theme-imports.mjs +30 -2
  169. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  170. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  171. package/foundation/doc-compiler/import.mjs +22 -15
  172. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  173. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  174. package/foundation/env/private-dir.d.mts +17 -0
  175. package/foundation/env/private-dir.mjs +42 -0
  176. package/foundation/fs/gather-cache.d.mts +108 -0
  177. package/foundation/fs/gather-cache.mjs +783 -0
  178. package/foundation/fs/jiti-cache.d.mts +21 -0
  179. package/foundation/fs/jiti-cache.mjs +66 -0
  180. package/foundation/fs/module-loader.mjs +14 -3
  181. package/foundation/fs/read-record.d.mts +31 -1
  182. package/foundation/fs/read-record.mjs +100 -7
  183. package/foundation/integrations/autolink.d.mts +1 -24
  184. package/foundation/integrations/autolink.mjs +7 -60
  185. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  186. package/foundation/integrations/declared-dependencies.mjs +73 -0
  187. package/foundation/integrations/integrations.d.mts +8 -0
  188. package/foundation/integrations/integrations.mjs +4 -0
  189. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  190. package/foundation/integrations/may-have-integrations.mjs +47 -0
  191. package/foundation/integrations/validate-contributions.d.mts +62 -1
  192. package/foundation/integrations/validate-contributions.mjs +476 -40
  193. package/foundation/release/cache.d.mts +32 -4
  194. package/foundation/release/cache.mjs +105 -16
  195. package/foundation/release/folder-lock.d.mts +28 -0
  196. package/foundation/release/folder-lock.mjs +205 -0
  197. package/foundation/release/lock-lease.d.mts +2 -1
  198. package/foundation/release/lock-lease.mjs +7 -2
  199. package/foundation/response/error-codes.doc.mjs +1 -1
  200. package/foundation/response/response-types.doc.mjs +5 -5
  201. package/package.json +8 -6
  202. package/api/theme-edit/_css-properties.d.mts +0 -10
  203. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -0,0 +1,90 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * A theme name as the identifier `theme build` gives its export: each run
6
+ * of dashes goes, and the letter after it is capitalized.
7
+ * @param {string} name
8
+ */
9
+ export function themeIdentifier(name: string): string;
10
+ /**
11
+ * The binding a theme named `name` exports, as `theme build` names it.
12
+ * @param {string} name
13
+ */
14
+ export function themeBinding(name: string): string;
15
+ /**
16
+ * A new theme's names, from a checked kebab-case slug.
17
+ * @param {string} slug
18
+ */
19
+ export function themeIdentity(slug: string): {
20
+ slug: string;
21
+ identifier: string;
22
+ displayName: string;
23
+ exportName: string;
24
+ entry: string;
25
+ descriptor: string;
26
+ };
27
+ /**
28
+ * Rename a file from the base theme's namespace to the new theme's namespace.
29
+ * Files whose name starts with the base identifier get the new identifier;
30
+ * others keep their name as-is.
31
+ * @param {string} file POSIX relative path inside the theme directory
32
+ * @param {string} baseIdentifier
33
+ * @param {string} newIdentifier
34
+ * @returns {string}
35
+ */
36
+ export function renameThemeFile(file: string, baseIdentifier: string, newIdentifier: string): string;
37
+ /**
38
+ * Rewrite a source file's contents from the base theme's names to the new
39
+ * theme's names. This replaces:
40
+ * 1. Identifier prefixes (camelCase variables, import paths): baseIdentifier
41
+ * followed by an uppercase letter.
42
+ * 2. The theme slug in string literals: 'baseSlug' → 'newSlug' and
43
+ * 'astryx-baseSlug' → 'astryx-newSlug'.
44
+ * 3. CSS custom properties scoped to the theme: --astryx-theme-baseSlug-.
45
+ * @param {string} source
46
+ * @param {string} baseSlug
47
+ * @param {string} baseIdentifier
48
+ * @param {string} newSlug
49
+ * @param {string} newIdentifier
50
+ * @returns {string}
51
+ */
52
+ export function rewriteThemeSource(source: string, baseSlug: string, baseIdentifier: string, newSlug: string, newIdentifier: string): string;
53
+ /**
54
+ * The theme source with its `defineTheme({...})` name set to `to`, wherever
55
+ * the `name` property sits in the object (after `extends`, under a
56
+ * comment), or null when no `defineTheme` call names a theme. Only that
57
+ * one string changes.
58
+ * @param {string} source
59
+ * @param {string} to
60
+ * @returns {string | null}
61
+ */
62
+ export function renameDefinedTheme(source: string, to: string): string | null;
63
+ /**
64
+ * The file names of a fork: the theme's own, except that a fork named other
65
+ * than the theme names its entry and descriptor after its binding
66
+ * (`acmeOceanTheme.ts`, `acmeOceanTheme.doc.mjs`), as discovery reads them.
67
+ * @param {{slug: string, docPath: string, files: string[]}} theme
68
+ * @param {string} forkName
69
+ * @returns {string[]} in the order of theme.files
70
+ */
71
+ export function forkFileNames(theme: {
72
+ slug: string;
73
+ docPath: string;
74
+ files: string[];
75
+ }, forkName: string): string[];
76
+ /**
77
+ * The theme entry renamed for a fork: its `defineTheme` name is the fork's,
78
+ * so the build writes `<fork>.css` and `<fork>.js`, and its export binding is
79
+ * the build's (`acmeOceanTheme`), the name discovery and `theme add` read.
80
+ * Refused when the entry names no theme to rename, since the fork would
81
+ * then build under the base theme's name.
82
+ * @param {string} contents
83
+ * @param {{slug: string, docPath: string}} theme
84
+ * @param {string} to
85
+ * @returns {string}
86
+ */
87
+ export function renamedEntry(contents: string, theme: {
88
+ slug: string;
89
+ docPath: string;
90
+ }, to: string): string;
@@ -0,0 +1,246 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The names a theme fork takes: its identity (slug, identifier,
5
+ * export binding, entry and descriptor file names), its renamed files, and
6
+ * its source rewritten from the base theme's names to the fork's.
7
+ *
8
+ * Shared by `theme eject` (api/theme/_adapter.mjs) and `integration add
9
+ * theme` (api/integration/add-theme.mjs), so the two forks name a theme the
10
+ * same way, and both the way `theme build` names its outputs.
11
+ */
12
+
13
+ import * as path from 'node:path';
14
+ import {parse} from '@babel/parser';
15
+ import {AstryxError} from '../error.mjs';
16
+ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
17
+ import {
18
+ PathSafetyError,
19
+ sanitizeName,
20
+ } from '../../foundation/fs/path-safety.mjs';
21
+
22
+ /**
23
+ * A theme name as the identifier `theme build` gives its export: each run
24
+ * of dashes goes, and the letter after it is capitalized.
25
+ * @param {string} name
26
+ */
27
+ export function themeIdentifier(name) {
28
+ return name.replace(/-+([a-z0-9])/gu, (_, c) => c.toUpperCase());
29
+ }
30
+
31
+ /**
32
+ * The binding a theme named `name` exports, as `theme build` names it.
33
+ * @param {string} name
34
+ */
35
+ export function themeBinding(name) {
36
+ return `${themeIdentifier(name)}Theme`;
37
+ }
38
+
39
+ /**
40
+ * A new theme's names, from a checked kebab-case slug.
41
+ * @param {string} slug
42
+ */
43
+ export function themeIdentity(slug) {
44
+ try {
45
+ sanitizeName(slug, {label: 'theme name'});
46
+ } catch (error) {
47
+ if (error instanceof PathSafetyError) {
48
+ throw new AstryxError(
49
+ error.message,
50
+ undefined,
51
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
52
+ );
53
+ }
54
+ throw error;
55
+ }
56
+ if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(slug)) {
57
+ throw new AstryxError(
58
+ `Invalid theme name "${slug}": use lowercase kebab-case starting with a letter.`,
59
+ undefined,
60
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
61
+ );
62
+ }
63
+ const identifier = themeIdentifier(slug);
64
+ const displayName = slug
65
+ .split('-')
66
+ .map(part =>
67
+ part === 'y2k' ? 'Y2K' : part[0].toUpperCase() + part.slice(1),
68
+ )
69
+ .join(' ');
70
+ return {
71
+ slug,
72
+ identifier,
73
+ displayName,
74
+ exportName: `${identifier}Theme`,
75
+ entry: `${identifier}Theme.ts`,
76
+ descriptor: `${identifier}Theme.doc.mjs`,
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Rename a file from the base theme's namespace to the new theme's namespace.
82
+ * Files whose name starts with the base identifier get the new identifier;
83
+ * others keep their name as-is.
84
+ * @param {string} file POSIX relative path inside the theme directory
85
+ * @param {string} baseIdentifier
86
+ * @param {string} newIdentifier
87
+ * @returns {string}
88
+ */
89
+ export function renameThemeFile(file, baseIdentifier, newIdentifier) {
90
+ const basename = path.posix.basename(file);
91
+ const dir = path.posix.dirname(file);
92
+ if (!basename.startsWith(baseIdentifier)) return file;
93
+ const renamed = newIdentifier + basename.slice(baseIdentifier.length);
94
+ return dir === '.' ? renamed : `${dir}/${renamed}`;
95
+ }
96
+
97
+ /** @param {string} s */
98
+ function escapeRegExp(s) {
99
+ return s.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
100
+ }
101
+
102
+ /**
103
+ * Rewrite a source file's contents from the base theme's names to the new
104
+ * theme's names. This replaces:
105
+ * 1. Identifier prefixes (camelCase variables, import paths): baseIdentifier
106
+ * followed by an uppercase letter.
107
+ * 2. The theme slug in string literals: 'baseSlug' → 'newSlug' and
108
+ * 'astryx-baseSlug' → 'astryx-newSlug'.
109
+ * 3. CSS custom properties scoped to the theme: --astryx-theme-baseSlug-.
110
+ * @param {string} source
111
+ * @param {string} baseSlug
112
+ * @param {string} baseIdentifier
113
+ * @param {string} newSlug
114
+ * @param {string} newIdentifier
115
+ * @returns {string}
116
+ */
117
+ export function rewriteThemeSource(
118
+ source,
119
+ baseSlug,
120
+ baseIdentifier,
121
+ newSlug,
122
+ newIdentifier,
123
+ ) {
124
+ let result = source;
125
+ const identRe = new RegExp(`${escapeRegExp(baseIdentifier)}(?=[A-Z])`, 'gu');
126
+ result = result.replace(identRe, newIdentifier);
127
+ result = result.replace(
128
+ new RegExp(`'astryx-${escapeRegExp(baseSlug)}'`, 'gu'),
129
+ `'astryx-${newSlug}'`,
130
+ );
131
+ result = result.replace(
132
+ new RegExp(`'${escapeRegExp(baseSlug)}'`, 'gu'),
133
+ `'${newSlug}'`,
134
+ );
135
+ result = result.replace(
136
+ new RegExp(`--astryx-theme-${escapeRegExp(baseSlug)}-`, 'gu'),
137
+ `--astryx-theme-${newSlug}-`,
138
+ );
139
+ return result;
140
+ }
141
+
142
+ /**
143
+ * The theme source with its `defineTheme({...})` name set to `to`, wherever
144
+ * the `name` property sits in the object (after `extends`, under a
145
+ * comment), or null when no `defineTheme` call names a theme. Only that
146
+ * one string changes.
147
+ * @param {string} source
148
+ * @param {string} to
149
+ * @returns {string | null}
150
+ */
151
+ export function renameDefinedTheme(source, to) {
152
+ /** @type {any} */
153
+ let ast;
154
+ try {
155
+ ast = parse(source, {
156
+ sourceType: 'module',
157
+ plugins: ['typescript', 'jsx'],
158
+ });
159
+ } catch {
160
+ return null;
161
+ }
162
+ /** @type {{start: number, end: number, quote: string} | null} */
163
+ let hit = null;
164
+ /** @param {any} node */
165
+ const visit = node => {
166
+ if (hit || !node || typeof node !== 'object') return;
167
+ if (
168
+ node.type === 'CallExpression' &&
169
+ node.callee?.type === 'Identifier' &&
170
+ node.callee.name === 'defineTheme' &&
171
+ node.arguments?.[0]?.type === 'ObjectExpression'
172
+ ) {
173
+ const prop = node.arguments[0].properties.find(
174
+ (/** @type {any} */ p) =>
175
+ p.type === 'ObjectProperty' &&
176
+ !p.computed &&
177
+ ((p.key.type === 'Identifier' && p.key.name === 'name') ||
178
+ (p.key.type === 'StringLiteral' && p.key.value === 'name')) &&
179
+ p.value.type === 'StringLiteral',
180
+ );
181
+ if (prop)
182
+ hit = {
183
+ start: prop.value.start,
184
+ end: prop.value.end,
185
+ quote: source[prop.value.start],
186
+ };
187
+ return;
188
+ }
189
+ for (const value of Object.values(node)) {
190
+ if (Array.isArray(value)) value.forEach(visit);
191
+ else if (value && typeof value === 'object' && value.type) visit(value);
192
+ }
193
+ };
194
+ visit(ast.program);
195
+ if (!hit) return null;
196
+ const {start, end, quote} = hit;
197
+ return `${source.slice(0, start)}${quote}${to}${quote}${source.slice(end)}`;
198
+ }
199
+
200
+ /**
201
+ * The file names of a fork: the theme's own, except that a fork named other
202
+ * than the theme names its entry and descriptor after its binding
203
+ * (`acmeOceanTheme.ts`, `acmeOceanTheme.doc.mjs`), as discovery reads them.
204
+ * @param {{slug: string, docPath: string, files: string[]}} theme
205
+ * @param {string} forkName
206
+ * @returns {string[]} in the order of theme.files
207
+ */
208
+ export function forkFileNames(theme, forkName) {
209
+ if (forkName === theme.slug) return [...theme.files];
210
+ const docName = path.basename(theme.docPath);
211
+ const stem = docName.slice(0, -'.doc.mjs'.length);
212
+ const binding = themeBinding(forkName);
213
+ return theme.files.map(name =>
214
+ name === docName
215
+ ? `${binding}.doc.mjs`
216
+ : name === theme.files[0] && path.basename(name).startsWith(`${stem}.`)
217
+ ? path.join(path.dirname(name), binding + path.extname(name))
218
+ : name,
219
+ );
220
+ }
221
+
222
+ /**
223
+ * The theme entry renamed for a fork: its `defineTheme` name is the fork's,
224
+ * so the build writes `<fork>.css` and `<fork>.js`, and its export binding is
225
+ * the build's (`acmeOceanTheme`), the name discovery and `theme add` read.
226
+ * Refused when the entry names no theme to rename, since the fork would
227
+ * then build under the base theme's name.
228
+ * @param {string} contents
229
+ * @param {{slug: string, docPath: string}} theme
230
+ * @param {string} to
231
+ * @returns {string}
232
+ */
233
+ export function renamedEntry(contents, theme, to) {
234
+ const stem = path.basename(theme.docPath).slice(0, -'.doc.mjs'.length);
235
+ const named = renameDefinedTheme(contents, to);
236
+ if (named == null)
237
+ throw new AstryxError(
238
+ `The entry of theme "${theme.slug}" names no theme in a defineTheme({name: ...}) call, so a fork named "${to}" would still build as "${theme.slug}". Fork it under its own name.`,
239
+ undefined,
240
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
241
+ );
242
+ return named.replace(
243
+ new RegExp(`\\b${escapeRegExp(stem)}\\b`, 'gu'),
244
+ themeBinding(to),
245
+ );
246
+ }
@@ -43,11 +43,39 @@ export function coreUnavailableMessage(cwd: string, importError: any): string;
43
43
  * the header and all real content — is compared verbatim. Used only by
44
44
  * `--check`: a differing command must NOT report a file as stale, but any real
45
45
  * content drift must. The `CLI:`/`Core:` provenance lines are deterministic
46
- * for a given toolchain, so they compare verbatim like real content.
46
+ * for a given toolchain, so they compare verbatim like real content. CRLF
47
+ * line endings read as LF.
47
48
  * @param {string} content
48
49
  * @returns {string}
49
50
  */
50
51
  export function normalizeThemeBuildForCompare(content: string): string;
52
+ /**
53
+ * The files a theme source is made of: the source and every local file it
54
+ * imports, directly or through other local files, read from their import
55
+ * statements. A watch rebuilds when any of them changes. Package imports and
56
+ * files that cannot be read are left out.
57
+ * @param {string} filePath absolute theme source
58
+ * @returns {string[]} absolute paths, the source first
59
+ */
60
+ export function themeSourceFiles(filePath: string): string[];
61
+ /**
62
+ * Theme sources a missing build input probably meant, relative to `cwd`: the
63
+ * same path with `/` for `\`; or, for a bare theme name, the theme sources in
64
+ * `themes/<name>/` and `src/themes/<name>/` of the project, and `<name>` with a
65
+ * theme source extension. A build output is never offered.
66
+ * @param {string} file the input as given
67
+ * @param {string} cwd
68
+ * @returns {string[]} at most three paths
69
+ */
70
+ export function themeSourceGuesses(file: string, cwd: string): string[];
71
+ /**
72
+ * Publish the outputs a batch deferred, one theme at a time, in build order.
73
+ * @param {Array<Array<{dest: string, content: string}>>} deferred
74
+ */
75
+ export function writeDeferredBuildOutputs(deferred: Array<Array<{
76
+ dest: string;
77
+ content: string;
78
+ }>>): void;
51
79
  /**
52
80
  * Import specifier for install/scaffold instructions. Drops a leading `src/`
53
81
  * from the cwd-relative dir (most consumers import from a file under src/) but
@@ -58,6 +86,12 @@ export function normalizeThemeBuildForCompare(content: string): string;
58
86
  * @returns {string}
59
87
  */
60
88
  export function importSpecifier(relDir: string, base: string): string;
89
+ /**
90
+ * The package a theme load failed on because it is not installed.
91
+ * @param {unknown} error
92
+ * @returns {string | null}
93
+ */
94
+ export function missingThemePackage(error: unknown): string | null;
61
95
  /**
62
96
  * Load one theme through the build's real module loader and validate the raw
63
97
  * input captured from its defineTheme lineage. Used by doctor so it applies the
@@ -144,12 +178,16 @@ export function themeBuild(file: string, options?: {
144
178
  cwd?: string;
145
179
  projectCore?: boolean;
146
180
  }): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
147
- /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void}} options @param {{cwd?: string}} [ctx] */
181
+ /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
148
182
  export function themeBuildFamily(files: string[], options: {
149
183
  familyKey: string;
150
184
  check?: boolean;
151
185
  iconsSpecifier?: string;
152
186
  __onPrivateVarError?: () => void;
187
+ __commandWords?: {
188
+ group: string;
189
+ build: string;
190
+ };
153
191
  }, { cwd }?: {
154
192
  cwd?: string;
155
193
  }): Promise<{