@astryxdesign/cli 0.7.3-canary.b74cf21 → 0.7.3-canary.be42333

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 (229) hide show
  1. package/README.md +68 -68
  2. package/api/build/blocks/blocks.d.mts +6 -4
  3. package/api/build/blocks/blocks.mjs +103 -20
  4. package/api/build/blocks/blocks.test.mjs +126 -13
  5. package/api/build/blocks/blocks.weights.json +1 -1
  6. package/api/build/kit/answer.d.mts +5 -4
  7. package/api/build/kit/answer.mjs +114 -12
  8. package/api/build/kit/answer.test.mjs +73 -3
  9. package/api/build/kit/signals.d.mts +8 -0
  10. package/api/build/kit/signals.mjs +10 -0
  11. package/api/build/tree.test.mjs +19 -11
  12. package/api/component/component-replacement.test.mjs +1 -0
  13. package/api/component/component.mjs +17 -3
  14. package/api/component/component.test.mjs +15 -0
  15. package/api/component/doc-links.test.mjs +2 -2
  16. package/api/discover/_adapter.d.mts +1 -2
  17. package/api/discover/_adapter.mjs +6 -8
  18. package/api/discover/discover.mjs +0 -1
  19. package/api/docs/_adapter.d.mts +2 -2
  20. package/api/docs/_adapter.mjs +61 -18
  21. package/api/docs/docs-homes.test.mjs +127 -0
  22. package/api/docs/docs.doc.mjs +3 -3
  23. package/api/docs/docs.test.mjs +28 -18
  24. package/api/docs/integration-tree.test.mjs +20 -20
  25. package/api/docs/integrationDocs.test.mjs +1 -1
  26. package/api/docs/namespace-section.test.mjs +6 -6
  27. package/api/docs/reference-blocks.test.mjs +2 -2
  28. package/api/doctor/_adapter.d.mts +24 -10
  29. package/api/doctor/_adapter.mjs +28 -25
  30. package/api/doctor/doctor.d.mts +7 -4
  31. package/api/doctor/doctor.mjs +68 -26
  32. package/api/doctor/doctor.test.mjs +95 -12
  33. package/api/hook/hook.mjs +1 -1
  34. package/api/integration/_adapter.d.mts +8 -0
  35. package/api/integration/_adapter.mjs +21 -1
  36. package/api/integration/authoring-checks.test.mjs +220 -0
  37. package/api/integration/pack-check.mjs +110 -4
  38. package/api/integration/pack-check.test.mjs +69 -0
  39. package/api/integration/validate-integration-fixes.test.mjs +6 -5
  40. package/api/integration/validate-integration-gaps.test.mjs +304 -1
  41. package/api/integration/validate-integration.d.mts +6 -1
  42. package/api/integration/validate-integration.mjs +82 -13
  43. package/api/integration/validate-integration.type.d.mts +37 -4
  44. package/api/integration/validate-integration.type.mjs +28 -5
  45. package/api/integration/validateIntegration.doc.mjs +1 -1
  46. package/api/search/_adapter.d.mts +16 -0
  47. package/api/search/_adapter.mjs +39 -0
  48. package/api/search/_adapter.test.mjs +173 -0
  49. package/api/search/_candidate-score.mjs +1 -1
  50. package/api/search/_entries.d.mts +11 -0
  51. package/api/search/_entries.mjs +77 -3
  52. package/api/search/_entries.test.mjs +48 -0
  53. package/api/search/_gather-docs.mjs +3 -3
  54. package/api/search/search.doc.mjs +1 -1
  55. package/api/search/search.mjs +6 -2
  56. package/api/search/search.test.mjs +14 -14
  57. package/api/upgrade/_adapter.d.mts +57 -3
  58. package/api/upgrade/_adapter.mjs +149 -27
  59. package/api/upgrade/registry/registry.d.mts +10 -4
  60. package/api/upgrade/registry/registry.mjs +33 -16
  61. package/api/upgrade/registry/registry.test.mjs +85 -0
  62. package/api/upgrade/run/run.d.mts +4 -2
  63. package/api/upgrade/run/run.mjs +13 -2
  64. package/api/upgrade/run/run.test.mjs +417 -3
  65. package/api/upgrade/upgrade.doc.mjs +10 -5
  66. package/api/upgrade/upgrade.mjs +13 -2
  67. package/api/upgrade/upgrade.type.d.mts +5 -3
  68. package/api/upgrade/upgrade.type.mjs +8 -6
  69. package/assets/docs/author-a-theme.doc.mjs +2 -2
  70. package/assets/docs/is-my-code-good.doc.mjs +287 -0
  71. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  72. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  73. package/assets/docs/tree/add-a-topic.doc.mjs +2 -2
  74. package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
  75. package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
  76. package/assets/docs/tree/block-template.doc.mjs +1 -1
  77. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  78. package/assets/docs/tree/building-blocks.doc.mjs +2 -2
  79. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  80. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  81. package/assets/docs/tree/checks.doc.mjs +3 -3
  82. package/assets/docs/tree/cli-command.doc.mjs +1 -1
  83. package/assets/docs/tree/cli.doc.mjs +1 -1
  84. package/assets/docs/tree/codemods.doc.mjs +1 -1
  85. package/assets/docs/tree/component-family.doc.mjs +1 -1
  86. package/assets/docs/tree/component-imports.doc.mjs +1 -1
  87. package/assets/docs/tree/components.doc.mjs +1 -1
  88. package/assets/docs/tree/configuration.doc.mjs +1 -1
  89. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  90. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  91. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  92. package/assets/docs/tree/docs.doc.mjs +1 -1
  93. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  94. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  95. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  96. package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
  97. package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
  98. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  99. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  100. package/assets/docs/tree/global-integrations.doc.mjs +2 -2
  101. package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
  102. package/assets/docs/tree/help.doc.mjs +2 -2
  103. package/assets/docs/tree/links.doc.mjs +1 -1
  104. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  105. package/assets/docs/tree/page-template.doc.mjs +1 -1
  106. package/assets/docs/tree/publishing.doc.mjs +1 -1
  107. package/assets/docs/tree/quick-start.doc.mjs +1 -1
  108. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  109. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  110. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  111. package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
  112. package/assets/docs/tree/ship.doc.mjs +2 -2
  113. package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
  114. package/assets/docs/tree/single-component.doc.mjs +1 -1
  115. package/assets/docs/tree/start-a-template.doc.mjs +1 -1
  116. package/assets/docs/tree/subcomponent.doc.mjs +1 -1
  117. package/assets/docs/tree/template-assets.doc.mjs +1 -1
  118. package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
  119. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  120. package/assets/docs/tree/template-grading-rubric.doc.mjs +17 -38
  121. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  122. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  123. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  124. package/assets/docs/tree/templates.doc.mjs +1 -1
  125. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  126. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  127. package/assets/docs/tree/themes.doc.mjs +1 -1
  128. package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
  129. package/assets/docs/tree/upgrading.doc.mjs +1 -1
  130. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  131. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  132. package/assets/docs/tree/versioning.doc.mjs +5 -1
  133. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  134. package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
  135. package/assets/docs/use-integrations.doc.mjs +120 -0
  136. package/assets/templates/themes/butter/butterTheme.ts +4 -2
  137. package/assets/templates/themes/stone/stoneTheme.ts +4 -2
  138. package/assets/templates/themes/y2k/y2kTheme.ts +4 -2
  139. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  140. package/authoring/integration/integration.doc.mjs +1 -1
  141. package/authoring/integration/type.ts +1 -1
  142. package/clients/cli/command-result-coverage.test.mjs +6 -5
  143. package/clients/cli/commands/build-theme.color-scheme.test.mjs +1 -1
  144. package/clients/cli/commands/{component/index.mjs → component.mjs} +37 -37
  145. package/clients/cli/commands/component.test.mjs +6 -6
  146. package/clients/cli/commands/docs.doc.mjs +2 -2
  147. package/clients/cli/commands/docs.mjs +1 -1
  148. package/clients/cli/commands/docs.test.mjs +14 -14
  149. package/clients/cli/commands/doctor-integration.test.mjs +49 -1
  150. package/clients/cli/commands/doctor.mjs +10 -0
  151. package/clients/cli/commands/{hook/index.mjs → hook.mjs} +22 -22
  152. package/clients/cli/commands/import-hint-correctness.test.mjs +1 -1
  153. package/clients/cli/commands/integration-check.test.mjs +48 -0
  154. package/clients/cli/commands/integration.doc.mjs +1 -1
  155. package/clients/cli/commands/manifest.doc.mjs +1 -1
  156. package/clients/cli/commands/manifest.mjs +67 -0
  157. package/clients/cli/commands/postinstall.doc.mjs +23 -0
  158. package/clients/cli/commands/postinstall.mjs +31 -0
  159. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  160. package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
  161. package/clients/cli/commands/upgrade.doc.mjs +4 -2
  162. package/clients/cli/commands/upgrade.mjs +9 -2
  163. package/clients/cli/commands/upgrade.subfolder-path.test.mjs +97 -0
  164. package/clients/cli/index.mjs +35 -93
  165. package/clients/cli/lib/component-format.mjs +1 -1
  166. package/clients/cli/lib/define-command.mjs +12 -7
  167. package/clients/cli/lib/exit-codes.test.mjs +5 -0
  168. package/clients/cli/lib/manifest.test.mjs +12 -0
  169. package/clients/cli/lib/welcome-box.mjs +50 -0
  170. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  171. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  172. package/foundation/agent-docs/agent-docs.mjs +7 -6
  173. package/foundation/agent-docs/agent-docs.test.mjs +5 -4
  174. package/foundation/agent-docs/computer-agent-text.mjs +16 -1
  175. package/foundation/agent-docs/computer-agent-text.test.mjs +23 -2
  176. package/foundation/config/project.mjs +5 -20
  177. package/foundation/config/project.test.mjs +56 -0
  178. package/foundation/discovery/authoring-self-docs.d.mts +7 -0
  179. package/foundation/discovery/authoring-self-docs.mjs +16 -4
  180. package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
  181. package/foundation/discovery/authoring-surface.d.mts +1 -1
  182. package/foundation/discovery/authoring-surface.mjs +2 -2
  183. package/foundation/discovery/authoring-surface.test.mjs +1 -1
  184. package/foundation/discovery/cli-self-docs.d.mts +2 -1
  185. package/foundation/discovery/cli-self-docs.mjs +4 -3
  186. package/foundation/discovery/cli-self-docs.test.mjs +2 -2
  187. package/foundation/discovery/runner-allowlist.d.mts +2 -4
  188. package/foundation/discovery/runner-allowlist.mjs +2 -4
  189. package/foundation/discovery/runner-commands.d.mts +77 -0
  190. package/foundation/discovery/runner-commands.mjs +294 -0
  191. package/foundation/discovery/runner-commands.test.mjs +128 -0
  192. package/foundation/discovery/stray-pointers.test.mjs +1 -1
  193. package/foundation/discovery/template-adapter.mjs +18 -1
  194. package/foundation/discovery/template-needs.mjs +1 -44
  195. package/foundation/discovery/theme-discovery.mjs +147 -3
  196. package/foundation/doc-compiler/doc-loads.test.mjs +25 -9
  197. package/foundation/doc-compiler/read.mjs +59 -1
  198. package/foundation/doc-compiler/read.test.mjs +11 -2
  199. package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
  200. package/foundation/doc-compiler/tree.d.mts +32 -6
  201. package/foundation/doc-compiler/tree.mjs +77 -43
  202. package/foundation/doc-compiler/tree.test.mjs +7 -7
  203. package/foundation/fs/paths.d.mts +70 -8
  204. package/foundation/fs/paths.mjs +526 -35
  205. package/foundation/fs/paths.test.mjs +430 -54
  206. package/foundation/fs/read-record.d.mts +18 -0
  207. package/foundation/fs/read-record.mjs +131 -0
  208. package/foundation/fs/read-record.test.mjs +77 -0
  209. package/foundation/integrations/autolink.d.mts +2 -1
  210. package/foundation/integrations/autolink.mjs +4 -13
  211. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  212. package/foundation/integrations/cli-peer-version.mjs +132 -0
  213. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  214. package/foundation/integrations/exports-subpaths.d.mts +57 -0
  215. package/foundation/integrations/exports-subpaths.mjs +113 -0
  216. package/foundation/integrations/integrations.d.mts +20 -1
  217. package/foundation/integrations/integrations.mjs +59 -2
  218. package/foundation/integrations/public-imports.d.mts +118 -0
  219. package/foundation/integrations/public-imports.mjs +1769 -0
  220. package/foundation/integrations/public-imports.test.mjs +1793 -0
  221. package/foundation/integrations/validate-contributions.d.mts +19 -0
  222. package/foundation/integrations/validate-contributions.mjs +172 -3
  223. package/foundation/release/global-state.d.mts +8 -4
  224. package/foundation/release/global-state.mjs +4 -2
  225. package/foundation/release/notices.d.mts +62 -8
  226. package/foundation/release/notices.mjs +136 -25
  227. package/foundation/release/notices.test.mjs +21 -0
  228. package/foundation/response/response-types.doc.mjs +1 -1
  229. package/package.json +9 -9
@@ -20,6 +20,14 @@ export function issueListed(code: string, message: string): Issue;
20
20
  * @param {Issue} issue
21
21
  */
22
22
  export function isListedIssue(issue: Issue): boolean;
23
+ /**
24
+ * The known manifest key `key` is a near miss of: a different letter case, or
25
+ * at most two letters added, dropped or changed (`component`, `doc`,
26
+ * `tempaltes`). Null when no known key is that close, or two are.
27
+ * @param {string} key
28
+ * @returns {string | null}
29
+ */
30
+ export function nearestKnownKey(key: string): string | null;
23
31
  /**
24
32
  * Why a declared root cannot be read as a folder, or null when it can.
25
33
  * A missing root keeps its own issue; a root that is a file or that the
@@ -98,6 +106,17 @@ export function componentDocNamesCheck(integration: LoadedIntegration): Promise<
98
106
  };
99
107
  notes: Note[];
100
108
  }>;
109
+ /**
110
+ * The `name` a theme source passes to defineTheme for its exported theme,
111
+ * when the file says it as a string literal: `export const oceanTheme =
112
+ * defineTheme({name: 'ocean', ...})`. Null whenever only running the module
113
+ * could tell (a variable, a factory, a spread after the name, `extends`
114
+ * alone), so nothing is judged that a build would decide.
115
+ * @param {string} file
116
+ * @param {string} exportName
117
+ * @returns {string | null}
118
+ */
119
+ export function literalThemeName(file: string, exportName: string): string | null;
101
120
  /**
102
121
  * Validate an already-LOADED integration (as produced by `loadIntegrations` —
103
122
  * absolute contribution roots plus identity) and return its issues. This is the
@@ -26,6 +26,7 @@ import * as path from 'node:path';
26
26
  import {parse as parseModule} from '@babel/parser';
27
27
  import {isValidSemver} from '../env/semver.mjs';
28
28
  import {findProjectCoreDir} from '../fs/paths.mjs';
29
+ import {KNOWN_INTEGRATION_KEYS} from '../../authoring/integration/schema.mjs';
29
30
  import {
30
31
  contributionFiles,
31
32
  findSourceOnlyCandidates,
@@ -127,11 +128,36 @@ export function isListedIssue(issue) {
127
128
  function checkUnknownKeys(integration, issues) {
128
129
  const keys = integration.__unknownKeys ?? [];
129
130
  if (keys.length === 0) return;
131
+ // A key one edit away from a known one is almost always a typo: say so
132
+ // first, since "a newer CLI" sends the author to upgrade for nothing.
133
+ const typos = keys
134
+ .map(key => ({key, known: nearestKnownKey(key)}))
135
+ .filter(each => each.known != null);
136
+ for (const {key, known} of typos) {
137
+ // The manifest object already declares the key it is a near miss of:
138
+ // renaming would give it twice, so the stray key goes. Read from what
139
+ // the manifest says, not the loaded integration, which fills some keys
140
+ // in (providerId from the package name).
141
+ const alreadySet = (integration.__declaredKeys ?? []).includes(
142
+ /** @type {string} */ (known),
143
+ );
144
+ const fix = alreadySet
145
+ ? `Fix: remove "${key}" from ${manifestName(integration)}; it already sets "${known}".`
146
+ : `Fix: rename "${key}" to "${known}" in ${manifestName(integration)}.`;
147
+ issues.push(
148
+ issueWarning(
149
+ 'unknown_manifest_key',
150
+ `This CLI does not know the manifest key "${key}", so it is ignored. Did you mean \`${known}\`? ${fix} If it is a key from a newer Astryx CLI instead, upgrading @astryxdesign/cli picks it up.`,
151
+ ),
152
+ );
153
+ }
154
+ const rest = keys.filter(key => !typos.some(each => each.key === key));
155
+ if (rest.length === 0) return;
130
156
  issues.push(
131
157
  issueWarning(
132
158
  'unknown_manifest_key',
133
- `This CLI does not know the manifest ${keys.length === 1 ? 'key' : 'keys'} ` +
134
- `${keys.map(key => `"${key}"`).join(', ')}, so ${keys.length === 1 ? 'it is' : 'they are'} ` +
159
+ `This CLI does not know the manifest ${rest.length === 1 ? 'key' : 'keys'} ` +
160
+ `${rest.map(key => `"${key}"`).join(', ')}, so ${rest.length === 1 ? 'it is' : 'they are'} ` +
135
161
  `ignored — everything else in the manifest still applies. This usually ` +
136
162
  `means the integration was published against a newer Astryx CLI than ` +
137
163
  `this project resolves; upgrading @astryxdesign/cli picks it up.`,
@@ -146,6 +172,53 @@ function manifestName(integration) {
146
172
  : 'the integration manifest';
147
173
  }
148
174
 
175
+ /**
176
+ * The known manifest key `key` is a near miss of: a different letter case, or
177
+ * at most two letters added, dropped or changed (`component`, `doc`,
178
+ * `tempaltes`). Null when no known key is that close, or two are.
179
+ * @param {string} key
180
+ * @returns {string | null}
181
+ */
182
+ export function nearestKnownKey(key) {
183
+ const lower = key.toLowerCase();
184
+ const limit = lower.length <= 4 ? 1 : 2;
185
+ /** @type {string[]} */
186
+ const close = [];
187
+ for (const known of KNOWN_INTEGRATION_KEYS) {
188
+ const distance = editDistance(lower, known.toLowerCase());
189
+ if (distance <= limit) close.push(known);
190
+ }
191
+ return close.length === 1 ? close[0] : null;
192
+ }
193
+
194
+ /**
195
+ * Levenshtein distance, with a swap of two neighbours counted as one edit.
196
+ * @param {string} a
197
+ * @param {string} b
198
+ */
199
+ function editDistance(a, b) {
200
+ /** @type {number[][]} */
201
+ const d = Array.from({length: a.length + 1}, (_, i) =>
202
+ Array.from({length: b.length + 1}, (_, j) =>
203
+ i === 0 ? j : j === 0 ? i : 0,
204
+ ),
205
+ );
206
+ for (let i = 1; i <= a.length; i++) {
207
+ for (let j = 1; j <= b.length; j++) {
208
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
209
+ d[i][j] = Math.min(
210
+ d[i - 1][j] + 1,
211
+ d[i][j - 1] + 1,
212
+ d[i - 1][j - 1] + cost,
213
+ );
214
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
215
+ d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
216
+ }
217
+ }
218
+ }
219
+ return d[a.length][b.length];
220
+ }
221
+
149
222
  /**
150
223
  * Why a declared root cannot be read as a folder, or null when it can.
151
224
  * A missing root keeps its own issue; a root that is a file or that the
@@ -1005,13 +1078,20 @@ async function checkComponents(integration, issues) {
1005
1078
  const docName = docPath
1006
1079
  ? path.basename(docPath)
1007
1080
  : `${record.name}.doc.mjs`;
1081
+ let message = error.message;
1008
1082
  let fix = `Fix: add ${record.name}.tsx beside ${docName}.`;
1009
1083
  const stamp = docPath ? readContributionStamp(docPath, false) : null;
1010
1084
  if (stamp && stamp.type !== 'component' && integration.__packageDir) {
1011
1085
  context ??= createFixContext(integration.__packageDir, integration);
1012
1086
  fix = notAComponentFix(context, docPath, stamp);
1087
+ } else {
1088
+ const other = docPath ? otherSourceFor(docPath) : null;
1089
+ if (other) {
1090
+ message = `${message.replace(/\.$/u, '')}: found ${other}, but a component source must be a .tsx file.`;
1091
+ fix = `Fix: rename ${other} to ${record.name}.tsx (and point its package export at the new file).`;
1092
+ }
1013
1093
  }
1014
- issues.push(issueError('invalid_component', `${error.message} ${fix}`));
1094
+ issues.push(issueError('invalid_component', `${message} ${fix}`));
1015
1095
  }
1016
1096
  /** @type {Set<string>} sources a case-only rename is reported for */
1017
1097
  const reportedSources = new Set();
@@ -1104,6 +1184,21 @@ function docStemOf(file) {
1104
1184
  return suffix ? file.slice(0, -suffix.length) : file;
1105
1185
  }
1106
1186
 
1187
+ /**
1188
+ * A same-stem source discovery does not read: `.jsx`, `.js`, `.ts` or `.mjs`.
1189
+ * @param {string} docPath
1190
+ * @returns {string | null} its file name
1191
+ */
1192
+ function otherSourceFor(docPath) {
1193
+ const stem = docStemOf(path.basename(docPath));
1194
+ const dir = path.dirname(docPath);
1195
+ return (
1196
+ ['.jsx', '.js', '.ts', '.mjs']
1197
+ .map(extension => `${stem}${extension}`)
1198
+ .find(file => fs.existsSync(path.join(dir, file))) ?? null
1199
+ );
1200
+ }
1201
+
1107
1202
  /**
1108
1203
  * The component docs under a root, read from the real directory listings:
1109
1204
  * those beside a source whose name differs only in letter case (which an
@@ -1370,6 +1465,80 @@ async function checkThemes(integration, issues) {
1370
1465
  }
1371
1466
  }
1372
1467
 
1468
+ /**
1469
+ * The `name` a theme source passes to defineTheme for its exported theme,
1470
+ * when the file says it as a string literal: `export const oceanTheme =
1471
+ * defineTheme({name: 'ocean', ...})`. Null whenever only running the module
1472
+ * could tell (a variable, a factory, a spread after the name, `extends`
1473
+ * alone), so nothing is judged that a build would decide.
1474
+ * @param {string} file
1475
+ * @param {string} exportName
1476
+ * @returns {string | null}
1477
+ */
1478
+ export function literalThemeName(file, exportName) {
1479
+ let ast;
1480
+ try {
1481
+ ast = parseModule(fs.readFileSync(file, 'utf8'), {
1482
+ sourceType: 'module',
1483
+ plugins: ['typescript', 'jsx'],
1484
+ errorRecovery: true,
1485
+ });
1486
+ } catch {
1487
+ return null;
1488
+ }
1489
+ /** @type {any} */
1490
+ let init = null;
1491
+ for (const node of ast.program.body) {
1492
+ const declaration =
1493
+ node.type === 'ExportNamedDeclaration' ? node.declaration : node;
1494
+ if (declaration?.type !== 'VariableDeclaration') continue;
1495
+ for (const declarator of declaration.declarations) {
1496
+ if (
1497
+ declarator.id.type === 'Identifier' &&
1498
+ declarator.id.name === exportName
1499
+ ) {
1500
+ init = declarator.init;
1501
+ }
1502
+ }
1503
+ }
1504
+ while (
1505
+ init?.type === 'TSAsExpression' ||
1506
+ init?.type === 'TSSatisfiesExpression'
1507
+ ) {
1508
+ init = init.expression;
1509
+ }
1510
+ if (init?.type !== 'CallExpression') return null;
1511
+ const callee =
1512
+ init.callee.type === 'Identifier'
1513
+ ? init.callee.name
1514
+ : init.callee.type === 'MemberExpression' &&
1515
+ init.callee.property.type === 'Identifier'
1516
+ ? init.callee.property.name
1517
+ : null;
1518
+ if (callee !== 'defineTheme') return null;
1519
+ const [config] = init.arguments;
1520
+ if (config?.type !== 'ObjectExpression') return null;
1521
+ /** @type {string | null} */
1522
+ let name = null;
1523
+ for (const property of config.properties) {
1524
+ if (property.type === 'SpreadElement') {
1525
+ name = null;
1526
+ continue;
1527
+ }
1528
+ if (property.type !== 'ObjectProperty' || property.computed) continue;
1529
+ const key =
1530
+ property.key.type === 'Identifier'
1531
+ ? property.key.name
1532
+ : property.key.type === 'StringLiteral'
1533
+ ? property.key.value
1534
+ : null;
1535
+ if (key !== 'name') continue;
1536
+ name =
1537
+ property.value.type === 'StringLiteral' ? property.value.value : null;
1538
+ }
1539
+ return name;
1540
+ }
1541
+
1373
1542
  /**
1374
1543
  * A warning for each contribution file a reader reads (the docs and sources
1375
1544
  * `integration verify` expects in the tarball) that the user running astryx
@@ -20,9 +20,11 @@
20
20
  */
21
21
  /**
22
22
  * Why an update notice did not print: `already-shown` (it printed within the
23
- * day) or `no-newer` (nothing newer is known). Recorded only while the run
23
+ * day), `no-newer` (nothing newer is known), or `no-project` (the folder
24
+ * installs Core but belongs to no Astryx project, so no install command
25
+ * fits). Recorded only while the run
24
26
  * holds the state file's lock.
25
- * @typedef {{reason: 'already-shown' | 'no-newer', at: number}} NoticeSkip
27
+ * @typedef {{reason: 'already-shown' | 'no-newer' | 'no-project', at: number}} NoticeSkip
26
28
  */
27
29
  /**
28
30
  * The state file.
@@ -242,11 +244,13 @@ export type GlobalState = {
242
244
  };
243
245
  /**
244
246
  * Why an update notice did not print: `already-shown` (it printed within the
245
- * day) or `no-newer` (nothing newer is known). Recorded only while the run
247
+ * day), `no-newer` (nothing newer is known), or `no-project` (the folder
248
+ * installs Core but belongs to no Astryx project, so no install command
249
+ * fits). Recorded only while the run
246
250
  * holds the state file's lock.
247
251
  */
248
252
  export type NoticeSkip = {
249
- reason: "already-shown" | "no-newer";
253
+ reason: "already-shown" | "no-newer" | "no-project";
250
254
  at: number;
251
255
  };
252
256
  /**
@@ -68,9 +68,11 @@ export const CHECK_INTERVAL_MS = 24 * 60 * 60_000;
68
68
 
69
69
  /**
70
70
  * Why an update notice did not print: `already-shown` (it printed within the
71
- * day) or `no-newer` (nothing newer is known). Recorded only while the run
71
+ * day), `no-newer` (nothing newer is known), or `no-project` (the folder
72
+ * installs Core but belongs to no Astryx project, so no install command
73
+ * fits). Recorded only while the run
72
74
  * holds the state file's lock.
73
- * @typedef {{reason: 'already-shown' | 'no-newer', at: number}} NoticeSkip
75
+ * @typedef {{reason: 'already-shown' | 'no-newer' | 'no-project', at: number}} NoticeSkip
74
76
  */
75
77
 
76
78
  /**
@@ -91,24 +91,71 @@ export function globalBehind({ self, stateDir }: {
91
91
  };
92
92
  stateDir?: string;
93
93
  }): GlobalBehind | null;
94
+ /**
95
+ * The command that adds a package to the project of a run in `cwd`, with the
96
+ * project's package manager (spec AST-081 FR12). Null when `cwd` belongs to
97
+ * no project `spec:AST-040` FR9 defines, and in a folder inside the project
98
+ * whose package.json is not the project's (see {@link installFolder}): a run
99
+ * there loads integrations from that package.json, so a package added to the
100
+ * project would stay unused there, and the advice is
101
+ * {@link RUN_FROM_PROJECT}.
102
+ * @param {string} cwd
103
+ * @returns {((name: string) => string) | null}
104
+ */
105
+ export function projectAddCommand(cwd: string): ((name: string) => string) | null;
94
106
  /**
95
107
  * The commands that bring a project's own CLI and Core to one release, with
96
108
  * the project's package manager: when the CLI is newer, Core up to it and then
97
109
  * the codemods from Core's release; otherwise the CLI to Core's release.
110
+ * Null in a folder that belongs to no project, or whose package.json is not
111
+ * the project's (see {@link installFolder}).
98
112
  * @param {{cwd: string, cli: string, core: string}} options
99
- * @returns {string}
113
+ * @returns {string | null}
100
114
  */
101
115
  export function alignCliAndCore({ cwd, cli, core }: {
102
116
  cwd: string;
103
117
  cli: string;
104
118
  core: string;
105
- }): string;
119
+ }): string | null;
120
+ /**
121
+ * Where a command that adds an Astryx package runs, for a run in `cwd`: in
122
+ * the project `spec:AST-040` FR9 defines, which stops at a repository root
123
+ * and never counts the home folder (spec AST-081 FR2, FR10). Null when `cwd`
124
+ * belongs to no such project, so no command adds anything. When `cwd`'s
125
+ * nearest package.json is not the project's, as in a tool folder that
126
+ * installs its own Core, a package manager would add to the tool's
127
+ * package.json, so `moved` says the command runs in the project's folder.
128
+ * @param {string} cwd
129
+ * @returns {{dir: string, moved: boolean} | null}
130
+ */
131
+ export function installFolder(cwd: string): {
132
+ dir: string;
133
+ moved: boolean;
134
+ } | null;
135
+ /**
136
+ * The command that adds the CLI at Core's version, for a run in `cwd` whose
137
+ * Core is `core`, with the project's package manager in the project root.
138
+ * `command` is null in a folder inside the project whose package.json is not
139
+ * the project's (see {@link installFolder}), where the advice is
140
+ * {@link RUN_FROM_PROJECT}. Null when the folder belongs to no project.
141
+ * @param {{cwd: string, core: string}} options
142
+ * @returns {{root: string, core: string, command: string | null} | null}
143
+ */
144
+ export function cliInstallAdvice({ cwd, core }: {
145
+ cwd: string;
146
+ core: string;
147
+ }): {
148
+ root: string;
149
+ core: string;
150
+ command: string | null;
151
+ } | null;
106
152
  /**
107
153
  * The hint for a project with no CLI of its own, answered by `answered` while
108
154
  * its Core is `core`: the command that adds the CLI at Core's version, with
109
- * the project's package manager.
155
+ * the project's package manager (see {@link cliInstallAdvice}). Null when no
156
+ * command fits, or when the project the command adds to already matches.
110
157
  * @param {{cwd: string, answered: string, core: string}} options
111
- * @returns {{root: string, line: string}}
158
+ * @returns {{root: string, line: string} | null}
112
159
  */
113
160
  export function noCliHint({ cwd, answered, core }: {
114
161
  cwd: string;
@@ -117,15 +164,16 @@ export function noCliHint({ cwd, answered, core }: {
117
164
  }): {
118
165
  root: string;
119
166
  line: string;
120
- };
167
+ } | null;
121
168
  /**
122
169
  * The hint's text.
123
170
  * @param {string} answered
124
171
  * @param {string} core
125
- * @param {string} command the command that adds the CLI at Core's version
172
+ * @param {string | null} command the command that adds the CLI at Core's
173
+ * version; null in a folder whose package.json is not the project's
126
174
  * @returns {string}
127
175
  */
128
- export function noCliHintLine(answered: string, core: string, command: string): string;
176
+ export function noCliHintLine(answered: string, core: string, command: string | null): string;
129
177
  /**
130
178
  * The command that installs the CLI at `version` in the project at `root`,
131
179
  * with its package manager.
@@ -140,7 +188,7 @@ export function addCliCommand(root: string, version: string): string;
140
188
  * @param {{cwd: string, current: string, stateDir?: string}} options
141
189
  * @returns {ProjectLag | null}
142
190
  */
143
- export function projectLag({ cwd, current, stateDir }: {
191
+ export function projectLag({ cwd, current: given, stateDir }: {
144
192
  cwd: string;
145
193
  current: string;
146
194
  stateDir?: string;
@@ -207,6 +255,12 @@ export function noticeLines({ cwd, self, choice, json, stateDir, cacheDir, now,
207
255
  }): string[];
208
256
  /** A notice prints at most once in this long. */
209
257
  export const NOTICE_INTERVAL_MS: number;
258
+ /**
259
+ * What to tell a run in a folder inside a project whose package.json is not
260
+ * the project's: run from the project's folder, since adding there would make
261
+ * the folder a project of its own (spec AST-081 FR2).
262
+ */
263
+ export const RUN_FROM_PROJECT: "Run this from the Astryx project's folder, or declare an Astryx package in this folder's package.json to make it a project of its own.";
210
264
  export type GlobalBehind = {
211
265
  /**
212
266
  * the global copy's version
@@ -43,9 +43,11 @@ import {userConfigDir} from '../env/user-dirs.mjs';
43
43
  import {astryxCommandsOnSearchPath} from '../env/search-path.mjs';
44
44
  import {
45
45
  CLI_PACKAGE,
46
+ commandInFolder,
46
47
  detectPackageManager,
47
48
  getCliInvocation,
48
49
  } from '../env/package-manager.mjs';
50
+ import {findAstryxProject, findPackageRoot} from '../fs/paths.mjs';
49
51
  import {satisfiesRange, semverCompare} from '../env/semver.mjs';
50
52
  import {isInReleaseCache, isReleaseVersion} from './cache.mjs';
51
53
  import {
@@ -55,7 +57,12 @@ import {
55
57
  tryStateLock,
56
58
  writeGlobalState,
57
59
  } from './global-state.mjs';
58
- import {globalFolderOf, isGlobalCopy, projectRootOf} from './choose.mjs';
60
+ import {
61
+ coreVersionOf,
62
+ globalFolderOf,
63
+ isGlobalCopy,
64
+ projectRootOf,
65
+ } from './choose.mjs';
59
66
  import {readReleaseFacts} from './project.mjs';
60
67
  import {samePath} from '../fs/path-compare.mjs';
61
68
  import {updateNoticesOff} from './update-notice-env.mjs';
@@ -375,16 +382,49 @@ const ADD = {
375
382
  bun: 'bun add',
376
383
  };
377
384
 
385
+ /**
386
+ * The command that adds a package to the project of a run in `cwd`, with the
387
+ * project's package manager (spec AST-081 FR12). Null when `cwd` belongs to
388
+ * no project `spec:AST-040` FR9 defines, and in a folder inside the project
389
+ * whose package.json is not the project's (see {@link installFolder}): a run
390
+ * there loads integrations from that package.json, so a package added to the
391
+ * project would stay unused there, and the advice is
392
+ * {@link RUN_FROM_PROJECT}.
393
+ * @param {string} cwd
394
+ * @returns {((name: string) => string) | null}
395
+ */
396
+ export function projectAddCommand(cwd) {
397
+ const target = installFolder(cwd);
398
+ if (target == null || target.moved) return null;
399
+ const add = ADD[detectPackageManager(cwd)] ?? ADD.npm;
400
+ return name => `${add} ${name}`;
401
+ }
402
+
378
403
  /**
379
404
  * The commands that bring a project's own CLI and Core to one release, with
380
405
  * the project's package manager: when the CLI is newer, Core up to it and then
381
406
  * the codemods from Core's release; otherwise the CLI to Core's release.
407
+ * Null in a folder that belongs to no project, or whose package.json is not
408
+ * the project's (see {@link installFolder}).
382
409
  * @param {{cwd: string, cli: string, core: string}} options
383
- * @returns {string}
410
+ * @returns {string | null}
384
411
  */
385
412
  export function alignCliAndCore({cwd, cli, core}) {
386
- const facts = readReleaseFacts(cwd);
387
- const root = projectRootOf(facts) ?? cwd;
413
+ const target = installFolder(cwd);
414
+ if (target == null || target.moved) return null;
415
+ const root = projectRootOf(readReleaseFacts(cwd)) ?? cwd;
416
+ return alignIn(root, cli, core);
417
+ }
418
+
419
+ /**
420
+ * The commands that bring the CLI and Core of the project at `root` to one
421
+ * release, run in `root`.
422
+ * @param {string} root
423
+ * @param {string} cli
424
+ * @param {string} core
425
+ * @returns {string}
426
+ */
427
+ function alignIn(root, cli, core) {
388
428
  const add = ADD[detectPackageManager(root)] ?? ADD.npm;
389
429
  if (semverCompare(cli, core) > 0) {
390
430
  return `${add} @astryxdesign/core@${cli}, then ${getCliInvocation(root, {installed: true})} upgrade --from ${core} --apply`;
@@ -392,27 +432,81 @@ export function alignCliAndCore({cwd, cli, core}) {
392
432
  return `${add} ${CLI_PACKAGE}@${core}`;
393
433
  }
394
434
 
435
+ /**
436
+ * Where a command that adds an Astryx package runs, for a run in `cwd`: in
437
+ * the project `spec:AST-040` FR9 defines, which stops at a repository root
438
+ * and never counts the home folder (spec AST-081 FR2, FR10). Null when `cwd`
439
+ * belongs to no such project, so no command adds anything. When `cwd`'s
440
+ * nearest package.json is not the project's, as in a tool folder that
441
+ * installs its own Core, a package manager would add to the tool's
442
+ * package.json, so `moved` says the command runs in the project's folder.
443
+ * @param {string} cwd
444
+ * @returns {{dir: string, moved: boolean} | null}
445
+ */
446
+ export function installFolder(cwd) {
447
+ const project = findAstryxProject(cwd);
448
+ if (project == null) return null;
449
+ const nearest = findPackageRoot(cwd);
450
+ if (nearest == null || nearest === project) return {dir: cwd, moved: false};
451
+ return {dir: project, moved: true};
452
+ }
453
+
454
+ /**
455
+ * What to tell a run in a folder inside a project whose package.json is not
456
+ * the project's: run from the project's folder, since adding there would make
457
+ * the folder a project of its own (spec AST-081 FR2).
458
+ */
459
+ export const RUN_FROM_PROJECT =
460
+ "Run this from the Astryx project's folder, or declare an Astryx package in this folder's package.json to make it a project of its own.";
461
+
462
+ /**
463
+ * The command that adds the CLI at Core's version, for a run in `cwd` whose
464
+ * Core is `core`, with the project's package manager in the project root.
465
+ * `command` is null in a folder inside the project whose package.json is not
466
+ * the project's (see {@link installFolder}), where the advice is
467
+ * {@link RUN_FROM_PROJECT}. Null when the folder belongs to no project.
468
+ * @param {{cwd: string, core: string}} options
469
+ * @returns {{root: string, core: string, command: string | null} | null}
470
+ */
471
+ export function cliInstallAdvice({cwd, core}) {
472
+ const target = installFolder(cwd);
473
+ if (target == null) return null;
474
+ if (target.moved) return {root: target.dir, core, command: null};
475
+ const root = projectRootOf(readReleaseFacts(cwd)) ?? cwd;
476
+ return {root, core, command: addCliCommand(root, core)};
477
+ }
478
+
395
479
  /**
396
480
  * The hint for a project with no CLI of its own, answered by `answered` while
397
481
  * its Core is `core`: the command that adds the CLI at Core's version, with
398
- * the project's package manager.
482
+ * the project's package manager (see {@link cliInstallAdvice}). Null when no
483
+ * command fits, or when the project the command adds to already matches.
399
484
  * @param {{cwd: string, answered: string, core: string}} options
400
- * @returns {{root: string, line: string}}
485
+ * @returns {{root: string, line: string} | null}
401
486
  */
402
487
  export function noCliHint({cwd, answered, core}) {
403
- const root = projectRootOf(readReleaseFacts(cwd)) ?? cwd;
404
- return {root, line: noCliHintLine(answered, core, addCliCommand(root, core))};
488
+ if (core === answered) return null;
489
+ const advice = cliInstallAdvice({cwd, core});
490
+ if (advice == null) return null;
491
+ return {
492
+ root: advice.root,
493
+ line: noCliHintLine(answered, core, advice.command),
494
+ };
405
495
  }
406
496
 
407
497
  /**
408
498
  * The hint's text.
409
499
  * @param {string} answered
410
500
  * @param {string} core
411
- * @param {string} command the command that adds the CLI at Core's version
501
+ * @param {string | null} command the command that adds the CLI at Core's
502
+ * version; null in a folder whose package.json is not the project's
412
503
  * @returns {string}
413
504
  */
414
505
  export function noCliHintLine(answered, core, command) {
415
- return `astryx: this project has no Astryx CLI installed; answered by CLI ${answered} while its Core is ${core}. To match, run: ${command}`;
506
+ const head = `astryx: this project has no Astryx CLI installed; answered by CLI ${answered} while its Core is ${core}.`;
507
+ return command
508
+ ? `${head} To match, run: ${command}`
509
+ : `${head} ${RUN_FROM_PROJECT}`;
416
510
  }
417
511
 
418
512
  /**
@@ -432,17 +526,29 @@ export function addCliCommand(root, version) {
432
526
  * @param {{cwd: string, current: string, stateDir?: string}} options
433
527
  * @returns {ProjectLag | null}
434
528
  */
435
- export function projectLag({cwd, current, stateDir = userConfigDir()}) {
529
+ export function projectLag({cwd, current: given, stateDir = userConfigDir()}) {
436
530
  const latest = knownLatest(stateDir);
437
- if (!latest || !isBehind(current, latest.version)) return null;
438
- const newest = latest.version;
531
+ if (!latest) return null;
439
532
  const facts = readReleaseFacts(cwd);
440
533
  if (!facts.inProject) return null;
441
- const root = projectRootOf(facts) ?? cwd;
534
+ const target = installFolder(cwd);
535
+ if (target == null) return null;
536
+ const root = target.moved ? target.dir : (projectRootOf(facts) ?? cwd);
537
+ // From a folder inside the project, the project's own release: its CLI's,
538
+ // else its Core's, so the project gets one notice and one --from.
539
+ const projectFacts = target.moved ? readReleaseFacts(root) : null;
540
+ const current = projectFacts
541
+ ? (projectFacts.cli?.version ?? coreVersionOf(projectFacts) ?? given)
542
+ : given;
543
+ if (!isBehind(current, latest.version)) return null;
544
+ const newest = latest.version;
442
545
  const pm = detectPackageManager(root);
443
546
  // The CLI is always installed beside Core: a project that installed only
444
547
  // Core gets it too, as recommended, so its version is pinned with Core's.
445
- const install = `${ADD[pm] ?? ADD.npm} @astryxdesign/core@${newest} ${CLI_PACKAGE}@${newest}`;
548
+ // From a folder inside the project whose package.json is not the
549
+ // project's, the install runs in the project's folder (see installFolder).
550
+ const add = `${ADD[pm] ?? ADD.npm} @astryxdesign/core@${newest} ${CLI_PACKAGE}@${newest}`;
551
+ const install = target.moved ? commandInFolder(root, add) : add;
446
552
  // The command runs after the install above, so the picker's guess is the
447
553
  // project's own CLI (spec AST-081 FR5).
448
554
  const stem = getCliInvocation(root, {installed: true});
@@ -452,7 +558,9 @@ export function projectLag({cwd, current, stateDir = userConfigDir()}) {
452
558
  newest,
453
559
  node: latest.node,
454
560
  install,
455
- upgrade: `${stem} upgrade --from ${current} --apply`,
561
+ upgrade: target.moved
562
+ ? commandInFolder(root, `${stem} upgrade --from ${current} --apply`)
563
+ : `${stem} upgrade --from ${current} --apply`,
456
564
  };
457
565
  }
458
566
 
@@ -536,18 +644,13 @@ export function noticeLines({
536
644
  try {
537
645
  // A project with no CLI of its own, answered by a release other than its
538
646
  // Core's: once a day per project, how to match them (FR2).
539
- if (
540
- choice.inProject &&
541
- choice.copy === 'starting' &&
542
- choice.coreVersion &&
543
- choice.coreVersion !== choice.version
544
- ) {
647
+ if (choice.inProject && choice.copy === 'starting' && choice.coreVersion) {
545
648
  const hint = noCliHint({
546
649
  cwd,
547
650
  answered: choice.version,
548
651
  core: choice.coreVersion,
549
652
  });
550
- if (take(`no-cli:${hint.root}`)) lines.push(hint.line);
653
+ if (hint && take(`no-cli:${hint.root}`)) lines.push(hint.line);
551
654
  }
552
655
  } catch {
553
656
  // A hint never fails a run.
@@ -559,8 +662,16 @@ export function noticeLines({
559
662
  choice.copy === 'starting' && choice.coreVersion
560
663
  ? choice.coreVersion
561
664
  : choice.version;
562
- const lag = projectLag({cwd, current, stateDir});
563
- if (!lag) recordNoticeSkip('project', 'no-newer', {stateDir, now});
665
+ // A folder that belongs to no project (spec AST-040 FR9) gets no
666
+ // project notice; the skip says why.
667
+ const noProject = installFolder(cwd) == null;
668
+ const lag = noProject ? null : projectLag({cwd, current, stateDir});
669
+ if (!lag) {
670
+ recordNoticeSkip('project', noProject ? 'no-project' : 'no-newer', {
671
+ stateDir,
672
+ now,
673
+ });
674
+ }
564
675
  if (lag && take(`project:${lag.root}`)) {
565
676
  lines.push(
566
677
  availableLine(lag.current, lag.newest),