@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
@@ -23,7 +23,10 @@ import {
23
23
  generateThemeRulesSplit as mockGenerateThemeRulesSplit,
24
24
  generateOnMediaCSS as mockGenerateOnMediaCSS,
25
25
  } from '@astryxdesign/core/theme';
26
- import {themeBuild} from './build.mjs';
26
+ import {
27
+ themeBuild,
28
+ validateComponentOverridesAgainstRegistry,
29
+ } from './build.mjs';
27
30
 
28
31
  // `themeBuild` captures core's generator once at module load. Wrap the two
29
32
  // CSS-emitting exports in vi.fn (call-through by default) so the receipt tests
@@ -91,12 +94,12 @@ describe('themeBuild() — receipt', () => {
91
94
  `export default {
92
95
  name: 'local-theme',
93
96
  localTokens: {
94
- '--astryx-theme-local-theme-color-status-fill-accent': ['#0077b6', '#48cae4'],
97
+ '--ac-selection-ink': ['#0077b6', '#48cae4'],
95
98
  },
96
99
  components: {
97
100
  badge: {
98
101
  'variant:info': {
99
- backgroundColor: 'var(--astryx-theme-local-theme-color-status-fill-accent)',
102
+ backgroundColor: 'var(--ac-selection-ink)',
100
103
  },
101
104
  },
102
105
  },
@@ -108,48 +111,12 @@ describe('themeBuild() — receipt', () => {
108
111
  const built = fs.readFileSync(path.join(tmpDir, 'local-theme.js'), 'utf8');
109
112
 
110
113
  expect(result?.data.tokenCount).toBe(1);
111
- expect(css).toContain(
112
- '--astryx-theme-local-theme-color-status-fill-accent: light-dark(#0077b6, #48cae4);',
113
- );
114
+ expect(css).toContain('--ac-selection-ink: light-dark(#0077b6, #48cae4);');
114
115
  expect(built).toContain('localTokens: {');
115
116
  expect(built).toContain('__localTokenOwners: {');
116
117
  expect(built).toContain('__localTokenLineage: ["local-theme"]');
117
118
  });
118
119
 
119
- it.each(['VAR', 'vAr'])(
120
- 'rejects undeclared local-token references using %s() before writing outputs',
121
- async functionName => {
122
- const themeFile = path.join(tmpDir, 'invalid-local-theme.mjs');
123
- fs.writeFileSync(
124
- themeFile,
125
- `export default {
126
- name: 'invalid-local-theme',
127
- localTokens: {},
128
- components: {
129
- badge: {
130
- base: {
131
- color: '${functionName}(--astryx-theme-invalid-local-theme-color-missing)',
132
- },
133
- },
134
- },
135
- };\n`,
136
- );
137
-
138
- await expect(
139
- themeBuild('invalid-local-theme.mjs', {}, {cwd: tmpDir}),
140
- ).rejects.toThrow(/has no declaration/);
141
- expect(fs.existsSync(path.join(tmpDir, 'invalid-local-theme.css'))).toBe(
142
- false,
143
- );
144
- expect(fs.existsSync(path.join(tmpDir, 'invalid-local-theme.js'))).toBe(
145
- false,
146
- );
147
- expect(fs.existsSync(path.join(tmpDir, 'invalid-local-theme.d.ts'))).toBe(
148
- false,
149
- );
150
- },
151
- );
152
-
153
120
  it.each(['VAR', 'vAr'])(
154
121
  'rejects local-token cycles using %s() before writing outputs',
155
122
  async functionName => {
@@ -351,7 +318,7 @@ describe('themeBuild() — check mode', () => {
351
318
  describe('themeBuild() — component override validation', () => {
352
319
  it('accepts documented state keys without an "Unknown prop" warning', async () => {
353
320
  // The state-key syntax the Theming Infrastructure wiki documents —
354
- // `radio: {checked}`, `calendar-day: {today, selected}` — is declared in
321
+ // `radio-indicator: {checked}`, `calendar-day: {today, selected}` — is declared in
355
322
  // each component's doc under `theming.targets[].states`, not
356
323
  // `visualProps`. `loadKnownComponents()` read only `visualProps`, so every
357
324
  // one of these warned "Unknown prop": documented syntax that looked broken.
@@ -362,7 +329,7 @@ describe('themeBuild() — component override validation', () => {
362
329
  name: 'states',
363
330
  tokens: {'--color-bg': '#0a0a0a'},
364
331
  components: {
365
- radio: {
332
+ 'radio-indicator': {
366
333
  checked: {borderColor: 'var(--color-accent)'},
367
334
  'checked+disabled': {opacity: '0.5'},
368
335
  },
@@ -409,16 +376,82 @@ describe('themeBuild() — component override validation', () => {
409
376
  `export default {
410
377
  name: 'bogus',
411
378
  tokens: {'--color-bg': '#0a0a0a'},
412
- components: {radio: {notAState: {opacity: '0.5'}}},
379
+ components: {'radio-indicator': {notAState: {opacity: '0.5'}}},
413
380
  };\n`,
414
381
  );
415
382
 
416
383
  const result = await themeBuild('bogus.mjs', {}, {cwd: tmpDir});
417
384
 
418
385
  expect(result?.data.warnings).toEqual([
419
- expect.stringContaining('Unknown prop "notAState" on component "radio"'),
386
+ expect.stringContaining(
387
+ 'Unknown prop "notAState" on component "radio-indicator"',
388
+ ),
420
389
  ]);
421
390
  });
391
+
392
+ it('warns with the exact replacement for deprecated root and media targets', () => {
393
+ const registry = {
394
+ propsByKey: {
395
+ 'old-target': ['variant'],
396
+ 'new-target': ['variant'],
397
+ },
398
+ deprecatedByKey: {'old-target': 'new-target'},
399
+ };
400
+
401
+ expect(
402
+ validateComponentOverridesAgainstRegistry(
403
+ {
404
+ components: {
405
+ 'old-target': {base: {color: 'red'}},
406
+ 'new-target': {base: {color: 'blue'}},
407
+ },
408
+ onDark: {
409
+ components: {
410
+ 'old-target': {'variant:quiet': {color: 'pink'}},
411
+ },
412
+ },
413
+ adaptations: {
414
+ rules: [
415
+ {
416
+ when: {contrast: 'more'},
417
+ value: {
418
+ components: {
419
+ 'old-target': {'variant:loud': {color: 'purple'}},
420
+ },
421
+ },
422
+ },
423
+ ],
424
+ },
425
+ },
426
+ registry,
427
+ ),
428
+ ).toEqual([
429
+ 'Deprecated component target "old-target". Use "new-target" instead.',
430
+ 'Deprecated component target "old-target" in onDark. Use "new-target" instead.',
431
+ 'Deprecated component target "old-target" in adaptation rule 1. Use "new-target" instead.',
432
+ ]);
433
+ });
434
+
435
+ it('warns with the exact replacement for a supported deprecated target', async () => {
436
+ const themeFile = path.join(tmpDir, 'deprecated-target.mjs');
437
+ fs.writeFileSync(
438
+ themeFile,
439
+ `export default {
440
+ name: 'deprecated-target',
441
+ tokens: {},
442
+ components: {progressbar: {base: {color: 'red'}}},
443
+ };\n`,
444
+ );
445
+
446
+ const result = await themeBuild('deprecated-target.mjs', {}, {cwd: tmpDir});
447
+
448
+ expect(result?.data.warnings).toContain(
449
+ 'Deprecated component target "progressbar". Use "progress-bar" instead.',
450
+ );
451
+ expect(
452
+ fs.readFileSync(path.join(tmpDir, 'deprecated-target.css'), 'utf8'),
453
+ ).toContain('.astryx-progressbar');
454
+ });
422
455
  });
423
456
 
424
457
  describe('themeBuild() — the shipped theme template', () => {
@@ -0,0 +1,183 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
4
+ import * as fs from 'node:fs';
5
+ import * as path from 'node:path';
6
+ import {themeAdd} from './add/add.mjs';
7
+
8
+ let tmpDir;
9
+
10
+ function installThemeIntegration(
11
+ packageName,
12
+ slug,
13
+ source = 'export const oceanTheme = {};\n',
14
+ extraFiles = {},
15
+ ) {
16
+ const packageDir = path.join(
17
+ tmpDir,
18
+ 'node_modules',
19
+ ...packageName.split('/'),
20
+ );
21
+ const themeDir = path.join(packageDir, 'themes', slug);
22
+ fs.mkdirSync(themeDir, {recursive: true});
23
+ fs.writeFileSync(
24
+ path.join(packageDir, 'package.json'),
25
+ JSON.stringify({name: packageName, version: '1.0.0'}),
26
+ );
27
+ fs.writeFileSync(
28
+ path.join(packageDir, 'astryx.integration.mjs'),
29
+ `export default {themes: './themes'};\n`,
30
+ );
31
+ fs.writeFileSync(
32
+ path.join(packageDir, 'themes', 'manifest.json'),
33
+ JSON.stringify({
34
+ version: 1,
35
+ themes: [
36
+ {
37
+ slug,
38
+ displayName: slug === 'neutral' ? 'Neutral Plus' : 'Ocean',
39
+ description: 'Integration-owned theme.',
40
+ maintained: true,
41
+ entry: 'oceanTheme.ts',
42
+ exportName: 'oceanTheme',
43
+ files: ['oceanTheme.ts', ...Object.keys(extraFiles)],
44
+ },
45
+ ],
46
+ }),
47
+ );
48
+ fs.writeFileSync(path.join(themeDir, 'oceanTheme.ts'), source);
49
+ for (const [relativePath, contents] of Object.entries(extraFiles)) {
50
+ const file = path.join(themeDir, relativePath);
51
+ fs.mkdirSync(path.dirname(file), {recursive: true});
52
+ fs.writeFileSync(file, contents);
53
+ }
54
+ }
55
+
56
+ beforeEach(() => {
57
+ tmpDir = fs.mkdtempSync(
58
+ path.join(process.cwd(), '.astryx-theme-integration-'),
59
+ );
60
+ fs.writeFileSync(
61
+ path.join(tmpDir, 'package.json'),
62
+ JSON.stringify({
63
+ name: 'consumer',
64
+ dependencies: {'@acme/themes': '^1.0.0'},
65
+ }),
66
+ );
67
+ });
68
+
69
+ afterEach(() => {
70
+ fs.rmSync(tmpDir, {recursive: true, force: true});
71
+ });
72
+
73
+ describe('themeAdd with integration themes', () => {
74
+ it('copies source from an installed integration and records its owner', async () => {
75
+ installThemeIntegration('@acme/themes', 'ocean');
76
+ const result = await themeAdd('ocean', {cwd: tmpDir});
77
+
78
+ expect(result.data.package).toBe('@acme/themes');
79
+ expect(result.data.outputDir).toBe(path.join('src', 'themes', 'ocean'));
80
+ expect(
81
+ fs.readFileSync(
82
+ path.join(tmpDir, 'src', 'themes', 'ocean', 'oceanTheme.ts'),
83
+ 'utf-8',
84
+ ),
85
+ ).toContain('oceanTheme');
86
+ });
87
+
88
+ it('copies nested files listed by an integration theme catalog', async () => {
89
+ installThemeIntegration(
90
+ '@acme/themes',
91
+ 'ocean',
92
+ "import {oceanBlue} from './tokens/colors';\nexport const oceanTheme = {oceanBlue};\n",
93
+ {'tokens/colors.ts': "export const oceanBlue = '#0064e0';\n"},
94
+ );
95
+
96
+ const result = await themeAdd('ocean', {cwd: tmpDir});
97
+
98
+ expect(result.data.files).toEqual(['oceanTheme.ts', 'tokens/colors.ts']);
99
+ expect(
100
+ fs.readFileSync(
101
+ path.join(tmpDir, 'src', 'themes', 'ocean', 'tokens', 'colors.ts'),
102
+ 'utf-8',
103
+ ),
104
+ ).toContain('oceanBlue');
105
+ });
106
+
107
+ it('rejects a nested destination symlink that escapes the project', async () => {
108
+ installThemeIntegration(
109
+ '@acme/themes',
110
+ 'ocean',
111
+ "import {oceanBlue} from './tokens/colors';\nexport const oceanTheme = {oceanBlue};\n",
112
+ {'tokens/colors.ts': "export const oceanBlue = '#0064e0';\n"},
113
+ );
114
+ const outsideDir = fs.mkdtempSync(
115
+ path.join(process.cwd(), '.astryx-theme-outside-'),
116
+ );
117
+ try {
118
+ const targetDir = path.join(tmpDir, 'src', 'themes', 'ocean');
119
+ fs.mkdirSync(targetDir, {recursive: true});
120
+ fs.symlinkSync(
121
+ outsideDir,
122
+ path.join(targetDir, 'tokens'),
123
+ process.platform === 'win32' ? 'junction' : 'dir',
124
+ );
125
+
126
+ await expect(themeAdd('ocean', {cwd: tmpDir})).rejects.toMatchObject({
127
+ code: 'ERR_PATH_TRAVERSAL',
128
+ });
129
+ expect(fs.existsSync(path.join(outsideDir, 'colors.ts'))).toBe(false);
130
+ expect(fs.existsSync(path.join(targetDir, 'oceanTheme.ts'))).toBe(false);
131
+ } finally {
132
+ fs.rmSync(outsideDir, {recursive: true, force: true});
133
+ }
134
+ });
135
+
136
+ it('fails closed on a duplicate slug and resolves it with package scope', async () => {
137
+ installThemeIntegration('@acme/themes', 'neutral');
138
+
139
+ await expect(themeAdd('neutral', {cwd: tmpDir})).rejects.toMatchObject({
140
+ code: 'ERR_AMBIGUOUS_THEME',
141
+ });
142
+ const result = await themeAdd('neutral', {
143
+ cwd: tmpDir,
144
+ package: '@acme/themes',
145
+ });
146
+ expect(result.data.package).toBe('@acme/themes');
147
+ });
148
+
149
+ it('reports a selected installed package with a corrupted theme catalog', async () => {
150
+ installThemeIntegration(
151
+ '@acme/themes',
152
+ 'ocean',
153
+ "export {oceanBlue} from './tokens/colors';\n",
154
+ {'tokens/colors.ts': "export const oceanBlue = '#0064e0';\n"},
155
+ );
156
+ fs.rmSync(
157
+ path.join(
158
+ tmpDir,
159
+ 'node_modules',
160
+ '@acme',
161
+ 'themes',
162
+ 'themes',
163
+ 'ocean',
164
+ 'tokens',
165
+ 'colors.ts',
166
+ ),
167
+ );
168
+
169
+ await expect(
170
+ themeAdd('ocean', {cwd: tmpDir, package: '@acme/themes'}),
171
+ ).rejects.toMatchObject({
172
+ code: 'ERR_THEME_INVALID',
173
+ message: expect.stringContaining('tokens/colors.ts'),
174
+ });
175
+ });
176
+
177
+ it('reports an unknown package selection without falling back to another owner', async () => {
178
+ installThemeIntegration('@acme/themes', 'ocean');
179
+ await expect(
180
+ themeAdd('ocean', {cwd: tmpDir, package: '@other/themes'}),
181
+ ).rejects.toMatchObject({code: 'ERR_UNKNOWN_THEME'});
182
+ });
183
+ });
@@ -2,8 +2,16 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * List the themes bundled with this CLI build (the ones `theme add` can
6
- * scaffold). Pure projection of the manifest; no I/O beyond the adapter read.
5
+ * List themes bundled with this CLI build.
7
6
  * @returns {import('../theme.type.mjs').ThemeListResponse}
8
7
  */
9
8
  export function themeList(): import("../theme.type.mjs").ThemeListResponse;
9
+ /**
10
+ * List bundled and installed integration themes available to this project.
11
+ * @param {{cwd?: string, package?: string}} [options]
12
+ * @returns {Promise<import('../theme.type.mjs').ThemeListResponse>}
13
+ */
14
+ export function themeListAvailable(options?: {
15
+ cwd?: string;
16
+ package?: string;
17
+ }): Promise<import("../theme.type.mjs").ThemeListResponse>;
@@ -1,25 +1,46 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file `astryx theme list` leaf — projects the bundled-theme manifest into the
5
- * `theme.list` envelope. Data source: ../_adapter.mjs (listThemes).
4
+ * @file Theme-list projections. `themeList()` retains its historical synchronous
5
+ * bundled-only API contract. `themeListAvailable()` is the project-aware command
6
+ * seam that adds installed integration themes and owner packages.
6
7
  */
7
8
 
8
- import {listThemes} from '../_adapter.mjs';
9
+ import {listAvailableThemes, listThemes} from '../_adapter.mjs';
9
10
 
10
11
  /**
11
- * List the themes bundled with this CLI build (the ones `theme add` can
12
- * scaffold). Pure projection of the manifest; no I/O beyond the adapter read.
12
+ * List themes bundled with this CLI build.
13
13
  * @returns {import('../theme.type.mjs').ThemeListResponse}
14
14
  */
15
15
  export function themeList() {
16
16
  return {
17
17
  type: 'theme.list',
18
- data: listThemes().map(t => ({
19
- slug: t.slug,
20
- displayName: t.displayName,
21
- description: t.description,
22
- maintained: t.maintained,
18
+ data: listThemes().map(theme => ({
19
+ slug: theme.slug,
20
+ displayName: theme.displayName,
21
+ description: theme.description,
22
+ maintained: theme.maintained,
23
23
  })),
24
24
  };
25
25
  }
26
+
27
+ /**
28
+ * List bundled and installed integration themes available to this project.
29
+ * @param {{cwd?: string, package?: string}} [options]
30
+ * @returns {Promise<import('../theme.type.mjs').ThemeListResponse>}
31
+ */
32
+ export async function themeListAvailable(options = {}) {
33
+ const themes = await listAvailableThemes(options.cwd);
34
+ return {
35
+ type: 'theme.list',
36
+ data: themes
37
+ .filter(theme => options.package == null || theme.package === options.package)
38
+ .map(theme => ({
39
+ slug: theme.slug,
40
+ displayName: theme.displayName,
41
+ description: theme.description,
42
+ maintained: theme.maintained,
43
+ package: theme.package,
44
+ })),
45
+ };
46
+ }
@@ -1,41 +1,120 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
- /**
4
- * @file Direct-API tests for the `theme list` leaf. Runs against the real
5
- * bundled-theme manifest (committed under templates/themes/), so it doubles as a
6
- * guard that the bundle stays readable and shaped as `theme.list` expects.
7
- */
3
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
4
+ import * as fs from 'node:fs';
5
+ import * as path from 'node:path';
6
+ import {themeList, themeListAvailable} from './list.mjs';
7
+ import {BUNDLED_THEME_PACKAGE} from '../../../foundation/discovery/theme-discovery.mjs';
8
8
 
9
- import {describe, it, expect} from 'vitest';
10
- import {themeList} from './list.mjs';
9
+ let tmpDir;
11
10
 
12
- describe('themeList (api/theme/list)', () => {
13
- it('returns a theme.list envelope of the bundled themes', () => {
11
+ function installThemeIntegration(packageName = '@acme/themes', slug = 'ocean') {
12
+ const packageDir = path.join(tmpDir, 'node_modules', ...packageName.split('/'));
13
+ const themeDir = path.join(packageDir, 'themes', slug);
14
+ fs.mkdirSync(themeDir, {recursive: true});
15
+ fs.writeFileSync(
16
+ path.join(packageDir, 'package.json'),
17
+ JSON.stringify({name: packageName, version: '1.0.0'}),
18
+ );
19
+ fs.writeFileSync(
20
+ path.join(packageDir, 'astryx.integration.mjs'),
21
+ `export default {themes: './themes'};\n`,
22
+ );
23
+ fs.writeFileSync(
24
+ path.join(packageDir, 'themes', 'manifest.json'),
25
+ JSON.stringify({
26
+ version: 1,
27
+ themes: [
28
+ {
29
+ slug,
30
+ displayName: 'Ocean',
31
+ description: 'Blue and calm.',
32
+ maintained: true,
33
+ entry: 'oceanTheme.ts',
34
+ exportName: 'oceanTheme',
35
+ files: ['oceanTheme.ts'],
36
+ },
37
+ ],
38
+ }),
39
+ );
40
+ fs.writeFileSync(
41
+ path.join(themeDir, 'oceanTheme.ts'),
42
+ 'export const oceanTheme = {};\n',
43
+ );
44
+ }
45
+
46
+ beforeEach(() => {
47
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-theme-list-'));
48
+ fs.writeFileSync(
49
+ path.join(tmpDir, 'package.json'),
50
+ JSON.stringify({name: 'consumer', dependencies: {'@acme/themes': '^1.0.0'}}),
51
+ );
52
+ });
53
+
54
+ afterEach(() => {
55
+ fs.rmSync(tmpDir, {recursive: true, force: true});
56
+ });
57
+
58
+ describe('themeList (bundled compatibility API)', () => {
59
+ it('stays synchronous and preserves the original entry shape', () => {
14
60
  const result = themeList();
15
61
  expect(result.type).toBe('theme.list');
16
- expect(Array.isArray(result.data)).toBe(true);
17
62
  expect(result.data.length).toBeGreaterThan(0);
18
- for (const t of result.data) {
19
- expect(typeof t.slug).toBe('string');
20
- expect(typeof t.displayName).toBe('string');
21
- expect(typeof t.description).toBe('string');
22
- expect(typeof t.maintained).toBe('boolean');
23
- }
63
+ expect(Object.keys(result.data[0]).sort()).toEqual([
64
+ 'description',
65
+ 'displayName',
66
+ 'maintained',
67
+ 'slug',
68
+ ]);
69
+ });
70
+ });
71
+
72
+ describe('themeListAvailable (project-aware API)', () => {
73
+ it('returns bundled themes with owner package', async () => {
74
+ const result = await themeListAvailable({cwd: tmpDir});
75
+ expect(result.type).toBe('theme.list');
76
+ expect(result.data.length).toBeGreaterThan(0);
77
+ expect(
78
+ result.data.some(theme => theme.package === BUNDLED_THEME_PACKAGE),
79
+ ).toBe(true);
80
+ });
81
+
82
+ it('surfaces a maintained installed integration theme', async () => {
83
+ installThemeIntegration();
84
+ const result = await themeListAvailable({cwd: tmpDir});
85
+ expect(result.data).toContainEqual({
86
+ slug: 'ocean',
87
+ displayName: 'Ocean',
88
+ description: 'Blue and calm.',
89
+ maintained: true,
90
+ package: '@acme/themes',
91
+ });
24
92
  });
25
93
 
26
- it('surfaces the maintained neutral theme', () => {
27
- const neutral = themeList().data.find(t => t.slug === 'neutral');
28
- expect(neutral).toBeTruthy();
29
- expect(neutral?.maintained).toBe(true);
94
+ it('filters by exact owner package', async () => {
95
+ installThemeIntegration();
96
+ const result = await themeListAvailable({
97
+ cwd: tmpDir,
98
+ package: '@acme/themes',
99
+ });
100
+ expect(result.data).toEqual([
101
+ {
102
+ slug: 'ocean',
103
+ displayName: 'Ocean',
104
+ description: 'Blue and calm.',
105
+ maintained: true,
106
+ package: '@acme/themes',
107
+ },
108
+ ]);
30
109
  });
31
110
 
32
- it('projects only the list fields (no entry/exportName/files leak)', () => {
33
- const [first] = themeList().data;
34
- expect(first).toBeTruthy();
111
+ it('projects only public list fields', async () => {
112
+ const [first] = (await themeListAvailable({cwd: tmpDir})).data;
35
113
  expect(Object.keys(first ?? {}).sort()).toEqual([
36
114
  'description',
37
115
  'displayName',
38
116
  'maintained',
117
+ 'package',
39
118
  'slug',
40
119
  ]);
41
120
  });
@@ -2,11 +2,7 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * @file FunctionDoc for the `listThemes()` helper. Colocated with the theme
6
- * command's shared data layer (`_adapter.mjs`); the BundledTheme shape lives
7
- * there. This helper has no CLI command of its own — themeList and themeAdd
8
- * sit on it.
9
- * @position packages/cli/api/theme — function documentation
5
+ * @file FunctionDoc for the synchronous bundled-theme compatibility helper.
10
6
  */
11
7
  /** @type {import('@astryxdesign/cli/authoring').FunctionDoc} */
12
8
  export const doc: import("@astryxdesign/cli/authoring").FunctionDoc;
@@ -1,11 +1,7 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file FunctionDoc for the `listThemes()` helper. Colocated with the theme
5
- * command's shared data layer (`_adapter.mjs`); the BundledTheme shape lives
6
- * there. This helper has no CLI command of its own — themeList and themeAdd
7
- * sit on it.
8
- * @position packages/cli/api/theme — function documentation
4
+ * @file FunctionDoc for the synchronous bundled-theme compatibility helper.
9
5
  */
10
6
 
11
7
  /** @type {import('@astryxdesign/cli/authoring').FunctionDoc} */
@@ -14,12 +10,9 @@ export const doc = {
14
10
  kind: 'api',
15
11
  name: 'listThemes',
16
12
  displayName: 'listThemes()',
17
- summary: 'Read the bundled-theme manifest and return its raw entries.',
13
+ summary: 'Read the CLI bundled-theme manifest.',
18
14
  description:
19
- "The shared data layer behind theme list/add: reads the CLI's bundled-theme manifest " +
20
- '(templates/themes/manifest.json, generated by scripts/generate-cli-themes.mjs) and returns ' +
21
- 'the parsed entries. themeList() projects this into the theme.list envelope; themeAdd() ' +
22
- 'resolves a slug against it. Returns synchronously.',
15
+ 'Reads templates/themes/manifest.json and returns its raw entries synchronously. This low-level helper keeps its historical bundled-only contract; project-aware themeList() and themeAdd() also discover source themes from installed integrations.',
23
16
  importPath: '@astryxdesign/cli/api',
24
17
  signature: 'listThemes(): BundledTheme[]',
25
18
  keywords: ['theme', 'themes', 'manifest', 'bundled', 'adapter', 'list'],
@@ -28,17 +21,17 @@ export const doc = {
28
21
  {
29
22
  type: 'BundledTheme[]',
30
23
  description:
31
- 'The parsed themes array from the bundle manifest: each BundledTheme has slug, displayName, description, maintained, entry, exportName, and files. Empty when the manifest has not been generated.',
24
+ 'The bundled manifest entries: slug, displayName, description, maintained, entry, exportName, and files.',
32
25
  },
33
26
  ],
34
27
  throws: [
35
28
  {
36
29
  code: 'ERR_NO_SOURCE',
37
- when: 'the manifest file exists but cannot be read or parsed as JSON',
30
+ when: 'the bundled catalog is missing, invalid, or references missing source files',
38
31
  },
39
32
  ],
40
33
  examples: [
41
- {label: 'Read the manifest', code: 'const themes = listThemes();'},
34
+ {label: 'Read bundled entries', code: 'const themes = listThemes();'},
42
35
  ],
43
36
  related: ['themeList', 'themeAdd', 'themeBuild'],
44
37
  };