@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
@@ -0,0 +1,497 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Contribution inventory for integration pack-check.
5
+ *
6
+ * Enumerates the files and contribution identities an integration package
7
+ * declares, for cross-referencing against the npm tarball. The file inventory
8
+ * is computed statically (no module imports); the identity inventory runs
9
+ * the same discovery functions a consumer uses.
10
+ *
11
+ * @position packages/cli/foundation/integrations — shared contribution inventory
12
+ */
13
+
14
+ import * as fs from 'node:fs';
15
+ import * as path from 'node:path';
16
+ import {isDeepStrictEqual} from 'node:util';
17
+ import {THEME_MANIFEST_BASENAME} from '../discovery/theme-discovery.mjs';
18
+ import {discoverIntegrationThemes} from '../discovery/theme-discovery.mjs';
19
+ import {discoverIntegrationComponents} from '../discovery/component-discovery.mjs';
20
+ import {loadComponentDoc} from '../discovery/component-loader.mjs';
21
+ import {discoverIntegrationTemplatesForOne} from '../discovery/template-adapter.mjs';
22
+ import {discoverIntegrationCodemods} from '../../assets/codemods/integration-discovery.mjs';
23
+ import {discoverIntegrationDocs} from '../discovery/docs-discovery.mjs';
24
+
25
+ // ── File-walk helpers (no module imports, no execution) ──────────
26
+
27
+ const TEMPLATE_RE = /\.(?:template|doc)\.(?:ts|mjs|js)$/u;
28
+ const COMPONENT_DOC_RE = /\.doc\.(?:ts|mjs|js)$/u;
29
+ const CODEMOD_RE = /\.(?:ts|mjs|js)$/u;
30
+ const CODEMOD_TEST_RE = /\.(?:test|spec|fixture)\.(?:ts|mjs|js)$/u;
31
+ const DOC_RE = /\.doc\.(?:ts|mjs|js)$/u;
32
+ const SKIP_DIRS = new Set([
33
+ 'node_modules',
34
+ '.git',
35
+ '__tests__',
36
+ '__fixtures__',
37
+ ]);
38
+
39
+ /**
40
+ * Recursively collect files under `dir` that satisfy `filter`, excluding
41
+ * `node_modules` and `.git`. Returns sorted absolute paths.
42
+ * @param {string} dir
43
+ * @param {(name: string) => boolean} filter
44
+ * @returns {string[]}
45
+ */
46
+ function walkDir(dir, filter) {
47
+ if (!dir || !fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) return [];
48
+ /** @type {string[]} */
49
+ const out = [];
50
+ for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
51
+ if (SKIP_DIRS.has(entry.name)) continue;
52
+ const full = path.join(dir, entry.name);
53
+ if (entry.isDirectory()) out.push(...walkDir(full, filter));
54
+ else if (filter(entry.name)) out.push(full);
55
+ }
56
+ return out.sort();
57
+ }
58
+
59
+ /** @param {string} packageDir @param {string} file */
60
+ function rel(packageDir, file) {
61
+ return path.relative(packageDir, file).split(path.sep).join('/');
62
+ }
63
+
64
+ // ── Per-kind file enumeration ────────────────────────────────────
65
+
66
+ /** @param {string} root @param {string} pkgDir */
67
+ function enumerateThemeFiles(root, pkgDir) {
68
+ /** @type {string[]} */
69
+ const files = [];
70
+ const catalog = path.join(root, THEME_MANIFEST_BASENAME);
71
+ if (!fs.existsSync(catalog)) return files;
72
+ files.push(rel(pkgDir, catalog));
73
+ try {
74
+ const data = JSON.parse(fs.readFileSync(catalog, 'utf-8'));
75
+ if (data?.version !== 1 || !Array.isArray(data.themes)) return files;
76
+ for (const theme of data.themes) {
77
+ if (typeof theme.slug !== 'string' || !Array.isArray(theme.files))
78
+ continue;
79
+ for (const f of theme.files) {
80
+ if (typeof f === 'string') {
81
+ files.push(rel(pkgDir, path.join(root, theme.slug, f)));
82
+ }
83
+ }
84
+ }
85
+ } catch {
86
+ /* Phase 1 catches structural issues */
87
+ }
88
+ return files;
89
+ }
90
+
91
+ /** @param {string} root @param {string} pkgDir */
92
+ function enumerateComponentFiles(root, pkgDir) {
93
+ const files = [];
94
+ for (const doc of walkDir(root, name => COMPONENT_DOC_RE.test(name))) {
95
+ files.push(rel(pkgDir, doc));
96
+ const source = `${doc.replace(COMPONENT_DOC_RE, '')}.tsx`;
97
+ if (fs.existsSync(source)) files.push(rel(pkgDir, source));
98
+ }
99
+ return files;
100
+ }
101
+
102
+ /** @param {string} root @param {string} pkgDir */
103
+ function enumerateTemplateFiles(root, pkgDir) {
104
+ const files = [];
105
+ for (const tmpl of walkDir(root, n => TEMPLATE_RE.test(n))) {
106
+ files.push(rel(pkgDir, tmpl));
107
+ const stem = tmpl.replace(TEMPLATE_RE, '');
108
+ const source = `${stem}.tsx`;
109
+ if (fs.existsSync(source)) files.push(rel(pkgDir, source));
110
+ }
111
+ return files;
112
+ }
113
+
114
+ /** @param {string} root @param {string} pkgDir */
115
+ function enumerateCodemodFiles(root, pkgDir) {
116
+ return walkDir(
117
+ root,
118
+ name => CODEMOD_RE.test(name) && !CODEMOD_TEST_RE.test(name),
119
+ ).map(file => rel(pkgDir, file));
120
+ }
121
+
122
+ /** @param {string} root @param {string} pkgDir */
123
+ function enumerateDocFiles(root, pkgDir) {
124
+ return walkDir(root, n => DOC_RE.test(n)).map(f => rel(pkgDir, f));
125
+ }
126
+
127
+ /** @type {Record<FileInventoryRoot['kind'], (root: string, pkgDir: string) => string[]>} */
128
+ const ENUMERATORS = {
129
+ themes: enumerateThemeFiles,
130
+ components: enumerateComponentFiles,
131
+ templates: enumerateTemplateFiles,
132
+ codemods: enumerateCodemodFiles,
133
+ docs: enumerateDocFiles,
134
+ };
135
+ const ROOT_KINDS = /** @type {const} */ ([
136
+ 'themes',
137
+ 'components',
138
+ 'templates',
139
+ 'codemods',
140
+ 'docs',
141
+ ]);
142
+
143
+ // ── Public: static file inventory ────────────────────────────────
144
+
145
+ /**
146
+ * @typedef {object} FileInventoryRoot
147
+ * @property {'themes'|'components'|'templates'|'codemods'|'docs'} kind
148
+ * @property {string} path — project-relative root path
149
+ * @property {string[]} files — project-relative required file paths
150
+ */
151
+
152
+ /**
153
+ * @typedef {object} FileInventory
154
+ * @property {string} manifest — project-relative manifest path
155
+ * @property {FileInventoryRoot[]} roots
156
+ * @property {string[]} allFiles — deduplicated flat list
157
+ */
158
+
159
+ /**
160
+ * Compute the files the tarball must contain for an integration's
161
+ * contributions to be visible. Reads catalogs and walks directories;
162
+ * never imports or executes authored modules.
163
+ *
164
+ * @param {import('./integrations.mjs').LoadedIntegration} loaded
165
+ * @returns {FileInventory}
166
+ */
167
+ export function computeRequiredFiles(loaded) {
168
+ const pkgDir = loaded.__packageDir;
169
+ const manifestRel = rel(pkgDir, loaded.__manifestFile);
170
+ /** @type {FileInventoryRoot[]} */
171
+ const roots = [];
172
+ const allFiles = [manifestRel];
173
+
174
+ for (const kind of ROOT_KINDS) {
175
+ const root = loaded[kind];
176
+ if (!root) continue;
177
+ const files = ENUMERATORS[kind](root, pkgDir);
178
+ roots.push({
179
+ kind,
180
+ path: rel(pkgDir, root),
181
+ files,
182
+ });
183
+ allFiles.push(...files);
184
+ }
185
+
186
+ return {manifest: manifestRel, roots, allFiles: [...new Set(allFiles)]};
187
+ }
188
+
189
+ // ── Public: identity collection ──────────────────────────────────
190
+
191
+ /**
192
+ * @typedef {object} ContributionIdentities
193
+ * @property {{slug: string, exportName: string}[]} themes
194
+ * @property {string[]} components
195
+ * @property {{id: string, type: string, name: string}[]} templates
196
+ * @property {{version: string, id: string}[]} codemods
197
+ * @property {string[]} docs
198
+ * @property {string[]} agentDocsAppend
199
+ */
200
+
201
+ /**
202
+ * The resolved fields needed to discover contribution identities.
203
+ * @typedef {object} IdentitySource
204
+ * @property {string} name
205
+ * @property {string} [themes]
206
+ * @property {string} [components]
207
+ * @property {string} [templates]
208
+ * @property {string} [codemods]
209
+ * @property {string} [docs]
210
+ * @property {{append?: readonly string[]}} [agentDocs]
211
+ */
212
+
213
+ /**
214
+ * Run the same discovery functions a consumer uses to collect every
215
+ * contribution identity from a loaded integration.
216
+ *
217
+ * @param {IdentitySource} loaded
218
+ * @returns {Promise<{identities: ContributionIdentities, errors: Array<{kind: string, message: string}>}>}
219
+ */
220
+ export async function collectIdentities(loaded) {
221
+ /** @type {ContributionIdentities} */
222
+ const identities = {
223
+ themes: [],
224
+ components: [],
225
+ templates: [],
226
+ codemods: [],
227
+ docs: [],
228
+ agentDocsAppend: loaded.agentDocs?.append
229
+ ? [...loaded.agentDocs.append]
230
+ : [],
231
+ };
232
+ /** @type {Array<{kind: string, message: string}>} */
233
+ const errors = [];
234
+
235
+ if (loaded.themes && fs.existsSync(loaded.themes)) {
236
+ try {
237
+ const themes = await discoverIntegrationThemes(
238
+ /** @type {import('./integrations.mjs').LoadedIntegration} */ (loaded),
239
+ );
240
+ identities.themes = themes
241
+ .map(t => ({slug: t.slug, exportName: t.exportName}))
242
+ .sort((a, b) => a.slug.localeCompare(b.slug));
243
+ } catch (err) {
244
+ errors.push({
245
+ kind: 'themes',
246
+ message: /** @type {Error} */ (err).message,
247
+ });
248
+ }
249
+ }
250
+
251
+ if (loaded.components && fs.existsSync(loaded.components)) {
252
+ try {
253
+ const records = discoverIntegrationComponents(loaded) ?? [];
254
+ for (const record of records) {
255
+ try {
256
+ await loadComponentDoc(record.docPath);
257
+ identities.components.push(record.name);
258
+ } catch (err) {
259
+ errors.push({
260
+ kind: 'components',
261
+ message: `${path.relative(loaded.components, record.docPath)}: ${
262
+ /** @type {Error} */ (err).message
263
+ }`,
264
+ });
265
+ }
266
+ }
267
+ identities.components.sort();
268
+ } catch (err) {
269
+ errors.push({
270
+ kind: 'components',
271
+ message: /** @type {Error} */ (err).message,
272
+ });
273
+ }
274
+ }
275
+
276
+ if (loaded.templates && fs.existsSync(loaded.templates)) {
277
+ try {
278
+ const {templates, errors: templateErrors} =
279
+ await discoverIntegrationTemplatesForOne(loaded);
280
+ for (const templateError of templateErrors) {
281
+ errors.push({kind: 'templates', message: templateError.message});
282
+ }
283
+ identities.templates = templates
284
+ .map(t => ({id: t.dirName, type: t.type, name: t.name}))
285
+ .sort((a, b) => a.id.localeCompare(b.id));
286
+ } catch (err) {
287
+ errors.push({
288
+ kind: 'templates',
289
+ message: /** @type {Error} */ (err).message,
290
+ });
291
+ }
292
+ }
293
+
294
+ if (loaded.codemods && fs.existsSync(loaded.codemods)) {
295
+ try {
296
+ const byVersion = await discoverIntegrationCodemods([loaded]);
297
+ /** @type {{version: string, id: string}[]} */
298
+ const entries = [];
299
+ for (const [version, codemods] of byVersion) {
300
+ for (const cm of codemods) entries.push({version, id: cm.id});
301
+ }
302
+ identities.codemods = entries.sort((a, b) =>
303
+ `${a.version}/${a.id}`.localeCompare(`${b.version}/${b.id}`),
304
+ );
305
+ } catch (err) {
306
+ errors.push({
307
+ kind: 'codemods',
308
+ message: /** @type {Error} */ (err).message,
309
+ });
310
+ }
311
+ }
312
+
313
+ if (loaded.docs && fs.existsSync(loaded.docs)) {
314
+ try {
315
+ const {records, errors: docErrors} =
316
+ await discoverIntegrationDocs(loaded);
317
+ for (const docError of docErrors) {
318
+ errors.push({kind: 'docs', message: docError.message});
319
+ }
320
+ identities.docs = records.map(r => r.name).sort();
321
+ } catch (err) {
322
+ errors.push({kind: 'docs', message: /** @type {Error} */ (err).message});
323
+ }
324
+ }
325
+
326
+ return {identities, errors};
327
+ }
328
+
329
+ /**
330
+ * Prove that one contribution is visible through the same inventory seam the
331
+ * packed-package checker uses. This is the shared postcondition for every add
332
+ * handler, not a second set of per-writer rules.
333
+ *
334
+ * @param {IdentitySource} loaded
335
+ * @param {'theme'|'component'|'template'|'codemod'|'doc'|'agent-doc'} kind
336
+ * @param {string} name
337
+ * @param {{version?: string}} [options]
338
+ * @returns {Promise<void>}
339
+ */
340
+ export async function assertContributionVisible(
341
+ loaded,
342
+ kind,
343
+ name,
344
+ {version} = {},
345
+ ) {
346
+ const {identities, errors} = await collectIdentities(loaded);
347
+ const errorKind =
348
+ kind === 'theme'
349
+ ? 'themes'
350
+ : kind === 'component'
351
+ ? 'components'
352
+ : kind === 'template'
353
+ ? 'templates'
354
+ : kind === 'codemod'
355
+ ? 'codemods'
356
+ : kind === 'doc'
357
+ ? 'docs'
358
+ : 'agentDocs';
359
+ const relevantError = errors.find(error => error.kind === errorKind);
360
+ if (relevantError) throw new Error(relevantError.message);
361
+
362
+ const visible =
363
+ kind === 'theme'
364
+ ? identities.themes.some(theme => theme.slug === name)
365
+ : kind === 'component'
366
+ ? identities.components.includes(name)
367
+ : kind === 'template'
368
+ ? identities.templates.some(template => template.id === name)
369
+ : kind === 'codemod'
370
+ ? identities.codemods.some(
371
+ codemod => codemod.id === name && codemod.version === version,
372
+ )
373
+ : kind === 'doc'
374
+ ? identities.docs.includes(name)
375
+ : identities.agentDocsAppend.includes(name);
376
+ if (!visible) {
377
+ const qualifier = version == null ? '' : ` under version ${version}`;
378
+ throw new Error(
379
+ `${kind} contribution "${name}" was not visible${qualifier} after writing.`,
380
+ );
381
+ }
382
+ }
383
+
384
+ // ── Public: identity comparison ──────────────────────────────────
385
+
386
+ /**
387
+ * @typedef {import('./issue').AstryxIntegrationIssue} Issue
388
+ */
389
+
390
+ /**
391
+ * Compare local and packed identities. Anything discoverable locally but
392
+ * missing from the packed tarball is an error.
393
+ *
394
+ * @param {ContributionIdentities} local
395
+ * @param {ContributionIdentities} packed
396
+ * @returns {Issue[]}
397
+ */
398
+ export function compareIdentities(local, packed) {
399
+ /** @type {Issue[]} */
400
+ const issues = [];
401
+
402
+ /**
403
+ * Compare one identity list in both directions, then compare the complete
404
+ * record for matching keys. A packed-only identity is just as suspicious as a
405
+ * missing one: npm shipped bytes the local authoring view did not expose.
406
+ * @param {string} kind
407
+ * @param {unknown[]} localItems
408
+ * @param {unknown[]} packedItems
409
+ * @param {(item: any) => string} keyOf
410
+ */
411
+ function compareKind(kind, localItems, packedItems, keyOf) {
412
+ const localByKey = new Map(localItems.map(item => [keyOf(item), item]));
413
+ const packedByKey = new Map(packedItems.map(item => [keyOf(item), item]));
414
+ for (const [key, item] of localByKey) {
415
+ if (!packedByKey.has(key)) {
416
+ issues.push({
417
+ code: 'identity_not_packed',
418
+ severity: 'error',
419
+ message: `${kind} "${key}" is discoverable locally but missing from the packed tarball.`,
420
+ });
421
+ continue;
422
+ }
423
+ const packedItem = packedByKey.get(key);
424
+ if (!isDeepStrictEqual(item, packedItem)) {
425
+ issues.push({
426
+ code: 'identity_mismatch',
427
+ severity: 'error',
428
+ message: `${kind} "${key}" resolves differently from the packed tarball.`,
429
+ });
430
+ }
431
+ }
432
+ for (const key of packedByKey.keys()) {
433
+ if (!localByKey.has(key)) {
434
+ issues.push({
435
+ code: 'packed_identity_unexpected',
436
+ severity: 'error',
437
+ message: `${kind} "${key}" exists only in the packed tarball.`,
438
+ });
439
+ }
440
+ }
441
+ }
442
+
443
+ compareKind('Theme', local.themes, packed.themes, item => item.slug);
444
+ compareKind('Component', local.components, packed.components, item => item);
445
+ compareKind('Template', local.templates, packed.templates, item => item.id);
446
+ compareKind(
447
+ 'Codemod',
448
+ local.codemods,
449
+ packed.codemods,
450
+ item => `${item.version}/${item.id}`,
451
+ );
452
+ compareKind('Doc topic', local.docs, packed.docs, item => item);
453
+
454
+ if (
455
+ JSON.stringify(local.agentDocsAppend) !==
456
+ JSON.stringify(packed.agentDocsAppend)
457
+ ) {
458
+ issues.push({
459
+ code: 'agent_docs_mismatch',
460
+ severity: 'error',
461
+ message:
462
+ 'agentDocs.append lines differ between local and packed manifests.',
463
+ });
464
+ }
465
+
466
+ return issues;
467
+ }
468
+
469
+ // ── Public: source-only candidate detection ──────────────────────
470
+
471
+ const PASCAL_CASE_TSX = /^([A-Z][A-Za-z0-9]+)\.tsx$/u;
472
+
473
+ /**
474
+ * Find top-level PascalCase `.tsx` files under a components root that are
475
+ * NOT registered as integration components. These are candidates that
476
+ * Astryx will ignore — surfaced as a warning so the author knows.
477
+ *
478
+ * Scans only direct children of the root (not recursive) and never
479
+ * enters node_modules.
480
+ *
481
+ * @param {string|undefined} componentsRoot absolute path
482
+ * @param {string[]} registeredNames names already returned by discovery
483
+ * @returns {string[]} unregistered PascalCase names
484
+ */
485
+ export function findSourceOnlyCandidates(componentsRoot, registeredNames) {
486
+ if (!componentsRoot || !fs.existsSync(componentsRoot)) return [];
487
+ const known = new Set(registeredNames);
488
+ /** @type {string[]} */
489
+ const candidates = [];
490
+ for (const entry of fs.readdirSync(componentsRoot, {withFileTypes: true})) {
491
+ if (!entry.isFile() && !entry.isSymbolicLink()) continue;
492
+ const match = entry.name.match(PASCAL_CASE_TSX);
493
+ if (!match) continue;
494
+ if (!known.has(match[1])) candidates.push(match[1]);
495
+ }
496
+ return candidates.sort();
497
+ }