@astryxdesign/cli 0.6.3-canary.98a2e4e → 0.6.3-canary.a860a50

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 (291) hide show
  1. package/README.md +32 -18
  2. package/api/build/build.doc.mjs +3 -3
  3. package/api/build/build.test.mjs +14 -3
  4. package/api/build/build.type.d.mts +36 -2
  5. package/api/build/build.type.mjs +25 -4
  6. package/api/build/help/help.d.mts +8 -5
  7. package/api/build/help/help.mjs +56 -6
  8. package/api/component/component.doc.mjs +11 -2
  9. package/api/component/component.mjs +29 -0
  10. package/api/component/component.test.mjs +38 -0
  11. package/api/component/component.type.d.mts +17 -7
  12. package/api/component/component.type.mjs +27 -20
  13. package/api/discover/discover.doc.mjs +1 -1
  14. package/api/discover/discover.type.d.mts +4 -4
  15. package/api/discover/discover.type.mjs +10 -10
  16. package/api/docs/_adapter.d.mts +30 -27
  17. package/api/docs/_adapter.mjs +154 -124
  18. package/api/docs/compiled-topics.test.mjs +78 -0
  19. package/api/docs/detail/detail.d.mts +0 -15
  20. package/api/docs/detail/detail.mjs +14 -78
  21. package/api/docs/detail/section/section.mjs +22 -18
  22. package/api/docs/detail/section/section.test.mjs +4 -3
  23. package/api/docs/docs.type.d.mts +4 -4
  24. package/api/docs/docs.type.mjs +10 -10
  25. package/api/docs/index/index.mjs +6 -5
  26. package/api/doctor/doctor.mjs +3 -7
  27. package/api/gap-report/gap-report.doc.mjs +7 -4
  28. package/api/hook/hook.type.d.mts +3 -3
  29. package/api/hook/hook.type.mjs +11 -11
  30. package/api/init/init.doc.mjs +4 -0
  31. package/api/init/init.test.mjs +41 -1
  32. package/api/init/remove/remove.mjs +1 -1
  33. package/api/init/run/run.mjs +20 -10
  34. package/api/integration/add-contribution.component-names.test.mjs +120 -0
  35. package/api/integration/add-contribution.mjs +16 -3
  36. package/api/integration/add-contribution.test.mjs +84 -4
  37. package/api/integration/integrationAdd.doc.mjs +7 -4
  38. package/api/integration/integrationAddComponent.doc.mjs +1 -1
  39. package/api/integration/pack-check.mjs +49 -7
  40. package/api/integration/pack-check.test.mjs +249 -0
  41. package/api/integration/validate-integration.mjs +2 -0
  42. package/api/integration/validate-integration.test.mjs +91 -0
  43. package/api/integration/validateIntegration.doc.mjs +1 -1
  44. package/api/json/envelope-types.test.mjs +76 -0
  45. package/api/json/parseResponse.doc.mjs +2 -2
  46. package/api/layout/expand/expand.mjs +7 -5
  47. package/api/layout/expand/expand.path-safety.test.mjs +53 -0
  48. package/api/layout/grammar/grammar.mjs +2 -1
  49. package/api/layout/layoutExpand.doc.mjs +1 -1
  50. package/api/search/search-return-type.test.mjs +54 -0
  51. package/api/search/search.d.mts +2 -9
  52. package/api/search/search.doc.mjs +5 -1
  53. package/api/search/search.mjs +15 -8
  54. package/api/search/search.test.mjs +34 -0
  55. package/api/search/search.type.d.mts +1 -1
  56. package/api/search/search.type.mjs +1 -1
  57. package/api/swizzle/copy/copy.mjs +28 -11
  58. package/api/swizzle/swizzle.doc.mjs +1 -1
  59. package/api/swizzle/swizzle.type.d.mts +2 -2
  60. package/api/swizzle/swizzle.type.mjs +2 -2
  61. package/api/template/copy/copy.mjs +17 -23
  62. package/api/template/copy/copy.test.mjs +17 -0
  63. package/api/template/template.doc.mjs +2 -1
  64. package/api/template/template.type.d.mts +5 -5
  65. package/api/template/template.type.mjs +12 -12
  66. package/api/theme/add/add.binary.test.mjs +91 -0
  67. package/api/theme/add/add.mjs +15 -2
  68. package/api/theme/build/build.mjs +133 -42
  69. package/api/theme/build/build.public-component-vars.test.mjs +1 -1
  70. package/api/theme/build/build.receipt-doc.test.mjs +111 -0
  71. package/api/theme/build/build.test.mjs +127 -0
  72. package/api/theme/build/font-warning.mjs +3 -3
  73. package/api/theme/build/font-warning.test.mjs +5 -2
  74. package/api/theme/palette/generate/generate.mjs +8 -3
  75. package/api/theme/palette/generate/generate.test.mjs +96 -0
  76. package/api/theme/palette/generate/generator.d.mts +10 -13
  77. package/api/theme/palette/generate/generator.mjs +15 -4
  78. package/api/theme/palette/generate/generator.test.mjs +10 -0
  79. package/api/theme/template/template.mjs +11 -2
  80. package/api/theme/template/template.test.mjs +15 -0
  81. package/api/theme/theme.type.d.mts +170 -11
  82. package/api/theme/theme.type.mjs +94 -27
  83. package/api/theme/themeBuild.doc.mjs +7 -4
  84. package/api/theme/themeTemplate.doc.mjs +4 -1
  85. package/api/upgrade/_adapter.mjs +27 -4
  86. package/api/upgrade/list/list.mjs +2 -1
  87. package/api/upgrade/list/list.test.mjs +73 -0
  88. package/api/upgrade/status/status.mjs +2 -2
  89. package/api/upgrade/upgrade.doc.mjs +2 -1
  90. package/api/upgrade/upgrade.type.d.mts +8 -4
  91. package/api/upgrade/upgrade.type.mjs +11 -10
  92. package/assets/codemods/integration-discovery.mjs +40 -2
  93. package/assets/codemods/integration-discovery.test.mjs +58 -0
  94. package/assets/codemods/term-log.mjs +32 -8
  95. package/assets/codemods/term-log.test.mjs +19 -1
  96. package/assets/codemods/transforms/v0.3.0/__tests__/unwrap-authoring-factories.test.mjs +27 -5
  97. package/assets/codemods/transforms/v0.3.0/unwrap-authoring-factories.mjs +20 -5
  98. package/assets/codemods/transforms/v0.6.0/__tests__/next-codemods.test.mjs +47 -0
  99. package/assets/codemods/transforms/v0.6.0/rename-resizable-pixel-bounds.mjs +57 -10
  100. package/assets/docs/cli-integrations.doc.mjs +9 -0
  101. package/assets/docs/styling-libraries.doc.mjs +1 -1
  102. package/assets/docs/working-with-ai.doc.mjs +1 -1
  103. package/assets/templates/pages/table-tree/page.tsx +1704 -0
  104. package/assets/templates/pages/table-tree/template.doc.mjs +12 -0
  105. package/authoring/_shared/contract.ts +22 -0
  106. package/authoring/codemod/codemod.doc.mjs +6 -1
  107. package/authoring/codemod/parse.d.mts +8 -8
  108. package/authoring/codemod/parse.mjs +8 -6
  109. package/authoring/config/config.doc.mjs +1 -1
  110. package/authoring/config/debug-composition.test.mjs +92 -0
  111. package/authoring/config/parse.d.mts +13 -13
  112. package/authoring/config/parse.mjs +8 -8
  113. package/authoring/config/type.ts +18 -6
  114. package/authoring/debug/parse.d.mts +4 -4
  115. package/authoring/debug/parse.mjs +3 -3
  116. package/authoring/doctypes/_schema.d.mts +121 -11
  117. package/authoring/doctypes/_schema.mjs +144 -13
  118. package/authoring/doctypes/base/graph-fields.doc.mjs +11 -4
  119. package/authoring/doctypes/base/type.ts +8 -4
  120. package/authoring/doctypes/command/command.doc.mjs +3 -2
  121. package/authoring/doctypes/command/parse.d.mts +2 -2
  122. package/authoring/doctypes/command/parse.mjs +1 -1
  123. package/authoring/doctypes/command/type.ts +2 -2
  124. package/authoring/doctypes/component/component.doc.mjs +5 -2
  125. package/authoring/doctypes/component/parse.d.mts +2 -2
  126. package/authoring/doctypes/component/parse.mjs +1 -1
  127. package/authoring/doctypes/component/type.ts +1 -1
  128. package/authoring/doctypes/enum/parse.d.mts +2 -2
  129. package/authoring/doctypes/enum/parse.mjs +1 -1
  130. package/authoring/doctypes/enum/type.ts +1 -1
  131. package/authoring/doctypes/function/function.doc.mjs +4 -0
  132. package/authoring/doctypes/function/parse.d.mts +2 -2
  133. package/authoring/doctypes/function/parse.mjs +1 -1
  134. package/authoring/doctypes/function/type.ts +1 -1
  135. package/authoring/doctypes/hook/hook.doc.mjs +4 -0
  136. package/authoring/doctypes/hook/parse.d.mts +2 -2
  137. package/authoring/doctypes/hook/parse.mjs +1 -1
  138. package/authoring/doctypes/hook/type.ts +1 -1
  139. package/authoring/doctypes/legacy.d.mts +6 -6
  140. package/authoring/doctypes/legacy.mjs +3 -3
  141. package/authoring/doctypes/load-contract.test.mjs +207 -0
  142. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -3
  143. package/authoring/doctypes/namespace/parse.d.mts +2 -2
  144. package/authoring/doctypes/namespace/parse.mjs +1 -1
  145. package/authoring/doctypes/namespace/type.ts +2 -2
  146. package/authoring/doctypes/parse.d.mts +18 -18
  147. package/authoring/doctypes/parse.mjs +9 -9
  148. package/authoring/doctypes/reference/parse.d.mts +2 -2
  149. package/authoring/doctypes/reference/parse.mjs +1 -1
  150. package/authoring/doctypes/reference/reference.doc.mjs +6 -2
  151. package/authoring/doctypes/reference/type.ts +1 -1
  152. package/authoring/doctypes/schema/parse.d.mts +2 -2
  153. package/authoring/doctypes/schema/parse.mjs +1 -1
  154. package/authoring/doctypes/schema/type.ts +2 -2
  155. package/authoring/doctypes/template/parse.d.mts +92 -1
  156. package/authoring/doctypes/template/parse.mjs +33 -1
  157. package/authoring/doctypes/template/template.doc.mjs +4 -0
  158. package/authoring/doctypes/template/type.ts +4 -1
  159. package/authoring/doctypes/types.ts +10 -10
  160. package/authoring/gap-report/parse.d.mts +9 -9
  161. package/authoring/gap-report/parse.mjs +6 -6
  162. package/authoring/gap-report/type.ts +1 -1
  163. package/authoring/identity/identity.doc.mjs +3 -2
  164. package/authoring/identity/type.ts +10 -10
  165. package/authoring/index.d.ts +19 -19
  166. package/authoring/integration/parse.d.mts +2 -2
  167. package/authoring/integration/parse.mjs +1 -1
  168. package/authoring/integration/schema.d.mts +4 -4
  169. package/authoring/integration/schema.mjs +3 -3
  170. package/authoring/integration/type.ts +1 -1
  171. package/clients/cli/command-load-failure.test.mjs +83 -0
  172. package/clients/cli/commands/blog.mjs +23 -8
  173. package/clients/cli/commands/blog.test.mjs +42 -1
  174. package/clients/cli/commands/build-theme.ascii-output.test.mjs +161 -0
  175. package/clients/cli/commands/build-theme.flag-docs.test.mjs +110 -0
  176. package/clients/cli/commands/build-theme.mjs +5 -5
  177. package/clients/cli/commands/build-theme.path-safety.test.mjs +86 -1
  178. package/clients/cli/commands/build-theme.variants.test.mjs +76 -0
  179. package/clients/cli/commands/build.doc.mjs +4 -1
  180. package/clients/cli/commands/build.exit-codes-doc.test.mjs +50 -0
  181. package/clients/cli/commands/build.mjs +32 -47
  182. package/clients/cli/commands/build.playbook.test.mjs +75 -0
  183. package/clients/cli/commands/build.text-fields.test.mjs +40 -0
  184. package/clients/cli/commands/component/index.mjs +2 -7
  185. package/clients/cli/commands/component-package.test.mjs +18 -0
  186. package/clients/cli/commands/component-resolution.test.mjs +21 -0
  187. package/clients/cli/commands/component.test.mjs +19 -0
  188. package/clients/cli/commands/detail-levels.test.mjs +2 -2
  189. package/clients/cli/commands/discover.broken-integration.test.mjs +48 -0
  190. package/clients/cli/commands/discover.components-flag.test.mjs +97 -0
  191. package/clients/cli/commands/discover.doc.mjs +4 -2
  192. package/clients/cli/commands/discover.mjs +3 -3
  193. package/clients/cli/commands/discover.text-projection.test.mjs +103 -0
  194. package/clients/cli/commands/doctor-integration.package-json.test.mjs +53 -0
  195. package/clients/cli/commands/doctor.mjs +6 -16
  196. package/clients/cli/commands/doctor.test.mjs +42 -0
  197. package/clients/cli/commands/gap-report.doc.mjs +16 -5
  198. package/clients/cli/commands/gap-report.test.mjs +72 -0
  199. package/clients/cli/commands/hook/index.mjs +7 -17
  200. package/clients/cli/commands/hook.text-projection.test.mjs +45 -0
  201. package/clients/cli/commands/init.doc.mjs +19 -8
  202. package/clients/cli/commands/init.flag-help.test.mjs +153 -0
  203. package/clients/cli/commands/integration-add.controls.test.mjs +132 -0
  204. package/clients/cli/commands/integration-add.doc.mjs +21 -5
  205. package/clients/cli/commands/integration-authoring.test.mjs +13 -9
  206. package/clients/cli/commands/interactive-guard.test.mjs +101 -24
  207. package/clients/cli/commands/json-contract.test.mjs +33 -0
  208. package/clients/cli/commands/layout-check.doc.mjs +14 -3
  209. package/clients/cli/commands/layout-expand.doc.mjs +21 -4
  210. package/clients/cli/commands/layout.doc.mjs +2 -2
  211. package/clients/cli/commands/layout.mjs +21 -9
  212. package/clients/cli/commands/layout.path-help.test.mjs +33 -0
  213. package/clients/cli/commands/layout.stdin-cap.test.mjs +47 -0
  214. package/clients/cli/commands/layout.text-fields.test.mjs +39 -0
  215. package/clients/cli/commands/no-prompt-wording.test.mjs +94 -0
  216. package/clients/cli/commands/search.doc.mjs +5 -2
  217. package/clients/cli/commands/search.mjs +13 -2
  218. package/clients/cli/commands/search.test.mjs +61 -0
  219. package/clients/cli/commands/swizzle.doc.mjs +2 -1
  220. package/clients/cli/commands/swizzle.path-safety.test.mjs +42 -0
  221. package/clients/cli/commands/template.doc.mjs +28 -6
  222. package/clients/cli/commands/template.flag-help.test.mjs +117 -0
  223. package/clients/cli/commands/template.path-help.test.mjs +40 -0
  224. package/clients/cli/commands/theme-add.doc.mjs +2 -1
  225. package/clients/cli/commands/theme-build.doc.mjs +7 -6
  226. package/clients/cli/commands/theme-palette-generate.test.mjs +19 -0
  227. package/clients/cli/commands/theme-template.behavior.test.mjs +12 -0
  228. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  229. package/clients/cli/commands/upgrade.ascii-output.test.mjs +87 -0
  230. package/clients/cli/commands/upgrade.doc.mjs +17 -6
  231. package/clients/cli/commands/upgrade.flag-help.test.mjs +188 -0
  232. package/clients/cli/commands/upgrade.hook-output.test.mjs +88 -0
  233. package/clients/cli/index.mjs +13 -30
  234. package/clients/cli/latest-version-env.test.mjs +50 -0
  235. package/clients/cli/lib/cli-error.test.mjs +7 -0
  236. package/clients/cli/lib/component-format.mjs +9 -9
  237. package/clients/cli/lib/component-format.test.mjs +1 -1
  238. package/clients/cli/lib/define-command.mjs +32 -6
  239. package/clients/cli/lib/doc-text-ascii.test.mjs +82 -0
  240. package/clients/cli/lib/exit-codes.test.mjs +97 -0
  241. package/clients/cli/lib/hook-format.mjs +5 -5
  242. package/clients/cli/lib/json-shim.mjs +38 -2
  243. package/clients/cli/lib/json-shim.test.mjs +83 -0
  244. package/clients/cli/lib/manifest.d.ts +2 -0
  245. package/clients/cli/lib/manifest.mjs +22 -0
  246. package/clients/cli/lib/manifest.test.mjs +17 -0
  247. package/foundation/agent-docs/agent-docs.d.mts +4 -0
  248. package/foundation/agent-docs/agent-docs.mjs +69 -3
  249. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +266 -4
  250. package/foundation/config/integration-debug.test.mjs +28 -3
  251. package/foundation/config/project.mjs +123 -9
  252. package/foundation/config/project.test.mjs +126 -0
  253. package/foundation/discovery/authoring-self-docs.test.mjs +71 -12
  254. package/foundation/discovery/docs-discovery.d.mts +4 -0
  255. package/foundation/discovery/docs-discovery.mjs +16 -2
  256. package/foundation/discovery/docs-discovery.test.mjs +47 -11
  257. package/foundation/discovery/template-adapter.d.mts +14 -5
  258. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +248 -0
  259. package/foundation/discovery/template-adapter.integration-isolation.test.mjs +94 -0
  260. package/foundation/discovery/template-adapter.mjs +292 -25
  261. package/foundation/discovery/theming-targets.test.mjs +4 -0
  262. package/foundation/doc-compiler/compile.d.mts +162 -0
  263. package/foundation/doc-compiler/compile.mjs +262 -0
  264. package/foundation/doc-compiler/doc-compiler.test.mjs +687 -0
  265. package/foundation/doc-compiler/ir.d.mts +9 -0
  266. package/foundation/doc-compiler/ir.mjs +287 -0
  267. package/foundation/doc-compiler/lenses.d.mts +33 -0
  268. package/foundation/doc-compiler/lenses.mjs +127 -0
  269. package/foundation/fs/module-loader.d.mts +1 -0
  270. package/foundation/fs/module-loader.mjs +50 -1
  271. package/foundation/fs/module-loader.stdout.test.mjs +332 -0
  272. package/foundation/fs/path-safety.d.mts +3 -2
  273. package/foundation/fs/path-safety.mjs +49 -19
  274. package/foundation/fs/path-safety.test.mjs +50 -0
  275. package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +129 -94
  276. package/foundation/integrations/autolink.mjs +6 -1
  277. package/foundation/response/base.d.ts +8 -4
  278. package/foundation/response/error-codes.doc.mjs +1 -2
  279. package/foundation/response/error-codes.mjs +1 -1
  280. package/foundation/response/error-codes.test.mjs +83 -0
  281. package/foundation/response/json-contract.test.mjs +11 -0
  282. package/foundation/response/json.d.mts +4 -2
  283. package/foundation/response/json.mjs +8 -10
  284. package/foundation/response/response-types.doc.mjs +3 -3
  285. package/foundation/xle/expand.d.mts +2 -0
  286. package/foundation/xle/expand.mjs +3 -2
  287. package/foundation/xle/expand.test.mjs +54 -0
  288. package/package.json +9 -11
  289. package/clients/cli/lib/update-check.mjs +0 -83
  290. package/clients/cli/lib/update-check.test.mjs +0 -137
  291. package/clients/cli/update-hint-commands.test.mjs +0 -54
@@ -17,7 +17,7 @@
17
17
  import * as path from 'node:path';
18
18
  import * as fs from 'node:fs';
19
19
  import {CLI_ROOT} from '../../../foundation/fs/paths.mjs';
20
- import {PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
20
+ import {PathSafetyError, assertWithin} from '../../../foundation/fs/path-safety.mjs';
21
21
  import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
22
22
  import {
23
23
  installAgentDocs,
@@ -98,7 +98,7 @@ async function applyAgents(cwd, options, invocation, data) {
98
98
  renderedBlock,
99
99
  });
100
100
  data.docsWritten = written;
101
- logger.log(`✓ AI agent docs installed → ${written.join(', ')}`);
101
+ logger.log(`[ok] AI agent docs installed -> ${written.join(', ')}`);
102
102
  } catch (err) {
103
103
  // PathSafetyError carries a precise, user-actionable message — surface it
104
104
  // (and flag exit 1) instead of the generic "could not install" warning so
@@ -132,8 +132,8 @@ function applyTheme(cwd, invocation, data) {
132
132
  data.themeTemplatePath = didWrite ? written : null;
133
133
  logger.log(
134
134
  didWrite
135
- ? `✓ Theme template written → ${written}`
136
- : `• ${written} already exists — left as is.`,
135
+ ? `[ok] Theme template written -> ${written}`
136
+ : `- ${written} already exists - left as is.`,
137
137
  );
138
138
  } catch {
139
139
  // Soft failure, like agent docs: the guidance below is still useful.
@@ -166,16 +166,16 @@ function applyTemplate(cwd, {templateName}, invocation, data) {
166
166
  // Point agents at the build workflow rather than dumping page-template
167
167
  // names — `build` surfaces pages AND blocks AND components for an idea,
168
168
  // and `build` with no args is the full how-to-build playbook.
169
- logger.log('✓ To build UI, use these commands:');
169
+ logger.log('[ok] To build UI, use these commands:');
170
170
  logger.log('');
171
171
  logger.log(
172
- ` ${invocation} build "<what you're building>" build a page — kit: closest template + blocks + components`,
172
+ ` ${invocation} build "<what you're building>" build a page - kit: closest template + blocks + components`,
173
173
  );
174
174
  logger.log(
175
175
  ` ${invocation} build the how-to-build workflow (read this first)`,
176
176
  );
177
177
  logger.log(
178
- ` ${invocation} search <query> find anything — components, docs, templates, blocks`,
178
+ ` ${invocation} search <query> find anything - components, docs, templates, blocks`,
179
179
  );
180
180
  logger.log('');
181
181
  data.template = 'workflow';
@@ -190,9 +190,19 @@ function applyTemplate(cwd, {templateName}, invocation, data) {
190
190
  );
191
191
  }
192
192
 
193
- const outputDir = path.resolve(cwd, `./src/pages/${templateName}`);
193
+ let destFile;
194
+ try {
195
+ destFile = assertWithin(path.join('src', 'pages', templateName, 'page.tsx'), cwd, {
196
+ label: 'template output path',
197
+ });
198
+ } catch (err) {
199
+ if (err instanceof PathSafetyError) {
200
+ throw new AstryxError(err.message, undefined, ERROR_CODES.ERR_PATH_TRAVERSAL);
201
+ }
202
+ throw err;
203
+ }
204
+ const outputDir = path.dirname(destFile);
194
205
  const srcPath = path.join(CLI_ROOT, 'assets', 'templates', 'pages', templateName, 'page.tsx');
195
- const destFile = path.join(outputDir, 'page.tsx');
196
206
  // Don't clobber a user's existing page — same guard the peer template/copy and
197
207
  // theme/add write-leaves apply (init is a public API surface too).
198
208
  if (fs.existsSync(destFile)) {
@@ -206,7 +216,7 @@ function applyTemplate(cwd, {templateName}, invocation, data) {
206
216
  fs.mkdirSync(outputDir, {recursive: true});
207
217
  fs.copyFileSync(srcPath, destFile);
208
218
  const rel = path.relative(cwd, outputDir);
209
- logger.log(`✓ Template created at ${rel}/page.tsx`);
219
+ logger.log(`[ok] Template created at ${rel}/page.tsx`);
210
220
  data.template = 'created';
211
221
  data.templatePath = rel;
212
222
  }
@@ -0,0 +1,120 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
4
+ import * as fs from 'node:fs';
5
+ import * as path from 'node:path';
6
+ import {integrationAdd, integrationAddComponent} from './add-contribution.mjs';
7
+ import {discoverIntegrationComponents} from '../../foundation/discovery/component-discovery.mjs';
8
+
9
+ let tmpDir;
10
+
11
+ beforeEach(() => {
12
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-add-component-'));
13
+ fs.writeFileSync(
14
+ path.join(tmpDir, 'package.json'),
15
+ `${JSON.stringify({name: '@acme/widgets', version: '1.0.0', files: ['dist']}, null, 2)}\n`,
16
+ );
17
+ fs.writeFileSync(
18
+ path.join(tmpDir, 'astryx.integration.mjs'),
19
+ "export default {\n components: './components',\n};\n",
20
+ );
21
+ });
22
+
23
+ afterEach(() => {
24
+ fs.rmSync(tmpDir, {recursive: true, force: true});
25
+ });
26
+
27
+ /** @param {string} relativeDoc */
28
+ function writeAuthoredComponent(relativeDoc) {
29
+ const doc = path.join(tmpDir, relativeDoc);
30
+ fs.mkdirSync(path.dirname(doc), {recursive: true});
31
+ fs.writeFileSync(
32
+ doc,
33
+ "export default {\n type: 'component',\n name: 'AcmeWidget',\n description: 'The authored AcmeWidget.',\n props: [],\n};\n",
34
+ );
35
+ fs.writeFileSync(
36
+ doc.replace(/\.doc\.(?:ts|mjs|js)$/u, '.tsx'),
37
+ 'export function AcmeWidget() {\n return <div>Authored</div>;\n}\n',
38
+ );
39
+ }
40
+
41
+ /** Every file under the package, with its bytes. */
42
+ function snapshot() {
43
+ /** @type {Record<string, string>} */
44
+ const files = {};
45
+ /** @param {string} dir */
46
+ const walk = dir => {
47
+ for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
48
+ const full = path.join(dir, entry.name);
49
+ if (entry.isDirectory()) walk(full);
50
+ else files[path.relative(tmpDir, full)] = fs.readFileSync(full, 'utf-8');
51
+ }
52
+ };
53
+ walk(tmpDir);
54
+ return files;
55
+ }
56
+
57
+ describe('integrationAddComponent name collisions', () => {
58
+ it('refuses a name a nested component doc already defines', async () => {
59
+ writeAuthoredComponent('components/AcmeWidget/AcmeWidget.doc.mjs');
60
+ const before = snapshot();
61
+
62
+ await expect(
63
+ integrationAddComponent('AcmeWidget', {cwd: tmpDir}),
64
+ ).rejects.toMatchObject({
65
+ code: 'ERR_FILE_EXISTS',
66
+ message: expect.stringContaining(
67
+ 'components/AcmeWidget/AcmeWidget.doc.mjs',
68
+ ),
69
+ });
70
+ expect(snapshot()).toEqual(before);
71
+ expect(
72
+ discoverIntegrationComponents({
73
+ name: '@acme/widgets',
74
+ components: path.join(tmpDir, 'components'),
75
+ }).map(component => path.relative(tmpDir, component.docPath)),
76
+ ).toEqual([path.join('components', 'AcmeWidget', 'AcmeWidget.doc.mjs')]);
77
+ });
78
+
79
+ it('refuses the same collision under --dry-run', async () => {
80
+ writeAuthoredComponent('components/widgets/AcmeWidget.doc.mjs');
81
+
82
+ await expect(
83
+ integrationAdd('component', 'AcmeWidget', {cwd: tmpDir, dryRun: true}),
84
+ ).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
85
+ });
86
+
87
+ it('refuses a same-stem doc with another extension in the root', async () => {
88
+ fs.mkdirSync(path.join(tmpDir, 'components'));
89
+ fs.writeFileSync(
90
+ path.join(tmpDir, 'components', 'AcmeWidget.doc.ts'),
91
+ "export default {type: 'component', name: 'AcmeWidget', props: []};\n",
92
+ );
93
+ const before = snapshot();
94
+
95
+ await expect(
96
+ integrationAddComponent('AcmeWidget', {cwd: tmpDir}),
97
+ ).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
98
+ expect(snapshot()).toEqual(before);
99
+ });
100
+
101
+ it('still adds a component whose name is free', async () => {
102
+ writeAuthoredComponent('components/AcmeWidget/AcmeWidget.doc.mjs');
103
+
104
+ const result = await integrationAddComponent('AcmeBadge', {cwd: tmpDir});
105
+
106
+ expect(result.data.files).toEqual([
107
+ 'components/AcmeBadge.doc.mjs',
108
+ 'components/AcmeBadge.tsx',
109
+ 'package.json',
110
+ ]);
111
+ expect(
112
+ discoverIntegrationComponents({
113
+ name: '@acme/widgets',
114
+ components: path.join(tmpDir, 'components'),
115
+ })
116
+ .map(component => component.name)
117
+ .sort(),
118
+ ).toEqual(['AcmeBadge', 'AcmeWidget']);
119
+ });
120
+ });
@@ -35,6 +35,7 @@ import {
35
35
  } from '../../foundation/integrations/integrations.mjs';
36
36
  import {isValidSemver} from '../../foundation/env/semver.mjs';
37
37
  import {assertContributionVisible} from '../../foundation/integrations/contribution-inventory.mjs';
38
+ import {findIntegrationComponentDoc} from '../../foundation/discovery/component-discovery.mjs';
38
39
  import {parseAgentDocsField} from '../../authoring/integration/schema.mjs';
39
40
  import {integrationAddTheme} from './add-theme.mjs';
40
41
  import {
@@ -248,9 +249,20 @@ async function addComponent(name, options) {
248
249
  ERROR_CODES.ERR_FILE_EXISTS,
249
250
  );
250
251
  }
252
+ // Discovery keys components by doc stem anywhere under the root, so a second
253
+ // doc with this name would shadow one of the two.
254
+ const existingDoc = findIntegrationComponentDoc({components: root}, name);
255
+ if (existingDoc != null) {
256
+ throw new AstryxError(
257
+ `Refusing to add component "${name}": ${projectPath(path.relative(packageDir, existingDoc))} already defines it.`,
258
+ undefined,
259
+ ERROR_CODES.ERR_FILE_EXISTS,
260
+ );
261
+ }
251
262
 
252
263
  const sourcePath = projectPath(path.relative(packageDir, sourceFile));
253
- const importSpecifier = `${owner}/${sourcePath}`;
264
+ const extensionlessPath = sourcePath.replace(/\.tsx?$/u, '');
265
+ const importSpecifier = `${owner}/${extensionlessPath}`;
254
266
  const docContents = `export default {\n type: 'component',\n name: '${name}',\n import: ${JSON.stringify(importSpecifier)},\n description: '${name} component.',\n props: [],\n};\n`;
255
267
  const sourceContents = `export function ${name}() {\n return <div>${name}</div>;\n}\n`;
256
268
 
@@ -263,7 +275,7 @@ async function addComponent(name, options) {
263
275
  packageFile,
264
276
  rootPath,
265
277
  path.basename(manifestFile),
266
- [{subpath: sourcePath, target: sourcePath}],
278
+ [{subpath: extensionlessPath, target: sourcePath}],
267
279
  );
268
280
  if (pkgUpdate != null) {
269
281
  plans.push({
@@ -576,6 +588,7 @@ async function addTemplate(name, options) {
576
588
 
577
589
  const pascalName = kebabToPascal(name);
578
590
  const sourcePath = projectPath(path.relative(packageDir, sourceFile));
591
+ const extensionlessPath = sourcePath.replace(/\.tsx?$/u, '');
579
592
  const specContents = `export default {\n type: '${templateType}',\n name: '${name}',\n description: '${kebabToTitle(name)} template.',\n};\n`;
580
593
  const sourceContents = `export default function ${pascalName}() {\n return <div>${kebabToTitle(name)}</div>;\n}\n`;
581
594
 
@@ -588,7 +601,7 @@ async function addTemplate(name, options) {
588
601
  packageFile,
589
602
  rootPath,
590
603
  path.basename(manifestFile),
591
- [{subpath: sourcePath, target: sourcePath}],
604
+ [{subpath: extensionlessPath, target: sourcePath}],
592
605
  );
593
606
  if (pkgUpdate != null) {
594
607
  plans.push({
@@ -118,14 +118,14 @@ describe('integrationAdd component', () => {
118
118
  );
119
119
  expect(pkg.exports).toEqual({
120
120
  '.': './index.mjs',
121
- './components/MyWidget.tsx': './components/MyWidget.tsx',
121
+ './components/MyWidget': './components/MyWidget.tsx',
122
122
  });
123
123
  expect(
124
124
  fs.readFileSync(
125
125
  path.join(tmpDir, 'components/MyWidget.doc.mjs'),
126
126
  'utf-8',
127
127
  ),
128
- ).toContain('import: "@acme/integration/components/MyWidget.tsx"');
128
+ ).toContain('import: "@acme/integration/components/MyWidget"');
129
129
  });
130
130
 
131
131
  it('does not create exports when the package has no exports map', async () => {
@@ -143,7 +143,7 @@ describe('integrationAdd component', () => {
143
143
  setup({
144
144
  exports: {
145
145
  '.': './index.mjs',
146
- './components/MyWidget.tsx': './different.tsx',
146
+ './components/MyWidget': './different.tsx',
147
147
  },
148
148
  });
149
149
 
@@ -421,7 +421,7 @@ describe('integrationAdd template', () => {
421
421
  );
422
422
  expect(pkg.exports).toEqual({
423
423
  '.': './index.mjs',
424
- './templates/my-widget.tsx': './templates/my-widget.tsx',
424
+ './templates/my-widget': './templates/my-widget.tsx',
425
425
  });
426
426
  });
427
427
 
@@ -731,3 +731,83 @@ describe('public dispatcher', () => {
731
731
  ).rejects.toThrow(/component, doc, template, codemod, agent-doc, or theme/);
732
732
  });
733
733
  });
734
+
735
+ describe('dry-run receipts match the real write', () => {
736
+ /** Package states each writer has to plan for. */
737
+ const STATES = {
738
+ 'no manifest': {pkg: {files: ['dist']}},
739
+ 'an empty manifest': {pkg: {}, manifest: 'export default {};\n'},
740
+ 'declared roots and an exports map': {
741
+ pkg: {files: ['dist'], exports: {'.': './dist/index.js'}},
742
+ manifest:
743
+ "export default {\n components: './components',\n docs: './docs',\n templates: './templates',\n codemods: './codemods',\n themes: './themes',\n};\n",
744
+ },
745
+ };
746
+ /** @type {Array<[any, string, Record<string, unknown>]>} */
747
+ const KINDS = [
748
+ ['component', 'AcmeWidget', {}],
749
+ ['doc', 'deploying', {}],
750
+ ['template', 'account-page', {}],
751
+ ['template', 'account-card', {templateType: 'block'}],
752
+ ['codemod', 'rename-widget', {to: '1.2.0'}],
753
+ ['agent-doc', 'Run acme verify before finishing.', {}],
754
+ ['theme', 'ocean', {}],
755
+ ];
756
+
757
+ /** Every file under the package, keyed by project path, with its bytes. */
758
+ function snapshot() {
759
+ /** @type {Record<string, string>} */
760
+ const files = {};
761
+ /** @param {string} dir */
762
+ const walk = dir => {
763
+ for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
764
+ const full = path.join(dir, entry.name);
765
+ if (entry.isDirectory()) walk(full);
766
+ else {
767
+ files[path.relative(tmpDir, full).split(path.sep).join('/')] =
768
+ fs.readFileSync(full, 'base64');
769
+ }
770
+ }
771
+ };
772
+ walk(tmpDir);
773
+ return files;
774
+ }
775
+
776
+ for (const [stateName, state] of Object.entries(STATES)) {
777
+ for (const [kind, name, options] of KINDS) {
778
+ it(`${kind} ${name} in a package with ${stateName}`, async () => {
779
+ fs.writeFileSync(
780
+ path.join(tmpDir, 'package.json'),
781
+ `${JSON.stringify({name: '@acme/integration', version: '1.0.0', ...state.pkg}, null, 2)}\n`,
782
+ );
783
+ if (state.manifest != null) {
784
+ fs.writeFileSync(
785
+ path.join(tmpDir, 'astryx.integration.mjs'),
786
+ state.manifest,
787
+ );
788
+ }
789
+ const before = snapshot();
790
+
791
+ const plan = await integrationAdd(kind, name, {
792
+ cwd: tmpDir,
793
+ dryRun: true,
794
+ ...options,
795
+ });
796
+ expect(snapshot()).toEqual(before);
797
+
798
+ const written = await integrationAdd(kind, name, {
799
+ cwd: tmpDir,
800
+ ...options,
801
+ });
802
+ const after = snapshot();
803
+ const changed = Object.keys(after)
804
+ .filter(file => after[file] !== before[file])
805
+ .sort();
806
+
807
+ expect(written.data.root).toEqual(plan.data.root);
808
+ expect(written.data.files).toEqual(plan.data.files);
809
+ expect([...written.data.files].sort()).toEqual(changed);
810
+ });
811
+ }
812
+ }
813
+ });
@@ -33,7 +33,8 @@ export const doc = {
33
33
  {
34
34
  name: 'name',
35
35
  type: 'string',
36
- description: 'Contribution name, or the literal agent-doc line.',
36
+ description:
37
+ 'Contribution name: PascalCase for component, lowercase kebab-case for template, codemod, and theme, letters, digits, _ and - for doc, or the literal agent-doc line.',
37
38
  required: true,
38
39
  },
39
40
  {
@@ -56,17 +57,19 @@ export const doc = {
56
57
  {
57
58
  name: 'options.replaces',
58
59
  type: 'string',
59
- description: 'Existing topic to replace. Only valid for doc.',
60
+ description:
61
+ 'Existing topic to replace. Only valid for doc, and not with options.extends.',
60
62
  },
61
63
  {
62
64
  name: 'options.extends',
63
65
  type: 'string',
64
- description: 'Existing topic to extend. Only valid for doc.',
66
+ description:
67
+ 'Existing topic to extend. Only valid for doc, and not with options.replaces.',
65
68
  },
66
69
  {
67
70
  name: 'options.to',
68
71
  type: 'string',
69
- description: 'Exact target semver. Required for codemod.',
72
+ description: 'Exact target semver (e.g. 1.2.0). Required for codemod and only valid there.',
70
73
  },
71
74
  ],
72
75
  returns: [
@@ -8,7 +8,7 @@ export const doc = {
8
8
  displayName: 'integrationAddComponent()',
9
9
  summary: 'Add a complete component contribution.',
10
10
  description:
11
- 'Creates the same-stem component source and metadata pair, declares the components root on first use, preserves existing package allowlists, and publishes an exact source subpath when the package already has an exports map.',
11
+ 'Creates the same-stem component source and metadata pair, declares the components root on first use, preserves existing package allowlists, and publishes an exact source subpath when the package already has an exports map. Refuses with ERR_FILE_EXISTS when a component doc anywhere under the components root already uses the name.',
12
12
  importPath: '@astryxdesign/cli/api',
13
13
  signature:
14
14
  'integrationAddComponent(name: string, options?: IntegrationAddComponentOptions): Promise<IntegrationAddResponse>',
@@ -388,6 +388,14 @@ async function validatePackedComponentExports(integration, scratchBase) {
388
388
  components.map(component => component.specifier),
389
389
  scratchBase,
390
390
  );
391
+ issues.push(
392
+ ...validateSpecifierExtensions(
393
+ components.map(({name, specifier}) => ({
394
+ label: `Component "${name}"`,
395
+ specifier,
396
+ })),
397
+ ),
398
+ );
391
399
  for (const {name, specifier} of components) {
392
400
  const result = resolved.get(specifier);
393
401
  if (!result?.url || result.error) {
@@ -427,19 +435,27 @@ async function validatePackedComponentExports(integration, scratchBase) {
427
435
  */
428
436
  async function validatePackedTemplateExports(integration, scratchBase) {
429
437
  const {templates} = await discoverIntegrationTemplatesForOne(integration);
430
- const entries = templates.map(template => ({
431
- id: template.dirName,
432
- specifier: `${integration.name}/${path
438
+ const entries = templates.map(template => {
439
+ const relPath = path
433
440
  .relative(integration.__packageDir, template.filePath)
434
441
  .split(path.sep)
435
- .join('/')}`,
436
- }));
442
+ .join('/');
443
+ const extensionless = relPath.replace(/\.tsx?$/u, '');
444
+ return {
445
+ id: template.dirName,
446
+ specifier: `${integration.name}/${extensionless}`,
447
+ };
448
+ });
437
449
  const resolved = resolveConsumerSpecifiers(
438
450
  entries.map(entry => entry.specifier),
439
451
  scratchBase,
440
452
  );
441
- /** @type {Issue[]} */
442
- const issues = [];
453
+ const issues = validateSpecifierExtensions(
454
+ entries.map(({id, specifier}) => ({
455
+ label: `Template "${id}"`,
456
+ specifier,
457
+ })),
458
+ );
443
459
  for (const {id, specifier} of entries) {
444
460
  const result = resolved.get(specifier);
445
461
  if (!result?.url || result.error) {
@@ -469,6 +485,32 @@ async function validatePackedTemplateExports(integration, scratchBase) {
469
485
  return issues;
470
486
  }
471
487
 
488
+ const TS_EXTENSION_RE = /\.tsx?$/u;
489
+
490
+ /**
491
+ * Reject specifiers that end in a TypeScript extension — they fail under
492
+ * default `moduleResolution` with TS5097/TS2307 unless the consumer enables
493
+ * `allowImportingTsExtensions`.
494
+ *
495
+ * @param {Array<{label: string, specifier: string}>} entries
496
+ * @returns {Issue[]}
497
+ */
498
+ function validateSpecifierExtensions(entries) {
499
+ /** @type {Issue[]} */
500
+ const issues = [];
501
+ for (const {label, specifier} of entries) {
502
+ if (TS_EXTENSION_RE.test(specifier)) {
503
+ issues.push(
504
+ error(
505
+ 'typescript_extension_in_specifier',
506
+ `${label} advertises import "${specifier}", which ends in a TypeScript extension. A consumer with default moduleResolution will reject it (TS5097). Use an extensionless specifier mapped through the package exports.`,
507
+ ),
508
+ );
509
+ }
510
+ }
511
+ return issues;
512
+ }
513
+
472
514
  /**
473
515
  * Verify an integration package is ready to publish.
474
516
  *