@astryxdesign/cli 0.7.2-canary.ba6a6e2 → 0.7.2-canary.bd72a5f

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 (294) hide show
  1. package/README.md +74 -73
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/component/_adapter.d.mts +72 -1
  4. package/api/component/_adapter.mjs +209 -7
  5. package/api/component/component.mjs +82 -15
  6. package/api/component/component.test.mjs +80 -0
  7. package/api/component/doc-links.test.mjs +386 -0
  8. package/api/component/integration-export-name.test.mjs +644 -0
  9. package/api/component/list/list.mjs +42 -4
  10. package/api/discover/_adapter.d.mts +119 -12
  11. package/api/discover/_adapter.mjs +449 -10
  12. package/api/discover/_adapter.test.mjs +599 -17
  13. package/api/discover/_catalog-view.d.mts +16 -5
  14. package/api/discover/_catalog-view.mjs +32 -8
  15. package/api/discover/detail/doc/doc.mjs +9 -1
  16. package/api/discover/discover.d.mts +11 -0
  17. package/api/discover/discover.doc.mjs +7 -6
  18. package/api/discover/discover.mjs +107 -19
  19. package/api/discover/discover.type.d.mts +18 -7
  20. package/api/discover/discover.type.mjs +15 -7
  21. package/api/discover/list/list.d.mts +4 -3
  22. package/api/discover/list/list.mjs +17 -10
  23. package/api/docs/_adapter.d.mts +74 -0
  24. package/api/docs/_adapter.mjs +550 -14
  25. package/api/docs/integration-tree.test.mjs +22 -0
  26. package/api/docs/integrationDocs.test.mjs +124 -0
  27. package/api/docs/list/list.mjs +12 -2
  28. package/api/doctor/doctor.mjs +27 -3
  29. package/api/doctor/doctor.test.mjs +43 -0
  30. package/api/doctor/theme-checks.mjs +1 -1
  31. package/api/doctor/theme-checks.test.mjs +136 -0
  32. package/api/gap-report/gap-report.d.mts +3 -0
  33. package/api/gap-report/gap-report.doc.mjs +11 -3
  34. package/api/gap-report/gap-report.mjs +219 -52
  35. package/api/gap-report/gap-report.test.mjs +233 -0
  36. package/api/gap-report/gap-report.type.d.mts +41 -0
  37. package/api/gap-report/gap-report.type.mjs +18 -0
  38. package/api/index.d.mts +2 -0
  39. package/api/index.mjs +2 -0
  40. package/api/init/run/run.mjs +2 -2
  41. package/api/integration/_adapter.d.mts +45 -0
  42. package/api/integration/_adapter.mjs +112 -0
  43. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  44. package/api/integration/add-contribution.mjs +8 -4
  45. package/api/integration/add-contribution.test.mjs +4 -2
  46. package/api/integration/authoring-checks.mjs +108 -4
  47. package/api/integration/authoring-checks.test.mjs +808 -0
  48. package/api/integration/authoring-checks.type.d.mts +143 -0
  49. package/api/integration/authoring-checks.type.mjs +74 -2
  50. package/api/integration/check/check.d.mts +96 -0
  51. package/api/integration/check/check.mjs +357 -0
  52. package/api/integration/check/check.test.mjs +489 -0
  53. package/api/integration/integration-check.type.d.mts +118 -0
  54. package/api/integration/integration-check.type.mjs +84 -0
  55. package/api/integration/integrationCheck.doc.d.mts +10 -0
  56. package/api/integration/integrationCheck.doc.mjs +73 -0
  57. package/api/integration/integrationComponentConflicts.doc.mjs +45 -6
  58. package/api/integration/integrationDocConflicts.doc.mjs +22 -5
  59. package/api/integration/pack-check.mjs +357 -114
  60. package/api/integration/pack-check.test.mjs +726 -0
  61. package/api/integration/validate-integration-fixes.test.mjs +67 -0
  62. package/api/integration/validate-integration.mjs +36 -3
  63. package/api/integration/validate-integration.test.mjs +88 -8
  64. package/api/integration/validate-integration.type.d.mts +8 -0
  65. package/api/integration/validate-integration.type.mjs +12 -1
  66. package/api/integration/validateIntegration.doc.mjs +19 -3
  67. package/api/search/search.d.mts +81 -12
  68. package/api/search/search.domain-priority.test.mjs +108 -18
  69. package/api/search/search.integration-check.test.mjs +24 -0
  70. package/api/search/search.mjs +611 -54
  71. package/api/search/search.test.mjs +175 -0
  72. package/api/swizzle/copy/copy.mjs +28 -14
  73. package/api/theme/build/build.family.test.mjs +64 -0
  74. package/api/theme/build/build.mjs +180 -24
  75. package/api/theme/themeBuild.doc.mjs +4 -4
  76. package/api/upgrade/_adapter.d.mts +40 -2
  77. package/api/upgrade/_adapter.mjs +117 -4
  78. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  79. package/api/upgrade/run/run.mjs +30 -1
  80. package/api/upgrade/status/status.d.mts +21 -5
  81. package/api/upgrade/status/status.mjs +45 -8
  82. package/api/upgrade/upgrade.doc.mjs +5 -3
  83. package/api/upgrade/upgrade.type.d.mts +23 -0
  84. package/api/upgrade/upgrade.type.mjs +16 -1
  85. package/assets/codemods/runner.mjs +7 -1
  86. package/assets/discover/official-packages.json +367 -0
  87. package/assets/docs/README.md +10 -0
  88. package/assets/docs/author-a-theme.doc.mjs +3 -3
  89. package/assets/docs/browser-support.doc.mjs +1 -1
  90. package/assets/docs/getting-started.doc.mjs +3 -3
  91. package/assets/docs/styling-overview.doc.mjs +1 -1
  92. package/assets/docs/theme.doc.dense.mjs +1 -1
  93. package/assets/docs/theme.doc.mjs +2 -2
  94. package/assets/docs/theme.doc.zh.mjs +1 -1
  95. package/assets/docs/tree/add-a-component.doc.mjs +11 -1
  96. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  97. package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
  98. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  99. package/assets/docs/tree/block-template.doc.mjs +8 -20
  100. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  101. package/assets/docs/tree/check-the-props.doc.mjs +201 -0
  102. package/assets/docs/tree/check-your-docs.doc.mjs +65 -7
  103. package/assets/docs/tree/checks.doc.mjs +26 -18
  104. package/assets/docs/tree/codemods.doc.mjs +4 -4
  105. package/assets/docs/tree/component-family.doc.mjs +8 -6
  106. package/assets/docs/tree/component-imports.doc.mjs +10 -2
  107. package/assets/docs/tree/components.doc.mjs +1 -1
  108. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
  109. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  110. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  111. package/assets/docs/tree/docs.doc.mjs +3 -3
  112. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  113. package/assets/docs/tree/document-the-theme.doc.mjs +3 -3
  114. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  115. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  116. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  117. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  118. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  119. package/assets/docs/tree/integrations.doc.mjs +8 -0
  120. package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
  121. package/assets/docs/tree/layout.doc.mjs +6 -6
  122. package/assets/docs/tree/links.doc.mjs +6 -5
  123. package/assets/docs/tree/migration-setup.doc.mjs +3 -2
  124. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  125. package/assets/docs/tree/migration.doc.mjs +0 -1
  126. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  127. package/assets/docs/tree/page-template.doc.mjs +4 -8
  128. package/assets/docs/tree/publishing.doc.mjs +4 -4
  129. package/assets/docs/tree/quick-start.doc.mjs +38 -22
  130. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  131. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  132. package/assets/docs/tree/sections-and-placement.doc.mjs +6 -8
  133. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  134. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  135. package/assets/docs/tree/single-component.doc.mjs +15 -6
  136. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  137. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  138. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  139. package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
  140. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  141. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  142. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  143. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  144. package/assets/docs/tree/templates.doc.mjs +1 -1
  145. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  146. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  147. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  148. package/assets/docs/tree/troubleshooting.doc.mjs +16 -8
  149. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  150. package/assets/docs/tree/upgrading.doc.mjs +4 -4
  151. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  152. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  153. package/assets/docs/tree/versioning.doc.mjs +7 -6
  154. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  155. package/assets/docs/use-a-theme.doc.mjs +2 -2
  156. package/assets/docs/working-with-ai.doc.mjs +43 -4
  157. package/assets/theme.template.ts +1 -1
  158. package/authoring/codemod/codemod.doc.mjs +7 -3
  159. package/authoring/config/config.doc.mjs +9 -6
  160. package/authoring/config/type.ts +4 -2
  161. package/authoring/discover/discover.doc.mjs +1 -1
  162. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  163. package/authoring/doctypes/command/command.doc.mjs +14 -12
  164. package/authoring/doctypes/component/component.doc.mjs +30 -27
  165. package/authoring/doctypes/component/type.ts +21 -8
  166. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  167. package/authoring/doctypes/function/function.doc.mjs +9 -8
  168. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  169. package/authoring/doctypes/hook/type.ts +4 -0
  170. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  171. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  172. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  173. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  174. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  175. package/authoring/doctypes/template/parse.d.mts +6 -2
  176. package/authoring/doctypes/template/parse.mjs +3 -1
  177. package/authoring/doctypes/template/template.doc.mjs +3 -3
  178. package/authoring/doctypes/template/type.ts +22 -0
  179. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  180. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  181. package/authoring/identity/identity.doc.mjs +3 -3
  182. package/authoring/index.d.ts +1 -0
  183. package/authoring/integration/integration.doc.mjs +12 -4
  184. package/authoring/integration/parse.test.mjs +10 -0
  185. package/authoring/integration/schema.d.mts +2 -0
  186. package/authoring/integration/schema.mjs +1 -0
  187. package/authoring/integration/type.ts +4 -0
  188. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  189. package/clients/cli/commands/build-theme.mjs +1 -1
  190. package/clients/cli/commands/build-theme.path-safety.test.mjs +224 -6
  191. package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
  192. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  193. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  194. package/clients/cli/commands/discover.doc.mjs +1 -1
  195. package/clients/cli/commands/discover.mjs +144 -93
  196. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  197. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  198. package/clients/cli/commands/doctor-integration-components.doc.mjs +18 -4
  199. package/clients/cli/commands/doctor-integration-docs.doc.mjs +19 -5
  200. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  201. package/clients/cli/commands/doctor-integration.test.mjs +884 -0
  202. package/clients/cli/commands/doctor.mjs +281 -5
  203. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  204. package/clients/cli/commands/gap-report.mjs +24 -2
  205. package/clients/cli/commands/gap-report.test.mjs +79 -0
  206. package/clients/cli/commands/integration-authoring.test.mjs +46 -0
  207. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  208. package/clients/cli/commands/integration-check.test.mjs +411 -0
  209. package/clients/cli/commands/integration.doc.mjs +6 -2
  210. package/clients/cli/commands/integration.mjs +116 -5
  211. package/clients/cli/commands/json-contract.test.mjs +5 -1
  212. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  213. package/clients/cli/commands/swizzle.mjs +5 -3
  214. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  215. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  216. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  217. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  218. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  219. package/clients/cli/index.mjs +30 -5
  220. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  221. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  222. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  223. package/foundation/agent-docs/agent-docs.mjs +8 -6
  224. package/foundation/config/project.mjs +82 -0
  225. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  226. package/foundation/discovery/component-discovery.d.mts +190 -10
  227. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  228. package/foundation/discovery/component-discovery.mjs +864 -56
  229. package/foundation/discovery/component-discovery.test.mjs +96 -0
  230. package/foundation/discovery/component-replacement.mjs +18 -0
  231. package/foundation/discovery/component-replacement.test.mjs +40 -0
  232. package/foundation/discovery/copied-passages.d.mts +216 -0
  233. package/foundation/discovery/copied-passages.mjs +720 -0
  234. package/foundation/discovery/copied-passages.test.mjs +124 -0
  235. package/foundation/discovery/doc-consistency.d.mts +34 -0
  236. package/foundation/discovery/doc-consistency.mjs +513 -0
  237. package/foundation/discovery/doc-consistency.test.mjs +347 -0
  238. package/foundation/discovery/doc-fluff.d.mts +112 -0
  239. package/foundation/discovery/doc-fluff.mjs +328 -0
  240. package/foundation/discovery/doc-fluff.test.mjs +142 -0
  241. package/foundation/discovery/doc-types.d.mts +157 -0
  242. package/foundation/discovery/doc-types.mjs +1231 -0
  243. package/foundation/discovery/doc-types.test.mjs +744 -0
  244. package/foundation/discovery/docs-discovery.d.mts +88 -0
  245. package/foundation/discovery/docs-discovery.mjs +83 -2
  246. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  247. package/foundation/discovery/integration-doc-files.mjs +231 -0
  248. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  249. package/foundation/discovery/module-exports.d.mts +27 -0
  250. package/foundation/discovery/module-exports.mjs +356 -31
  251. package/foundation/discovery/module-exports.test.mjs +172 -0
  252. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  253. package/foundation/discovery/package-tsconfig.mjs +228 -0
  254. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  255. package/foundation/discovery/project-typescript.d.mts +32 -0
  256. package/foundation/discovery/project-typescript.mjs +89 -0
  257. package/foundation/discovery/prop-drift.d.mts +297 -0
  258. package/foundation/discovery/prop-drift.mjs +2428 -0
  259. package/foundation/discovery/prop-drift.test.mjs +2337 -0
  260. package/foundation/discovery/stray-pointers.d.mts +52 -0
  261. package/foundation/discovery/stray-pointers.mjs +293 -0
  262. package/foundation/discovery/stray-pointers.test.mjs +86 -0
  263. package/foundation/discovery/type-match.d.mts +53 -0
  264. package/foundation/discovery/type-match.mjs +660 -0
  265. package/foundation/discovery/type-match.test.mjs +169 -0
  266. package/foundation/discovery/type-text.d.mts +68 -0
  267. package/foundation/discovery/type-text.mjs +658 -0
  268. package/foundation/discovery/type-text.test.mjs +196 -0
  269. package/foundation/discovery/unresolved-references.d.mts +62 -0
  270. package/foundation/discovery/unresolved-references.mjs +790 -0
  271. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  272. package/foundation/doc-compiler/doc-loads.test.mjs +30 -0
  273. package/foundation/doc-compiler/inputs.mjs +23 -0
  274. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  275. package/foundation/doc-compiler/links.d.mts +41 -5
  276. package/foundation/doc-compiler/links.mjs +167 -28
  277. package/foundation/doc-compiler/links.test.mjs +97 -4
  278. package/foundation/doc-compiler/tree.mjs +30 -1
  279. package/foundation/doc-compiler/tree.test.mjs +7 -0
  280. package/foundation/env/package-manager.d.mts +32 -0
  281. package/foundation/env/package-manager.mjs +47 -0
  282. package/foundation/env/package-manager.test.mjs +194 -7
  283. package/foundation/fs/module-loader.d.mts +2 -1
  284. package/foundation/fs/module-loader.mjs +60 -4
  285. package/foundation/fs/module-loader.test.mjs +194 -0
  286. package/foundation/integrations/contribution-inventory.d.mts +11 -0
  287. package/foundation/integrations/contribution-inventory.mjs +56 -3
  288. package/foundation/integrations/issue.ts +6 -0
  289. package/foundation/integrations/validate-contributions.mjs +30 -1
  290. package/foundation/response/response-types.doc.mjs +15 -9
  291. package/foundation/xle/registry.mjs +4 -0
  292. package/foundation/xle/registry.test.mjs +28 -0
  293. package/package.json +11 -11
  294. package/scripts/postinstall.mjs +3 -3
@@ -1,6 +1,7 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  import {describe, it, expect, afterEach, vi} from 'vitest';
4
+ import {spawnSync} from 'node:child_process';
4
5
  import * as fs from 'node:fs';
5
6
  import * as path from 'node:path';
6
7
  import * as os from 'node:os';
@@ -12,11 +13,32 @@ import {
12
13
  cliBinResolves,
13
14
  getCliInvocation,
14
15
  formatCliCommand,
16
+ quoteCommandArgument,
17
+ commandInFolder,
15
18
  } from './package-manager.mjs';
16
19
 
17
20
  let tmpDir;
18
21
  const ORIGINAL_ARGV1 = process.argv[1];
19
22
 
23
+ /** Prints, as JSON, the folder a command ran in and the arguments it got. */
24
+ const PRINT_RUN =
25
+ 'process.stdout.write(JSON.stringify({cwd: process.cwd(), argv: process.argv.slice(1)}))';
26
+
27
+ /** PowerShell, when it is on the PATH: printed commands target it on Windows. */
28
+ const PWSH = (process.env.PATH ?? '')
29
+ .split(path.delimiter)
30
+ .flatMap(dir => ['pwsh', 'pwsh.exe'].map(name => path.join(dir, name)))
31
+ .find(file => isFile(file));
32
+
33
+ /** @param {string} file */
34
+ function isFile(file) {
35
+ try {
36
+ return fs.statSync(file).isFile();
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+
20
42
  afterEach(() => {
21
43
  if (tmpDir) {
22
44
  fs.rmSync(tmpDir, {recursive: true, force: true});
@@ -48,7 +70,8 @@ const YARN_BERRY_LOCK =
48
70
  '# This file is generated by running "yarn install" inside your project.\n# Manual changes might be lost - proceed with caution!\n\n__metadata:\n version: 8\n';
49
71
 
50
72
  /** An installed CLI's entry, outside any runner cache (a global or workspace install). */
51
- const INSTALLED_ENTRY = '/usr/local/lib/node_modules/@astryxdesign/cli/clients/cli/bin/astryx.mjs';
73
+ const INSTALLED_ENTRY =
74
+ '/usr/local/lib/node_modules/@astryxdesign/cli/clients/cli/bin/astryx.mjs';
52
75
 
53
76
  describe('detectPackageManager', () => {
54
77
  it('detects yarn from yarn.lock', () => {
@@ -132,7 +155,10 @@ describe('detectPackageManager', () => {
132
155
  const dir = makeTmpDir();
133
156
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
134
157
  fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
135
- fs.writeFileSync(path.join(dir, '.yarnrc.yml'), 'nodeLinker: node-modules\n');
158
+ fs.writeFileSync(
159
+ path.join(dir, '.yarnrc.yml'),
160
+ 'nodeLinker: node-modules\n',
161
+ );
136
162
  expect(detectPackageManager(dir)).toBe('yarn');
137
163
  });
138
164
 
@@ -425,12 +451,14 @@ describe('isCliOneOff', () => {
425
451
  });
426
452
 
427
453
  it('detects a pnpm dlx cache entry', () => {
428
- process.argv[1] = '/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
454
+ process.argv[1] =
455
+ '/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
429
456
  expect(isCliOneOff()).toBe(true);
430
457
  });
431
458
 
432
459
  it('detects a bunx cache entry', () => {
433
- process.argv[1] = '/home/u/.bun/install/cache/@astryxdesign/cli/bin/astryx.mjs';
460
+ process.argv[1] =
461
+ '/home/u/.bun/install/cache/@astryxdesign/cli/bin/astryx.mjs';
434
462
  expect(isCliOneOff()).toBe(true);
435
463
  });
436
464
 
@@ -538,7 +566,8 @@ describe('getCliInvocation', () => {
538
566
  });
539
567
 
540
568
  it('pairs the dlx runner with the scoped package for pnpm one-off', () => {
541
- process.argv[1] = '/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
569
+ process.argv[1] =
570
+ '/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
542
571
  const dir = makeTmpDir();
543
572
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
544
573
  expect(getCliInvocation(dir)).toBe('pnpm dlx @astryxdesign/cli');
@@ -551,7 +580,9 @@ describe('formatCliCommand', () => {
551
580
  const dir = makeTmpDir();
552
581
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
553
582
  linkCliBin(dir);
554
- expect(formatCliCommand('astryx component Button', dir)).toBe('pnpm exec astryx component Button');
583
+ expect(formatCliCommand('astryx component Button', dir)).toBe(
584
+ 'pnpm exec astryx component Button',
585
+ );
555
586
  });
556
587
 
557
588
  it('accepts a bare subcommand (no leading astryx)', () => {
@@ -566,6 +597,162 @@ describe('formatCliCommand', () => {
566
597
  process.argv[1] = '/home/u/.npm/_npx/a1b2/node_modules/.bin/astryx';
567
598
  const dir = makeTmpDir();
568
599
  fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
569
- expect(formatCliCommand('astryx component Button', dir)).toBe('npx @astryxdesign/cli component Button');
600
+ expect(formatCliCommand('astryx component Button', dir)).toBe(
601
+ 'npx @astryxdesign/cli component Button',
602
+ );
603
+ });
604
+ });
605
+
606
+ describe('quoteCommandArgument', () => {
607
+ it('leaves a plain value bare', () => {
608
+ for (const platform of ['linux', 'darwin', 'win32']) {
609
+ expect(quoteCommandArgument('0.7.1', platform)).toBe('0.7.1');
610
+ expect(quoteCommandArgument('@acme/widgets', platform)).toBe(
611
+ '@acme/widgets',
612
+ );
613
+ expect(quoteCommandArgument('/home/me/app/src', platform)).toBe(
614
+ '/home/me/app/src',
615
+ );
616
+ }
617
+ });
618
+
619
+ it('single-quotes for a POSIX shell, so $, backticks and double quotes stay literal', () => {
620
+ expect(quoteCommandArgument('/tmp/my app/src', 'linux')).toBe(
621
+ "'/tmp/my app/src'",
622
+ );
623
+ expect(quoteCommandArgument('/tmp/cost $5/src', 'darwin')).toBe(
624
+ "'/tmp/cost $5/src'",
625
+ );
626
+ expect(quoteCommandArgument('a`id`"b"!', 'linux')).toBe('\'a`id`"b"!\'');
627
+ expect(quoteCommandArgument("it's", 'linux')).toBe("'it'\\''s'");
628
+ expect(quoteCommandArgument('C:\\app', 'linux')).toBe("'C:\\app'");
629
+ expect(quoteCommandArgument('', 'linux')).toBe("''");
630
+ });
631
+
632
+ it('keeps a Windows drive path bare', () => {
633
+ expect(quoteCommandArgument('C:\\Users\\me\\app\\src', 'win32')).toBe(
634
+ 'C:\\Users\\me\\app\\src',
635
+ );
636
+ });
637
+
638
+ // Windows output targets PowerShell, not cmd.exe: PowerShell reads a
639
+ // single-quoted value literally, `$`, backticks, `%` and `!` included.
640
+ it('single-quotes for PowerShell on Windows, doubling an embedded quote', () => {
641
+ expect(quoteCommandArgument('C:\\Users\\Jo Smith\\app\\src', 'win32')).toBe(
642
+ "'C:\\Users\\Jo Smith\\app\\src'",
643
+ );
644
+ expect(quoteCommandArgument('C:\\cost $5 %x% !y\\src', 'win32')).toBe(
645
+ "'C:\\cost $5 %x% !y\\src'",
646
+ );
647
+ expect(quoteCommandArgument('C:\\it\'s `x` "q"', 'win32')).toBe(
648
+ "'C:\\it''s `x` \"q\"'",
649
+ );
650
+ // PowerShell also ends a single-quoted string at ‘ ’ ‚ and ‛.
651
+ expect(
652
+ quoteCommandArgument('C:\\Users\\jo\\OneDrive - Macy’s\\app', 'win32'),
653
+ ).toBe("'C:\\Users\\jo\\OneDrive - Macy’’s\\app'");
654
+ expect(quoteCommandArgument('‘a’ ‚b‛', 'win32')).toBe("'‘‘a’’ ‚‚b‛‛'");
655
+ // A POSIX shell reads them literally inside single quotes.
656
+ expect(quoteCommandArgument('/home/jo/Macy’s app', 'linux')).toBe(
657
+ "'/home/jo/Macy’s app'",
658
+ );
659
+ });
660
+ });
661
+
662
+ describe('commandInFolder', () => {
663
+ it('enters the folder, then runs the command only if that worked, in a POSIX shell', () => {
664
+ expect(commandInFolder('/tmp/my app', 'npx x', 'linux')).toBe(
665
+ "cd '/tmp/my app' && npx x",
666
+ );
667
+ expect(commandInFolder('/srv/app', 'npx x', 'darwin')).toBe(
668
+ 'cd /srv/app && npx x',
669
+ );
670
+ });
671
+
672
+ it('enters the folder literally and stops if it cannot, in PowerShell', () => {
673
+ expect(commandInFolder('C:\\a[1] b', 'npx x', 'win32')).toBe(
674
+ "cd -LiteralPath 'C:\\a[1] b' -ErrorAction Stop; npx x",
675
+ );
676
+ });
677
+
678
+ it.skipIf(process.platform === 'win32')(
679
+ 'runs in the folder with every argument unchanged, pasted into /bin/sh elsewhere',
680
+ () => {
681
+ const root = makeTmpDir();
682
+ const project = path.join(root, 'it\'s Macy’s ‘q’ $5 %x% !y `z` "q" [1]');
683
+ fs.mkdirSync(project);
684
+ const args = [path.join(project, 'src'), 'a$b c', "it's", '@scope/pkg@1'];
685
+ const command = commandInFolder(
686
+ project,
687
+ ['npx', ...args.map(arg => quoteCommandArgument(arg, 'linux'))].join(
688
+ ' ',
689
+ ),
690
+ 'linux',
691
+ );
692
+ const ran = spawnSync(
693
+ '/bin/sh',
694
+ [
695
+ '-c',
696
+ `npx() { "$0" -e '${PRINT_RUN}' -- "$@"; }; ${command}`,
697
+ process.execPath,
698
+ ],
699
+ {cwd: root, encoding: 'utf8'},
700
+ );
701
+
702
+ expect(ran.status, ran.stderr).toBe(0);
703
+ expect(JSON.parse(ran.stdout)).toEqual({
704
+ cwd: fs.realpathSync(project),
705
+ argv: args,
706
+ });
707
+ },
708
+ );
709
+
710
+ describe.runIf(PWSH)('in PowerShell, where it is installed', () => {
711
+ it('runs in the folder with every argument unchanged', () => {
712
+ const root = makeTmpDir();
713
+ const project = path.join(root, 'it\'s Macy’s ‘q’ $5 %x% !y `z` "q" [1]');
714
+ fs.mkdirSync(project);
715
+ const args = [path.join(project, 'src'), 'a$b c', "it's", '@scope/pkg@1'];
716
+ const command = commandInFolder(
717
+ project,
718
+ ['npx', ...args.map(arg => quoteCommandArgument(arg, 'win32'))].join(
719
+ ' ',
720
+ ),
721
+ 'win32',
722
+ );
723
+ const npx = `function npx { & ${quoteCommandArgument(process.execPath, 'win32')} -e '${PRINT_RUN}' -- @args }`;
724
+ const ran = spawnSync(
725
+ /** @type {string} */ (PWSH),
726
+ ['-NoProfile', '-NonInteractive', '-Command', `${npx}; ${command}`],
727
+ {cwd: root, encoding: 'utf8'},
728
+ );
729
+
730
+ expect(ran.status, ran.stderr).toBe(0);
731
+ expect(JSON.parse(ran.stdout)).toEqual({
732
+ cwd: fs.realpathSync(project),
733
+ argv: args,
734
+ });
735
+ });
736
+
737
+ it('stops when the folder cannot be entered', () => {
738
+ const root = makeTmpDir();
739
+ const command = commandInFolder(
740
+ path.join(root, 'missing'),
741
+ 'npx',
742
+ 'win32',
743
+ );
744
+ const ran = spawnSync(
745
+ /** @type {string} */ (PWSH),
746
+ [
747
+ '-NoProfile',
748
+ '-NonInteractive',
749
+ '-Command',
750
+ `function npx { 'RAN' }; ${command}`,
751
+ ],
752
+ {cwd: root, encoding: 'utf8'},
753
+ );
754
+
755
+ expect(ran.stdout).not.toContain('RAN');
756
+ });
570
757
  });
571
758
  });
@@ -21,7 +21,8 @@ export function importUserModule(file: string, { fresh }?: {
21
21
  /**
22
22
  * Load a generated theme artifact and its extensionless JS/JSX/TS/TSX graph.
23
23
  * Package specifiers resolve from the consumer project, while relative paths
24
- * resolve from that same project root.
24
+ * resolve from that same project root. An import of an existing `.css` file
25
+ * loads as an empty module.
25
26
  * @param {string} specifier
26
27
  * @param {string} cwd
27
28
  * @returns {Promise<Record<string, unknown>>}
@@ -7,9 +7,11 @@
7
7
  * user-authored module (`.ts` via jiti, `.mjs`/`.js` via native dynamic
8
8
  * import) and (b) find conventional files by basename in a fixed
9
9
  * load-precedence order. Generated theme artifacts also use a dedicated jiti
10
- * path that resolves extensionless JSX/TSX registry imports. These helpers
11
- * centralize that behavior so callers stay in lockstep. A module's stdout writes go to stderr while it loads, so
12
- * project code that prints cannot corrupt a `--json` envelope.
10
+ * path that resolves extensionless JSX/TSX registry imports and loads the
11
+ * stylesheets they import as empty modules. These helpers centralize that
12
+ * behavior so callers stay in lockstep. A module's stdout writes go to stderr
13
+ * while it loads, so project code that prints cannot corrupt a `--json`
14
+ * envelope.
13
15
  *
14
16
  * `loadModuleWithParser` builds on these primitives to provide the single
15
17
  * load/validation boundary shared by config, integration, codemod, and
@@ -125,6 +127,56 @@ const THEME_ARTIFACT_EXTENSIONS = [
125
127
  '.cts',
126
128
  ];
127
129
 
130
+ /**
131
+ * @param {string | symbol} specifier
132
+ * @returns {specifier is string}
133
+ */
134
+ function isStylesheetSpecifier(specifier) {
135
+ return typeof specifier === 'string' && specifier.endsWith('.css');
136
+ }
137
+
138
+ /**
139
+ * Whether `specifier`, resolved from the module at `from`, names an existing
140
+ * `.css` file.
141
+ * @param {string} specifier
142
+ * @param {string} from
143
+ */
144
+ function resolvesToStylesheet(specifier, from) {
145
+ try {
146
+ return createRequire(from).resolve(specifier).endsWith('.css');
147
+ } catch {
148
+ return false;
149
+ }
150
+ }
151
+
152
+ /**
153
+ * A built theme module may import a stylesheet so that the app's bundler emits
154
+ * it. Node cannot load a stylesheet, so an import that ends in `.css` and
155
+ * resolves from the theme module to an existing `.css` file loads as an empty
156
+ * module. Any other import loads as before: a missing stylesheet fails like
157
+ * any missing import, and `./tokens.css` loads `tokens.css.js` when that is
158
+ * the file it names. jiti shows only the import text, so the check resolves it
159
+ * from the theme module's folder, not from the importing module's. A module in
160
+ * another folder fails on a stylesheet it reaches by a different relative
161
+ * path, and passes on a missing stylesheet whose path exists from the theme
162
+ * module's folder.
163
+ * @param {() => string} themeModule returns the theme module's path
164
+ * @returns {Record<string, unknown>}
165
+ */
166
+ function themeArtifactStylesheets(themeModule) {
167
+ return new Proxy(
168
+ {},
169
+ {
170
+ has: (_target, specifier) =>
171
+ specifier !== themeModule() &&
172
+ isStylesheetSpecifier(specifier) &&
173
+ resolvesToStylesheet(specifier, themeModule()),
174
+ get: (_target, specifier) =>
175
+ isStylesheetSpecifier(specifier) ? {} : undefined,
176
+ },
177
+ );
178
+ }
179
+
128
180
  class ThemeArtifactNotFoundError extends Error {
129
181
  code = 'ERR_THEME_ARTIFACT_NOT_FOUND';
130
182
 
@@ -153,17 +205,20 @@ function isMissingPackageExport(error) {
153
205
  /**
154
206
  * Load a generated theme artifact and its extensionless JS/JSX/TS/TSX graph.
155
207
  * Package specifiers resolve from the consumer project, while relative paths
156
- * resolve from that same project root.
208
+ * resolve from that same project root. An import of an existing `.css` file
209
+ * loads as an empty module.
157
210
  * @param {string} specifier
158
211
  * @param {string} cwd
159
212
  * @returns {Promise<Record<string, unknown>>}
160
213
  */
161
214
  export async function importThemeArtifact(specifier, cwd) {
215
+ let themeModule = path.join(cwd, 'package.json');
162
216
  const loader = createJiti(path.join(cwd, 'package.json'), {
163
217
  moduleCache: false,
164
218
  jsx: true,
165
219
  interopDefault: true,
166
220
  extensions: THEME_ARTIFACT_EXTENSIONS,
221
+ virtualModules: themeArtifactStylesheets(() => themeModule),
167
222
  });
168
223
  let target;
169
224
  if (specifier.startsWith('.') || path.isAbsolute(specifier)) {
@@ -179,6 +234,7 @@ export async function importThemeArtifact(specifier, cwd) {
179
234
  if (!fs.existsSync(target)) {
180
235
  throw new ThemeArtifactNotFoundError(specifier);
181
236
  }
237
+ themeModule = target;
182
238
  return await withStdoutOnStderr(() => loader.import(target));
183
239
  }
184
240
 
@@ -9,6 +9,7 @@ import {pathToFileURL} from 'node:url';
9
9
  import {z} from 'zod';
10
10
  import {
11
11
  findPresentFiles,
12
+ importThemeArtifact,
12
13
  importUserModule,
13
14
  loadModuleWithParser,
14
15
  } from './module-loader.mjs';
@@ -155,6 +156,199 @@ process.stdout.write(JSON.stringify({first: first.default?.answer, fresh: fresh.
155
156
  });
156
157
  });
157
158
 
159
+ describe('importThemeArtifact', () => {
160
+ const STYLESHEET_RAN = '__astryxThemeArtifactStylesheetRan';
161
+
162
+ /** @param {string} file @param {string} content */
163
+ function write(file, content) {
164
+ const target = path.join(tmpDir, file);
165
+ fs.mkdirSync(path.dirname(target), {recursive: true});
166
+ fs.writeFileSync(target, content);
167
+ }
168
+
169
+ beforeEach(() => {
170
+ write('package.json', JSON.stringify({type: 'module'}));
171
+ write(
172
+ 'ocean.css',
173
+ '[data-astryx-theme="ocean"] { --color-text: black; }\n',
174
+ );
175
+ });
176
+
177
+ afterEach(() => {
178
+ Reflect.deleteProperty(globalThis, STYLESHEET_RAN);
179
+ });
180
+
181
+ it('loads a built module that imports its stylesheet, without running the stylesheet', async () => {
182
+ // Valid JavaScript, so running this stylesheet would leave a trace.
183
+ write('ran.css', `globalThis.${STYLESHEET_RAN} = true;\n`);
184
+ write(
185
+ 'ocean.js',
186
+ "import './ocean.css';\nimport './ran.css';\nexport const oceanTheme = {name: 'ocean'};\n",
187
+ );
188
+
189
+ const mod = await importThemeArtifact('./ocean.js', tmpDir);
190
+
191
+ expect(mod.oceanTheme).toEqual({name: 'ocean'});
192
+ expect(Reflect.get(globalThis, STYLESHEET_RAN)).toBeUndefined();
193
+ });
194
+
195
+ it('loads a CommonJS built module that requires its stylesheet', async () => {
196
+ write('commonjs/package.json', JSON.stringify({type: 'commonjs'}));
197
+ write(
198
+ 'commonjs/ocean.css',
199
+ '[data-astryx-theme="ocean"] { --color-text: black; }\n',
200
+ );
201
+ write(
202
+ 'commonjs/ocean.js',
203
+ "require('./ocean.css');\nexports.oceanTheme = {name: 'ocean'};\n",
204
+ );
205
+
206
+ const mod = await importThemeArtifact('./commonjs/ocean.js', tmpDir);
207
+
208
+ expect(mod.oceanTheme).toEqual({name: 'ocean'});
209
+ });
210
+
211
+ it('loads stylesheets imported by a nested module, through a package export, and dynamically', async () => {
212
+ const packageDir = 'node_modules/@acme/themes';
213
+ write(
214
+ `${packageDir}/package.json`,
215
+ JSON.stringify({
216
+ name: '@acme/themes',
217
+ type: 'module',
218
+ exports: {
219
+ './themes/ocean': './dist/ocean.js',
220
+ './themes/ocean.css': './dist/ocean.css',
221
+ },
222
+ }),
223
+ );
224
+ write(
225
+ `${packageDir}/dist/ocean.css`,
226
+ '[data-astryx-theme="ocean"] { --color-text: black; }\n',
227
+ );
228
+ write(
229
+ `${packageDir}/dist/tokens.js`,
230
+ "import '@acme/themes/themes/ocean.css';\nexport const tokens = {};\n",
231
+ );
232
+ write(
233
+ `${packageDir}/dist/ocean.js`,
234
+ "import {tokens} from './tokens.js';\nawait import('./ocean.css');\nexport const oceanTheme = {name: 'ocean', tokens};\n",
235
+ );
236
+
237
+ const mod = await importThemeArtifact('@acme/themes/themes/ocean', tmpDir);
238
+
239
+ expect(mod.oceanTheme).toEqual({name: 'ocean', tokens: {}});
240
+ });
241
+
242
+ it('still resolves an extensionless import to its directory index beside a same-named stylesheet', async () => {
243
+ write('ocean/index.js', "export const oceanTheme = {name: 'ocean'};\n");
244
+ write(
245
+ 'entry.js',
246
+ "import './ocean.css';\nexport {oceanTheme} from './ocean';\n",
247
+ );
248
+
249
+ const mod = await importThemeArtifact('./entry.js', tmpDir);
250
+
251
+ expect(mod.oceanTheme).toEqual({name: 'ocean'});
252
+ });
253
+
254
+ it('loads a module whose import ends in .css but names a JavaScript file', async () => {
255
+ write('tokens.css.js', "export const vars = {accent: 'blue'};\n");
256
+ write(
257
+ 'ocean.js',
258
+ "import './ocean.css';\nimport {vars} from './tokens.css';\nexport const oceanTheme = {name: 'ocean', vars};\n",
259
+ );
260
+
261
+ const mod = await importThemeArtifact('./ocean.js', tmpDir);
262
+
263
+ expect(mod.oceanTheme).toEqual({name: 'ocean', vars: {accent: 'blue'}});
264
+ });
265
+
266
+ it.each([
267
+ ['a missing file', "import './fonts.css';\n", /fonts\.css/],
268
+ [
269
+ 'a package that is not installed',
270
+ "import '@acme/missing-fonts/inter.css';\n",
271
+ /@acme\/missing-fonts\/inter\.css/,
272
+ ],
273
+ ])(
274
+ 'still rejects a stylesheet import of %s',
275
+ async (_label, stylesheetImport, expected) => {
276
+ write(
277
+ 'ocean.js',
278
+ `import './ocean.css';\n${stylesheetImport}export const oceanTheme = {name: 'ocean'};\n`,
279
+ );
280
+
281
+ await expect(importThemeArtifact('./ocean.js', tmpDir)).rejects.toThrow(
282
+ expected,
283
+ );
284
+ },
285
+ );
286
+
287
+ it('still rejects a theme module path that names a stylesheet', async () => {
288
+ await expect(importThemeArtifact('./ocean.css', tmpDir)).rejects.toThrow(
289
+ /Unknown file extension "\.css"/,
290
+ );
291
+ });
292
+
293
+ it('still rejects a stylesheet import that its package does not export', async () => {
294
+ const packageDir = 'node_modules/@acme/themes';
295
+ write(
296
+ `${packageDir}/package.json`,
297
+ JSON.stringify({
298
+ name: '@acme/themes',
299
+ type: 'module',
300
+ exports: {'./themes/ocean': './dist/ocean.js'},
301
+ }),
302
+ );
303
+ write(
304
+ `${packageDir}/dist/ocean.css`,
305
+ '[data-astryx-theme="ocean"] { --color-text: black; }\n',
306
+ );
307
+ write(
308
+ `${packageDir}/dist/ocean.js`,
309
+ "import '@acme/themes/themes/ocean.css';\nexport const oceanTheme = {name: 'ocean'};\n",
310
+ );
311
+
312
+ await expect(
313
+ importThemeArtifact('@acme/themes/themes/ocean', tmpDir),
314
+ ).rejects.toThrow(/not defined by "exports"/);
315
+ });
316
+
317
+ it.each([
318
+ [
319
+ 'a missing dependency',
320
+ "import './missing.js';\nexport const oceanTheme = {name: 'ocean'};\n",
321
+ /missing\.js/,
322
+ ],
323
+ [
324
+ 'a syntax error in a module it imports',
325
+ "import './broken.js';\nexport const oceanTheme = {name: 'ocean'};\n",
326
+ /ParseError/,
327
+ ],
328
+ [
329
+ 'a throwing module',
330
+ "throw new Error('broken theme module');\n",
331
+ /broken theme module/,
332
+ ],
333
+ [
334
+ 'an asset that is not a stylesheet',
335
+ "import './logo.svg';\nexport const oceanTheme = {name: 'ocean'};\n",
336
+ /Unknown file extension "\.svg"/,
337
+ ],
338
+ ])(
339
+ 'still rejects a built module that imports its stylesheet and has %s',
340
+ async (_label, rest, expected) => {
341
+ write('logo.svg', '<svg xmlns="http://www.w3.org/2000/svg"/>\n');
342
+ write('broken.js', 'export const broken = ;\n');
343
+ write('ocean.js', `import './ocean.css';\n${rest}`);
344
+
345
+ await expect(importThemeArtifact('./ocean.js', tmpDir)).rejects.toThrow(
346
+ expected,
347
+ );
348
+ },
349
+ );
350
+ });
351
+
158
352
  describe('loadModuleWithParser', () => {
159
353
  // Temp module files live under a repo-local dir (not /tmp): Vite's dynamic
160
354
  // import blocks /tmp, so we mirror the existing repo-local temp pattern.
@@ -95,6 +95,17 @@ export function compareIdentities(local: ContributionIdentities, packed: Contrib
95
95
  * @returns {string[]} unregistered PascalCase names
96
96
  */
97
97
  export function findSourceOnlyCandidates(componentsRoot: string | undefined, registeredNames: string[]): string[];
98
+ /**
99
+ * Find `.tsx` files directly in a templates root that have no same-stem
100
+ * template metadata, so template discovery never lists them. Like the
101
+ * component check, it scans only direct children of the root: a file in a
102
+ * subfolder may be a helper a template imports. A file with a dotted stem (a
103
+ * test, story, or similar companion) is never a candidate.
104
+ *
105
+ * @param {string|undefined} templatesRoot absolute path
106
+ * @returns {string[]} basenames of the unpaired sources, sorted
107
+ */
108
+ export function findTemplateSourceOnlyCandidates(templatesRoot: string | undefined): string[];
98
109
  export type FileInventoryRoot = {
99
110
  kind: "themes" | "components" | "templates" | "codemods" | "docs";
100
111
  /**
@@ -248,11 +248,16 @@ export async function collectIdentities(loaded) {
248
248
  if (loaded.components && fs.existsSync(loaded.components)) {
249
249
  try {
250
250
  const records = discoverIntegrationComponents(loaded) ?? [];
251
+ // A family doc backs several records: load it, and report it, once.
252
+ const loads = new Map();
251
253
  for (const record of records) {
254
+ const first = !loads.has(record.docPath);
255
+ if (first) loads.set(record.docPath, loadComponentDoc(record.docPath));
252
256
  try {
253
- await loadComponentDoc(record.docPath);
257
+ await loads.get(record.docPath);
254
258
  identities.components.push(record.name);
255
259
  } catch (err) {
260
+ if (!first) continue;
256
261
  errors.push({
257
262
  kind: 'components',
258
263
  message: `${path.relative(loaded.components, record.docPath)}: ${
@@ -314,8 +319,11 @@ export async function collectIdentities(loaded) {
314
319
 
315
320
  if (loaded.docs && fs.existsSync(loaded.docs)) {
316
321
  try {
317
- const {records, guides, errors: docErrors} =
318
- await discoverIntegrationDocs(loaded);
322
+ const {
323
+ records,
324
+ guides,
325
+ errors: docErrors,
326
+ } = await discoverIntegrationDocs(loaded);
319
327
  for (const docError of docErrors) {
320
328
  errors.push({kind: 'docs', message: docError.message});
321
329
  }
@@ -498,3 +506,48 @@ export function findSourceOnlyCandidates(componentsRoot, registeredNames) {
498
506
  }
499
507
  return candidates.sort();
500
508
  }
509
+
510
+ /**
511
+ * Metadata suffixes that pair a template source with its spec: the canonical
512
+ * `.doc.*` family and the released `.template.*` compatibility family.
513
+ */
514
+ const TEMPLATE_DOC_SUFFIXES = [
515
+ '.doc.ts',
516
+ '.doc.mjs',
517
+ '.doc.js',
518
+ '.template.ts',
519
+ '.template.mjs',
520
+ '.template.js',
521
+ ];
522
+
523
+ /** A `.tsx` source and its stem, which may hold a dot (`landing.page`). */
524
+ const TSX_SOURCE = /^(.+)\.tsx$/u;
525
+
526
+ /** A test, spec or story stem: never a template. */
527
+ const NOT_A_TEMPLATE = /\.(?:test|spec|stories)$/u;
528
+
529
+ /**
530
+ * Find `.tsx` files directly in a templates root that have no same-stem
531
+ * template metadata, so template discovery never lists them. Like the
532
+ * component check, it scans only direct children of the root: a file in a
533
+ * subfolder may be a helper a template imports. A file with a dotted stem (a
534
+ * test, story, or similar companion) is never a candidate.
535
+ *
536
+ * @param {string|undefined} templatesRoot absolute path
537
+ * @returns {string[]} basenames of the unpaired sources, sorted
538
+ */
539
+ export function findTemplateSourceOnlyCandidates(templatesRoot) {
540
+ if (!templatesRoot || !fs.existsSync(templatesRoot)) return [];
541
+ /** @type {string[]} */
542
+ const candidates = [];
543
+ for (const entry of fs.readdirSync(templatesRoot, {withFileTypes: true})) {
544
+ if (!entry.isFile() && !entry.isSymbolicLink()) continue;
545
+ const match = entry.name.match(TSX_SOURCE);
546
+ if (!match || NOT_A_TEMPLATE.test(match[1])) continue;
547
+ const paired = TEMPLATE_DOC_SUFFIXES.some(suffix =>
548
+ fs.existsSync(path.join(templatesRoot, `${match[1]}${suffix}`)),
549
+ );
550
+ if (!paired) candidates.push(entry.name);
551
+ }
552
+ return candidates.sort();
553
+ }