@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,430 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Colocated tests for autolink — loading an installed integration the
5
+ * config does not name.
6
+ *
7
+ * The fixtures are the shapes that actually exist in the projects this
8
+ * targets: a scaffold that added the dependency and wrote no config, an npm
9
+ * alias, a package mid-rename declared under both spellings, and a hoisted
10
+ * install. Temp dirs are repo-local because the loader dynamically imports the
11
+ * manifest and Vite refuses to import out of the OS temp dir.
12
+ */
13
+
14
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
15
+ import * as fs from 'node:fs';
16
+ import * as path from 'node:path';
17
+ import {
18
+ DEPENDENCY_FIELDS,
19
+ autolinkIntegrations,
20
+ findAutolinkCandidates,
21
+ readDeclaredDependencies,
22
+ resolveInstalledPackageDir,
23
+ } from './autolink.mjs';
24
+ import {Project} from '../config/project.mjs';
25
+
26
+ let tmpDir;
27
+
28
+ beforeEach(() => {
29
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-autolink-test-'));
30
+ });
31
+
32
+ afterEach(() => {
33
+ fs.rmSync(tmpDir, {recursive: true, force: true});
34
+ });
35
+
36
+ /**
37
+ * Write a project package.json.
38
+ * @param {string} dir
39
+ * @param {object} fields
40
+ */
41
+ function writeProject(dir, fields = {}) {
42
+ fs.mkdirSync(dir, {recursive: true});
43
+ fs.writeFileSync(
44
+ path.join(dir, 'package.json'),
45
+ JSON.stringify({name: 'consumer', ...fields}),
46
+ );
47
+ }
48
+
49
+ /**
50
+ * Install a package under `<hostDir>/node_modules/<installAs>`.
51
+ *
52
+ * `installAs` is the directory (what an npm alias controls); `name` is the
53
+ * package's own identity, which is a different string exactly when the
54
+ * dependency is aliased.
55
+ *
56
+ * @param {string} hostDir
57
+ * @param {object} options
58
+ * @returns {string} the installed package directory
59
+ */
60
+ function installPackage(
61
+ hostDir,
62
+ {
63
+ installAs,
64
+ name = installAs,
65
+ version = '1.0.0',
66
+ manifest = {components: './components'},
67
+ manifestBasenames = ['astryx.integration.mjs'],
68
+ componentName = 'Widget',
69
+ } = {},
70
+ ) {
71
+ const pkgDir = path.join(hostDir, 'node_modules', ...installAs.split('/'));
72
+ fs.mkdirSync(pkgDir, {recursive: true});
73
+ fs.writeFileSync(
74
+ path.join(pkgDir, 'package.json'),
75
+ JSON.stringify({name, version}),
76
+ );
77
+ for (const basename of manifestBasenames) {
78
+ fs.writeFileSync(
79
+ path.join(pkgDir, basename),
80
+ typeof manifest === 'string'
81
+ ? manifest
82
+ : `export default ${JSON.stringify(manifest)};\n`,
83
+ );
84
+ }
85
+ if (manifest && typeof manifest === 'object' && manifest.components) {
86
+ const componentsDir = path.join(pkgDir, 'components');
87
+ fs.mkdirSync(componentsDir, {recursive: true});
88
+ fs.writeFileSync(
89
+ path.join(componentsDir, `${componentName}.doc.mjs`),
90
+ `export const docs = {name: '${componentName}', usage: {description: 'A widget'}};\n`,
91
+ );
92
+ fs.writeFileSync(
93
+ path.join(componentsDir, `${componentName}.tsx`),
94
+ `export function ${componentName}() { return null; }\n`,
95
+ );
96
+ }
97
+ return pkgDir;
98
+ }
99
+
100
+ /** @param {string} dir @param {string[]} integrations */
101
+ function writeConfig(dir, integrations) {
102
+ fs.writeFileSync(
103
+ path.join(dir, 'astryx.config.mjs'),
104
+ `export default ${JSON.stringify({integrations})};\n`,
105
+ );
106
+ }
107
+
108
+ describe('readDeclaredDependencies', () => {
109
+ it('reads dependencies, devDependencies and optionalDependencies — not peerDependencies', () => {
110
+ writeProject(tmpDir, {
111
+ dependencies: {a: '1'},
112
+ devDependencies: {b: '1'},
113
+ optionalDependencies: {c: '1'},
114
+ peerDependencies: {d: '1'},
115
+ });
116
+ const declared = readDeclaredDependencies(tmpDir);
117
+ expect(declared.map(entry => entry.name)).toEqual(['a', 'b', 'c']);
118
+ expect(declared.map(entry => entry.field)).toEqual(DEPENDENCY_FIELDS);
119
+ });
120
+
121
+ it('keeps the first field a name is declared in', () => {
122
+ writeProject(tmpDir, {
123
+ dependencies: {a: '1'},
124
+ devDependencies: {a: '2'},
125
+ });
126
+ expect(readDeclaredDependencies(tmpDir)).toEqual([
127
+ {name: 'a', field: 'dependencies'},
128
+ ]);
129
+ });
130
+
131
+ it('refuses a key that is not a bare package name', () => {
132
+ writeProject(tmpDir, {
133
+ dependencies: {'../evil': '1', '/abs': '1', './rel': '1', ok: '1'},
134
+ });
135
+ expect(readDeclaredDependencies(tmpDir).map(e => e.name)).toEqual(['ok']);
136
+ });
137
+
138
+ it('is empty when there is no readable package.json', () => {
139
+ expect(readDeclaredDependencies(tmpDir)).toEqual([]);
140
+ fs.writeFileSync(path.join(tmpDir, 'package.json'), '{not json');
141
+ expect(readDeclaredDependencies(tmpDir)).toEqual([]);
142
+ });
143
+ });
144
+
145
+ describe('resolveInstalledPackageDir', () => {
146
+ it('finds a package hoisted to a parent node_modules', () => {
147
+ const appDir = path.join(tmpDir, 'apps', 'web');
148
+ writeProject(appDir);
149
+ installPackage(tmpDir, {installAs: '@acme/widgets'});
150
+ const resolved = resolveInstalledPackageDir('@acme/widgets', appDir);
151
+ expect(resolved?.hostDir).toBe(tmpDir);
152
+ expect(resolved?.packageDir).toBe(
153
+ path.join(tmpDir, 'node_modules', '@acme', 'widgets'),
154
+ );
155
+ });
156
+
157
+ it('prefers the nearest node_modules', () => {
158
+ const appDir = path.join(tmpDir, 'apps', 'web');
159
+ writeProject(appDir);
160
+ installPackage(tmpDir, {installAs: '@acme/widgets'});
161
+ installPackage(appDir, {installAs: '@acme/widgets'});
162
+ expect(resolveInstalledPackageDir('@acme/widgets', appDir)?.hostDir).toBe(
163
+ appDir,
164
+ );
165
+ });
166
+
167
+ it('is null for a directory with no package.json', () => {
168
+ writeProject(tmpDir);
169
+ fs.mkdirSync(path.join(tmpDir, 'node_modules', 'empty'), {recursive: true});
170
+ expect(resolveInstalledPackageDir('empty', tmpDir)).toBeNull();
171
+ expect(resolveInstalledPackageDir('../escape', tmpDir)).toBeNull();
172
+ });
173
+ });
174
+
175
+ describe('findAutolinkCandidates', () => {
176
+ it('probes declared dependencies only — never walks node_modules', () => {
177
+ writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
178
+ installPackage(tmpDir, {installAs: '@acme/widgets'});
179
+ installPackage(tmpDir, {installAs: '@acme/undeclared'});
180
+
181
+ const candidates = findAutolinkCandidates(tmpDir);
182
+ expect(candidates.map(candidate => candidate.spec)).toEqual([
183
+ '@acme/widgets',
184
+ ]);
185
+ });
186
+
187
+ it('ignores a transitive dependency that ships a manifest', () => {
188
+ writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
189
+ const pkgDir = installPackage(tmpDir, {installAs: '@acme/widgets'});
190
+ // @acme/widgets depends on @acme/inner; the project does not.
191
+ fs.writeFileSync(
192
+ path.join(pkgDir, 'package.json'),
193
+ JSON.stringify({
194
+ name: '@acme/widgets',
195
+ version: '1.0.0',
196
+ dependencies: {'@acme/inner': '^1.0.0'},
197
+ }),
198
+ );
199
+ installPackage(tmpDir, {installAs: '@acme/inner'});
200
+
201
+ expect(findAutolinkCandidates(tmpDir).map(c => c.spec)).toEqual([
202
+ '@acme/widgets',
203
+ ]);
204
+ });
205
+
206
+ it('skips a declared dependency with no manifest', () => {
207
+ writeProject(tmpDir, {dependencies: {react: '^19.0.0'}});
208
+ installPackage(tmpDir, {installAs: 'react', manifestBasenames: []});
209
+ expect(findAutolinkCandidates(tmpDir)).toEqual([]);
210
+ });
211
+
212
+ it('skips a package with more than one root manifest instead of failing', () => {
213
+ writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
214
+ installPackage(tmpDir, {
215
+ installAs: '@acme/widgets',
216
+ manifestBasenames: ['astryx.integration.mjs', 'astryx.integration.js'],
217
+ });
218
+ expect(findAutolinkCandidates(tmpDir)).toEqual([]);
219
+ });
220
+
221
+ it('collapses two dependency keys that link to one package directory', () => {
222
+ // pnpm links every dependency from one store entry, so the two spellings of
223
+ // a package mid-rename share a real path.
224
+ writeProject(tmpDir, {
225
+ dependencies: {'@acme/legacy-ui': '^0.5.0', '@acme/ui': '^0.1.0'},
226
+ });
227
+ const real = installPackage(tmpDir, {
228
+ installAs: '@acme/ui',
229
+ name: '@acme/ui',
230
+ version: '0.1.22',
231
+ });
232
+ const linkDir = path.join(tmpDir, 'node_modules', '@acme');
233
+ fs.mkdirSync(linkDir, {recursive: true});
234
+ fs.symlinkSync(real, path.join(linkDir, 'legacy-ui'), 'dir');
235
+
236
+ const candidates = findAutolinkCandidates(tmpDir);
237
+ expect(candidates).toHaveLength(1);
238
+ expect(candidates[0].spec).toBe('@acme/legacy-ui');
239
+ });
240
+
241
+ it('excludes package directories already loaded', () => {
242
+ writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
243
+ const pkgDir = installPackage(tmpDir, {installAs: '@acme/widgets'});
244
+ expect(findAutolinkCandidates(tmpDir, {exclude: [pkgDir]})).toEqual([]);
245
+ });
246
+ });
247
+
248
+ describe('autolinkIntegrations', () => {
249
+ it('loads a declared dependency that ships a manifest, and marks it', async () => {
250
+ writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
251
+ installPackage(tmpDir, {installAs: '@acme/widgets'});
252
+
253
+ const [integration, ...rest] = await autolinkIntegrations({
254
+ projectDir: tmpDir,
255
+ });
256
+ expect(rest).toEqual([]);
257
+ expect(integration.name).toBe('@acme/widgets');
258
+ expect(integration.__autolinked).toBe(true);
259
+ expect(integration.__dependencyField).toBe('dependencies');
260
+ expect(integration.components).toBe(
261
+ path.join(tmpDir, 'node_modules', '@acme', 'widgets', 'components'),
262
+ );
263
+ });
264
+
265
+ it('reads the dependency KEY, never the value', async () => {
266
+ // Every one of these is a real installed shape and none is a semver range.
267
+ writeProject(tmpDir, {
268
+ dependencies: {
269
+ '@acme/legacy-ui': 'npm:@acme/ui@0.1.22',
270
+ '@acme/linked': 'link:../linked',
271
+ '@acme/filed': 'file:../filed',
272
+ },
273
+ devDependencies: {
274
+ '@acme/workspaced': 'workspace:*',
275
+ '@acme/cataloged': 'catalog:',
276
+ },
277
+ });
278
+ // The aliased key installs a package whose own name is the aliased one.
279
+ installPackage(tmpDir, {
280
+ installAs: '@acme/legacy-ui',
281
+ name: '@acme/ui',
282
+ version: '0.1.22',
283
+ });
284
+ for (const installAs of [
285
+ '@acme/linked',
286
+ '@acme/filed',
287
+ '@acme/workspaced',
288
+ '@acme/cataloged',
289
+ ]) {
290
+ installPackage(tmpDir, {installAs});
291
+ }
292
+
293
+ const loaded = await autolinkIntegrations({projectDir: tmpDir});
294
+ expect(loaded.map(i => i.name)).toEqual([
295
+ // Identity is the resolved package's own name, not the key it is under.
296
+ '@acme/ui',
297
+ '@acme/linked',
298
+ '@acme/filed',
299
+ '@acme/workspaced',
300
+ '@acme/cataloged',
301
+ ]);
302
+ const aliased = loaded[0];
303
+ expect(aliased.__spec).toBe('@acme/legacy-ui');
304
+ expect(aliased.version).toBe('0.1.22');
305
+ });
306
+
307
+ it('loads one integration when both spellings of a rename are installed', async () => {
308
+ // Mid-rename, with two directories on disk rather than one linked store
309
+ // entry: the package name is the identity that collapses them.
310
+ writeProject(tmpDir, {
311
+ dependencies: {'@acme/legacy-ui': '^0.5.0', '@acme/ui': '^0.1.0'},
312
+ });
313
+ installPackage(tmpDir, {
314
+ installAs: '@acme/legacy-ui',
315
+ name: '@acme/ui',
316
+ version: '0.1.22',
317
+ });
318
+ installPackage(tmpDir, {
319
+ installAs: '@acme/ui',
320
+ name: '@acme/ui',
321
+ version: '0.1.22',
322
+ });
323
+
324
+ const loaded = await autolinkIntegrations({projectDir: tmpDir});
325
+ expect(loaded).toHaveLength(1);
326
+ expect(loaded[0].name).toBe('@acme/ui');
327
+ });
328
+
329
+ it('does not load one already loaded from config', async () => {
330
+ writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
331
+ const pkgDir = installPackage(tmpDir, {installAs: '@acme/widgets'});
332
+ const loaded = await autolinkIntegrations({
333
+ projectDir: tmpDir,
334
+ loaded: [
335
+ /** @type {any} */ ({name: '@acme/widgets', __packageDir: pkgDir}),
336
+ ],
337
+ });
338
+ expect(loaded).toEqual([]);
339
+ });
340
+
341
+ it('drops a dependency whose manifest is broken, and raises no issue for it', async () => {
342
+ // The project cannot fix a dependency's packaging bug, so autolink must not
343
+ // hand it one to look at. Both failure modes: a manifest that throws on
344
+ // import, and one that loads but fails schema validation.
345
+ writeProject(tmpDir, {
346
+ dependencies: {
347
+ '@acme/throws': '^1.0.0',
348
+ '@acme/invalid': '^1.0.0',
349
+ '@acme/widgets': '^1.0.0',
350
+ },
351
+ });
352
+ installPackage(tmpDir, {
353
+ installAs: '@acme/throws',
354
+ manifest: 'throw new Error("boom");\n',
355
+ });
356
+ installPackage(tmpDir, {
357
+ installAs: '@acme/invalid',
358
+ manifest: {components: 42},
359
+ });
360
+ installPackage(tmpDir, {installAs: '@acme/widgets'});
361
+
362
+ const loaded = await autolinkIntegrations({projectDir: tmpDir});
363
+ expect(loaded.map(i => i.name)).toEqual(['@acme/widgets']);
364
+
365
+ const project = await Project.load(tmpDir);
366
+ expect(await project.issues()).toEqual([]);
367
+ });
368
+ });
369
+
370
+ describe('Project.load with autolink', () => {
371
+ it('discovers components from an installed integration with no config at all', async () => {
372
+ // The population this exists for: the scaffold added the dependency and
373
+ // wrote no astryx.config, so the CLI used to report the component missing.
374
+ writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
375
+ installPackage(tmpDir, {
376
+ installAs: '@acme/widgets',
377
+ componentName: 'MetaOncall',
378
+ });
379
+
380
+ const project = await Project.load(tmpDir);
381
+ expect(project.configPath).toBeNull();
382
+ expect(project.integrations).toEqual([]);
383
+ expect(project.loadedIntegrations.map(i => i.name)).toEqual([
384
+ '@acme/widgets',
385
+ ]);
386
+ const components = await project.components();
387
+ expect(components.map(component => component.name)).toContain('MetaOncall');
388
+ });
389
+
390
+ it('keeps a configured integration explicit and puts autolinked ones after it', async () => {
391
+ writeProject(tmpDir, {
392
+ dependencies: {'@acme/widgets': '^1.0.0', '@acme/extras': '^1.0.0'},
393
+ });
394
+ writeConfig(tmpDir, ['@acme/widgets']);
395
+ installPackage(tmpDir, {installAs: '@acme/widgets'});
396
+ installPackage(tmpDir, {
397
+ installAs: '@acme/extras',
398
+ componentName: 'Extra',
399
+ });
400
+
401
+ const project = await Project.load(tmpDir);
402
+ expect(project.integrations).toEqual(['@acme/widgets']);
403
+ expect(
404
+ project.loadedIntegrations.map(i => [i.name, i.__autolinked ?? false]),
405
+ ).toEqual([
406
+ ['@acme/widgets', false],
407
+ ['@acme/extras', true],
408
+ ]);
409
+ });
410
+
411
+ it('resolves a dependency hoisted to a workspace root', async () => {
412
+ const appDir = path.join(tmpDir, 'apps', 'web');
413
+ writeProject(appDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
414
+ installPackage(tmpDir, {installAs: '@acme/widgets'});
415
+
416
+ const project = await Project.load(appDir);
417
+ expect(project.loadedIntegrations.map(i => i.name)).toEqual([
418
+ '@acme/widgets',
419
+ ]);
420
+ });
421
+
422
+ it('leaves a project with no astryx dependencies untouched', async () => {
423
+ writeProject(tmpDir, {dependencies: {react: '^19.0.0'}});
424
+ installPackage(tmpDir, {installAs: 'react', manifestBasenames: []});
425
+
426
+ const project = await Project.load(tmpDir);
427
+ expect(project.loadedIntegrations).toEqual([]);
428
+ expect(await project.issues()).toEqual([]);
429
+ });
430
+ });
@@ -0,0 +1,152 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @typedef {object} FileInventoryRoot
6
+ * @property {'themes'|'components'|'templates'|'codemods'|'docs'} kind
7
+ * @property {string} path — project-relative root path
8
+ * @property {string[]} files — project-relative required file paths
9
+ */
10
+ /**
11
+ * @typedef {object} FileInventory
12
+ * @property {string} manifest — project-relative manifest path
13
+ * @property {FileInventoryRoot[]} roots
14
+ * @property {string[]} allFiles — deduplicated flat list
15
+ */
16
+ /**
17
+ * Compute the files the tarball must contain for an integration's
18
+ * contributions to be visible. Reads catalogs and walks directories;
19
+ * never imports or executes authored modules.
20
+ *
21
+ * @param {import('./integrations.mjs').LoadedIntegration} loaded
22
+ * @returns {FileInventory}
23
+ */
24
+ export function computeRequiredFiles(loaded: import("./integrations.mjs").LoadedIntegration): FileInventory;
25
+ /**
26
+ * @typedef {object} ContributionIdentities
27
+ * @property {{slug: string, exportName: string}[]} themes
28
+ * @property {string[]} components
29
+ * @property {{id: string, type: string, name: string}[]} templates
30
+ * @property {{version: string, id: string}[]} codemods
31
+ * @property {string[]} docs
32
+ * @property {string[]} agentDocsAppend
33
+ */
34
+ /**
35
+ * The resolved fields needed to discover contribution identities.
36
+ * @typedef {object} IdentitySource
37
+ * @property {string} name
38
+ * @property {string} [themes]
39
+ * @property {string} [components]
40
+ * @property {string} [templates]
41
+ * @property {string} [codemods]
42
+ * @property {string} [docs]
43
+ * @property {{append?: readonly string[]}} [agentDocs]
44
+ */
45
+ /**
46
+ * Run the same discovery functions a consumer uses to collect every
47
+ * contribution identity from a loaded integration.
48
+ *
49
+ * @param {IdentitySource} loaded
50
+ * @returns {Promise<{identities: ContributionIdentities, errors: Array<{kind: string, message: string}>}>}
51
+ */
52
+ export function collectIdentities(loaded: IdentitySource): Promise<{
53
+ identities: ContributionIdentities;
54
+ errors: Array<{
55
+ kind: string;
56
+ message: string;
57
+ }>;
58
+ }>;
59
+ /**
60
+ * Prove that one contribution is visible through the same inventory seam the
61
+ * packed-package checker uses. This is the shared postcondition for every add
62
+ * handler, not a second set of per-writer rules.
63
+ *
64
+ * @param {IdentitySource} loaded
65
+ * @param {'theme'|'component'|'template'|'codemod'|'doc'|'agent-doc'} kind
66
+ * @param {string} name
67
+ * @param {{version?: string}} [options]
68
+ * @returns {Promise<void>}
69
+ */
70
+ export function assertContributionVisible(loaded: IdentitySource, kind: "theme" | "component" | "template" | "codemod" | "doc" | "agent-doc", name: string, { version }?: {
71
+ version?: string;
72
+ }): Promise<void>;
73
+ /**
74
+ * @typedef {import('./issue').AstryxIntegrationIssue} Issue
75
+ */
76
+ /**
77
+ * Compare local and packed identities. Anything discoverable locally but
78
+ * missing from the packed tarball is an error.
79
+ *
80
+ * @param {ContributionIdentities} local
81
+ * @param {ContributionIdentities} packed
82
+ * @returns {Issue[]}
83
+ */
84
+ export function compareIdentities(local: ContributionIdentities, packed: ContributionIdentities): Issue[];
85
+ /**
86
+ * Find top-level PascalCase `.tsx` files under a components root that are
87
+ * NOT registered as integration components. These are candidates that
88
+ * Astryx will ignore — surfaced as a warning so the author knows.
89
+ *
90
+ * Scans only direct children of the root (not recursive) and never
91
+ * enters node_modules.
92
+ *
93
+ * @param {string|undefined} componentsRoot absolute path
94
+ * @param {string[]} registeredNames names already returned by discovery
95
+ * @returns {string[]} unregistered PascalCase names
96
+ */
97
+ export function findSourceOnlyCandidates(componentsRoot: string | undefined, registeredNames: string[]): string[];
98
+ export type FileInventoryRoot = {
99
+ kind: "themes" | "components" | "templates" | "codemods" | "docs";
100
+ /**
101
+ * — project-relative root path
102
+ */
103
+ path: string;
104
+ /**
105
+ * — project-relative required file paths
106
+ */
107
+ files: string[];
108
+ };
109
+ export type FileInventory = {
110
+ /**
111
+ * — project-relative manifest path
112
+ */
113
+ manifest: string;
114
+ roots: FileInventoryRoot[];
115
+ /**
116
+ * — deduplicated flat list
117
+ */
118
+ allFiles: string[];
119
+ };
120
+ export type ContributionIdentities = {
121
+ themes: {
122
+ slug: string;
123
+ exportName: string;
124
+ }[];
125
+ components: string[];
126
+ templates: {
127
+ id: string;
128
+ type: string;
129
+ name: string;
130
+ }[];
131
+ codemods: {
132
+ version: string;
133
+ id: string;
134
+ }[];
135
+ docs: string[];
136
+ agentDocsAppend: string[];
137
+ };
138
+ /**
139
+ * The resolved fields needed to discover contribution identities.
140
+ */
141
+ export type IdentitySource = {
142
+ name: string;
143
+ themes?: string | undefined;
144
+ components?: string | undefined;
145
+ templates?: string | undefined;
146
+ codemods?: string | undefined;
147
+ docs?: string | undefined;
148
+ agentDocs?: {
149
+ append?: readonly string[];
150
+ } | undefined;
151
+ };
152
+ export type Issue = import("./issue").AstryxIntegrationIssue;