@astryxdesign/cli 0.7.3 → 0.7.4-canary.1a552f2

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 (244) hide show
  1. package/README.md +63 -63
  2. package/api/component/_adapter.mjs +4 -3
  3. package/api/component/component.mjs +13 -6
  4. package/api/component/doc-links.test.mjs +33 -0
  5. package/api/discover/_adapter.mjs +22 -10
  6. package/api/discover/_catalog-view.d.mts +2 -0
  7. package/api/discover/_catalog-view.mjs +1 -0
  8. package/api/discover/_catalog-view.test.mjs +1 -0
  9. package/api/discover/detail/detail.mjs +1 -0
  10. package/api/discover/detail/detail.test.mjs +3 -0
  11. package/api/discover/detail/doc/doc.mjs +5 -1
  12. package/api/discover/detail/doc/doc.test.mjs +1 -0
  13. package/api/discover/detail/item/item.mjs +2 -0
  14. package/api/discover/detail/item/item.test.mjs +2 -0
  15. package/api/discover/discover.doc.mjs +4 -4
  16. package/api/discover/discover.type.d.mts +20 -0
  17. package/api/discover/discover.type.mjs +5 -0
  18. package/api/discover/list/list.test.mjs +2 -0
  19. package/api/discover/search/search.d.mts +3 -2
  20. package/api/discover/search/search.mjs +26 -7
  21. package/api/discover/search/search.test.mjs +67 -0
  22. package/api/docs/_adapter.d.mts +80 -0
  23. package/api/docs/_adapter.mjs +261 -11
  24. package/api/docs/detail/detail.mjs +8 -0
  25. package/api/docs/docOverlays.test.mjs +2 -1
  26. package/api/docs/docs.d.mts +16 -6
  27. package/api/docs/docs.doc.mjs +1 -1
  28. package/api/docs/docs.mjs +55 -6
  29. package/api/docs/docs.type.d.mts +28 -2
  30. package/api/docs/docs.type.mjs +13 -3
  31. package/api/docs/guide-route-targets.test.mjs +1002 -0
  32. package/api/docs/index/index.mjs +9 -0
  33. package/api/docs/integration-tree.test.mjs +22 -0
  34. package/api/docs/integrationDocs.test.mjs +85 -0
  35. package/api/docs/list/list.mjs +7 -1
  36. package/api/docs/node/node.mjs +9 -1
  37. package/api/docs/reference-blocks.test.mjs +1 -1
  38. package/api/doctor/_adapter.d.mts +40 -0
  39. package/api/doctor/_adapter.mjs +171 -1
  40. package/api/doctor/built-checks.d.mts +85 -0
  41. package/api/doctor/built-checks.mjs +837 -0
  42. package/api/doctor/built-checks.test.mjs +531 -0
  43. package/api/doctor/doctor.d.mts +6 -5
  44. package/api/doctor/doctor.doc.mjs +11 -1
  45. package/api/doctor/doctor.mjs +18 -3
  46. package/api/doctor/doctor.type.d.mts +6 -0
  47. package/api/doctor/doctor.type.mjs +3 -0
  48. package/api/hook/list/list.d.mts +1 -1
  49. package/api/integration/_adapter.d.mts +11 -2
  50. package/api/integration/_adapter.mjs +30 -4
  51. package/api/integration/authoring-checks.mjs +29 -2
  52. package/api/integration/authoring-checks.test.mjs +131 -1
  53. package/api/integration/check/check.d.mts +4 -1
  54. package/api/integration/check/check.mjs +34 -4
  55. package/api/integration/check/check.test.mjs +49 -0
  56. package/api/integration/integration-check.type.d.mts +8 -0
  57. package/api/integration/integration-check.type.mjs +4 -1
  58. package/api/integration/integrationCheck.doc.mjs +8 -1
  59. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  60. package/api/integration/pack-check.mjs +71 -2
  61. package/api/integration/pack-check.test.mjs +77 -0
  62. package/api/integration/validate-integration-case-disk.test.mjs +2 -0
  63. package/api/integration/validate-integration-gaps.test.mjs +7 -4
  64. package/api/integration/validate-integration.mjs +96 -14
  65. package/api/integration/validate-integration.type.d.mts +10 -4
  66. package/api/integration/validate-integration.type.mjs +10 -5
  67. package/api/integration/validateIntegration.doc.mjs +1 -1
  68. package/api/search/_candidate-score.d.mts +3 -2
  69. package/api/search/_candidate-score.mjs +66 -3
  70. package/api/search/_gather-docs.mjs +12 -2
  71. package/api/search/_priority.mjs +2 -1
  72. package/api/search/_score.d.mts +2 -1
  73. package/api/search/_score.mjs +2 -2
  74. package/api/search/search.doc.mjs +1 -1
  75. package/api/search/search.family-members.test.mjs +124 -0
  76. package/api/search/search.mjs +28 -0
  77. package/api/theme/palette/generate/generate.d.mts +8 -0
  78. package/api/theme/palette/generate/generate.mjs +38 -11
  79. package/api/theme/palette/generate/generate.test.mjs +83 -4
  80. package/api/theme/palette/generate/generator.d.mts +6 -0
  81. package/api/theme/palette/generate/generator.mjs +6 -0
  82. package/api/theme/theme.type.d.mts +12 -1
  83. package/api/theme/theme.type.mjs +7 -1
  84. package/api/theme/themeBuild.doc.mjs +1 -1
  85. package/api/theme/themeList.doc.mjs +1 -1
  86. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  87. package/api/theme/themeTargets.doc.mjs +1 -1
  88. package/assets/discover/official-packages.json +16 -0
  89. package/assets/docs/author-a-theme.doc.mjs +15 -15
  90. package/assets/docs/browser-support.doc.mjs +1 -1
  91. package/assets/docs/getting-started.doc.mjs +16 -16
  92. package/assets/docs/is-my-code-good.doc.mjs +6 -6
  93. package/assets/docs/styling-overview.doc.mjs +5 -5
  94. package/assets/docs/theme.doc.mjs +5 -5
  95. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  96. package/assets/docs/tree/add-a-theme.doc.mjs +2 -2
  97. package/assets/docs/tree/add-a-topic.doc.mjs +6 -6
  98. package/assets/docs/tree/agent-guidance.doc.mjs +5 -5
  99. package/assets/docs/tree/authoring.doc.mjs +2 -2
  100. package/assets/docs/tree/block-template.doc.mjs +1 -1
  101. package/assets/docs/tree/check-the-props.doc.mjs +3 -3
  102. package/assets/docs/tree/check-your-docs.doc.mjs +6 -6
  103. package/assets/docs/tree/checks.doc.mjs +11 -11
  104. package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
  105. package/assets/docs/tree/cli-command.doc.mjs +6 -6
  106. package/assets/docs/tree/codemods.doc.mjs +7 -7
  107. package/assets/docs/tree/component-family.doc.mjs +1 -1
  108. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  109. package/assets/docs/tree/component-lookups.doc.mjs +6 -5
  110. package/assets/docs/tree/computer-agent-guide.doc.mjs +7 -7
  111. package/assets/docs/tree/computer-integrations.doc.mjs +5 -5
  112. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +3 -3
  113. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  114. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  115. package/assets/docs/tree/doc-syntax.doc.mjs +219 -0
  116. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  117. package/assets/docs/tree/extend-or-replace.doc.mjs +39 -7
  118. package/assets/docs/tree/font-setup.doc.mjs +1 -1
  119. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  120. package/assets/docs/tree/global-integrations.doc.mjs +11 -11
  121. package/assets/docs/tree/global.doc.mjs +2 -2
  122. package/assets/docs/tree/host-entry.doc.mjs +1 -1
  123. package/assets/docs/tree/install-once.doc.mjs +4 -4
  124. package/assets/docs/tree/layout.doc.mjs +1 -1
  125. package/assets/docs/tree/links.doc.mjs +2 -2
  126. package/assets/docs/tree/migration-setup.doc.mjs +15 -15
  127. package/assets/docs/tree/migration.doc.mjs +2 -1
  128. package/assets/docs/tree/other-libraries.doc.mjs +1 -1
  129. package/assets/docs/tree/page-template.doc.mjs +2 -2
  130. package/assets/docs/tree/problems.doc.mjs +8 -8
  131. package/assets/docs/tree/project-global-or-both.doc.mjs +2 -2
  132. package/assets/docs/tree/publishing.doc.mjs +7 -7
  133. package/assets/docs/tree/quick-start.doc.mjs +9 -9
  134. package/assets/docs/tree/reference.doc.mjs +2 -2
  135. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  136. package/assets/docs/tree/replace-a-core-template.doc.mjs +4 -4
  137. package/assets/docs/tree/scaffold.doc.mjs +1 -1
  138. package/assets/docs/tree/sections-and-placement.doc.mjs +3 -3
  139. package/assets/docs/tree/see-it-in-an-app.doc.mjs +3 -3
  140. package/assets/docs/tree/short-and-findable.doc.mjs +3 -3
  141. package/assets/docs/tree/single-component.doc.mjs +4 -4
  142. package/assets/docs/tree/start-a-template.doc.mjs +5 -5
  143. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  144. package/assets/docs/tree/styling-libraries.doc.mjs +2 -1
  145. package/assets/docs/tree/styling.doc.mjs +1 -1
  146. package/assets/docs/tree/tailwind.doc.mjs +1 -1
  147. package/assets/docs/tree/test-in-an-app.doc.mjs +5 -5
  148. package/assets/docs/tree/test-template-in-app.doc.mjs +6 -6
  149. package/assets/docs/tree/tokens-and-setup.doc.mjs +1 -1
  150. package/assets/docs/tree/troubleshooting.doc.mjs +24 -20
  151. package/assets/docs/tree/uninstall.doc.mjs +2 -2
  152. package/assets/docs/tree/updates.doc.mjs +1 -1
  153. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  154. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  155. package/assets/docs/tree/verify-packed-template.doc.mjs +3 -3
  156. package/assets/docs/tree/versioning.doc.mjs +4 -4
  157. package/assets/docs/tree/who-answers.doc.mjs +4 -4
  158. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -4
  159. package/assets/docs/use-a-theme.doc.mjs +10 -10
  160. package/assets/docs/use-integrations.doc.mjs +1 -1
  161. package/assets/docs/working-with-ai.doc.mjs +15 -15
  162. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +1 -1
  163. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +1 -1
  164. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +54 -0
  165. package/assets/templates/themes/butter/butterPalettes.generated.receipt.json +1499 -0
  166. package/assets/templates/themes/butter/butterPalettes.generated.ts +550 -0
  167. package/assets/templates/themes/butter/butterTheme.ts +274 -234
  168. package/assets/templates/themes/butter/palette.config.json +484 -0
  169. package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +41 -0
  170. package/assets/templates/themes/gothic/gothicPalettes.generated.receipt.json +979 -0
  171. package/assets/templates/themes/gothic/gothicPalettes.generated.ts +271 -0
  172. package/assets/templates/themes/gothic/gothicTheme.ts +130 -160
  173. package/assets/templates/themes/gothic/palette.config.json +371 -0
  174. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +51 -0
  175. package/assets/templates/themes/matcha/matchaPalettes.generated.receipt.json +1502 -0
  176. package/assets/templates/themes/matcha/matchaPalettes.generated.ts +501 -0
  177. package/assets/templates/themes/matcha/matchaPalettes.ts +21 -0
  178. package/assets/templates/themes/matcha/matchaTheme.ts +164 -103
  179. package/assets/templates/themes/matcha/palette.config.json +448 -0
  180. package/assets/templates/themes/stone/palette.config.json +262 -0
  181. package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +51 -0
  182. package/assets/templates/themes/stone/stonePalettes.generated.receipt.json +840 -0
  183. package/assets/templates/themes/stone/stonePalettes.generated.ts +501 -0
  184. package/assets/templates/themes/stone/stoneTheme.ts +190 -207
  185. package/assets/templates/themes/y2k/palette.config.json +166 -0
  186. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +54 -0
  187. package/assets/templates/themes/y2k/y2kPalettes.generated.receipt.json +872 -0
  188. package/assets/templates/themes/y2k/y2kPalettes.generated.ts +550 -0
  189. package/assets/templates/themes/y2k/y2kPalettes.ts +257 -0
  190. package/assets/templates/themes/y2k/y2kTheme.ts +164 -391
  191. package/authoring/codemod/codemod.doc.mjs +1 -1
  192. package/authoring/config/config.doc.mjs +4 -4
  193. package/authoring/debug/parse.d.mts +1 -1
  194. package/authoring/discover/discover.doc.mjs +1 -1
  195. package/authoring/doctypes/_schema.d.mts +4 -0
  196. package/authoring/doctypes/_schema.mjs +4 -0
  197. package/authoring/doctypes/reference/type.ts +14 -2
  198. package/authoring/gap-report/gap-report.doc.mjs +1 -1
  199. package/authoring/integration/integration.doc.mjs +6 -6
  200. package/clients/cli/commands/discover.mjs +1 -1
  201. package/clients/cli/commands/discover.sources.test.mjs +6 -0
  202. package/clients/cli/commands/docs.doc.mjs +1 -1
  203. package/clients/cli/commands/docs.mjs +27 -2
  204. package/clients/cli/commands/docs.test.mjs +1 -1
  205. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  206. package/clients/cli/commands/doctor.doc.mjs +13 -1
  207. package/clients/cli/commands/doctor.mjs +25 -9
  208. package/clients/cli/commands/integration-check.doc.mjs +11 -0
  209. package/clients/cli/commands/integration-check.test.mjs +36 -3
  210. package/clients/cli/commands/integration-pack.doc.mjs +1 -1
  211. package/clients/cli/commands/integration-verify.doc.mjs +1 -1
  212. package/clients/cli/commands/integration.mjs +15 -3
  213. package/clients/cli/commands/theme-targets.doc.mjs +1 -1
  214. package/clients/cli/commands/upgrade.doc.mjs +2 -2
  215. package/clients/cli/lib/define-command.mjs +5 -3
  216. package/foundation/agent-docs/agent-docs.d.mts +14 -2
  217. package/foundation/agent-docs/agent-docs.mjs +65 -4
  218. package/foundation/agent-docs/agent-docs.test.mjs +107 -0
  219. package/foundation/discovery/docs-discovery.d.mts +93 -2
  220. package/foundation/discovery/docs-discovery.mjs +237 -8
  221. package/foundation/discovery/runner-allowlist.d.mts +2 -0
  222. package/foundation/discovery/runner-allowlist.mjs +4 -0
  223. package/foundation/discovery/runner-commands.d.mts +29 -13
  224. package/foundation/discovery/runner-commands.mjs +253 -17
  225. package/foundation/discovery/stray-pointers.mjs +11 -5
  226. package/foundation/discovery/stray-pointers.test.mjs +6 -0
  227. package/foundation/doc-compiler/compile.mjs +8 -1
  228. package/foundation/doc-compiler/doc-loads.test.mjs +3 -0
  229. package/foundation/doc-compiler/doc-syntax.d.mts +194 -0
  230. package/foundation/doc-compiler/doc-syntax.mjs +739 -0
  231. package/foundation/doc-compiler/doc-syntax.test.mjs +383 -0
  232. package/foundation/doc-compiler/links.d.mts +13 -16
  233. package/foundation/doc-compiler/links.mjs +40 -7
  234. package/foundation/doc-compiler/tree.d.mts +5 -0
  235. package/foundation/doc-compiler/tree.mjs +9 -0
  236. package/foundation/env/package-manager.d.mts +18 -0
  237. package/foundation/env/package-manager.mjs +40 -0
  238. package/foundation/integrations/cli-requirement.d.mts +29 -0
  239. package/foundation/integrations/cli-requirement.mjs +47 -0
  240. package/foundation/integrations/cli-requirement.test.mjs +23 -2
  241. package/foundation/response/error-codes.test.mjs +9 -0
  242. package/foundation/response/response-types.doc.mjs +11 -11
  243. package/foundation/response/response-types.doc.test.mjs +29 -0
  244. package/package.json +9 -9
@@ -0,0 +1,383 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+
5
+ import {
6
+ commandTokensIn,
7
+ DOC_PACKAGE_MANAGERS,
8
+ parseCommandToken,
9
+ renderCommandTokens,
10
+ renderPmStep,
11
+ tokenForCommand,
12
+ unknownTokensIn,
13
+ unclosedTokensIn,
14
+ } from './doc-syntax.mjs';
15
+
16
+ /** @param {string} body */
17
+ function pm(body) {
18
+ const step = parseCommandToken('pm', body);
19
+ if ('error' in step) throw new Error(step.error);
20
+ if (step.kind !== 'pm') throw new Error('not a pm step');
21
+ return step;
22
+ }
23
+
24
+ /** @param {string} body */
25
+ const everyManager = body =>
26
+ Object.fromEntries(
27
+ DOC_PACKAGE_MANAGERS.map(each => [each, renderPmStep(pm(body), each)]),
28
+ );
29
+
30
+ describe('renderPmStep', () => {
31
+ // Each row was run on npm 10.9, pnpm 11.10, Yarn 4.18, Yarn 1.22 and Bun
32
+ // 1.4 in a throwaway project, and did what the token says.
33
+ it('adds packages, as dependencies or dev dependencies', () => {
34
+ expect(everyManager('install @acme/x')).toEqual({
35
+ npm: 'npm install @acme/x',
36
+ pnpm: 'pnpm add @acme/x',
37
+ yarn: 'yarn add @acme/x',
38
+ 'yarn-classic': 'yarn add @acme/x',
39
+ bun: 'bun add @acme/x',
40
+ });
41
+ expect(everyManager('install @acme/x --dev')).toEqual({
42
+ npm: 'npm install -D @acme/x',
43
+ pnpm: 'pnpm add -D @acme/x',
44
+ yarn: 'yarn add -D @acme/x',
45
+ 'yarn-classic': 'yarn add -D @acme/x',
46
+ bun: 'bun add -d @acme/x',
47
+ });
48
+ expect(everyManager('install')).toEqual({
49
+ npm: 'npm install',
50
+ pnpm: 'pnpm install',
51
+ yarn: 'yarn install',
52
+ 'yarn-classic': 'yarn install',
53
+ bun: 'bun install',
54
+ });
55
+ });
56
+
57
+ it('installs for the computer, with npm where Yarn 2 has no global install', () => {
58
+ expect(everyManager('install @astryxdesign/cli --global')).toEqual({
59
+ npm: 'npm install -g @astryxdesign/cli',
60
+ pnpm: 'pnpm add -g @astryxdesign/cli',
61
+ yarn: 'npm install -g @astryxdesign/cli',
62
+ 'yarn-classic': 'yarn global add @astryxdesign/cli',
63
+ bun: 'bun add -g @astryxdesign/cli',
64
+ });
65
+ expect(everyManager('remove @astryxdesign/cli --global')).toEqual({
66
+ npm: 'npm uninstall -g @astryxdesign/cli',
67
+ pnpm: 'pnpm remove -g @astryxdesign/cli',
68
+ yarn: 'npm uninstall -g @astryxdesign/cli',
69
+ 'yarn-classic': 'yarn global remove @astryxdesign/cli',
70
+ bun: 'bun remove -g @astryxdesign/cli',
71
+ });
72
+ });
73
+
74
+ it('passes script arguments with `--` only where the package manager needs it', () => {
75
+ // pnpm and Yarn 2 hand a `--` on to the script; npm needs one.
76
+ expect(everyManager('run build --watch')).toEqual({
77
+ npm: 'npm run build -- --watch',
78
+ pnpm: 'pnpm run build --watch',
79
+ yarn: 'yarn run build --watch',
80
+ 'yarn-classic': 'yarn run build --watch',
81
+ bun: 'bun run build --watch',
82
+ });
83
+ });
84
+
85
+ it('runs an installed binary, and a package without installing it', () => {
86
+ expect(everyManager('exec tsc --noEmit')).toEqual({
87
+ npm: 'npx tsc --noEmit',
88
+ pnpm: 'pnpm exec tsc --noEmit',
89
+ yarn: 'yarn run tsc --noEmit',
90
+ 'yarn-classic': 'yarn run tsc --noEmit',
91
+ bun: 'bunx tsc --noEmit',
92
+ });
93
+ expect(everyManager('dlx @astryxdesign/cli init')).toEqual({
94
+ npm: 'npx @astryxdesign/cli init',
95
+ pnpm: 'pnpm dlx @astryxdesign/cli init',
96
+ yarn: 'yarn dlx @astryxdesign/cli init',
97
+ 'yarn-classic': 'npx @astryxdesign/cli init',
98
+ bun: 'bunx @astryxdesign/cli init',
99
+ });
100
+ });
101
+
102
+ it('updates packages, to the latest release when asked', () => {
103
+ expect(everyManager('update @acme/x --latest')).toEqual({
104
+ npm: 'npm install @acme/x@latest',
105
+ pnpm: 'pnpm update --latest @acme/x',
106
+ yarn: 'yarn up @acme/x',
107
+ 'yarn-classic': 'yarn upgrade --latest @acme/x',
108
+ bun: 'bun update --latest @acme/x',
109
+ });
110
+ });
111
+
112
+ it('updates within the declared range unless asked for the latest', () => {
113
+ expect(everyManager('update @acme/x')).toEqual({
114
+ npm: 'npm update @acme/x',
115
+ pnpm: 'pnpm update @acme/x',
116
+ yarn: 'yarn up -R @acme/x',
117
+ 'yarn-classic': 'yarn upgrade @acme/x',
118
+ bun: 'bun update @acme/x',
119
+ });
120
+ });
121
+
122
+ it('passes an initializer its flags, after `--` on npm', () => {
123
+ expect(everyManager('create vite my-app --template react')).toEqual({
124
+ npm: 'npm create vite my-app -- --template react',
125
+ pnpm: 'pnpm create vite my-app --template react',
126
+ yarn: 'yarn create vite my-app --template react',
127
+ 'yarn-classic': 'yarn create vite my-app --template react',
128
+ bun: 'bun create vite my-app --template react',
129
+ });
130
+ });
131
+ });
132
+
133
+ describe('a token whose body holds braces or quotes', () => {
134
+ it('renders and is found by doctor', () => {
135
+ const text =
136
+ 'Run {@pm-only npm "edits package.json" pkg set \'exports={}\' --json} first.';
137
+ expect(renderCommandTokens(text, {stem: 'astryx', pm: 'pnpm'})).toBe(
138
+ "Run `npm pkg set 'exports={}' --json` (only with npm: edits package.json) first.",
139
+ );
140
+ expect(commandTokensIn(text).map(each => each.name)).toEqual(['pm-only']);
141
+ });
142
+ });
143
+
144
+ describe('the token for a script, binary or initializer', () => {
145
+ it('keeps every word after the name, flags included', () => {
146
+ expect(tokenForCommand('pnpm exec tsc --noEmit')).toBe(
147
+ '{@pm exec tsc --noEmit}',
148
+ );
149
+ expect(
150
+ tokenForCommand('pnpm dlx create-vite my-app --template react'),
151
+ ).toBe('{@pm dlx create-vite my-app --template react}');
152
+ expect(tokenForCommand('pnpm run build -d')).toBe('{@pm run build -d}');
153
+ expect(tokenForCommand('npm run test -- -g smoke')).toBe(
154
+ '{@pm run test -g smoke}',
155
+ );
156
+ });
157
+ });
158
+
159
+ describe('npm script shortcuts', () => {
160
+ it('suggest {@pm run …}, which every package manager runs', () => {
161
+ expect(tokenForCommand('npm test')).toBe('{@pm run test}');
162
+ expect(tokenForCommand('npm start -- --port 3000')).toBe(
163
+ '{@pm run start --port 3000}',
164
+ );
165
+ expect(tokenForCommand('npm test -- --watch')).toBe(
166
+ '{@pm run test --watch}',
167
+ );
168
+ expect(tokenForCommand('npm run-script build')).toBe('{@pm run build}');
169
+ });
170
+ });
171
+
172
+ describe('a token that never closes', () => {
173
+ it('counts a token broken across lines, or holding a backtick, as unclosed', () => {
174
+ expect(
175
+ unclosedTokensIn(
176
+ '{@command theme palette generate palette.config.json \\\n --out src/acme.palette.ts}',
177
+ ),
178
+ ).toEqual(['{@command theme palette generate palette.config.json \\']);
179
+ expect(
180
+ unclosedTokensIn(
181
+ 'Run {@pm-only npm "edits `package.json`" pkg set name=acme}.',
182
+ ),
183
+ ).toHaveLength(1);
184
+ });
185
+
186
+ it('is found, with the rest of its line', () => {
187
+ expect(
188
+ unclosedTokensIn(
189
+ 'Run {@pm install @acme/widgets --dev and go.\nNext {@command doctor}.',
190
+ ),
191
+ ).toEqual(['{@pm install @acme/widgets --dev and go.']);
192
+ expect(
193
+ unclosedTokensIn('Run {@pm-only npm "never closes pkg set x}.'),
194
+ ).toEqual(['{@pm-only npm "never closes pkg set x}.']);
195
+ });
196
+ });
197
+
198
+ describe('parseCommandToken', () => {
199
+ it('names what is wrong and how to write it', () => {
200
+ expect(parseCommandToken('pm', 'install -D x')).toMatchObject({
201
+ error: expect.stringContaining('--dev'),
202
+ });
203
+ expect(parseCommandToken('pm', 'add x')).toMatchObject({
204
+ error: expect.stringContaining('install'),
205
+ });
206
+ expect(parseCommandToken('pm', 'install x@^1.2.0 --exact')).toMatchObject({
207
+ error: expect.stringContaining('range'),
208
+ });
209
+ expect(parseCommandToken('pm', 'update --latest')).toMatchObject({
210
+ error: expect.stringContaining('packages'),
211
+ });
212
+ expect(parseCommandToken('pm-only', 'npm pkg set name=x')).toMatchObject({
213
+ error: expect.stringContaining('reason'),
214
+ });
215
+ expect(parseCommandToken('pm-only', 'npmx "why" pkg')).toMatchObject({
216
+ error: expect.stringContaining('package manager'),
217
+ });
218
+ expect(parseCommandToken('command', 'astryx docs')).toMatchObject({
219
+ error: expect.stringContaining('{@command docs}'),
220
+ });
221
+ });
222
+
223
+ it('reads a one-manager step with its reason', () => {
224
+ expect(
225
+ parseCommandToken(
226
+ 'pm-only',
227
+ 'npm "no other manager has it" pkg set name=x',
228
+ ),
229
+ ).toEqual({
230
+ kind: 'pm-only',
231
+ manager: 'npm',
232
+ reason: 'no other manager has it',
233
+ args: ['pkg', 'set', 'name=x'],
234
+ });
235
+ });
236
+ });
237
+
238
+ describe('renderCommandTokens', () => {
239
+ const reader = {stem: 'pnpm exec astryx', pm: /** @type {const} */ ('pnpm')};
240
+
241
+ it('renders each token for the reader, as a code span in prose', () => {
242
+ expect(
243
+ renderCommandTokens(
244
+ 'Add it with {@pm install @acme/x}, then run {@command docs acme}.',
245
+ reader,
246
+ ),
247
+ ).toBe(
248
+ 'Add it with `pnpm add @acme/x`, then run `pnpm exec astryx docs acme`.',
249
+ );
250
+ });
251
+
252
+ it('renders a fence inside prose as a code block in its language', () => {
253
+ expect(
254
+ renderCommandTokens(
255
+ [
256
+ 'Install it with {@pm install @acme/fence --dev}:',
257
+ '',
258
+ '```bash',
259
+ '{@pm install @acme/fence --dev}',
260
+ '{@command doctor}',
261
+ '{@pm-only npm "edits package.json" pkg set x=1}',
262
+ '```',
263
+ '',
264
+ '~~~text',
265
+ '{@command doctor}',
266
+ '~~~',
267
+ 'Then {@command doctor}.',
268
+ ].join('\n'),
269
+ reader,
270
+ ),
271
+ ).toBe(
272
+ [
273
+ 'Install it with `pnpm add -D @acme/fence`:',
274
+ '',
275
+ '```bash',
276
+ 'pnpm add -D @acme/fence',
277
+ 'pnpm exec astryx doctor',
278
+ 'npm pkg set x=1 # only with npm: edits package.json',
279
+ '```',
280
+ '',
281
+ '~~~text',
282
+ 'pnpm exec astryx doctor',
283
+ '~~~',
284
+ 'Then `pnpm exec astryx doctor`.',
285
+ ].join('\n'),
286
+ );
287
+ });
288
+
289
+ it('renders inside a code span and a code block without extra ticks', () => {
290
+ expect(renderCommandTokens('Run `{@pm run build}`.', reader)).toBe(
291
+ 'Run `pnpm run build`.',
292
+ );
293
+ expect(
294
+ renderCommandTokens(
295
+ '{@pm install}\n{@command integration check --strict}',
296
+ reader,
297
+ 'bash',
298
+ ),
299
+ ).toBe('pnpm install\npnpm exec astryx integration check --strict');
300
+ });
301
+
302
+ it('shows a one-manager step with its reason, as a comment in a shell block', () => {
303
+ expect(
304
+ renderCommandTokens(
305
+ '{@pm-only npm "pnpm and Yarn have no pkg" pkg set name=x}',
306
+ reader,
307
+ ),
308
+ ).toBe('`npm pkg set name=x` (only with npm: pnpm and Yarn have no pkg)');
309
+ expect(
310
+ renderCommandTokens(
311
+ '{@pm-only pnpm "once per computer" setup}',
312
+ reader,
313
+ 'sh',
314
+ ),
315
+ ).toBe('pnpm setup # only with pnpm: once per computer');
316
+ });
317
+
318
+ it('shows {@@…} as written, and leaves a token that does not parse as it was', () => {
319
+ expect(renderCommandTokens('Write {@@pm install x}.', reader)).toBe(
320
+ 'Write {@pm install x}.',
321
+ );
322
+ expect(
323
+ renderCommandTokens('{@pm add x} and {@link generic:x}', reader),
324
+ ).toBe('{@pm add x} and {@link generic:x}');
325
+ });
326
+ });
327
+
328
+ describe('tokenForCommand', () => {
329
+ it.each([
330
+ [
331
+ 'npm install -D @astryxdesign/cli',
332
+ '{@pm install @astryxdesign/cli --dev}',
333
+ ],
334
+ [
335
+ 'pnpm add -g @astryxdesign/cli',
336
+ '{@pm install @astryxdesign/cli --global}',
337
+ ],
338
+ [
339
+ 'yarn global add @astryxdesign/cli',
340
+ '{@pm install @astryxdesign/cli --global}',
341
+ ],
342
+ [
343
+ 'npm uninstall -g @astryxdesign/cli',
344
+ '{@pm remove @astryxdesign/cli --global}',
345
+ ],
346
+ ['npm install', '{@pm install}'],
347
+ ['yarn typecheck', '{@pm run typecheck}'],
348
+ ['npx tsc --noEmit', '{@pm exec tsc --noEmit}'],
349
+ ['npx @astryxdesign/cli init', '{@pm dlx @astryxdesign/cli init}'],
350
+ ['pnpm exec astryx docs theme', '{@command docs theme}'],
351
+ ['yarn astryx integration verify', '{@command integration verify}'],
352
+ ['npm run astryx -- docs tokens', '{@command docs tokens}'],
353
+ ['astryx docs theme', '{@command docs theme}'],
354
+ ['npm pkg set name=x', '{@pm-only npm "<why only npm>" pkg set name=x}'],
355
+ ['pnpm setup', '{@pm-only pnpm "<why only pnpm>" setup}'],
356
+ ])('%s is written %s', (command, token) => {
357
+ expect(tokenForCommand(command)).toBe(token);
358
+ });
359
+
360
+ it('leaves a command that is not a package manager or the CLI', () => {
361
+ expect(tokenForCommand('git status')).toBeNull();
362
+ });
363
+
364
+ it('suggests a token that renders back to the command in its own package manager', () => {
365
+ const step = pm('install @astryxdesign/cli --dev');
366
+ expect(renderPmStep(step, 'npm')).toBe('npm install -D @astryxdesign/cli');
367
+ });
368
+ });
369
+
370
+ describe('commandTokensIn and unknownTokensIn', () => {
371
+ it('finds each token with its parse, and names the ones that are not doc tokens', () => {
372
+ const text =
373
+ '{@pm install x} {@command docs} {@pm add y} {@@pm z} {@cmd docs} {@link generic:a}';
374
+ expect(
375
+ commandTokensIn(text).map(each => [each.name, 'error' in each.step]),
376
+ ).toEqual([
377
+ ['pm', false],
378
+ ['command', false],
379
+ ['pm', true],
380
+ ]);
381
+ expect(unknownTokensIn(text)).toEqual(['{@cmd docs}']);
382
+ });
383
+ });
@@ -51,12 +51,23 @@ export function parseLinkTarget(target: unknown): LinkTarget | {
51
51
  error: string;
52
52
  };
53
53
  /**
54
- * Text with each inline link replaced by its name, for indexes that must not
55
- * read the link syntax as words.
54
+ * Text with each inline link replaced by its name and each doc token by its
55
+ * command, for indexes that must not read the syntax as words.
56
56
  * @param {string} text
57
57
  * @returns {string}
58
58
  */
59
59
  export function unlinkText(text: string): string;
60
+ /**
61
+ * Text with its doc tokens rendered (doc-syntax.mjs): `{@command …}` as the
62
+ * bare `astryx …` command, which text output then starts with the reader's
63
+ * runner the way it starts every command, and `{@pm …}` in the package
64
+ * manager of the project the CLI runs in. JSON readers get runnable commands,
65
+ * the way they did before docs wrote tokens.
66
+ * @param {unknown} text
67
+ * @param {string | null} [lang] the code block's language for a block's body
68
+ * @returns {any}
69
+ */
70
+ export function renderTokens(text: unknown, lang?: string | null): any;
60
71
  /**
61
72
  * Every text field of a doc object, in authored order, by the same rules
62
73
  * {@link linkFields} resolves links by: the strings a reader reads, never a
@@ -107,20 +118,6 @@ export function linkSections(sections: any[], resolve: LinkResolver): Promise<{
107
118
  sections: any[];
108
119
  problems: LinkProblem[];
109
120
  }>;
110
- /**
111
- * @file Links between docs, named by doc identity (spec:AST-047 FR9).
112
- *
113
- * @input A link target, `[<provider>:]<kind>:<name>`, written as a `reference`
114
- * block, in a `workflow` step's `references`, or inline in text as
115
- * `{@link <target>}`; and a resolver that finds the doc a target names.
116
- * @output The same content with every link resolved: an inline link becomes
117
- * the `astryx docs` command that opens its doc, and a block carries a `link`
118
- * with the doc's identity, route, title, summary, and command. A reference
119
- * block in a topic section also carries the `content` it includes. A link
120
- * that names no doc is a problem, never a guess.
121
- * @position Pure. The docs adapter owns the resolver (the project's docs tree
122
- * and topic catalog) and applies this to every read and every doctor check.
123
- */
124
121
  /** The kinds a link can name: every authored doc kind. */
125
122
  export const LINK_KINDS: Set<string>;
126
123
  /** An inline link in text: `{@link <target>}`. */
@@ -11,10 +11,17 @@
11
11
  * with the doc's identity, route, title, summary, and command. A reference
12
12
  * block in a topic section also carries the `content` it includes. A link
13
13
  * that names no doc is a problem, never a guess.
14
- * @position Pure. The docs adapter owns the resolver (the project's docs tree
15
- * and topic catalog) and applies this to every read and every doctor check.
14
+ * Doc tokens render here too (renderTokens), so text and JSON carry the
15
+ * same commands.
16
+ * @position Pure, apart from reading which package manager the working
17
+ * directory's project uses, for `{@pm}` tokens. The docs adapter owns the
18
+ * resolver (the project's docs tree and topic catalog) and applies this to
19
+ * every read and every doctor check.
16
20
  */
17
21
 
22
+ import {renderCommandTokens} from './doc-syntax.mjs';
23
+ import {docPackageManager} from '../env/package-manager.mjs';
24
+
18
25
  /** The kinds a link can name: every authored doc kind. */
19
26
  export const LINK_KINDS = new Set([
20
27
  'generic',
@@ -114,13 +121,13 @@ export function parseLinkTarget(target) {
114
121
  }
115
122
 
116
123
  /**
117
- * Text with each inline link replaced by its name, for indexes that must not
118
- * read the link syntax as words.
124
+ * Text with each inline link replaced by its name and each doc token by its
125
+ * command, for indexes that must not read the syntax as words.
119
126
  * @param {string} text
120
127
  * @returns {string}
121
128
  */
122
129
  export function unlinkText(text) {
123
- return text
130
+ return String(renderTokens(text))
124
131
  .split(CODE_SPAN)
125
132
  .map(part =>
126
133
  part.startsWith('`')
@@ -133,6 +140,25 @@ export function unlinkText(text) {
133
140
  .join('');
134
141
  }
135
142
 
143
+ /**
144
+ * Text with its doc tokens rendered (doc-syntax.mjs): `{@command …}` as the
145
+ * bare `astryx …` command, which text output then starts with the reader's
146
+ * runner the way it starts every command, and `{@pm …}` in the package
147
+ * manager of the project the CLI runs in. JSON readers get runnable commands,
148
+ * the way they did before docs wrote tokens.
149
+ * @param {unknown} text
150
+ * @param {string | null} [lang] the code block's language for a block's body
151
+ * @returns {any}
152
+ */
153
+ export function renderTokens(text, lang = null) {
154
+ if (typeof text !== 'string' || !text.includes('{@')) return text;
155
+ return renderCommandTokens(
156
+ text,
157
+ {stem: 'astryx', pm: docPackageManager(process.cwd())},
158
+ lang,
159
+ );
160
+ }
161
+
136
162
  /**
137
163
  * Text with each inline link replaced by the command that opens its doc. A
138
164
  * link written inside code ticks is shown as written: it documents the syntax,
@@ -143,7 +169,8 @@ export function unlinkText(text) {
143
169
  * @returns {Promise<any>}
144
170
  */
145
171
  async function resolveInline(text, find) {
146
- if (typeof text !== 'string' || !text.includes('{@link')) return text;
172
+ if (typeof text !== 'string') return text;
173
+ if (!text.includes('{@link')) return renderTokens(text);
147
174
  let out = '';
148
175
  for (const part of text.split(CODE_SPAN)) {
149
176
  if (part.startsWith('`')) {
@@ -160,7 +187,7 @@ async function resolveInline(text, find) {
160
187
  }
161
188
  out += part.slice(last);
162
189
  }
163
- return out;
190
+ return renderTokens(out);
164
191
  }
165
192
 
166
193
  /**
@@ -396,6 +423,12 @@ export async function linkBlocks(blocks, resolve, at = {}, include) {
396
423
  content.push({...block, steps});
397
424
  break;
398
425
  }
426
+ case 'code':
427
+ content.push({
428
+ ...block,
429
+ code: renderTokens(block.code, block.lang ?? ''),
430
+ });
431
+ break;
399
432
  case 'collection':
400
433
  problems.push({
401
434
  target: `collection:${block.source?.slot ?? ''}`,
@@ -300,6 +300,11 @@ export type TreeNode = {
300
300
  slots: TreeSlot[];
301
301
  source: string;
302
302
  ref?: any;
303
+ /**
304
+ * what integrations do to a guide the tree places, by its route: set by the
305
+ * project's tree, absent when nothing replaces or extends it
306
+ */
307
+ guideOverlay?: import("../discovery/docs-discovery.mjs").GuideOverlay | undefined;
303
308
  };
304
309
  export type DocsTree = {
305
310
  /**
@@ -25,6 +25,7 @@ import {routeSegment} from '../discovery/docs-section-key.mjs';
25
25
  import {diagnostic, sortDiagnostics} from './diagnostics.mjs';
26
26
  import {readDocView} from './read.mjs';
27
27
  import {packageSource} from './source.mjs';
28
+ import {renderTokens} from './links.mjs';
28
29
  import {createDocId} from '../identity/provider-identity.mjs';
29
30
  import {CLI_PROVIDER_ID} from '../identity/providers.mjs';
30
31
 
@@ -178,6 +179,9 @@ export const topicLevel = category =>
178
179
  * @property {TreeSlot[]} slots a namespace's slots; empty for a leaf
179
180
  * @property {string} source
180
181
  * @property {any} [ref]
182
+ * @property {import('../discovery/docs-discovery.mjs').GuideOverlay} [guideOverlay]
183
+ * what integrations do to a guide the tree places, by its route: set by the
184
+ * project's tree, absent when nothing replaces or extends it
181
185
  */
182
186
 
183
187
  /**
@@ -952,6 +956,11 @@ export function loadDocsTree({selfDocs = true, fresh = false} = {}) {
952
956
  if (!tree) {
953
957
  tree = loadTreeInputs({selfDocs}).then(inputs => {
954
958
  const result = buildDocsTree(inputs);
959
+ // Tree inputs carry authored summaries; each renders its doc tokens
960
+ // once, here or where the project tree is built.
961
+ for (const node of result.nodes.values()) {
962
+ node.summary = renderTokens(node.summary);
963
+ }
955
964
  return {
956
965
  ...result,
957
966
  diagnostics: sortDiagnostics([
@@ -209,6 +209,24 @@ export function formatCliCommand(command: string, targetDir?: string): string;
209
209
  * @returns {string}
210
210
  */
211
211
  export function prefixCliCommands(text: string, stem: string, lang?: string | null): string;
212
+ /**
213
+ * Run `fn` with doc `{@pm}` steps rendered for `pm`, whatever the working
214
+ * directory's project uses: a host that shows docs to readers of every
215
+ * package manager, such as the docsite, picks one.
216
+ * @template T
217
+ * @param {import('../doc-compiler/doc-syntax.mjs').DocPackageManager} pm
218
+ * @param {() => T} fn
219
+ * @returns {T}
220
+ */
221
+ export function runWithDocPackageManager<T>(pm: import("../doc-compiler/doc-syntax.mjs").DocPackageManager, fn: () => T): T;
222
+ /**
223
+ * The package manager a doc's `{@pm}` steps render for, from the project in
224
+ * `targetDir`: npm when nothing is detected, and Yarn 1 told apart from Yarn
225
+ * 2 and newer; the one a host chose with runWithDocPackageManager wins.
226
+ * @param {string} [targetDir]
227
+ * @returns {import('../doc-compiler/doc-syntax.mjs').DocPackageManager}
228
+ */
229
+ export function docPackageManager(targetDir?: string): import("../doc-compiler/doc-syntax.mjs").DocPackageManager;
212
230
  /**
213
231
  * Quote one argument of a printed command so the shell it is pasted into
214
232
  * passes it on unchanged. Printed commands target a POSIX shell (sh, bash,
@@ -12,6 +12,7 @@
12
12
  * a host's door name, come first (see cli-command.mjs).
13
13
  */
14
14
 
15
+ import {AsyncLocalStorage} from 'node:async_hooks';
15
16
  import * as fs from 'node:fs';
16
17
  import * as path from 'node:path';
17
18
  import {cliDoor, declaredCliCommand} from './cli-command.mjs';
@@ -637,6 +638,45 @@ export function prefixCliCommands(text, stem, lang = null) {
637
638
  .join('\n');
638
639
  }
639
640
 
641
+ /** @type {AsyncLocalStorage<{pm: import('../doc-compiler/doc-syntax.mjs').DocPackageManager}>} */
642
+ const docPackageManagerScope = new AsyncLocalStorage();
643
+
644
+ /**
645
+ * Run `fn` with doc `{@pm}` steps rendered for `pm`, whatever the working
646
+ * directory's project uses: a host that shows docs to readers of every
647
+ * package manager, such as the docsite, picks one.
648
+ * @template T
649
+ * @param {import('../doc-compiler/doc-syntax.mjs').DocPackageManager} pm
650
+ * @param {() => T} fn
651
+ * @returns {T}
652
+ */
653
+ export function runWithDocPackageManager(pm, fn) {
654
+ return docPackageManagerScope.run({pm}, fn);
655
+ }
656
+
657
+ /**
658
+ * The package manager a doc's `{@pm}` steps render for, from the project in
659
+ * `targetDir`: npm when nothing is detected, and Yarn 1 told apart from Yarn
660
+ * 2 and newer; the one a host chose with runWithDocPackageManager wins.
661
+ * @param {string} [targetDir]
662
+ * @returns {import('../doc-compiler/doc-syntax.mjs').DocPackageManager}
663
+ */
664
+ export function docPackageManager(targetDir) {
665
+ const chosen = docPackageManagerScope.getStore()?.pm;
666
+ if (chosen) return chosen;
667
+ const resolution = explainPackageManager(targetDir);
668
+ switch (resolution.pm) {
669
+ case 'yarn':
670
+ return isYarnClassic(resolution) ? 'yarn-classic' : 'yarn';
671
+ case 'pnpm':
672
+ return 'pnpm';
673
+ case 'bun':
674
+ return 'bun';
675
+ default:
676
+ return 'npm';
677
+ }
678
+ }
679
+
640
680
  /**
641
681
  * Quote one argument of a printed command so the shell it is pasted into
642
682
  * passes it on unchanged. Printed commands target a POSIX shell (sh, bash,
@@ -56,6 +56,23 @@ export function componentReplacesCliProblem(pkg: any): string | null;
56
56
  * @returns {string | null}
57
57
  */
58
58
  export function sectionIdsCliProblem(pkg: any): string | null;
59
+ /**
60
+ * Why a package with a doc section that sets `before` or `after` would lose
61
+ * its doc topics on an older CLI, or null when its declared CLI range admits
62
+ * only CLIs that read the fields (spec:AST-046 FR11).
63
+ * @param {any} pkg package.json
64
+ * @returns {string | null}
65
+ */
66
+ export function sectionPositionCliProblem(pkg: any): string | null;
67
+ /**
68
+ * Why a package whose docs write doc tokens would show them raw on an older
69
+ * CLI, or null when its declared CLI range admits only CLIs that render
70
+ * them. Every release before the first that renders them prints a token as
71
+ * written.
72
+ * @param {any} pkg package.json
73
+ * @returns {string | null}
74
+ */
75
+ export function docTokensCliProblem(pkg: any): string | null;
59
76
  /**
60
77
  * Why a package that ships a theme would lose its themes and doc topics on an
61
78
  * older CLI, or null when its declared CLI range admits only CLIs that read
@@ -140,3 +157,15 @@ export const THEMES_CLI: "0.6.4";
140
157
  * published 0.6.4 reads the section by its id.
141
158
  */
142
159
  export const SECTION_IDS_CLI: "0.6.4";
160
+ /**
161
+ * The first CLI release that reads a doc section's `before` and `after`.
162
+ * Earlier releases reject the fields and hide every doc topic the package
163
+ * ships.
164
+ */
165
+ export const SECTION_POSITION_CLI: "0.7.4";
166
+ /**
167
+ * The first stable CLI release that renders doc tokens (`{@command …}`,
168
+ * `{@pm …}`, `{@pm-only …}`) for the reader. Every earlier release prints
169
+ * them as written, so readers see raw tokens.
170
+ */
171
+ export const DOC_TOKENS_CLI: "0.7.4";