@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
@@ -66,6 +66,7 @@ export const RESPONSE_TYPES = {
66
66
  search: ['search'],
67
67
  build: ['build.help', 'build.kit'],
68
68
  swizzle: ['swizzle.list', 'swizzle.copy'],
69
+ 'gap-report': ['gap-report.categories', 'gap-report.file'],
69
70
  template: [
70
71
  'template.list',
71
72
  'template.show',
@@ -80,6 +81,8 @@ export const RESPONSE_TYPES = {
80
81
  'theme template': ['theme.template'],
81
82
  'theme targets': ['theme.targets'],
82
83
  'theme palette generate': ['theme.palette.generate'],
84
+ 'integration add': ['integration.add'],
85
+ 'integration pack': ['integration.pack-check'],
83
86
  upgrade: ['upgrade.list', 'upgrade.status', 'upgrade.run'],
84
87
  manifest: ['manifest'],
85
88
  doctor: ['doctor'],
@@ -110,6 +113,10 @@ const EXAMPLES = {
110
113
  ],
111
114
  build: ['astryx build', 'astryx build "analytics dashboard" --json'],
112
115
  swizzle: ['astryx swizzle XDSButton'],
116
+ 'gap-report': [
117
+ 'astryx gap-report --list-categories',
118
+ "astryx gap-report Button --category docs_gap --reason 'Missing keyboard example'",
119
+ ],
113
120
  template: [
114
121
  'astryx template --json',
115
122
  'astryx template dashboard ./src/app',
@@ -134,6 +141,11 @@ const EXAMPLES = {
134
141
  'astryx theme palette generate palette.config.json',
135
142
  'astryx theme palette generate palette.config.json --out ocean.palette.json',
136
143
  ],
144
+ 'integration add': [
145
+ 'astryx integration add component AcmeWidget',
146
+ 'astryx integration add doc deploying --dry-run --json',
147
+ ],
148
+ 'integration pack': ['astryx integration pack --check --json'],
137
149
  upgrade: ['astryx upgrade --json'],
138
150
  manifest: ['astryx manifest --json', 'astryx --json'],
139
151
  doctor: ['astryx doctor', 'astryx doctor --json'],
@@ -0,0 +1,127 @@
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 {Project} from './project.mjs';
7
+ import {BUNDLED_THEME_PACKAGE} from '../discovery/theme-discovery.mjs';
8
+
9
+ let tmpDir;
10
+
11
+ function installThemeIntegration(packageName, slug) {
12
+ const packageDir = path.join(
13
+ tmpDir,
14
+ 'node_modules',
15
+ ...packageName.split('/'),
16
+ );
17
+ const themeDir = path.join(packageDir, 'themes', slug);
18
+ fs.mkdirSync(themeDir, {recursive: true});
19
+ fs.writeFileSync(
20
+ path.join(packageDir, 'package.json'),
21
+ JSON.stringify({name: packageName, version: '1.0.0'}),
22
+ );
23
+ fs.writeFileSync(
24
+ path.join(packageDir, 'astryx.integration.mjs'),
25
+ `export default {themes: './themes'};\n`,
26
+ );
27
+ fs.writeFileSync(
28
+ path.join(packageDir, 'themes', 'manifest.json'),
29
+ JSON.stringify({
30
+ version: 1,
31
+ themes: [
32
+ {
33
+ slug,
34
+ displayName: 'Ocean',
35
+ description: 'Blue and calm.',
36
+ maintained: true,
37
+ entry: 'oceanTheme.ts',
38
+ exportName: 'oceanTheme',
39
+ files: ['oceanTheme.ts'],
40
+ },
41
+ ],
42
+ }),
43
+ );
44
+ fs.writeFileSync(
45
+ path.join(themeDir, 'oceanTheme.ts'),
46
+ `export const oceanTheme = {};\n`,
47
+ );
48
+ }
49
+
50
+ beforeEach(() => {
51
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-project-themes-'));
52
+ fs.writeFileSync(
53
+ path.join(tmpDir, 'package.json'),
54
+ JSON.stringify({
55
+ name: 'consumer',
56
+ dependencies: {'@acme/themes': '^1.0.0'},
57
+ }),
58
+ );
59
+ });
60
+
61
+ afterEach(() => {
62
+ fs.rmSync(tmpDir, {recursive: true, force: true});
63
+ });
64
+
65
+ describe('Project themes', () => {
66
+ it('combines bundled and autolinked integration themes with owners', async () => {
67
+ installThemeIntegration('@acme/themes', 'ocean');
68
+ const project = await Project.load(tmpDir);
69
+ const themes = await project.themes();
70
+
71
+ expect(themes.some(theme => theme.package === BUNDLED_THEME_PACKAGE)).toBe(
72
+ true,
73
+ );
74
+ expect(themes).toContainEqual(
75
+ expect.objectContaining({
76
+ slug: 'ocean',
77
+ package: '@acme/themes',
78
+ sourceDir: path.join(
79
+ tmpDir,
80
+ 'node_modules',
81
+ '@acme',
82
+ 'themes',
83
+ 'themes',
84
+ 'ocean',
85
+ ),
86
+ }),
87
+ );
88
+ });
89
+
90
+ it('keeps duplicate slugs from different owners for scoped resolution', async () => {
91
+ installThemeIntegration('@acme/themes', 'neutral');
92
+ const project = await Project.load(tmpDir);
93
+ const matches = (await project.themes()).filter(
94
+ theme => theme.slug === 'neutral',
95
+ );
96
+ expect(matches.map(theme => theme.package)).toEqual([
97
+ BUNDLED_THEME_PACKAGE,
98
+ '@acme/themes',
99
+ ]);
100
+ });
101
+
102
+ it('records an invalid integration theme catalog as an issue', async () => {
103
+ installThemeIntegration('@acme/themes', 'ocean');
104
+ fs.rmSync(
105
+ path.join(
106
+ tmpDir,
107
+ 'node_modules',
108
+ '@acme',
109
+ 'themes',
110
+ 'themes',
111
+ 'ocean',
112
+ 'oceanTheme.ts',
113
+ ),
114
+ );
115
+ const project = await Project.load(tmpDir);
116
+ const themes = await project.themes();
117
+
118
+ expect(themes.some(theme => theme.package === '@acme/themes')).toBe(false);
119
+ expect(await project.issues()).toContainEqual(
120
+ expect.objectContaining({
121
+ package: '@acme/themes',
122
+ code: 'invalid_theme',
123
+ severity: 'error',
124
+ }),
125
+ );
126
+ });
127
+ });
@@ -62,9 +62,19 @@ export class Project {
62
62
  * @returns {import('../../authoring/config/type').AstryxConfig}
63
63
  */
64
64
  get config(): import("../../authoring/config/type").AstryxConfig;
65
- /** Configured integration package names. @returns {string[]} */
65
+ /**
66
+ * Integration package names the config names. NOT the full set that is
67
+ * loaded — an autolinked integration is absent here by definition. For
68
+ * everything in play, read {@link Project.loadedIntegrations}.
69
+ * @returns {string[]}
70
+ */
66
71
  get integrations(): string[];
67
- /** Resolved loaded integrations (lib/integrations.mjs shape). @returns {import('../integrations/integrations.mjs').LoadedIntegration[]} */
72
+ /**
73
+ * Every resolved integration (lib/integrations.mjs shape): configured first,
74
+ * then autolinked (`__autolinked`), with the local authoring package
75
+ * (`__local`) replacing the same installed package or appended last.
76
+ * @returns {import('../integrations/integrations.mjs').LoadedIntegration[]}
77
+ */
68
78
  get loadedIntegrations(): import("../integrations/integrations.mjs").LoadedIntegration[];
69
79
  /** @returns {string} */
70
80
  get cwd(): string;
@@ -100,6 +110,15 @@ export class Project {
100
110
  * @returns {Promise<Array<object>>}
101
111
  */
102
112
  templates(): Promise<Array<object>>;
113
+ /**
114
+ * Bundled source themes plus themes contributed by installed integrations.
115
+ * Each record keeps its package owner and source directory so callers can
116
+ * both list and copy it without reconstructing paths. A broken integration's
117
+ * themes are skipped under the same issue policy as every other kind.
118
+ *
119
+ * @returns {Promise<import('../discovery/theme-discovery.mjs').DiscoveredTheme[]>}
120
+ */
121
+ themes(): Promise<import("../discovery/theme-discovery.mjs").DiscoveredTheme[]>;
103
122
  /**
104
123
  * The CLI's own doc topics plus the ones the configured integrations
105
124
  * contribute, resolved into one catalog: additions, replacements (with the
@@ -155,9 +174,9 @@ export class Project {
155
174
  * When called directly, also validates any configured integration not yet
156
175
  * visited by a discovery call, so the returned set is complete on demand.
157
176
  *
158
- * @returns {Promise<import('../integrations/issue').AstryxIntegrationIssue[]>}
177
+ * @returns {Promise<ProjectIntegrationIssue[]>}
159
178
  */
160
- issues(): Promise<import("../integrations/issue").AstryxIntegrationIssue[]>;
179
+ issues(): Promise<ProjectIntegrationIssue[]>;
161
180
  #private;
162
181
  }
163
182
  /**
@@ -6,7 +6,7 @@
6
6
  * `Project` is the one entry point a command uses to read everything it needs
7
7
  * about a consumer's project: the validated config surface, the configured
8
8
  * integrations, and the resolved discovery sets (components, templates,
9
- * codemods, docs) — plus issue routing (issuesUrl) and the accumulated
9
+ * codemods, docs, themes) — plus issue routing (issuesUrl) and the accumulated
10
10
  * integration issues. It replaces the old `loadConfig(cwd)` plain-object loader
11
11
  * and the per-command fan-out into the various discovery helpers.
12
12
  *
@@ -14,8 +14,9 @@
14
14
  * - `Project.load(cwd, {cache})` is the async factory (constructors can't be
15
15
  * async). It does what loadConfig did — find the config sibling-of
16
16
  * package.json, import + validate it, load the configured integrations —
17
- * and nothing more. Discovery is LAZY.
18
- * - Discovery methods (components/templates/codemods/docs) are MEMOIZED per
17
+ * plus autolink the installed ones no config names, and self-resolve the
18
+ * package being authored when it carries a manifest. Discovery is LAZY.
19
+ * - Discovery methods (components/templates/codemods/docs/themes) are MEMOIZED per
19
20
  * instance (via the pluggable cache) and orchestrate the EXISTING discovery
20
21
  * functions — Project never reimplements discovery.
21
22
  * - SKIP + WARN policy: as a discovery method runs, per-integration work is
@@ -34,7 +35,11 @@ import * as fs from 'node:fs';
34
35
  import * as path from 'node:path';
35
36
  import {findPresentFiles, loadModuleWithParser} from '../fs/module-loader.mjs';
36
37
  import {parseConfig} from '../../authoring/config/parse.mjs';
37
- import {loadIntegrations} from '../integrations/integrations.mjs';
38
+ import {
39
+ loadIntegrations,
40
+ loadLocalIntegration,
41
+ } from '../integrations/integrations.mjs';
42
+ import {autolinkIntegrations} from '../integrations/autolink.mjs';
38
43
  import {
39
44
  setProject as setDebugProject,
40
45
  setEventHandler as setDebugEventHandler,
@@ -54,6 +59,10 @@ import {
54
59
  DocsCatalog,
55
60
  discoverIntegrationDocs,
56
61
  } from '../discovery/docs-discovery.mjs';
62
+ import {
63
+ discoverBundledThemes,
64
+ discoverIntegrationThemes,
65
+ } from '../discovery/theme-discovery.mjs';
57
66
  import {getTransformsBetween} from '../../assets/codemods/registry.mjs';
58
67
  import {
59
68
  discoverIntegrationCodemods,
@@ -244,6 +253,13 @@ export class Project {
244
253
  : (cache ?? new InMemoryConfigCache());
245
254
  const configPath = findConfigPath(cwd);
246
255
  const hash = configContentHash(configPath);
256
+ // The project root: the config's directory when there is one (findConfigPath
257
+ // resolves the config as a sibling of the nearest package.json, so the two
258
+ // agree), otherwise that package.json's directory. Dependencies are declared
259
+ // there, and node_modules sits there.
260
+ const projectDir = configPath
261
+ ? path.dirname(configPath)
262
+ : (findPackageRoot(cwd) ?? cwd);
247
263
 
248
264
  /** @type {import('../../authoring/config/type').AstryxConfig} */
249
265
  let config = {integrations: []};
@@ -257,14 +273,43 @@ export class Project {
257
273
  label: 'astryx.config',
258
274
  fresh,
259
275
  });
260
- const configDir = path.dirname(configPath);
261
276
  integrations = config.integrations ?? [];
262
277
  loadedIntegrations = await loadIntegrations(integrations, {
263
- cwd: configDir,
278
+ cwd: projectDir,
264
279
  fresh,
265
280
  });
266
281
  }
267
282
 
283
+ // An installed integration the config does not name is still installed.
284
+ // This runs whether or not a config exists, because the projects it reaches
285
+ // are overwhelmingly the ones with no astryx.config at all: a scaffold adds
286
+ // the dependency and writes no config, and the integration then contributes
287
+ // nothing for want of a line nobody knew to write. Appended AFTER the
288
+ // configured ones so an explicit entry keeps its position and its
289
+ // precedence in every discovery order.
290
+ loadedIntegrations = [
291
+ ...loadedIntegrations,
292
+ ...(await autolinkIntegrations({
293
+ projectDir,
294
+ loaded: loadedIntegrations,
295
+ fresh,
296
+ })),
297
+ ];
298
+
299
+ // The package being authored is the one package that cannot install itself.
300
+ // When it carries a manifest, resolve its working bytes directly so every
301
+ // existing consumer command doubles as the author's preview. A local copy
302
+ // replaces the same installed package in place, preserving configured
303
+ // precedence while making the source being edited authoritative.
304
+ const localIntegration = await loadLocalIntegration(projectDir, {fresh});
305
+ if (localIntegration) {
306
+ const existing = loadedIntegrations.findIndex(
307
+ integration => integration.name === localIntegration.name,
308
+ );
309
+ if (existing === -1) loadedIntegrations.push(localIntegration);
310
+ else loadedIntegrations[existing] = localIntegration;
311
+ }
312
+
268
313
  // The debug recorder resolves its settings synchronously, long before any
269
314
  // command gets here, so this is where a project's `debug` block gets a
270
315
  // turn. The event is not written until process exit, so settings applied
@@ -314,12 +359,22 @@ export class Project {
314
359
  return this.#config;
315
360
  }
316
361
 
317
- /** Configured integration package names. @returns {string[]} */
362
+ /**
363
+ * Integration package names the config names. NOT the full set that is
364
+ * loaded — an autolinked integration is absent here by definition. For
365
+ * everything in play, read {@link Project.loadedIntegrations}.
366
+ * @returns {string[]}
367
+ */
318
368
  get integrations() {
319
369
  return this.#integrations;
320
370
  }
321
371
 
322
- /** Resolved loaded integrations (lib/integrations.mjs shape). @returns {import('../integrations/integrations.mjs').LoadedIntegration[]} */
372
+ /**
373
+ * Every resolved integration (lib/integrations.mjs shape): configured first,
374
+ * then autolinked (`__autolinked`), with the local authoring package
375
+ * (`__local`) replacing the same installed package or appended last.
376
+ * @returns {import('../integrations/integrations.mjs').LoadedIntegration[]}
377
+ */
323
378
  get loadedIntegrations() {
324
379
  return this.#loadedIntegrations;
325
380
  }
@@ -542,6 +597,38 @@ export class Project {
542
597
  });
543
598
  }
544
599
 
600
+ /**
601
+ * Bundled source themes plus themes contributed by installed integrations.
602
+ * Each record keeps its package owner and source directory so callers can
603
+ * both list and copy it without reconstructing paths. A broken integration's
604
+ * themes are skipped under the same issue policy as every other kind.
605
+ *
606
+ * @returns {Promise<import('../discovery/theme-discovery.mjs').DiscoveredTheme[]>}
607
+ */
608
+ async themes() {
609
+ return this.#memo('themes', async () => {
610
+ const themes = discoverBundledThemes();
611
+
612
+ for (const integration of this.#loadedIntegrations) {
613
+ await this.#collectIssues(integration);
614
+ const pkg = this.#pkgLabel(integration);
615
+ if (this.#hasBlockingContributionIssue(pkg)) continue;
616
+ if (!integration?.themes) continue;
617
+ try {
618
+ themes.push(...(await discoverIntegrationThemes(integration)));
619
+ } catch (err) {
620
+ this.#pushIssue(pkg, {
621
+ code: 'invalid_theme',
622
+ severity: 'error',
623
+ message: errorMessage(err),
624
+ });
625
+ }
626
+ }
627
+
628
+ return themes;
629
+ });
630
+ }
631
+
545
632
  /**
546
633
  * The CLI's own doc topics plus the ones the configured integrations
547
634
  * contribute, resolved into one catalog: additions, replacements (with the
@@ -670,7 +757,7 @@ export class Project {
670
757
  * When called directly, also validates any configured integration not yet
671
758
  * visited by a discovery call, so the returned set is complete on demand.
672
759
  *
673
- * @returns {Promise<import('../integrations/issue').AstryxIntegrationIssue[]>}
760
+ * @returns {Promise<ProjectIntegrationIssue[]>}
674
761
  */
675
762
  async issues() {
676
763
  for (const integration of this.#loadedIntegrations) {
@@ -128,11 +128,81 @@ function topicDoc(fields) {
128
128
  name: 'deploying',
129
129
  title: 'Deploying',
130
130
  description: 'How to ship it.',
131
- sections: [{title: 'Overview', content: [{type: 'prose', text: 'Ship it.'}]}],
131
+ sections: [
132
+ {title: 'Overview', content: [{type: 'prose', text: 'Ship it.'}]},
133
+ ],
132
134
  ...fields,
133
135
  };
134
136
  }
135
137
 
138
+ /** Scaffold the package being authored, with no config and no installation. */
139
+ function scaffoldLocalPackage({name = '@acme/local'} = {}) {
140
+ fs.writeFileSync(
141
+ path.join(tmpDir, 'package.json'),
142
+ JSON.stringify({name, version: '1.0.0'}),
143
+ );
144
+ fs.writeFileSync(
145
+ path.join(tmpDir, 'astryx.integration.mjs'),
146
+ `export default {
147
+ components: './components',
148
+ templates: './templates',
149
+ docs: './docs',
150
+ themes: './themes',
151
+ };\n`,
152
+ );
153
+
154
+ fs.mkdirSync(path.join(tmpDir, 'components'));
155
+ fs.writeFileSync(
156
+ path.join(tmpDir, 'components', 'LocalWidget.doc.mjs'),
157
+ `export default {type: 'component', name: 'LocalWidget', props: []};\n`,
158
+ );
159
+ fs.writeFileSync(
160
+ path.join(tmpDir, 'components', 'LocalWidget.tsx'),
161
+ `export function LocalWidget() { return null; }\n`,
162
+ );
163
+
164
+ fs.mkdirSync(path.join(tmpDir, 'templates'));
165
+ fs.writeFileSync(
166
+ path.join(tmpDir, 'templates', 'local-page.template.mjs'),
167
+ `export default {type: 'page', name: 'Local page', description: 'Local page.'};\n`,
168
+ );
169
+ fs.writeFileSync(
170
+ path.join(tmpDir, 'templates', 'local-page.tsx'),
171
+ `export default function LocalPage() { return null; }\n`,
172
+ );
173
+
174
+ fs.mkdirSync(path.join(tmpDir, 'docs'));
175
+ fs.writeFileSync(
176
+ path.join(tmpDir, 'docs', 'local-guide.doc.mjs'),
177
+ `export default ${JSON.stringify(
178
+ topicDoc({name: 'local-guide', title: 'Local guide'}),
179
+ )};\n`,
180
+ );
181
+
182
+ fs.mkdirSync(path.join(tmpDir, 'themes', 'ocean'), {recursive: true});
183
+ fs.writeFileSync(
184
+ path.join(tmpDir, 'themes', 'manifest.json'),
185
+ JSON.stringify({
186
+ version: 1,
187
+ themes: [
188
+ {
189
+ slug: 'ocean',
190
+ displayName: 'Ocean',
191
+ description: 'Ocean theme.',
192
+ maintained: true,
193
+ entry: 'oceanTheme.ts',
194
+ exportName: 'oceanTheme',
195
+ files: ['oceanTheme.ts'],
196
+ },
197
+ ],
198
+ }),
199
+ );
200
+ fs.writeFileSync(
201
+ path.join(tmpDir, 'themes', 'ocean', 'oceanTheme.ts'),
202
+ `export const oceanTheme = {};\n`,
203
+ );
204
+ }
205
+
136
206
  beforeEach(() => {
137
207
  originalCwd = process.cwd();
138
208
  tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-project-test-'));
@@ -158,6 +228,52 @@ describe('Project.load', () => {
158
228
  expect(project.cwd).toBe(tmpDir);
159
229
  });
160
230
 
231
+ it('self-resolves the package being authored through every consumer surface', async () => {
232
+ scaffoldLocalPackage();
233
+
234
+ const project = await Project.load(tmpDir);
235
+
236
+ expect(project.loadedIntegrations).toHaveLength(1);
237
+ expect(project.loadedIntegrations[0]).toMatchObject({
238
+ name: '@acme/local',
239
+ __local: true,
240
+ });
241
+ expect(
242
+ (await project.components()).some(
243
+ component =>
244
+ component.name === 'LocalWidget' &&
245
+ component.package === '@acme/local',
246
+ ),
247
+ ).toBe(true);
248
+ expect(
249
+ (await project.templates()).some(
250
+ template =>
251
+ template.dirName === 'local-page' &&
252
+ template.package === '@acme/local',
253
+ ),
254
+ ).toBe(true);
255
+ expect((await project.docs()).resolve('local-guide')).toMatchObject({
256
+ package: '@acme/local',
257
+ });
258
+ expect(await project.themes()).toContainEqual(
259
+ expect.objectContaining({slug: 'ocean', package: '@acme/local'}),
260
+ );
261
+ });
262
+
263
+ it('prefers local bytes over an installed copy of the same package', async () => {
264
+ scaffold();
265
+ scaffoldLocalPackage({name: '@acme/widgets'});
266
+
267
+ const project = await Project.load(tmpDir);
268
+
269
+ expect(project.loadedIntegrations).toHaveLength(1);
270
+ expect(project.loadedIntegrations[0].__local).toBe(true);
271
+ const owned = (await project.components()).filter(
272
+ component => component.package === '@acme/widgets',
273
+ );
274
+ expect(owned.map(component => component.name)).toEqual(['LocalWidget']);
275
+ });
276
+
161
277
  it('exposes the validated config surface and loaded integrations', async () => {
162
278
  scaffold({issuesUrl: 'https://example.com/issues'});
163
279
  const project = await Project.load(tmpDir);
@@ -194,7 +310,9 @@ describe('findConfigPath', () => {
194
310
  path.join(tmpDir, 'astryx.config.js'),
195
311
  `module.exports = {};\n`,
196
312
  );
197
- expect(() => findConfigPath(tmpDir)).toThrow(/Multiple Astryx config files/);
313
+ expect(() => findConfigPath(tmpDir)).toThrow(
314
+ /Multiple Astryx config files/,
315
+ );
198
316
  });
199
317
  });
200
318
 
@@ -265,7 +383,9 @@ describe('Project discovery', () => {
265
383
  const catalog = await project.docs();
266
384
  expect(catalog.resolve('deploying')).toBeUndefined();
267
385
  const issues = await project.issues();
268
- expect(issues.some(i => i.code === 'invalid_doc' && i.severity === 'error')).toBe(true);
386
+ expect(
387
+ issues.some(i => i.code === 'invalid_doc' && i.severity === 'error'),
388
+ ).toBe(true);
269
389
  });
270
390
 
271
391
  it('keeps regular contributions when agentDocs is invalid', async () => {
@@ -323,8 +443,12 @@ describe('Project forward compatibility', () => {
323
443
  const project = await Project.load(tmpDir);
324
444
 
325
445
  const comps = await project.components();
326
- expect(comps.some(c => c.name === 'Widget' && c.package === '@acme/widgets')).toBe(true);
327
- expect((await project.templates()).some(t => t.package === '@acme/widgets')).toBe(true);
446
+ expect(
447
+ comps.some(c => c.name === 'Widget' && c.package === '@acme/widgets'),
448
+ ).toBe(true);
449
+ expect(
450
+ (await project.templates()).some(t => t.package === '@acme/widgets'),
451
+ ).toBe(true);
328
452
  const {integration} = await project.codemods('0.1.0', '0.2.0');
329
453
  expect(integration).toHaveLength(1);
330
454
 
@@ -376,7 +500,9 @@ describe('Project issues (skip + warn)', () => {
376
500
  const b = await project.issues();
377
501
  expect(a).toEqual(b);
378
502
  // No duplicate (package, code, message) tuples.
379
- const seen = new Set(a.map(i => `${i.package}\u0000${i.code}\u0000${i.message}`));
503
+ const seen = new Set(
504
+ a.map(i => `${i.package}\u0000${i.code}\u0000${i.message}`),
505
+ );
380
506
  expect(seen.size).toBe(a.length);
381
507
  });
382
508
 
@@ -46,6 +46,42 @@ export function findComponentSource(coreDir: string, name: string): string | nul
46
46
  * @returns {string}
47
47
  */
48
48
  export function resolveImportPath(coreDir: string, componentName: string): string;
49
+ /**
50
+ * Resolve the specifier an integration component is imported from, against the
51
+ * owning package's `exports` map.
52
+ *
53
+ * A component lives in a directory that need not share its name — several
54
+ * components can be exported from one entry point — so the specifier has to
55
+ * come from the directory the doc file sits in, checked against `exports`,
56
+ * rather than from the component name. Falls back to the package root when the
57
+ * package does not publish that subpath, matching what a consumer would have
58
+ * to write by hand.
59
+ *
60
+ * Lives here, beside {@link resolveImportPath}, because more than one surface
61
+ * answers "where is this imported from" and they have to agree: `component`
62
+ * reports it as ownership metadata and `search` reports it on every hit. When
63
+ * each resolved it for itself the two disagreed, and an import specifier that
64
+ * does not resolve is worse than no answer.
65
+ *
66
+ * `exportsMap` is the map `loadIntegrations` already parsed onto the loaded
67
+ * integration, so the common path reads no manifest at all. `undefined` means
68
+ * the caller has no parsed map — a record built by hand rather than by the
69
+ * loader — and only then is the manifest read here. `null` means the loader
70
+ * looked and the package has no `exports`, which is an answer, not a gap: it
71
+ * must not trigger a read. Resolution that depended on every producer of a
72
+ * record remembering to populate a field would degrade silently, and silently
73
+ * is how this bug got here.
74
+ *
75
+ * @param {{exportsMap?: Record<string, unknown>|null, packageDir?: string, docPath?: string|null, packageName: string}} owner
76
+ * @param {string} componentName
77
+ * @returns {string}
78
+ */
79
+ export function resolveIntegrationImportPath(owner: {
80
+ exportsMap?: Record<string, unknown> | null;
81
+ packageDir?: string;
82
+ docPath?: string | null;
83
+ packageName: string;
84
+ }, componentName: string): string;
49
85
  /**
50
86
  * Discover components from an external package's docs directory,
51
87
  * reading `group:` fields from each .doc.mjs for subcategories.