@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,569 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
4
+ import * as fs from 'node:fs';
5
+ import * as os from 'node:os';
6
+ import * as path from 'node:path';
7
+ import {spawnSync} from 'node:child_process';
8
+ import {integrationPackCheck, parseNpmPackOutput} from './pack-check.mjs';
9
+ import {
10
+ integrationAddComponent,
11
+ integrationAddTemplate,
12
+ } from './add-contribution.mjs';
13
+
14
+ let tmpDir;
15
+
16
+ beforeEach(() => {
17
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-pack-check-'));
18
+ });
19
+
20
+ afterEach(() => {
21
+ fs.rmSync(tmpDir, {recursive: true, force: true});
22
+ });
23
+
24
+ /**
25
+ * Write a minimal integration package into tmpDir.
26
+ * Returns the package directory.
27
+ */
28
+ function writePackage({
29
+ name = '@acme/widgets',
30
+ version = '1.0.0',
31
+ files,
32
+ manifest = "export default {themes: './themes'};\n",
33
+ themes = true,
34
+ npmignore,
35
+ components = false,
36
+ scripts,
37
+ } = {}) {
38
+ const pkg = {name, version};
39
+ if (files !== undefined) pkg.files = files;
40
+ if (scripts !== undefined) pkg.scripts = scripts;
41
+ fs.writeFileSync(
42
+ path.join(tmpDir, 'package.json'),
43
+ JSON.stringify(pkg, null, 2) + '\n',
44
+ );
45
+ if (manifest != null) {
46
+ fs.writeFileSync(path.join(tmpDir, 'astryx.integration.mjs'), manifest);
47
+ }
48
+ if (themes) {
49
+ const root = path.join(tmpDir, 'themes');
50
+ fs.mkdirSync(path.join(root, 'ocean'), {recursive: true});
51
+ fs.writeFileSync(
52
+ path.join(root, 'ocean', 'oceanTheme.ts'),
53
+ "import {defineTheme} from '@astryxdesign/core/theme';\n\nexport const oceanTheme = defineTheme({name: 'ocean'});\n",
54
+ );
55
+ fs.writeFileSync(
56
+ path.join(root, 'manifest.json'),
57
+ JSON.stringify(
58
+ {
59
+ version: 1,
60
+ themes: [
61
+ {
62
+ slug: 'ocean',
63
+ displayName: 'Ocean',
64
+ description: 'Ocean theme.',
65
+ maintained: true,
66
+ entry: 'oceanTheme.ts',
67
+ exportName: 'oceanTheme',
68
+ files: ['oceanTheme.ts'],
69
+ },
70
+ ],
71
+ },
72
+ null,
73
+ 2,
74
+ ) + '\n',
75
+ );
76
+ }
77
+ if (components) {
78
+ const root = path.join(tmpDir, 'components');
79
+ fs.mkdirSync(root, {recursive: true});
80
+ fs.writeFileSync(
81
+ path.join(root, 'Card.tsx'),
82
+ 'export default function Card() { return null; }\n',
83
+ );
84
+ }
85
+ if (npmignore) {
86
+ fs.writeFileSync(path.join(tmpDir, '.npmignore'), npmignore);
87
+ }
88
+ return tmpDir;
89
+ }
90
+
91
+ describe('integrationPackCheck', () => {
92
+ it('returns packable:true for a valid integration with themes', async () => {
93
+ writePackage({files: ['astryx.integration.mjs', 'themes']});
94
+ const result = await integrationPackCheck({cwd: tmpDir});
95
+
96
+ expect(result.type).toBe('integration.pack-check');
97
+ expect(result.data.packable).toBe(true);
98
+ expect(result.data.name).toBe('@acme/widgets');
99
+ expect(result.data.tarball).not.toBeNull();
100
+ expect(result.data.inventory.manifest).toBe('astryx.integration.mjs');
101
+ expect(result.data.contributions.local?.themes).toEqual([
102
+ {slug: 'ocean', exportName: 'oceanTheme'},
103
+ ]);
104
+ expect(result.data.contributions.packed).toEqual(
105
+ result.data.contributions.local,
106
+ );
107
+ expect(result.data.issues.filter(i => i.severity === 'error')).toHaveLength(
108
+ 0,
109
+ );
110
+ });
111
+
112
+ it('fails when a theme entry omits its catalog export', async () => {
113
+ writePackage({files: ['astryx.integration.mjs', 'themes']});
114
+ fs.writeFileSync(
115
+ path.join(tmpDir, 'themes', 'ocean', 'oceanTheme.ts'),
116
+ 'export const anotherTheme = {};\n',
117
+ );
118
+
119
+ const result = await integrationPackCheck({cwd: tmpDir});
120
+
121
+ expect(result.data.packable).toBe(false);
122
+ expect(result.data.issues).toContainEqual(
123
+ expect.objectContaining({
124
+ code: 'invalid_theme',
125
+ message: expect.stringContaining(
126
+ 'entry "oceanTheme.ts" does not export "oceanTheme"',
127
+ ),
128
+ }),
129
+ );
130
+ });
131
+
132
+ it('fails when a theme imports a file omitted from its catalog', async () => {
133
+ writePackage({files: ['astryx.integration.mjs', 'themes']});
134
+ fs.mkdirSync(path.join(tmpDir, 'themes', 'ocean', 'tokens'), {
135
+ recursive: true,
136
+ });
137
+ fs.writeFileSync(
138
+ path.join(tmpDir, 'themes', 'ocean', 'oceanTheme.ts'),
139
+ "import {oceanPalette} from './tokens/ocean.palette';\nexport const oceanTheme = {oceanPalette};\n",
140
+ );
141
+ fs.writeFileSync(
142
+ path.join(tmpDir, 'themes', 'ocean', 'tokens', 'ocean.palette.ts'),
143
+ 'export const oceanPalette = {};\n',
144
+ );
145
+
146
+ const result = await integrationPackCheck({cwd: tmpDir});
147
+
148
+ expect(result.data.packable).toBe(false);
149
+ expect(result.data.issues).toContainEqual(
150
+ expect.objectContaining({
151
+ code: 'invalid_theme',
152
+ message: expect.stringContaining(
153
+ 'must resolve to a listed file inside the theme directory',
154
+ ),
155
+ }),
156
+ );
157
+ });
158
+
159
+ it('fails when a discovered component is not exported to consumers', async () => {
160
+ writePackage({
161
+ manifest: "export default {components: './components'};\n",
162
+ files: ['astryx.integration.mjs', 'components', 'index.mjs'],
163
+ themes: false,
164
+ });
165
+ const pkgFile = path.join(tmpDir, 'package.json');
166
+ const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
167
+ pkg.exports = {'.': './index.mjs'};
168
+ fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`);
169
+ fs.writeFileSync(
170
+ path.join(tmpDir, 'index.mjs'),
171
+ 'export const existing = 1;\n',
172
+ );
173
+ fs.mkdirSync(path.join(tmpDir, 'components'));
174
+ fs.writeFileSync(
175
+ path.join(tmpDir, 'components', 'AcmeWidget.doc.mjs'),
176
+ "export default {type: 'component', name: 'AcmeWidget', description: 'Widget.', props: []};\n",
177
+ );
178
+ fs.writeFileSync(
179
+ path.join(tmpDir, 'components', 'AcmeWidget.tsx'),
180
+ 'export function AcmeWidget() { return null; }\n',
181
+ );
182
+
183
+ const result = await integrationPackCheck({cwd: tmpDir});
184
+
185
+ expect(result.data.packable).toBe(false);
186
+ expect(result.data.issues).toContainEqual(
187
+ expect.objectContaining({
188
+ code: 'component_export_missing',
189
+ message: expect.stringContaining('AcmeWidget'),
190
+ }),
191
+ );
192
+ });
193
+
194
+ it('passes a generated component through its exact packed export', async () => {
195
+ fs.writeFileSync(
196
+ path.join(tmpDir, 'package.json'),
197
+ `${JSON.stringify({
198
+ name: '@acme/widgets',
199
+ version: '1.0.0',
200
+ files: ['index.mjs'],
201
+ exports: {'.': './index.mjs'},
202
+ })}\n`,
203
+ );
204
+ fs.writeFileSync(
205
+ path.join(tmpDir, 'index.mjs'),
206
+ 'export const existing = 1;\n',
207
+ );
208
+ await integrationAddComponent('AcmeWidget', {cwd: tmpDir});
209
+
210
+ const result = await integrationPackCheck({cwd: tmpDir});
211
+
212
+ expect(result.data.packable).toBe(true);
213
+ expect(result.data.issues).not.toContainEqual(
214
+ expect.objectContaining({code: 'component_export_missing'}),
215
+ );
216
+ });
217
+
218
+ it('fails when packed template source is hidden by package exports', async () => {
219
+ writePackage({
220
+ manifest: "export default {templates: './templates'};\n",
221
+ files: ['astryx.integration.mjs', 'templates', 'index.mjs'],
222
+ themes: false,
223
+ });
224
+ const pkgFile = path.join(tmpDir, 'package.json');
225
+ const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
226
+ pkg.exports = {'.': './index.mjs'};
227
+ fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`);
228
+ fs.writeFileSync(
229
+ path.join(tmpDir, 'index.mjs'),
230
+ 'export const existing = 1;\n',
231
+ );
232
+ fs.mkdirSync(path.join(tmpDir, 'templates'));
233
+ fs.writeFileSync(
234
+ path.join(tmpDir, 'templates', 'account-page.template.mjs'),
235
+ "export default {type: 'page', name: 'Account page', description: 'Account page.'};\n",
236
+ );
237
+ fs.writeFileSync(
238
+ path.join(tmpDir, 'templates', 'account-page.tsx'),
239
+ 'export default function AccountPage() { return null; }\n',
240
+ );
241
+
242
+ const result = await integrationPackCheck({cwd: tmpDir});
243
+
244
+ expect(result.data.packable).toBe(false);
245
+ expect(result.data.issues).toContainEqual(
246
+ expect.objectContaining({
247
+ code: 'template_import_unresolvable',
248
+ message: expect.stringContaining('account-page'),
249
+ }),
250
+ );
251
+ });
252
+
253
+ it('passes generated component and template source through exact packed exports', async () => {
254
+ fs.writeFileSync(
255
+ path.join(tmpDir, 'package.json'),
256
+ `${JSON.stringify({
257
+ name: '@acme/widgets',
258
+ version: '1.0.0',
259
+ files: ['index.mjs'],
260
+ exports: {'.': './index.mjs'},
261
+ })}\n`,
262
+ );
263
+ fs.writeFileSync(
264
+ path.join(tmpDir, 'index.mjs'),
265
+ 'export const existing = 1;\n',
266
+ );
267
+ await integrationAddComponent('AcmeWidget', {cwd: tmpDir});
268
+ await integrationAddTemplate('account-page', {cwd: tmpDir, type: 'page'});
269
+
270
+ const result = await integrationPackCheck({cwd: tmpDir});
271
+
272
+ expect(result.data.packable).toBe(true);
273
+ expect(result.data.issues).not.toContainEqual(
274
+ expect.objectContaining({code: 'component_export_missing'}),
275
+ );
276
+ expect(result.data.issues).not.toContainEqual(
277
+ expect.objectContaining({code: 'template_import_unresolvable'}),
278
+ );
279
+ });
280
+
281
+ it('errors when a root directory is excluded from files[]', async () => {
282
+ // Include manifest but NOT themes
283
+ writePackage({files: ['astryx.integration.mjs']});
284
+ const result = await integrationPackCheck({cwd: tmpDir});
285
+
286
+ expect(result.data.packable).toBe(false);
287
+ const rootError = result.data.issues.find(
288
+ i => i.code === 'root_not_packed',
289
+ );
290
+ expect(rootError).toBeDefined();
291
+ expect(rootError.message).toContain('themes');
292
+ });
293
+
294
+ it('errors when .npmignore excludes a contribution', async () => {
295
+ writePackage({npmignore: 'themes/\n'});
296
+ const result = await integrationPackCheck({cwd: tmpDir});
297
+
298
+ expect(result.data.packable).toBe(false);
299
+ const fileErrors = result.data.issues.filter(
300
+ i => i.code === 'root_not_packed' || i.code === 'file_not_packed',
301
+ );
302
+ expect(fileErrors.length).toBeGreaterThan(0);
303
+ });
304
+
305
+ it('passes when package.json has no files field', async () => {
306
+ writePackage({files: undefined});
307
+ const result = await integrationPackCheck({cwd: tmpDir});
308
+
309
+ // No files field → npm includes everything
310
+ expect(result.data.packable).toBe(true);
311
+ });
312
+
313
+ it('detects a lifecycle script that changes the packed identity', async () => {
314
+ const script = [
315
+ "const fs=require('fs')",
316
+ "fs.renameSync('themes/ocean','themes/storm')",
317
+ "const p='themes/manifest.json'",
318
+ 'const x=JSON.parse(fs.readFileSync(p))',
319
+ "x.themes[0].slug='storm'",
320
+ 'fs.writeFileSync(p,JSON.stringify(x))',
321
+ ].join(';');
322
+ writePackage({
323
+ files: ['astryx.integration.mjs', 'themes'],
324
+ scripts: {prepack: `node -e "${script}"`},
325
+ });
326
+
327
+ const result = await integrationPackCheck({cwd: tmpDir});
328
+
329
+ expect(result.data.packable).toBe(false);
330
+ expect(
331
+ result.data.issues.find(issue => issue.code === 'identity_not_packed')
332
+ ?.message,
333
+ ).toContain('ocean');
334
+ expect(
335
+ result.data.issues.find(
336
+ issue => issue.code === 'packed_identity_unexpected',
337
+ )?.message,
338
+ ).toContain('storm');
339
+ });
340
+
341
+ it('rejects a declared root with no contribution files', async () => {
342
+ writePackage({
343
+ manifest: "export default {docs: './docs'};\n",
344
+ files: ['astryx.integration.mjs', 'docs'],
345
+ themes: false,
346
+ });
347
+ fs.mkdirSync(path.join(tmpDir, 'docs'));
348
+
349
+ const result = await integrationPackCheck({cwd: tmpDir});
350
+
351
+ expect(result.data.packable).toBe(false);
352
+ expect(
353
+ result.data.issues.some(
354
+ issue => issue.code === 'empty_contribution_root',
355
+ ),
356
+ ).toBe(true);
357
+ });
358
+
359
+ it('handles scoped package extraction correctly', async () => {
360
+ writePackage({
361
+ name: '@my-org/deep-integration',
362
+ files: ['astryx.integration.mjs', 'themes'],
363
+ });
364
+ const result = await integrationPackCheck({cwd: tmpDir});
365
+
366
+ expect(result.data.name).toBe('@my-org/deep-integration');
367
+ expect(result.data.packable).toBe(true);
368
+ });
369
+
370
+ it('reports source-only component candidates as warnings', async () => {
371
+ writePackage({
372
+ manifest:
373
+ "export default {themes: './themes', components: './components'};\n",
374
+ files: ['astryx.integration.mjs', 'themes', 'components'],
375
+ components: true,
376
+ });
377
+ const result = await integrationPackCheck({cwd: tmpDir});
378
+
379
+ const sourceWarnings = result.data.issues.filter(
380
+ issue => issue.code === 'source_without_component_doc',
381
+ );
382
+ // Card.tsx is PascalCase but has no doc metadata → warning
383
+ expect(sourceWarnings.length).toBeGreaterThanOrEqual(1);
384
+ expect(sourceWarnings[0].severity).toBe('warning');
385
+ expect(sourceWarnings[0].message).toContain('Card.tsx');
386
+ });
387
+
388
+ it('cleans up its scratch consumer when npm pack fails', async () => {
389
+ writePackage({
390
+ files: ['astryx.integration.mjs', 'themes'],
391
+ scripts: {prepack: 'node -e "process.exit(17)"'},
392
+ });
393
+
394
+ const result = await integrationPackCheck({cwd: tmpDir});
395
+
396
+ expect(result.data.packable).toBe(false);
397
+ expect(result.data.issues.some(issue => issue.code === 'pack_failed')).toBe(
398
+ true,
399
+ );
400
+ expect(
401
+ fs
402
+ .readdirSync(tmpDir)
403
+ .filter(name => name.startsWith('.astryx-pack-check-')),
404
+ ).toEqual([]);
405
+ });
406
+
407
+ it('cleans up its scratch consumer after a successful check', async () => {
408
+ writePackage({files: ['astryx.integration.mjs', 'themes']});
409
+
410
+ const result = await integrationPackCheck({cwd: tmpDir});
411
+
412
+ expect(result.data.packable).toBe(true);
413
+ expect(
414
+ fs
415
+ .readdirSync(tmpDir)
416
+ .filter(name => name.startsWith('.astryx-pack-check-')),
417
+ ).toEqual([]);
418
+ });
419
+
420
+ it('rejects malformed npm pack output without a raw TypeError', () => {
421
+ expect(() =>
422
+ parseNpmPackOutput(
423
+ JSON.stringify([
424
+ {filename: 'pkg.tgz', entryCount: 1, size: 1, unpackedSize: 1},
425
+ ]),
426
+ ),
427
+ ).toThrow(/without a files array/);
428
+ });
429
+
430
+ it('reports npm missing from PATH as pack_failed', async () => {
431
+ writePackage({files: ['astryx.integration.mjs', 'themes']});
432
+ const originalPath = process.env.PATH;
433
+ process.env.PATH = '';
434
+ try {
435
+ const result = await integrationPackCheck({cwd: tmpDir});
436
+ expect(result.data.packable).toBe(false);
437
+ expect(result.data.issues).toContainEqual(
438
+ expect.objectContaining({
439
+ code: 'pack_failed',
440
+ message: expect.stringContaining('Could not start npm pack'),
441
+ }),
442
+ );
443
+ } finally {
444
+ process.env.PATH = originalPath;
445
+ }
446
+ });
447
+
448
+ it('does not execute shell metacharacters embedded in the cwd', async () => {
449
+ const marker = path.join(process.cwd(), 'astryx-pack-check-injected');
450
+ fs.rmSync(marker, {force: true});
451
+ const weirdDir = fs.mkdtempSync(
452
+ path.join(process.cwd(), '.astryx-;touch astryx-pack-check-injected;#-'),
453
+ );
454
+ try {
455
+ const pkg = {name: 'safe-pkg', version: '1.0.0'};
456
+ fs.writeFileSync(
457
+ path.join(weirdDir, 'package.json'),
458
+ JSON.stringify(pkg),
459
+ );
460
+ fs.writeFileSync(
461
+ path.join(weirdDir, 'astryx.integration.mjs'),
462
+ 'export default {};\n',
463
+ );
464
+ const result = await integrationPackCheck({cwd: weirdDir});
465
+ expect(result.type).toBe('integration.pack-check');
466
+ expect(fs.existsSync(marker)).toBe(false);
467
+ } finally {
468
+ fs.rmSync(weirdDir, {recursive: true, force: true});
469
+ fs.rmSync(marker, {force: true});
470
+ }
471
+ });
472
+
473
+ it('returns early with issues for a directory without package.json', async () => {
474
+ const emptyDir = fs.mkdtempSync(
475
+ path.join(os.tmpdir(), 'astryx-pack-check-empty-'),
476
+ );
477
+ try {
478
+ const result = await integrationPackCheck({cwd: emptyDir});
479
+ expect(result.data.packable).toBe(false);
480
+ expect(result.data.issues.some(i => i.code === 'no_package')).toBe(true);
481
+ } finally {
482
+ fs.rmSync(emptyDir, {recursive: true, force: true});
483
+ }
484
+ });
485
+
486
+ it('reports malformed package.json instead of treating it as missing', async () => {
487
+ fs.writeFileSync(path.join(tmpDir, 'package.json'), '{bad-json');
488
+ fs.writeFileSync(
489
+ path.join(tmpDir, 'astryx.integration.mjs'),
490
+ 'export default {};\n',
491
+ );
492
+
493
+ const result = await integrationPackCheck({cwd: tmpDir});
494
+
495
+ expect(result.data.packable).toBe(false);
496
+ expect(result.data.issues).toContainEqual(
497
+ expect.objectContaining({code: 'invalid_package_json'}),
498
+ );
499
+ });
500
+
501
+ it('returns early with issues for a package without a manifest', async () => {
502
+ fs.writeFileSync(
503
+ path.join(tmpDir, 'package.json'),
504
+ '{"name":"bare-pkg","version":"1.0.0"}\n',
505
+ );
506
+ const result = await integrationPackCheck({cwd: tmpDir});
507
+
508
+ expect(result.data.packable).toBe(false);
509
+ expect(result.data.issues.some(i => i.code === 'missing_manifest')).toBe(
510
+ true,
511
+ );
512
+ });
513
+ });
514
+
515
+ describe('pack-check mutation tests', () => {
516
+ it('detects when a theme file is deleted after initial add', async () => {
517
+ writePackage({files: ['astryx.integration.mjs', 'themes']});
518
+
519
+ // Write a second theme file then delete it — catalog still references it
520
+ const catalog = JSON.parse(
521
+ fs.readFileSync(path.join(tmpDir, 'themes', 'manifest.json'), 'utf-8'),
522
+ );
523
+ catalog.themes[0].files.push('tokens.ts');
524
+ fs.writeFileSync(
525
+ path.join(tmpDir, 'themes', 'manifest.json'),
526
+ JSON.stringify(catalog, null, 2) + '\n',
527
+ );
528
+ // tokens.ts doesn't exist on disk → will be in inventory but not on disk
529
+ // (Phase 1 catches this; the file won't be in the pack list either)
530
+
531
+ const result = await integrationPackCheck({cwd: tmpDir});
532
+ expect(result.data.packable).toBe(false);
533
+ });
534
+
535
+ it('detects when files[] is narrowed after add removes themes', async () => {
536
+ // First: valid package
537
+ writePackage({files: ['astryx.integration.mjs', 'themes']});
538
+
539
+ // Narrow files to exclude themes
540
+ const pkg = JSON.parse(
541
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
542
+ );
543
+ pkg.files = ['astryx.integration.mjs'];
544
+ fs.writeFileSync(
545
+ path.join(tmpDir, 'package.json'),
546
+ JSON.stringify(pkg, null, 2) + '\n',
547
+ );
548
+
549
+ const result = await integrationPackCheck({cwd: tmpDir});
550
+ expect(result.data.packable).toBe(false);
551
+ expect(result.data.issues.some(i => i.code === 'root_not_packed')).toBe(
552
+ true,
553
+ );
554
+ });
555
+
556
+ it('correctly counts packed vs expected files in inventory', async () => {
557
+ writePackage({files: ['astryx.integration.mjs', 'themes']});
558
+ const result = await integrationPackCheck({cwd: tmpDir});
559
+
560
+ expect(result.data.inventory.expectedFiles).toBeGreaterThan(0);
561
+ expect(result.data.inventory.packedFiles).toBe(
562
+ result.data.inventory.expectedFiles,
563
+ );
564
+ for (const root of result.data.inventory.roots) {
565
+ expect(root.complete).toBe(true);
566
+ expect(root.missingFiles).toEqual([]);
567
+ }
568
+ });
569
+ });
@@ -0,0 +1,45 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ export type IntegrationPackCheckOptions = {
5
+ cwd?: string | undefined;
6
+ };
7
+ export type IntegrationPackCheckResponse = {
8
+ type: "integration.pack-check";
9
+ data: PackCheckData;
10
+ };
11
+ export type PackCheckResponse = IntegrationPackCheckResponse;
12
+ export type PackCheckData = {
13
+ name: string | null;
14
+ version: string | null;
15
+ /**
16
+ * — true when zero error-severity issues
17
+ */
18
+ packable: boolean;
19
+ tarball: PackCheckTarball | null;
20
+ inventory: PackCheckInventory;
21
+ contributions: {
22
+ local: import("../../foundation/integrations/contribution-inventory.mjs").ContributionIdentities | null;
23
+ packed: import("../../foundation/integrations/contribution-inventory.mjs").ContributionIdentities | null;
24
+ };
25
+ issues: import("../../foundation/integrations/issue").AstryxIntegrationIssue[];
26
+ };
27
+ export type PackCheckTarball = {
28
+ filename: string;
29
+ fileCount: number;
30
+ size: number;
31
+ unpackedSize: number;
32
+ };
33
+ export type PackCheckInventory = {
34
+ manifest: string | null;
35
+ roots: PackCheckInventoryRoot[];
36
+ expectedFiles: number;
37
+ packedFiles: number;
38
+ };
39
+ export type PackCheckInventoryRoot = {
40
+ kind: "themes" | "components" | "templates" | "codemods" | "docs";
41
+ path: string;
42
+ expectedFiles: number;
43
+ missingFiles: string[];
44
+ complete: boolean;
45
+ };
@@ -0,0 +1,56 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Colocated types for `astryx integration pack --check`.
5
+ */
6
+
7
+ /**
8
+ * @typedef {object} IntegrationPackCheckOptions
9
+ * @property {string} [cwd]
10
+ */
11
+
12
+ /**
13
+ * @typedef {object} IntegrationPackCheckResponse
14
+ * @property {'integration.pack-check'} type
15
+ * @property {PackCheckData} data
16
+ */
17
+
18
+ /** @typedef {IntegrationPackCheckResponse} PackCheckResponse */
19
+
20
+ /**
21
+ * @typedef {object} PackCheckData
22
+ * @property {string|null} name
23
+ * @property {string|null} version
24
+ * @property {boolean} packable — true when zero error-severity issues
25
+ * @property {PackCheckTarball|null} tarball
26
+ * @property {PackCheckInventory} inventory
27
+ * @property {{local: import('../../foundation/integrations/contribution-inventory.mjs').ContributionIdentities|null, packed: import('../../foundation/integrations/contribution-inventory.mjs').ContributionIdentities|null}} contributions
28
+ * @property {import('../../foundation/integrations/issue').AstryxIntegrationIssue[]} issues
29
+ */
30
+
31
+ /**
32
+ * @typedef {object} PackCheckTarball
33
+ * @property {string} filename
34
+ * @property {number} fileCount
35
+ * @property {number} size
36
+ * @property {number} unpackedSize
37
+ */
38
+
39
+ /**
40
+ * @typedef {object} PackCheckInventory
41
+ * @property {string|null} manifest
42
+ * @property {PackCheckInventoryRoot[]} roots
43
+ * @property {number} expectedFiles
44
+ * @property {number} packedFiles
45
+ */
46
+
47
+ /**
48
+ * @typedef {object} PackCheckInventoryRoot
49
+ * @property {'themes'|'components'|'templates'|'codemods'|'docs'} kind
50
+ * @property {string} path
51
+ * @property {number} expectedFiles
52
+ * @property {string[]} missingFiles
53
+ * @property {boolean} complete
54
+ */
55
+
56
+ export {};
@@ -0,0 +1,21 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+ import * as api from '../index.mjs';
5
+
6
+ describe('integration authoring public API', () => {
7
+ it('exports the generic dispatcher, every per-kind writer, and pack-check', () => {
8
+ for (const name of [
9
+ 'integrationAdd',
10
+ 'integrationAddComponent',
11
+ 'integrationAddDoc',
12
+ 'integrationAddTemplate',
13
+ 'integrationAddCodemod',
14
+ 'integrationAddAgentDoc',
15
+ 'integrationAddTheme',
16
+ 'integrationPackCheck',
17
+ ]) {
18
+ expect(api[name], name).toBeTypeOf('function');
19
+ }
20
+ });
21
+ });