@astryxdesign/cli 0.6.0 → 0.6.1

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 (219) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +76 -67
  3. package/api/build/build.test.mjs +37 -0
  4. package/api/build/build.type.mjs +1 -1
  5. package/api/build/kit/kit.mjs +31 -1
  6. package/api/component/_adapter.mjs +14 -28
  7. package/api/component/integration-import-agreement.test.mjs +318 -0
  8. package/api/doctor/doctor.d.mts +32 -3
  9. package/api/doctor/doctor.doc.mjs +2 -1
  10. package/api/doctor/doctor.mjs +97 -4
  11. package/api/doctor/doctor.test.mjs +90 -1
  12. package/api/gap-report/gap-report-worker.d.mts +4 -0
  13. package/api/gap-report/gap-report-worker.mjs +73 -0
  14. package/api/gap-report/gap-report.d.mts +81 -0
  15. package/api/gap-report/gap-report.doc.d.mts +9 -0
  16. package/api/gap-report/gap-report.doc.mjs +127 -0
  17. package/api/gap-report/gap-report.mjs +707 -0
  18. package/api/gap-report/gap-report.test.mjs +1210 -0
  19. package/api/gap-report/gap-report.type.d.mts +88 -0
  20. package/api/gap-report/gap-report.type.mjs +69 -0
  21. package/api/index.d.mts +8 -1
  22. package/api/index.mjs +24 -1
  23. package/api/integration/add-contribution.d.mts +44 -0
  24. package/api/integration/add-contribution.mjs +1160 -0
  25. package/api/integration/add-contribution.test.mjs +733 -0
  26. package/api/integration/add-helpers.d.mts +80 -0
  27. package/api/integration/add-helpers.mjs +333 -0
  28. package/api/integration/add-helpers.test.mjs +161 -0
  29. package/api/integration/add-theme.d.mts +10 -0
  30. package/api/integration/add-theme.mjs +332 -0
  31. package/api/integration/add-theme.test.mjs +194 -0
  32. package/api/integration/integration-authoring.type.d.mts +55 -0
  33. package/api/integration/integration-authoring.type.mjs +76 -0
  34. package/api/integration/integration-block-exports.test.mjs +4 -0
  35. package/api/integration/integrationAdd.doc.d.mts +5 -0
  36. package/api/integration/integrationAdd.doc.mjs +100 -0
  37. package/api/integration/integrationAddAgentDoc.doc.d.mts +5 -0
  38. package/api/integration/integrationAddAgentDoc.doc.mjs +49 -0
  39. package/api/integration/integrationAddCodemod.doc.d.mts +5 -0
  40. package/api/integration/integrationAddCodemod.doc.mjs +55 -0
  41. package/api/integration/integrationAddComponent.doc.d.mts +5 -0
  42. package/api/integration/integrationAddComponent.doc.mjs +49 -0
  43. package/api/integration/integrationAddDoc.doc.d.mts +5 -0
  44. package/api/integration/integrationAddDoc.doc.mjs +59 -0
  45. package/api/integration/integrationAddTemplate.doc.d.mts +5 -0
  46. package/api/integration/integrationAddTemplate.doc.mjs +55 -0
  47. package/api/integration/integrationAddTheme.doc.d.mts +5 -0
  48. package/api/integration/integrationAddTheme.doc.mjs +85 -0
  49. package/api/integration/integrationPackCheck.doc.d.mts +5 -0
  50. package/api/integration/integrationPackCheck.doc.mjs +35 -0
  51. package/api/integration/pack-check.d.mts +27 -0
  52. package/api/integration/pack-check.mjs +795 -0
  53. package/api/integration/pack-check.test.mjs +569 -0
  54. package/api/integration/pack-check.type.d.mts +45 -0
  55. package/api/integration/pack-check.type.mjs +56 -0
  56. package/api/integration/public-api.test.mjs +21 -0
  57. package/api/integration/validate-integration.mjs +221 -11
  58. package/api/integration/validate-integration.test.mjs +189 -5
  59. package/api/integration/validateIntegration.doc.mjs +2 -2
  60. package/api/json/index.ts +1 -0
  61. package/api/search/search.mjs +19 -1
  62. package/api/theme/_adapter.d.mts +26 -28
  63. package/api/theme/_adapter.mjs +101 -38
  64. package/api/theme/add/add.d.mts +2 -1
  65. package/api/theme/add/add.mjs +56 -20
  66. package/api/theme/add/add.test.mjs +1 -0
  67. package/api/theme/build/build.d.mts +25 -0
  68. package/api/theme/build/build.mjs +101 -70
  69. package/api/theme/build/build.test.mjs +77 -44
  70. package/api/theme/integration-themes.test.mjs +183 -0
  71. package/api/theme/list/list.d.mts +10 -2
  72. package/api/theme/list/list.mjs +31 -10
  73. package/api/theme/list/list.test.mjs +102 -23
  74. package/api/theme/listThemes.doc.d.mts +1 -5
  75. package/api/theme/listThemes.doc.mjs +6 -13
  76. package/api/theme/targets/targets.test.mjs +22 -8
  77. package/api/theme/theme.d.mts +1 -1
  78. package/api/theme/theme.mjs +1 -1
  79. package/api/theme/theme.type.d.mts +9 -0
  80. package/api/theme/theme.type.mjs +3 -1
  81. package/api/theme/themeAdd.doc.d.mts +1 -4
  82. package/api/theme/themeAdd.doc.mjs +31 -31
  83. package/api/theme/themeBuild.doc.mjs +1 -1
  84. package/api/theme/themeList.doc.d.mts +1 -4
  85. package/api/theme/themeList.doc.mjs +7 -15
  86. package/api/theme/themeListAvailable.doc.d.mts +8 -0
  87. package/api/theme/themeListAvailable.doc.mjs +57 -0
  88. package/api/theme/themeTargets.doc.mjs +21 -7
  89. package/api/upgrade/_adapter.d.mts +2 -0
  90. package/api/upgrade/_adapter.mjs +1 -0
  91. package/api/upgrade/registry/registry.d.mts +40 -0
  92. package/api/upgrade/registry/registry.mjs +1154 -0
  93. package/api/upgrade/registry/registry.test.mjs +826 -0
  94. package/api/upgrade/run/run.mjs +49 -8
  95. package/api/upgrade/status/status.d.mts +6 -4
  96. package/api/upgrade/status/status.mjs +26 -8
  97. package/api/upgrade/upgrade.d.mts +2 -2
  98. package/api/upgrade/upgrade.doc.mjs +33 -9
  99. package/api/upgrade/upgrade.mjs +34 -7
  100. package/api/upgrade/upgrade.test.mjs +198 -8
  101. package/api/upgrade/upgrade.type.d.mts +90 -1
  102. package/api/upgrade/upgrade.type.mjs +51 -2
  103. package/assets/docs/cli-integrations.doc.mjs +152 -28
  104. package/assets/docs/getting-started.doc.mjs +1 -1
  105. package/assets/docs/{shadcn-compatibility.doc.mjs → shadcn-compatibility.doc.draft.mjs} +23 -13
  106. package/assets/docs/styling.doc.mjs +3 -3
  107. package/assets/docs/theme.doc.dense.mjs +2 -2
  108. package/assets/docs/theme.doc.mjs +23 -13
  109. package/assets/docs/theme.doc.zh.mjs +1 -1
  110. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +2 -1
  111. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +38 -12
  112. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.doc.mjs +15 -0
  113. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.tsx +87 -0
  114. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +23 -0
  115. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +75 -0
  116. package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +5 -19
  117. package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +3 -2
  118. package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +4 -5
  119. package/assets/templates/blocks/components/Toast/ToastAction.tsx +2 -1
  120. package/assets/templates/blocks/components/Toast/ToastDeduplication.tsx +2 -1
  121. package/assets/templates/blocks/components/Toast/ToastDismiss.tsx +2 -1
  122. package/assets/templates/blocks/components/Toast/ToastShowcase.tsx +2 -1
  123. package/assets/templates/blocks/components/Toast/ToastStacking.tsx +2 -1
  124. package/assets/templates/blocks/components/Toast/ToastTypes.tsx +2 -1
  125. package/assets/templates/pages/dashboard/template.doc.mjs +2 -2
  126. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +3 -2
  127. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +3 -2
  128. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +3 -3
  129. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -2
  130. package/assets/templates/pages/dashboard-progress/template.doc.mjs +2 -2
  131. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -2
  132. package/assets/templates/themes/butter/butterTheme.ts +3 -3
  133. package/assets/templates/themes/neutral/neutralTheme.ts +2 -2
  134. package/assets/templates/themes/stone/stoneTheme.ts +3 -3
  135. package/assets/theme.template.ts +4 -7
  136. package/authoring/config/config.doc.mjs +9 -1
  137. package/authoring/config/parse.d.mts +2 -0
  138. package/authoring/config/parse.mjs +28 -3
  139. package/authoring/config/parse.test.mjs +25 -3
  140. package/authoring/config/type.ts +3 -0
  141. package/authoring/doctypes/_schema.d.mts +3 -0
  142. package/authoring/doctypes/_schema.mjs +6 -1
  143. package/authoring/doctypes/base/type.ts +6 -6
  144. package/authoring/doctypes/component/component.doc.mjs +6 -0
  145. package/authoring/doctypes/component/type.ts +2 -0
  146. package/authoring/gap-report/parse.d.mts +63 -0
  147. package/authoring/gap-report/parse.mjs +121 -0
  148. package/authoring/gap-report/parse.test.mjs +172 -0
  149. package/authoring/gap-report/type.ts +107 -0
  150. package/authoring/index.d.mts +1 -0
  151. package/authoring/index.d.ts +12 -0
  152. package/authoring/index.mjs +4 -0
  153. package/authoring/integration/integration.doc.mjs +14 -2
  154. package/authoring/integration/parse.test.mjs +9 -4
  155. package/authoring/integration/schema.d.mts +2 -0
  156. package/authoring/integration/schema.mjs +1 -0
  157. package/authoring/integration/type.ts +23 -6
  158. package/authoring/shadcn/receipt.d.mts +219 -0
  159. package/authoring/shadcn/receipt.mjs +248 -0
  160. package/authoring/shadcn/receipt.test.mjs +187 -0
  161. package/authoring/shadcn/source-variants.d.mts +28 -0
  162. package/authoring/shadcn/source-variants.mjs +176 -0
  163. package/authoring/shadcn/source-variants.test.mjs +120 -0
  164. package/clients/cli/commands/build-theme.mjs +54 -19
  165. package/clients/cli/commands/build-theme.variants.test.mjs +15 -12
  166. package/clients/cli/commands/component/index.mjs +1 -1
  167. package/clients/cli/commands/docs.test.mjs +1 -0
  168. package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
  169. package/clients/cli/commands/gap-report.doc.mjs +73 -0
  170. package/clients/cli/commands/gap-report.mjs +114 -0
  171. package/clients/cli/commands/gap-report.test.mjs +198 -0
  172. package/clients/cli/commands/import-hint-correctness.test.mjs +88 -0
  173. package/clients/cli/commands/integration-add.doc.mjs +88 -0
  174. package/clients/cli/commands/integration-authoring.test.mjs +177 -0
  175. package/clients/cli/commands/integration-pack.doc.mjs +34 -0
  176. package/clients/cli/commands/integration-real-world.test.mjs +618 -0
  177. package/clients/cli/commands/integration.doc.mjs +28 -0
  178. package/clients/cli/commands/integration.mjs +153 -0
  179. package/clients/cli/commands/theme-add.doc.mjs +11 -6
  180. package/clients/cli/commands/theme-list.doc.mjs +21 -5
  181. package/clients/cli/commands/theme-targets.behavior.test.mjs +19 -2
  182. package/clients/cli/commands/theme.doc.mjs +2 -2
  183. package/clients/cli/commands/upgrade.doc.mjs +17 -4
  184. package/clients/cli/commands/upgrade.mjs +12 -1
  185. package/clients/cli/commands/upgrade.test.mjs +41 -0
  186. package/clients/cli/index.mjs +5 -0
  187. package/clients/cli/lib/component-format.mjs +42 -26
  188. package/clients/cli/lib/component-format.test.mjs +34 -3
  189. package/clients/cli/lib/manifest.mjs +12 -0
  190. package/foundation/config/project-themes.test.mjs +127 -0
  191. package/foundation/config/project.d.mts +23 -4
  192. package/foundation/config/project.mjs +96 -9
  193. package/foundation/config/project.test.mjs +132 -6
  194. package/foundation/discovery/component-discovery.d.mts +36 -0
  195. package/foundation/discovery/component-discovery.mjs +96 -0
  196. package/foundation/discovery/theme-discovery.d.mts +39 -0
  197. package/foundation/discovery/theme-discovery.mjs +650 -0
  198. package/foundation/discovery/theme-discovery.test.mjs +375 -0
  199. package/foundation/discovery/theming-targets.d.mts +16 -0
  200. package/foundation/discovery/theming-targets.mjs +39 -3
  201. package/foundation/discovery/theming-targets.test.mjs +139 -0
  202. package/foundation/integrations/autolink.d.mts +96 -0
  203. package/foundation/integrations/autolink.mjs +265 -0
  204. package/foundation/integrations/autolink.test.mjs +430 -0
  205. package/foundation/integrations/contribution-inventory.d.mts +152 -0
  206. package/foundation/integrations/contribution-inventory.mjs +497 -0
  207. package/foundation/integrations/contribution-inventory.test.mjs +361 -0
  208. package/foundation/integrations/integrations.d.mts +73 -9
  209. package/foundation/integrations/integrations.mjs +158 -8
  210. package/foundation/integrations/integrations.test.mjs +152 -29
  211. package/foundation/integrations/manifest-writer.d.mts +56 -0
  212. package/foundation/integrations/manifest-writer.mjs +328 -0
  213. package/foundation/integrations/manifest-writer.test.mjs +229 -0
  214. package/foundation/integrations/validate-contributions.mjs +81 -6
  215. package/foundation/response/error-codes.d.mts +4 -1
  216. package/foundation/response/error-codes.doc.mjs +16 -1
  217. package/foundation/response/error-codes.mjs +10 -1
  218. package/foundation/response/response-types.doc.mjs +23 -2
  219. package/package.json +8 -1
@@ -1,63 +1,126 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Shared data layer for the `theme` command's `add`/`list` leaves — reads
5
- * the bundled-theme manifest (`templates/themes/manifest.json`, generated by
6
- * scripts/generate-cli-themes.mjs) and resolves a theme by slug. Both leaves
7
- * sit on this; neither reads the manifest itself.
4
+ * @file Shared data layer for `theme list` and `theme add`.
5
+ *
6
+ * `listThemes()` intentionally keeps its historical synchronous, bundled-only
7
+ * contract. Project-aware callers use `listAvailableThemes()`, which asks
8
+ * Project for the bundled catalog plus every installed integration catalog.
8
9
  */
9
10
 
10
- import * as fs from 'node:fs';
11
- import * as path from 'node:path';
12
- import {CLI_ROOT} from '../../foundation/fs/paths.mjs';
11
+ import {Project} from '../../foundation/config/project.mjs';
12
+ import {
13
+ BUNDLED_THEME_PACKAGE,
14
+ MANIFEST_PATH,
15
+ THEMES_DIR,
16
+ discoverBundledThemes,
17
+ } from '../../foundation/discovery/theme-discovery.mjs';
13
18
  import {AstryxError} from '../error.mjs';
14
19
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
15
20
 
16
- /** Directory holding the generated theme bundle. */
17
- export const THEMES_DIR = path.join(CLI_ROOT, 'assets', 'templates', 'themes');
18
- /** The bundle manifest that lists every theme (+ its files). */
19
- export const MANIFEST_PATH = path.join(THEMES_DIR, 'manifest.json');
21
+ export {BUNDLED_THEME_PACKAGE, MANIFEST_PATH, THEMES_DIR};
20
22
 
21
23
  /**
22
- * A single bundled theme entry from `templates/themes/manifest.json`.
23
- * @typedef {object} BundledTheme
24
- * @property {string} slug
25
- * @property {string} displayName
26
- * @property {string} description
27
- * @property {boolean} maintained
28
- * @property {string} entry
29
- * @property {string} exportName
30
- * @property {string[]} files
24
+ * A bundled theme entry kept for the historical public `listThemes()` helper.
25
+ * @typedef {Pick<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme, 'slug' | 'displayName' | 'description' | 'maintained' | 'entry' | 'exportName' | 'files'>} BundledTheme
31
26
  */
32
27
 
33
28
  /**
34
- * Parsed `themes` array from the bundle manifest (empty if not generated).
29
+ * The themes bundled in this CLI build. Kept synchronous for compatibility with
30
+ * programmatic callers that use this low-level helper directly.
35
31
  * @returns {BundledTheme[]}
36
32
  */
37
33
  export function listThemes() {
38
- if (!fs.existsSync(MANIFEST_PATH)) return [];
39
- /** @type {{themes?: BundledTheme[]}} */
40
- let manifest;
34
+ return availableBundledThemes().map(theme => ({
35
+ slug: theme.slug,
36
+ displayName: theme.displayName,
37
+ description: theme.description,
38
+ maintained: theme.maintained,
39
+ entry: theme.entry,
40
+ exportName: theme.exportName,
41
+ files: theme.files,
42
+ }));
43
+ }
44
+
45
+ /** @returns {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} */
46
+ function availableBundledThemes() {
41
47
  try {
42
- manifest = JSON.parse(fs.readFileSync(MANIFEST_PATH, 'utf-8'));
43
- } catch (err) {
44
- throw new AstryxError(
45
- `Theme bundle manifest is unreadable (${MANIFEST_PATH}): ${/** @type {any} */ (err).message}`,
46
- undefined,
47
- ERROR_CODES.ERR_NO_SOURCE,
48
- );
48
+ return discoverBundledThemes();
49
+ } catch (error) {
50
+ const message = error instanceof Error ? error.message : String(error);
51
+ throw new AstryxError(message, undefined, ERROR_CODES.ERR_NO_SOURCE);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Load available themes with any package-owned integration issues found while
57
+ * discovering them. The issue set lets a package-scoped lookup distinguish an
58
+ * absent theme from an installed package whose catalog is broken.
59
+ * @param {string} cwd
60
+ * @returns {Promise<{themes: import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[], issues: Array<import('../../foundation/integrations/issue').AstryxIntegrationIssue & {package: string}>}>}
61
+ */
62
+ async function availableThemeState(cwd) {
63
+ try {
64
+ const project = await Project.load(cwd);
65
+ const themes = await project.themes();
66
+ return {themes, issues: await project.issues()};
67
+ } catch {
68
+ return {themes: availableBundledThemes(), issues: []};
49
69
  }
50
- return Array.isArray(manifest.themes) ? manifest.themes : [];
51
70
  }
52
71
 
53
72
  /**
54
- * Resolve a bundled theme by slug (case-insensitive). `undefined` when the slug
55
- * is empty or unknown.
73
+ * Bundled themes plus source themes from integrations installed in `cwd`.
74
+ * A project/config load failure degrades to the bundled catalog, preserving the
75
+ * command's historical usefulness outside a configured project.
76
+ * @param {string} [cwd]
77
+ * @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]>}
78
+ */
79
+ export async function listAvailableThemes(cwd = process.cwd()) {
80
+ return (await availableThemeState(cwd)).themes;
81
+ }
82
+
83
+ /**
84
+ * Resolve an available theme by case-insensitive slug and optional owner package.
85
+ * Duplicate slugs fail closed until the caller selects an owner.
56
86
  * @param {string} [slug]
57
- * @returns {BundledTheme | undefined}
87
+ * @param {{cwd?: string, package?: string}} [options]
88
+ * @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme | undefined>}
58
89
  */
59
- export function findTheme(slug) {
90
+ export async function findTheme(slug, options = {}) {
60
91
  if (!slug) return undefined;
61
- const lc = String(slug).toLowerCase();
62
- return listThemes().find(t => t.slug.toLowerCase() === lc);
92
+ const {themes, issues} = await availableThemeState(
93
+ options.cwd ?? process.cwd(),
94
+ );
95
+ const normalized = String(slug).toLowerCase();
96
+ const matches = themes.filter(
97
+ theme =>
98
+ theme.slug.toLowerCase() === normalized &&
99
+ (options.package == null || theme.package === options.package),
100
+ );
101
+ if (matches.length === 0 && options.package != null) {
102
+ const packageIssue = issues.find(
103
+ issue => issue.package === options.package && issue.severity === 'error',
104
+ );
105
+ if (packageIssue) {
106
+ throw new AstryxError(
107
+ `Theme package "${options.package}" is installed but unavailable: ${packageIssue.message}`,
108
+ undefined,
109
+ ERROR_CODES.ERR_THEME_INVALID,
110
+ );
111
+ }
112
+ }
113
+ if (matches.length > 1) {
114
+ throw new AstryxError(
115
+ `Theme "${slug}" is provided by more than one package. Select one with --package.`,
116
+ matches.map(theme => ({
117
+ name: `${theme.slug} --package ${theme.package}`,
118
+ reason: theme.bundled
119
+ ? 'bundled theme'
120
+ : `provided by ${theme.package}`,
121
+ })),
122
+ ERROR_CODES.ERR_AMBIGUOUS_THEME,
123
+ );
124
+ }
125
+ return matches[0];
63
126
  }
@@ -9,11 +9,12 @@
9
9
  * file (without `overwrite`), a missing bundled file, or a write failure.
10
10
  *
11
11
  * @param {string} slug
12
- * @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} [options]
12
+ * @param {{targetPath?: string, overwrite?: boolean, cwd?: string, package?: string}} [options]
13
13
  * @returns {Promise<import('../theme.type.mjs').ThemeAddResponse>}
14
14
  */
15
15
  export function themeAdd(slug: string, options?: {
16
16
  targetPath?: string;
17
17
  overwrite?: boolean;
18
18
  cwd?: string;
19
+ package?: string;
19
20
  }): Promise<import("../theme.type.mjs").ThemeAddResponse>;
@@ -1,18 +1,20 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file `astryx theme add` leaf — copies a bundled theme's source
5
- * (`templates/themes/<slug>/`) into the consumer's project so they own it,
6
- * without needing the theme package. Which theme is resolved by ../_adapter.mjs;
4
+ * @file `astryx theme add` leaf — copies an available theme's source from the
5
+ * CLI bundle or an installed integration into the consumer's project so they own it.
7
6
  * this leaf owns the copy I/O + path-safety and returns a `theme.add` receipt.
8
7
  */
9
8
 
10
9
  import * as fs from 'node:fs';
11
10
  import * as path from 'node:path';
12
- import {assertWithin, PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
11
+ import {
12
+ assertWithin,
13
+ PathSafetyError,
14
+ } from '../../../foundation/fs/path-safety.mjs';
13
15
  import {AstryxError} from '../../error.mjs';
14
16
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
15
- import {THEMES_DIR, listThemes, findTheme} from '../_adapter.mjs';
17
+ import {listAvailableThemes, findTheme} from '../_adapter.mjs';
16
18
  // Scaffolded files must not carry our repo boilerplate into a consumer's tree.
17
19
  import {stripCopyrightHeader} from '../../../foundation/text/copyright-header.mjs';
18
20
 
@@ -32,25 +34,33 @@ function defaultTargetDir(slug) {
32
34
  * file (without `overwrite`), a missing bundled file, or a write failure.
33
35
  *
34
36
  * @param {string} slug
35
- * @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} [options]
37
+ * @param {{targetPath?: string, overwrite?: boolean, cwd?: string, package?: string}} [options]
36
38
  * @returns {Promise<import('../theme.type.mjs').ThemeAddResponse>}
37
39
  */
38
40
  export async function themeAdd(slug, options = {}) {
39
- const {targetPath, overwrite = false, cwd = process.cwd()} = options;
41
+ const {
42
+ targetPath,
43
+ overwrite = false,
44
+ cwd = process.cwd(),
45
+ package: packageName,
46
+ } = options;
40
47
 
41
- const match = findTheme(slug);
48
+ const match = await findTheme(slug, {cwd, package: packageName});
42
49
  if (!match) {
50
+ const available = await listAvailableThemes(cwd);
43
51
  throw new AstryxError(
44
- `Unknown theme "${slug}"`,
45
- listThemes().map(t => ({
46
- name: t.slug,
47
- reason: t.maintained ? 'maintained theme' : 'example theme',
52
+ `Unknown theme "${slug}"${packageName ? ` in package "${packageName}"` : ''}`,
53
+ available.map(theme => ({
54
+ name: `${theme.slug} --package ${theme.package}`,
55
+ reason: theme.bundled
56
+ ? 'bundled theme'
57
+ : `provided by ${theme.package}`,
48
58
  })),
49
59
  ERROR_CODES.ERR_UNKNOWN_THEME,
50
60
  );
51
61
  }
52
62
 
53
- const themeSrcDir = path.join(THEMES_DIR, match.slug);
63
+ const themeSrcDir = match.sourceDir;
54
64
 
55
65
  // Path-safe destination; reject traversal outside cwd.
56
66
  const rawTarget = targetPath || defaultTargetDir(match.slug);
@@ -68,11 +78,25 @@ export async function themeAdd(slug, options = {}) {
68
78
  throw err;
69
79
  }
70
80
 
71
- const writes = match.files.map(name => ({
72
- name,
73
- src: path.join(themeSrcDir, name),
74
- dest: path.join(resolvedDir, name),
75
- }));
81
+ let writes;
82
+ try {
83
+ writes = match.files.map(name => ({
84
+ name,
85
+ src: path.join(themeSrcDir, name),
86
+ dest: assertWithin(name, resolvedDir, {
87
+ label: `theme destination for ${name}`,
88
+ }),
89
+ }));
90
+ } catch (err) {
91
+ if (err instanceof PathSafetyError) {
92
+ throw new AstryxError(
93
+ err.message,
94
+ undefined,
95
+ ERROR_CODES.ERR_PATH_TRAVERSAL,
96
+ );
97
+ }
98
+ throw err;
99
+ }
76
100
  for (const w of writes) {
77
101
  if (!fs.existsSync(w.src)) {
78
102
  throw new AstryxError(
@@ -106,10 +130,14 @@ export async function themeAdd(slug, options = {}) {
106
130
  try {
107
131
  fs.mkdirSync(resolvedDir, {recursive: true});
108
132
  for (const w of writes) {
109
- const tmp = `${w.dest}.${process.pid}.tmp`;
133
+ const dest = assertWithin(w.name, resolvedDir, {
134
+ label: `theme destination for ${w.name}`,
135
+ });
136
+ fs.mkdirSync(path.dirname(dest), {recursive: true});
137
+ const tmp = `${dest}.${process.pid}.tmp`;
110
138
  const contents = stripCopyrightHeader(fs.readFileSync(w.src, 'utf-8'));
111
139
  fs.writeFileSync(tmp, contents);
112
- staged.push({tmp, dest: w.dest});
140
+ staged.push({tmp, dest});
113
141
  }
114
142
  for (const s of staged) {
115
143
  fs.renameSync(s.tmp, s.dest);
@@ -122,6 +150,13 @@ export async function themeAdd(slug, options = {}) {
122
150
  /* best-effort */
123
151
  }
124
152
  }
153
+ if (err instanceof PathSafetyError) {
154
+ throw new AstryxError(
155
+ err.message,
156
+ undefined,
157
+ ERROR_CODES.ERR_PATH_TRAVERSAL,
158
+ );
159
+ }
125
160
  throw new AstryxError(
126
161
  `Failed to write theme files: ${/** @type {any} */ (err).message}`,
127
162
  undefined,
@@ -136,6 +171,7 @@ export async function themeAdd(slug, options = {}) {
136
171
  slug: match.slug,
137
172
  displayName: match.displayName,
138
173
  maintained: match.maintained,
174
+ package: match.package,
139
175
  outputDir: relDir,
140
176
  entry: match.entry,
141
177
  exportName: match.exportName,
@@ -28,6 +28,7 @@ describe('themeAdd (api/theme/add)', () => {
28
28
  const result = await themeAdd('neutral', {cwd: tmpDir});
29
29
  expect(result.type).toBe('theme.add');
30
30
  expect(result.data.slug).toBe('neutral');
31
+ expect(result.data.package).toBe('@astryxdesign/cli');
31
32
  expect(result.data.outputDir).toBe(path.join('src', 'themes', 'neutral'));
32
33
  expect(result.data.files.length).toBeGreaterThan(0);
33
34
  for (const f of result.data.files) {
@@ -13,6 +13,31 @@
13
13
  * @returns {string}
14
14
  */
15
15
  export function importSpecifier(relDir: string, base: string): string;
16
+ /**
17
+ * Validate component overrides against one discovered target registry.
18
+ *
19
+ * @param {{components?: Record<string, Record<string, unknown>>, onDark?: {components?: Record<string, Record<string, unknown>>}, onLight?: {components?: Record<string, Record<string, unknown>>}, __onDark?: {components?: Record<string, Record<string, unknown>>}, __onLight?: {components?: Record<string, Record<string, unknown>>}}} themeDef
20
+ * @param {{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>}} knownComponents
21
+ * @returns {string[]}
22
+ */
23
+ export function validateComponentOverridesAgainstRegistry(themeDef: {
24
+ components?: Record<string, Record<string, unknown>>;
25
+ onDark?: {
26
+ components?: Record<string, Record<string, unknown>>;
27
+ };
28
+ onLight?: {
29
+ components?: Record<string, Record<string, unknown>>;
30
+ };
31
+ __onDark?: {
32
+ components?: Record<string, Record<string, unknown>>;
33
+ };
34
+ __onLight?: {
35
+ components?: Record<string, Record<string, unknown>>;
36
+ };
37
+ }, knownComponents: {
38
+ propsByKey: Record<string, string[]>;
39
+ deprecatedByKey: Record<string, string>;
40
+ }): string[];
16
41
  /**
17
42
  * Compile a defineTheme file to CSS + JS + .d.ts (and an optional
18
43
  * `.variants.d.ts`). Performs the writes and returns a `theme.build` receipt,
@@ -54,7 +54,7 @@ import {logger} from '../../logger.mjs';
54
54
  import {loadComponentDoc} from '../../../foundation/discovery/component-loader.mjs';
55
55
  import {
56
56
  collectThemingTargets,
57
- targetsByKey,
57
+ targetValidationRegistry,
58
58
  } from '../../../foundation/discovery/theming-targets.mjs';
59
59
  import {collectUnloadedFonts, formatFontLoadingHelp} from './font-warning.mjs';
60
60
  import {interceptCore} from './core-interception.mjs';
@@ -1497,32 +1497,30 @@ ${iconType}export declare const ${toIdentifier(themeDef.name)}Theme: DefinedThem
1497
1497
 
1498
1498
  /**
1499
1499
  * Load known theme target keys from core component docs: the visual props AND
1500
- * the runtime states each target reflects. Both are legal override keys — the
1501
- * Theming Infrastructure wiki documents `radio: {checked}` and
1502
- * `'calendar-day': {today, selected}` alongside `button: {'variant:secondary'}`
1503
- * — so validation has to know both or documented syntax warns as unknown.
1504
- * Returns null when docs are unavailable so validation can skip unknown-key
1505
- * warnings rather than guessing from a second registry.
1500
+ * runtime states each target reflects, plus canonical replacements for
1501
+ * deprecated target keys. Deprecated targets remain accepted for compatibility,
1502
+ * but every use receives actionable build guidance. Returns null when docs are
1503
+ * unavailable so validation skips warnings rather than guessing from a second
1504
+ * registry.
1506
1505
  *
1507
- * Shares its enumeration with `theme targets`, so what a theme author can list
1508
- * is exactly what this validator accepts.
1509
- *
1510
- * @returns {Promise<Record<string, string[]> | null>}
1506
+ * @returns {Promise<{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>} | null>}
1511
1507
  */
1512
1508
  async function loadKnownComponents() {
1513
1509
  const coreRoot = resolveCoreRoot();
1514
1510
  const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
1515
1511
  if (!coreSrc || !fs.existsSync(coreSrc)) return null;
1516
1512
 
1517
- const targets = targetsByKey(await collectThemingTargets(coreSrc));
1518
- return Object.keys(targets).length > 0 ? targets : null;
1513
+ const registry = targetValidationRegistry(
1514
+ await collectThemingTargets(coreSrc),
1515
+ );
1516
+ return Object.keys(registry.propsByKey).length > 0 ? registry : null;
1519
1517
  }
1520
1518
 
1521
- /** @type {Record<string, string[]> | null | undefined} */
1519
+ /** @type {{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>} | null | undefined} */
1522
1520
  let knownComponentsCache;
1523
1521
 
1524
1522
  /**
1525
- * @returns {Promise<Record<string, string[]> | null>}
1523
+ * @returns {Promise<{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>} | null>}
1526
1524
  */
1527
1525
  async function getKnownComponents() {
1528
1526
  if (knownComponentsCache === undefined) {
@@ -1532,67 +1530,86 @@ async function getKnownComponents() {
1532
1530
  }
1533
1531
 
1534
1532
  /**
1535
- * Validate component overrides in a theme definition.
1536
- * Warns on unknown component names and unknown prop names.
1537
- * Returns array of warning strings.
1538
- * @param {{components?: Record<string, Record<string, unknown>>}} themeDef
1539
- * @returns {Promise<string[]>}
1533
+ * Validate component overrides against one discovered target registry.
1534
+ *
1535
+ * @param {{components?: Record<string, Record<string, unknown>>, onDark?: {components?: Record<string, Record<string, unknown>>}, onLight?: {components?: Record<string, Record<string, unknown>>}, __onDark?: {components?: Record<string, Record<string, unknown>>}, __onLight?: {components?: Record<string, Record<string, unknown>>}}} themeDef
1536
+ * @param {{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>}} knownComponents
1537
+ * @returns {string[]}
1540
1538
  */
1541
- async function validateComponentOverrides(themeDef) {
1539
+ export function validateComponentOverridesAgainstRegistry(
1540
+ themeDef,
1541
+ knownComponents,
1542
+ ) {
1542
1543
  /** @type {string[]} */
1543
1544
  const warnings = [];
1544
- const componentEntries = themedComponentEntries(themeDef);
1545
- if (componentEntries.length === 0) return warnings;
1545
+ /** @type {{name: string, components: Record<string, Record<string, unknown>>}[]} */
1546
+ const layers = [...getThemeComponentLayers(themeDef)];
1547
+ let adaptationIndex = 0;
1548
+ for (const value of adaptationRuleValues(themeDef)) {
1549
+ adaptationIndex++;
1550
+ if (
1551
+ value.components &&
1552
+ typeof value.components === 'object' &&
1553
+ Object.keys(value.components).length > 0
1554
+ ) {
1555
+ layers.push({
1556
+ name: `adaptation rule ${adaptationIndex}`,
1557
+ components: value.components,
1558
+ });
1559
+ }
1560
+ }
1546
1561
 
1547
- const knownComponents = await getKnownComponents();
1548
- if (knownComponents == null) return warnings;
1549
-
1550
- for (const [component, rules] of componentEntries) {
1551
- // Check component name
1552
- if (!(component in knownComponents)) {
1553
- const similar = Object.keys(knownComponents)
1554
- .filter(k => {
1555
- if (k.includes(component) || component.includes(k)) return true;
1556
- // Levenshtein distance 1-2 for short names
1557
- if (Math.abs(k.length - component.length) <= 2) {
1558
- let diff = 0;
1559
- const longer = k.length >= component.length ? k : component;
1560
- const shorter = k.length < component.length ? k : component;
1561
- let j = 0;
1562
- for (let i = 0; i < longer.length && diff <= 2; i++) {
1563
- if (longer[i] !== shorter[j]) diff++;
1564
- else j++;
1562
+ for (const {name: layerName, components} of layers) {
1563
+ for (const [component, rules] of Object.entries(components)) {
1564
+ const location = layerName === 'base' ? '' : ` in ${layerName}`;
1565
+ if (!(component in knownComponents.propsByKey)) {
1566
+ const similar = Object.keys(knownComponents.propsByKey)
1567
+ .filter(k => {
1568
+ if (k.includes(component) || component.includes(k)) return true;
1569
+ if (Math.abs(k.length - component.length) <= 2) {
1570
+ let diff = 0;
1571
+ const longer = k.length >= component.length ? k : component;
1572
+ const shorter = k.length < component.length ? k : component;
1573
+ let j = 0;
1574
+ for (let i = 0; i < longer.length && diff <= 2; i++) {
1575
+ if (longer[i] !== shorter[j]) diff++;
1576
+ else j++;
1577
+ }
1578
+ diff += shorter.length - j;
1579
+ return diff <= 2;
1565
1580
  }
1566
- diff += shorter.length - j;
1567
- return diff <= 2;
1568
- }
1569
- return false;
1570
- })
1571
- .slice(0, 3);
1572
- const hint =
1573
- similar.length > 0 ? ` Did you mean: ${similar.join(', ')}?` : '';
1574
- warnings.push(`Unknown component "${component}".${hint}`);
1575
- continue;
1576
- }
1581
+ return false;
1582
+ })
1583
+ .slice(0, 3);
1584
+ const hint =
1585
+ similar.length > 0 ? ` Did you mean: ${similar.join(', ')}?` : '';
1586
+ warnings.push(`Unknown component "${component}".${hint}`);
1587
+ continue;
1588
+ }
1577
1589
 
1578
- // Check prop/state names in the override keys. A key is either `base`, a
1579
- // `prop:value` pair (possibly `+`-joined), or a bare state name.
1580
- const knownProps = knownComponents[component];
1581
- for (const key of Object.keys(rules)) {
1582
- if (key === 'base') continue;
1583
-
1584
- // Parse prop:value pairs (e.g. 'variant:secondary' or 'variant:destructive+size:sm')
1585
- const pairs = key.split('+');
1586
- for (const pair of pairs) {
1587
- const [prop] = pair.split(':');
1588
- if (prop && !knownProps.includes(prop)) {
1589
- const hint =
1590
- knownProps.length > 0
1591
- ? ` Known props/states: ${knownProps.join(', ')}`
1592
- : ' This component has no variant props or states.';
1593
- warnings.push(
1594
- `Unknown prop "${prop}" on component "${component}".${hint}`,
1595
- );
1590
+ const replacement = knownComponents.deprecatedByKey[component];
1591
+ if (replacement != null) {
1592
+ warnings.push(
1593
+ `Deprecated component target "${component}"${location}. Use "${replacement}" instead.`,
1594
+ );
1595
+ }
1596
+
1597
+ const knownProps = knownComponents.propsByKey[component];
1598
+ for (const key of Object.keys(rules)) {
1599
+ if (key === 'base') continue;
1600
+
1601
+ const pairs = key.split('+');
1602
+ for (const pair of pairs) {
1603
+ const [prop] = pair.split(':');
1604
+ if (prop && !knownProps.includes(prop)) {
1605
+ const hint =
1606
+ knownProps.length > 0
1607
+ ? ` Known props/states: ${knownProps.join(', ')}`
1608
+ : ' This component has no variant props or states.';
1609
+ warnings.push(
1610
+ `Unknown prop "${prop}" on component "${component}".${hint}`,
1611
+ );
1612
+ }
1596
1613
  }
1597
1614
  }
1598
1615
  }
@@ -1601,6 +1618,20 @@ async function validateComponentOverrides(themeDef) {
1601
1618
  return [...new Set(warnings)];
1602
1619
  }
1603
1620
 
1621
+ /**
1622
+ * Validate component overrides in a theme definition.
1623
+ * Warns on unknown component names, deprecated targets, and unknown prop names.
1624
+ *
1625
+ * @param {{components?: Record<string, Record<string, unknown>>, onDark?: {components?: Record<string, Record<string, unknown>>}, onLight?: {components?: Record<string, Record<string, unknown>>}, __onDark?: {components?: Record<string, Record<string, unknown>>}, __onLight?: {components?: Record<string, Record<string, unknown>>}}} themeDef
1626
+ * @returns {Promise<string[]>}
1627
+ */
1628
+ async function validateComponentOverrides(themeDef) {
1629
+ const knownComponents = await getKnownComponents();
1630
+ return knownComponents == null
1631
+ ? []
1632
+ : validateComponentOverridesAgainstRegistry(themeDef, knownComponents);
1633
+ }
1634
+
1604
1635
  /**
1605
1636
  * Validate that themes don't set private (--_*) CSS custom properties directly.
1606
1637
  * Private vars are internal implementation details managed by the derived var