@astryxdesign/cli 0.7.17 → 0.7.18-canary.g57306fd

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 (241) hide show
  1. package/README.md +1 -1
  2. package/api/discover/_adapter.d.mts +7 -5
  3. package/api/discover/_adapter.mjs +12 -11
  4. package/api/docs/_adapter.d.mts +19 -2
  5. package/api/docs/_adapter.mjs +66 -5
  6. package/api/doctor/_adapter.d.mts +11 -62
  7. package/api/doctor/_adapter.mjs +242 -472
  8. package/api/doctor/doctor.d.mts +1 -1
  9. package/api/doctor/doctor.mjs +3 -3
  10. package/api/doctor/theme-checks.mjs +37 -45
  11. package/api/error.d.mts +21 -0
  12. package/api/error.mjs +89 -0
  13. package/api/hook/list/list.d.mts +1 -1
  14. package/api/icon/_adapter.d.mts +8 -0
  15. package/api/icon/_adapter.mjs +17 -0
  16. package/api/icon/_authoring.mjs +6 -6
  17. package/api/icon/_default-look.mjs +16 -16
  18. package/api/icon/add/add.mjs +3 -3
  19. package/api/icon/exportIconIndex.doc.mjs +2 -2
  20. package/api/icon/icon.doc.mjs +2 -2
  21. package/api/icon/icon.type.d.mts +4 -0
  22. package/api/icon/icon.type.mjs +2 -1
  23. package/api/icon/search/icon-index.mjs +16 -3
  24. package/api/icon/search/search.d.mts +15 -5
  25. package/api/icon/search/search.mjs +74 -16
  26. package/api/icon/use/use.mjs +4 -4
  27. package/api/render/_adapter.mjs +233 -40
  28. package/api/render/render.type.d.mts +1 -1
  29. package/api/render/render.type.mjs +1 -1
  30. package/api/search/ORDERING.md +2 -2
  31. package/api/search/_adapter.mjs +4 -0
  32. package/api/search/_candidate-score.mjs +32 -8
  33. package/api/search/_cards.json +1 -1
  34. package/api/search/_compound.d.mts +0 -1
  35. package/api/search/_compound.mjs +93 -2
  36. package/api/search/_icons.d.mts +4 -2
  37. package/api/search/_icons.mjs +4 -2
  38. package/api/search/_lexical.mjs +177 -17
  39. package/api/search/_order.d.mts +3 -1
  40. package/api/search/_order.mjs +16 -5
  41. package/api/search/_result.d.mts +9 -0
  42. package/api/search/_result.mjs +10 -0
  43. package/api/search/_score.mjs +21 -3
  44. package/api/swizzle/_moduleGraph.d.mts +8 -0
  45. package/api/swizzle/_moduleGraph.mjs +61 -3
  46. package/api/template/copy/copy.mjs +5 -3
  47. package/api/theme/_adapter.mjs +48 -12
  48. package/api/theme/build/build.d.mts +4 -0
  49. package/api/theme/build/build.mjs +69 -18
  50. package/api/theme/build/style-keys.mjs +4 -5
  51. package/api/theme/build/theme-object.mjs +5 -0
  52. package/api/theme/palette/generate/color.d.mts +47 -0
  53. package/api/theme/palette/generate/color.mjs +58 -1
  54. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  55. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  56. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  57. package/api/theme/palette/generate/editor-look.mjs +550 -0
  58. package/api/theme/palette/generate/mapping.d.mts +94 -9
  59. package/api/theme/palette/generate/mapping.mjs +94 -22
  60. package/api/theme-edit/_adapter.mjs +13 -2
  61. package/api/theme-edit/_catalog.d.mts +13 -13
  62. package/api/theme-edit/_catalog.mjs +66 -28
  63. package/api/theme-edit/_check.d.mts +82 -6
  64. package/api/theme-edit/_check.mjs +1270 -238
  65. package/api/theme-edit/_color.d.mts +74 -0
  66. package/api/theme-edit/_color.mjs +168 -3
  67. package/api/theme-edit/_compiler.d.mts +3 -5
  68. package/api/theme-edit/_compiler.mjs +122 -23
  69. package/api/theme-edit/_context.d.mts +55 -12
  70. package/api/theme-edit/_context.mjs +114 -60
  71. package/api/theme-edit/_css.d.mts +11 -0
  72. package/api/theme-edit/_css.mjs +40 -0
  73. package/api/theme-edit/_edit.d.mts +15 -2
  74. package/api/theme-edit/_edit.mjs +1469 -133
  75. package/api/theme-edit/_how-commands.d.mts +116 -0
  76. package/api/theme-edit/_how-commands.mjs +227 -115
  77. package/api/theme-edit/_how-question.d.mts +74 -29
  78. package/api/theme-edit/_how-question.mjs +8514 -1256
  79. package/api/theme-edit/_how-sides.d.mts +22 -0
  80. package/api/theme-edit/_how-sides.mjs +173 -0
  81. package/api/theme-edit/_how-steps.d.mts +42 -0
  82. package/api/theme-edit/_how-steps.mjs +208 -0
  83. package/api/theme-edit/_how-values.d.mts +29 -0
  84. package/api/theme-edit/_how-values.mjs +111 -0
  85. package/api/theme-edit/_how-words.d.mts +15 -0
  86. package/api/theme-edit/_how-words.mjs +239 -0
  87. package/api/theme-edit/_how.d.mts +1 -1
  88. package/api/theme-edit/_how.mjs +422 -37
  89. package/api/theme-edit/_missed.d.mts +2 -1
  90. package/api/theme-edit/_missed.mjs +125 -13
  91. package/api/theme-edit/_normal.d.mts +5 -3
  92. package/api/theme-edit/_normal.mjs +54 -14
  93. package/api/theme-edit/_palette.d.mts +204 -4
  94. package/api/theme-edit/_palette.mjs +901 -25
  95. package/api/theme-edit/_part-pieces.d.mts +54 -0
  96. package/api/theme-edit/_part-pieces.mjs +179 -0
  97. package/api/theme-edit/_part-words.mjs +33 -5
  98. package/api/theme-edit/_parts.d.mts +133 -0
  99. package/api/theme-edit/_parts.mjs +599 -10
  100. package/api/theme-edit/_picture-traits.d.mts +259 -0
  101. package/api/theme-edit/_picture-traits.mjs +1030 -0
  102. package/api/theme-edit/_preview.d.mts +95 -4
  103. package/api/theme-edit/_preview.mjs +284 -31
  104. package/api/theme-edit/_project.d.mts +14 -4
  105. package/api/theme-edit/_project.mjs +95 -26
  106. package/api/theme-edit/_resolved.d.mts +46 -0
  107. package/api/theme-edit/_resolved.mjs +800 -0
  108. package/api/theme-edit/_set-line.d.mts +29 -0
  109. package/api/theme-edit/_set-line.mjs +100 -0
  110. package/api/theme-edit/_settings.d.mts +625 -28
  111. package/api/theme-edit/_settings.mjs +4867 -888
  112. package/api/theme-edit/_tables.d.mts +25 -1
  113. package/api/theme-edit/_tables.mjs +115 -11
  114. package/api/theme-edit/_text-looks.d.mts +78 -0
  115. package/api/theme-edit/_text-looks.mjs +376 -0
  116. package/api/theme-edit/_vet.d.mts +3 -26
  117. package/api/theme-edit/_vet.mjs +5 -89
  118. package/api/theme-edit/how/how.d.mts +1 -1
  119. package/api/theme-edit/how/how.mjs +1 -1
  120. package/api/theme-edit/show/show.d.mts +4 -3
  121. package/api/theme-edit/show/show.mjs +3 -2
  122. package/api/theme-edit/theme-edit.type.d.mts +117 -1
  123. package/api/theme-edit/theme-edit.type.mjs +46 -3
  124. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  125. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  126. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  127. package/api/theme-edit/themeEditShow.doc.mjs +22 -3
  128. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  129. package/assets/component-list.generated.json +1 -1
  130. package/assets/docs/author-a-theme.doc.mjs +7 -4
  131. package/assets/docs/theme.doc.dense.mjs +10 -0
  132. package/assets/docs/theme.doc.mjs +10 -0
  133. package/assets/docs/theme.doc.zh.mjs +10 -0
  134. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  135. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  136. package/assets/docs/use-a-theme.doc.mjs +89 -17
  137. package/assets/docs-routes.generated.json +1 -1
  138. package/assets/docs.generated.json +2 -2
  139. package/assets/icons/definitions/article.doc.mjs +9 -0
  140. package/assets/icons/template-icons.json +5 -0
  141. package/assets/search-catalog.generated.json +2 -2
  142. package/assets/self-audit.generated.json +1 -1
  143. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  144. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  145. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  146. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  147. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  148. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  149. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  150. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  151. package/assets/templates/components.generated.json +1 -1
  152. package/assets/templates/pages/ide/page.tsx +5 -10
  153. package/assets/templates/pages/payment-form/page.tsx +16 -60
  154. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  155. package/authoring/debug/parse.d.mts +1 -1
  156. package/authoring/doctypes/_schema.d.mts +13 -13
  157. package/authoring/gap-report/parse.d.mts +1 -1
  158. package/clients/cli/build-id.generated.json +1 -1
  159. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  160. package/clients/cli/commands/experimental/icon.mjs +7 -7
  161. package/clients/cli/commands/experimental/theme.mjs +175 -13
  162. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  163. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  164. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  165. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  166. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +15 -5
  167. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  168. package/clients/cli/commands/hook.mjs +7 -0
  169. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  170. package/clients/cli/index.mjs +6 -2
  171. package/clients/cli/lib/hook-format.mjs +41 -1
  172. package/clients/cli/lib/json-shim.mjs +34 -14
  173. package/clients/cli/lib/other-cli-words.mjs +7 -0
  174. package/clients/cli/lib/unknown-command.mjs +345 -46
  175. package/clients/cli/manifest.generated.json +1 -1
  176. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  177. package/foundation/agent-docs/agent-docs.mjs +51 -8
  178. package/foundation/config/project.d.mts +11 -1
  179. package/foundation/config/project.mjs +11 -2
  180. package/foundation/discovery/component-replacement.d.mts +5 -8
  181. package/foundation/discovery/component-replacement.mjs +12 -14
  182. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  183. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  184. package/foundation/discovery/core-elements.d.mts +6 -0
  185. package/foundation/discovery/core-elements.mjs +10 -2
  186. package/foundation/discovery/core-prop-types.d.mts +5 -0
  187. package/foundation/discovery/core-prop-types.mjs +10 -3
  188. package/foundation/discovery/core-props.d.mts +8 -0
  189. package/foundation/discovery/core-props.mjs +29 -13
  190. package/foundation/discovery/icon-ranking.d.mts +5 -2
  191. package/foundation/discovery/icon-ranking.mjs +101 -18
  192. package/foundation/discovery/icon-set-checks.mjs +1 -1
  193. package/foundation/discovery/icon-set-writer.mjs +1 -1
  194. package/foundation/discovery/official-list.d.mts +17 -0
  195. package/foundation/discovery/official-list.mjs +77 -0
  196. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  197. package/foundation/discovery/unknown-core-props.mjs +601 -0
  198. package/foundation/discovery/written-prop-values.d.mts +35 -0
  199. package/foundation/discovery/written-prop-values.mjs +258 -0
  200. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  201. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  202. package/foundation/fs/package-name.d.mts +10 -0
  203. package/foundation/fs/package-name.mjs +37 -0
  204. package/foundation/fs/project-source-files.d.mts +27 -0
  205. package/foundation/fs/project-source-files.mjs +115 -0
  206. package/foundation/fs/project-sources.d.mts +25 -0
  207. package/foundation/fs/project-sources.mjs +83 -0
  208. package/foundation/fs/read-record.d.mts +18 -0
  209. package/foundation/fs/read-record.mjs +36 -2
  210. package/foundation/integrations/integration-warnings.d.mts +39 -7
  211. package/foundation/integrations/integration-warnings.mjs +141 -19
  212. package/foundation/integrations/missing-dependency.d.mts +11 -0
  213. package/foundation/integrations/missing-dependency.mjs +20 -5
  214. package/foundation/release/folder-lock.d.mts +5 -2
  215. package/foundation/release/folder-lock.mjs +9 -3
  216. package/foundation/release/notices.mjs +2 -8
  217. package/foundation/render/cut-short.d.mts +8 -2
  218. package/foundation/render/cut-short.mjs +50 -5
  219. package/foundation/render/drawn-contrast.d.mts +40 -0
  220. package/foundation/render/drawn-contrast.mjs +355 -0
  221. package/foundation/render/file-header.mjs +4 -0
  222. package/foundation/render/layers.d.mts +2 -1
  223. package/foundation/render/layers.mjs +22 -1
  224. package/foundation/render/package-resolve-hooks.d.mts +38 -9
  225. package/foundation/render/package-resolve-hooks.mjs +124 -32
  226. package/foundation/render/page-worker.mjs +95 -23
  227. package/foundation/render/part-boxes.d.mts +27 -0
  228. package/foundation/render/part-boxes.mjs +45 -0
  229. package/foundation/render/picture-chrome.mjs +36 -4
  230. package/foundation/render/picture-playwright.mjs +26 -2
  231. package/foundation/render/picture-window.d.mts +29 -2
  232. package/foundation/render/picture-window.mjs +99 -1
  233. package/foundation/render/render-page.d.mts +39 -6
  234. package/foundation/render/render-page.mjs +26 -10
  235. package/foundation/render/ts-paths.mjs +2 -1
  236. package/foundation/response/error-codes.doc.mjs +1 -1
  237. package/foundation/response/error-codes.mjs +1 -1
  238. package/foundation/response/response-types.doc.mjs +9 -5
  239. package/foundation/text/written-string.d.mts +4 -1
  240. package/foundation/text/written-string.mjs +4 -1
  241. package/package.json +8 -7
@@ -0,0 +1,10 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The `name` in the package.json at `file`. A name kept from an unchanged
6
+ * file counts as a read of the file, as reading it does.
7
+ * @param {string} file
8
+ * @returns {unknown}
9
+ */
10
+ export function packageNameAt(file: string): unknown;
@@ -0,0 +1,37 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file A package.json's `name`, read again only when the file changes.
5
+ * @input The path of a package.json.
6
+ * @output Its `name`, or undefined when it is absent or unreadable.
7
+ * @position foundation/fs — theme build's walk up to Core's folder
8
+ */
9
+
10
+ import * as fs from 'node:fs';
11
+ import {fileStamp, recordContentRead} from './read-record.mjs';
12
+
13
+ /** Each name read, by path, with the file's stamp then. */
14
+ const names = new Map();
15
+
16
+ /**
17
+ * The `name` in the package.json at `file`. A name kept from an unchanged
18
+ * file counts as a read of the file, as reading it does.
19
+ * @param {string} file
20
+ * @returns {unknown}
21
+ */
22
+ export function packageNameAt(file) {
23
+ const kept = names.get(file);
24
+ // Recorded before the stamp is compared: a write after it shows as a change.
25
+ if (kept) recordContentRead(file);
26
+ const stamp = fileStamp(file);
27
+ if (kept?.stamp === stamp) return kept.name;
28
+ let name;
29
+ try {
30
+ name = JSON.parse(fs.readFileSync(file, 'utf-8'))?.name;
31
+ } catch {
32
+ // Absent, unreadable, or not JSON: no name.
33
+ }
34
+ // A name read from a file that appeared after its stamp is not kept.
35
+ if (stamp !== '-' || name === undefined) names.set(file, {stamp, name});
36
+ return name;
37
+ }
@@ -0,0 +1,27 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * A bounded app-source walk that excludes dependencies, generated output, and
6
+ * links. Callers parse the returned bytes without executing app code.
7
+ * @param {string} root
8
+ * @param {string} generatedModule
9
+ * @param {{stylesheets?: boolean, pages?: boolean, markup?: boolean, outputAtRootsOnly?: boolean, skippedLinks?: string[]}} [options] - also list
10
+ * `.css` files, `.html` pages, and `.mdx` and `.astro` pages; with
11
+ * `outputAtRootsOnly`, skip a `build`, `dist` or `coverage` folder only in
12
+ * a folder with a package.json, where a build writes its output, and read
13
+ * one anywhere else (an app route named `build`); `skippedLinks` collects
14
+ * each linked folder or source file the walk does not follow
15
+ */
16
+ export function listProjectSourceFiles(root: string, generatedModule: string, options?: {
17
+ stylesheets?: boolean;
18
+ pages?: boolean;
19
+ markup?: boolean;
20
+ outputAtRootsOnly?: boolean;
21
+ skippedLinks?: string[];
22
+ }): string[];
23
+ export const SOURCE_EXTENSIONS: Set<string>;
24
+ /** A page in a format that renders components but is not a script: MDX or Astro. */
25
+ export const MARKUP_PAGE: RegExp;
26
+ /** The most source files {@link listProjectSourceFiles} reads. */
27
+ export const SOURCE_FILE_LIMIT: 5000;
@@ -0,0 +1,115 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The app's own source files, found by a bounded walk.
5
+ * @input A project folder.
6
+ * @output The source files under it, leaving out dependencies, generated
7
+ * output and links, up to a limit.
8
+ * @position Read by `astryx doctor` and by the Core prop check that doctor
9
+ * and `astryx experimental export` share (discovery/unknown-core-props.mjs).
10
+ */
11
+
12
+ import * as fs from 'node:fs';
13
+ import * as path from 'node:path';
14
+
15
+ export const SOURCE_EXTENSIONS = new Set([
16
+ '.js',
17
+ '.jsx',
18
+ '.mjs',
19
+ '.cjs',
20
+ '.ts',
21
+ '.tsx',
22
+ '.mts',
23
+ '.cts',
24
+ ]);
25
+
26
+ /** The folders the source walk skips as a build's output, at a package's root. */
27
+ const ROOT_OUTPUT_DIRS = new Set(['build', 'coverage', 'dist']);
28
+
29
+ const SKIP_DIRS = new Set([
30
+ '.git',
31
+ '.next',
32
+ 'build',
33
+ 'coverage',
34
+ 'dist',
35
+ 'node_modules',
36
+ ]);
37
+
38
+ /** A page in a format that renders components but is not a script: MDX or Astro. */
39
+ export const MARKUP_PAGE = /\.(?:mdx|astro)$/u;
40
+
41
+ /** The most source files {@link listProjectSourceFiles} reads. */
42
+ export const SOURCE_FILE_LIMIT = 5000;
43
+
44
+ /**
45
+ * A bounded app-source walk that excludes dependencies, generated output, and
46
+ * links. Callers parse the returned bytes without executing app code.
47
+ * @param {string} root
48
+ * @param {string} generatedModule
49
+ * @param {{stylesheets?: boolean, pages?: boolean, markup?: boolean, outputAtRootsOnly?: boolean, skippedLinks?: string[]}} [options] - also list
50
+ * `.css` files, `.html` pages, and `.mdx` and `.astro` pages; with
51
+ * `outputAtRootsOnly`, skip a `build`, `dist` or `coverage` folder only in
52
+ * a folder with a package.json, where a build writes its output, and read
53
+ * one anywhere else (an app route named `build`); `skippedLinks` collects
54
+ * each linked folder or source file the walk does not follow
55
+ */
56
+ export function listProjectSourceFiles(root, generatedModule, options = {}) {
57
+ /** @type {string[]} */
58
+ const files = [];
59
+ /** @type {string[]} */
60
+ const queue = [root];
61
+ while (queue.length > 0 && files.length < SOURCE_FILE_LIMIT) {
62
+ const dir = /** @type {string} */ (queue.shift());
63
+ let entries;
64
+ try {
65
+ entries = fs.readdirSync(dir, {withFileTypes: true});
66
+ } catch {
67
+ continue;
68
+ }
69
+ for (const entry of entries) {
70
+ const file = path.join(dir, entry.name);
71
+ if (entry.isSymbolicLink()) {
72
+ if (options.skippedLinks && !SKIP_DIRS.has(entry.name)) {
73
+ let linkedFolder = false;
74
+ try {
75
+ linkedFolder = fs.statSync(file).isDirectory();
76
+ } catch {
77
+ // A link that resolves to nothing holds no module.
78
+ }
79
+ if (
80
+ linkedFolder ||
81
+ SOURCE_EXTENSIONS.has(path.extname(entry.name)) ||
82
+ MARKUP_PAGE.test(entry.name)
83
+ ) {
84
+ options.skippedLinks.push(file);
85
+ }
86
+ }
87
+ continue;
88
+ }
89
+ if (entry.isDirectory()) {
90
+ const skipped =
91
+ SKIP_DIRS.has(entry.name) &&
92
+ !(
93
+ options.outputAtRootsOnly === true &&
94
+ ROOT_OUTPUT_DIRS.has(entry.name) &&
95
+ !fs.existsSync(path.join(dir, 'package.json'))
96
+ );
97
+ if (!skipped && !entry.name.startsWith('.astryx-')) {
98
+ queue.push(file);
99
+ }
100
+ } else if (
101
+ entry.isFile() &&
102
+ file !== generatedModule &&
103
+ (SOURCE_EXTENSIONS.has(path.extname(entry.name)) ||
104
+ (options.stylesheets === true &&
105
+ path.extname(entry.name) === '.css') ||
106
+ (options.pages === true &&
107
+ /^\.html?$/u.test(path.extname(entry.name))) ||
108
+ (options.markup === true && MARKUP_PAGE.test(entry.name)))
109
+ ) {
110
+ files.push(file);
111
+ }
112
+ }
113
+ }
114
+ return files;
115
+ }
@@ -0,0 +1,25 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Whether a specifier in `fromFile` names `target`, with or without its
6
+ * extension, or as a folder's index file: a relative specifier from the
7
+ * file's folder, and a bare one through the `compilerOptions.paths` of the
8
+ * tsconfig (or jsconfig) TypeScript reads for the file (`@/astryx-themes`
9
+ * with `"@/*": ["./src/*"]`).
10
+ * @param {string} specifier
11
+ * @param {string} fromFile
12
+ * @param {string} target
13
+ */
14
+ export function specifierTargets(specifier: string, fromFile: string, target: string): boolean;
15
+ /**
16
+ * Whether the project's own source imports `moduleFile` (statically, by
17
+ * `import()` or by `require()`), and how many files did not parse.
18
+ * @param {string} root
19
+ * @param {string} moduleFile
20
+ * @returns {{found: boolean, parseFailures: number}}
21
+ */
22
+ export function projectImportsModule(root: string, moduleFile: string): {
23
+ found: boolean;
24
+ parseFailures: number;
25
+ };
@@ -0,0 +1,83 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The app's own source files, and whether any of them imports a given
5
+ * module: read as files and syntax, never run.
6
+ *
7
+ * @input a project folder and a module path
8
+ * @output specifierTargets, projectImportsModule (the source walk itself is
9
+ * project-source-files.mjs)
10
+ * @position read by doctor (whether the app imports the generated theme
11
+ * module and its stylesheets); no command receipt reads app source
12
+ */
13
+
14
+ import * as fs from 'node:fs';
15
+ import * as path from 'node:path';
16
+ import {moduleImports} from '../render/embedded-imports.mjs';
17
+ import {candidatesOf, matchPath, pathsFor} from '../render/ts-paths.mjs';
18
+ import {
19
+ SOURCE_EXTENSIONS,
20
+ listProjectSourceFiles,
21
+ } from './project-source-files.mjs';
22
+
23
+ /**
24
+ * Whether a specifier in `fromFile` names `target`, with or without its
25
+ * extension, or as a folder's index file: a relative specifier from the
26
+ * file's folder, and a bare one through the `compilerOptions.paths` of the
27
+ * tsconfig (or jsconfig) TypeScript reads for the file (`@/astryx-themes`
28
+ * with `"@/*": ["./src/*"]`).
29
+ * @param {string} specifier
30
+ * @param {string} fromFile
31
+ * @param {string} target
32
+ */
33
+ export function specifierTargets(specifier, fromFile, target) {
34
+ /** @type {string[]} */
35
+ let bases;
36
+ if (specifier.startsWith('.')) {
37
+ bases = [path.resolve(path.dirname(fromFile), specifier)];
38
+ } else {
39
+ const match = matchPath(pathsFor(path.resolve(fromFile)), specifier);
40
+ if (!match) return false;
41
+ bases = candidatesOf(match);
42
+ }
43
+ const wanted = path.resolve(target);
44
+ return bases.some(base =>
45
+ [
46
+ base,
47
+ ...[...SOURCE_EXTENSIONS].map(extension => `${base}${extension}`),
48
+ ...[...SOURCE_EXTENSIONS].map(extension =>
49
+ path.join(base, `index${extension}`),
50
+ ),
51
+ ].some(candidate => path.resolve(candidate) === wanted),
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Whether the project's own source imports `moduleFile` (statically, by
57
+ * `import()` or by `require()`), and how many files did not parse.
58
+ * @param {string} root
59
+ * @param {string} moduleFile
60
+ * @returns {{found: boolean, parseFailures: number}}
61
+ */
62
+ export function projectImportsModule(root, moduleFile) {
63
+ let parseFailures = 0;
64
+ for (const file of listProjectSourceFiles(root, moduleFile)) {
65
+ let records;
66
+ try {
67
+ records = moduleImports(fs.readFileSync(file, 'utf-8'), file);
68
+ } catch {
69
+ records = null;
70
+ }
71
+ if (records === null) {
72
+ parseFailures += 1;
73
+ continue;
74
+ }
75
+ if (
76
+ records.some(record =>
77
+ specifierTargets(record.specifier, file, moduleFile),
78
+ )
79
+ )
80
+ return {found: true, parseFailures};
81
+ }
82
+ return {found: false, parseFailures};
83
+ }
@@ -127,6 +127,24 @@ export function recordReads<T>(seen: Map<string, string>, fn: () => T, { exact }
127
127
  export function reusedWhileUnchanged<T>(load: () => Promise<T>, isUnchanged?: (recorded: Map<string, string>) => boolean): (options?: {
128
128
  fresh?: boolean;
129
129
  }) => Promise<T>;
130
+ /**
131
+ * {@link reusedWhileUnchanged} for a loader that returns its value at once:
132
+ * kept while every file and folder it read is unchanged, loaded again after
133
+ * a change, and tried again after a load that throws. What a kept value read
134
+ * counts as read by the operation that asks for it.
135
+ * @template T
136
+ * @param {() => T} load
137
+ * @param {{exact?: boolean, isUnchanged?: (recorded: Map<string, string>) => boolean}} [options]
138
+ * - `exact`: record reads as {@link recordReads} does with `exact`.
139
+ * `isUnchanged`: as for {@link reusedWhileUnchanged}.
140
+ * @returns {(options?: {fresh?: boolean}) => T}
141
+ */
142
+ export function reusedWhileUnchangedSync<T>(load: () => T, { exact, isUnchanged }?: {
143
+ exact?: boolean;
144
+ isUnchanged?: (recorded: Map<string, string>) => boolean;
145
+ }): (options?: {
146
+ fresh?: boolean;
147
+ }) => T;
130
148
  /**
131
149
  * What an existence check of a present path records: only that it is there,
132
150
  * all the check returns. An absent path records `-`, as every kind does.
@@ -13,8 +13,10 @@
13
13
  * `unchangedSince(seen)` says whether all are still in that state.
14
14
  * @position Used by search's adapter to reuse a gathered catalog only while
15
15
  * it is exact, by the docs adapter to rebuild the CLI's own docs tree after
16
- * an edit (`reusedWhileUnchanged`), and by the doc importers and reader
17
- * (../doc-compiler) to read an edited doc file again. A run inside another
16
+ * an edit (`reusedWhileUnchanged`), by the doc importers and reader
17
+ * (../doc-compiler) to read an edited doc file again, and by swizzle's
18
+ * copy to keep a package's public surface (`reusedWhileUnchangedSync`).
19
+ * A run inside another
18
20
  * records into both, so an outer reuse sees what an inner one read.
19
21
  * Outside `recordReads` nothing is recorded and every fs call behaves as
20
22
  * before.
@@ -585,3 +587,35 @@ export function reusedWhileUnchanged(load, isUnchanged = unchangedSince) {
585
587
  return value;
586
588
  };
587
589
  }
590
+
591
+ /**
592
+ * {@link reusedWhileUnchanged} for a loader that returns its value at once:
593
+ * kept while every file and folder it read is unchanged, loaded again after
594
+ * a change, and tried again after a load that throws. What a kept value read
595
+ * counts as read by the operation that asks for it.
596
+ * @template T
597
+ * @param {() => T} load
598
+ * @param {{exact?: boolean, isUnchanged?: (recorded: Map<string, string>) => boolean}} [options]
599
+ * - `exact`: record reads as {@link recordReads} does with `exact`.
600
+ * `isUnchanged`: as for {@link reusedWhileUnchanged}.
601
+ * @returns {(options?: {fresh?: boolean}) => T}
602
+ */
603
+ export function reusedWhileUnchangedSync(
604
+ load,
605
+ {exact = false, isUnchanged = unchangedSince} = {},
606
+ ) {
607
+ /** @type {{reads: Map<string, string>, value: T} | undefined} */
608
+ let last;
609
+ return ({fresh = false} = {}) => {
610
+ if (!fresh && last && isUnchanged(last.reads)) {
611
+ recordStates(last.reads);
612
+ return last.value;
613
+ }
614
+ last = undefined;
615
+ /** @type {Map<string, string>} */
616
+ const seen = new Map();
617
+ const value = recordReads(seen, load, {exact});
618
+ last = {reads: seen, value};
619
+ return value;
620
+ };
621
+ }
@@ -4,30 +4,62 @@
4
4
  /**
5
5
  * Whether the nudge counts `issue` and points to doctor for it. A provider
6
6
  * conflict carries the specific message that `doctor integration validate`
7
- * would not explain, so the nudge prints it instead.
8
- * @param {{code: string}} issue
7
+ * would not explain, so the nudge prints it instead. So does an issue that
8
+ * compares a component with Core components (`needsCore`) where doctor reads
9
+ * no Core (outside a project, or in a project with no Core installed): doctor
10
+ * cannot name one there.
11
+ * @param {{code: string, needsCore?: boolean}} issue
12
+ * @param {{doctorReadsCore?: boolean}} [where]
9
13
  * @returns {boolean}
10
14
  */
11
15
  export function pointsToDoctor(issue: {
12
16
  code: string;
17
+ needsCore?: boolean;
18
+ }, { doctorReadsCore }?: {
19
+ doctorReadsCore?: boolean;
13
20
  }): boolean;
14
21
  /**
15
- * For each configured (already-loaded) integration, compute its issues using
16
- * the shared integration validators and, if any exist, print exactly
17
- * ONE line per integration to stderr:
22
+ * Whether doctor outside a project names the issues of `integration`, a
23
+ * record the folder loads: doctor checks the computer there, so only an
24
+ * integration installed for the computer that loads (spec AST-081 FR4, FR12).
25
+ * @param {{__computer?: boolean, __loadError?: string}} integration
26
+ * @returns {boolean}
27
+ */
28
+ export function doctorChecksOutside(integration: {
29
+ __computer?: boolean;
30
+ __loadError?: string;
31
+ }): boolean;
32
+ /**
33
+ * Print the issues of the loaded integrations to stderr: ONE line per
34
+ * integration with issues, naming the check that shows them,
35
+ *
36
+ * Warning: <pkg> has N integration issue(s). Run: astryx doctor
37
+ *
38
+ * (`doctor integration validate <pkg>` for a bare list of integrations, and
39
+ * outside a project for an integration doctor does not check there), and a
40
+ * line of its own for each issue that check cannot show:
18
41
  *
19
- * Warning: <pkg> has N integration issue(s). Run: astryx doctor integration validate <pkg>
42
+ * Warning: <pkg>: <message>
20
43
  *
21
- * @param {Array<import('./integrations.mjs').LoadedIntegration> | {issues: () => Promise<Array<{package: string, code: string, severity: string, message: string}>>}} source loaded integrations or their Project owner
44
+ * @param {Array<import('./integrations.mjs').LoadedIntegration> | {cwd?: string, loadedIntegrations?: ReadonlyArray<{name?: string, __computer?: boolean, __loadError?: string, __local?: boolean}>, issues: () => Promise<Array<{package: string, code: string, severity: string, message: string, needsCore?: boolean, needsCatalog?: boolean}>>}} source loaded integrations or their Project owner
22
45
  * @param {{json?: boolean}} [options]
23
46
  * @returns {Promise<void>}
24
47
  */
25
48
  export function warnOnIntegrationIssues(source: Array<import("./integrations.mjs").LoadedIntegration> | {
49
+ cwd?: string;
50
+ loadedIntegrations?: ReadonlyArray<{
51
+ name?: string;
52
+ __computer?: boolean;
53
+ __loadError?: string;
54
+ __local?: boolean;
55
+ }>;
26
56
  issues: () => Promise<Array<{
27
57
  package: string;
28
58
  code: string;
29
59
  severity: string;
30
60
  message: string;
61
+ needsCore?: boolean;
62
+ needsCatalog?: boolean;
31
63
  }>>;
32
64
  }, { json }?: {
33
65
  json?: boolean;
@@ -3,11 +3,18 @@
3
3
  /**
4
4
  * @file Compact, non-blocking integration-issue nudge for everyday commands.
5
5
  *
6
- * When a CONFIGURED integration (from the Project's `loadedIntegrations`) has
7
- * validation issues, the everyday commands (component / template / upgrade)
8
- * should print ONE compact, non-blocking line per integration telling the user
9
- * to run `doctor integration validate` — instead of silently skipping broken
10
- * contributions or spamming per-contribution diagnostics.
6
+ * When a loaded integration has validation issues, the everyday commands
7
+ * print ONE compact, non-blocking line per integration that names the check
8
+ * to run, instead of silently skipping broken contributions or printing each
9
+ * diagnostic. For a Project's issues the check is `doctor`. Outside a
10
+ * project, doctor checks the computer. There, an integration that doctor
11
+ * does not check gets `doctor integration validate <pkg>`: one the folder
12
+ * loads itself, or one installed for the computer that cannot load because
13
+ * a package it imports is missing. A bare list of integrations gets the same
14
+ * command. An issue that the named check cannot show gets its own line
15
+ * instead: a provider conflict, a comparison with Core components where
16
+ * doctor reads no Core, and a replacement finding where the line names
17
+ * `doctor integration validate`, which does not resolve replacements.
11
18
  *
12
19
  * Design constraints (all enforced here):
13
20
  * - Reuses Project.issues() when a Project is available, so cross-package
@@ -17,31 +24,90 @@
17
24
  * - Suppressed entirely in --json mode.
18
25
  * - Best-effort: never throws, never changes the exit code. Broken
19
26
  * contributions are still skipped downstream exactly as before; this only
20
- * ADDS a one-line nudge.
27
+ * ADDS lines to stderr.
21
28
  */
22
29
 
23
30
  import {validateLoadedIntegration} from './validate-contributions.mjs';
24
31
  import {formatCliCommand} from '../env/package-manager.mjs';
32
+ import {findProjectCoreDir} from '../fs/paths.mjs';
33
+ import {isOutsideProject} from '../env/project-scope.mjs';
34
+ import {isPackageName} from '../identity/provider-identity.mjs';
35
+ import {shellArg} from '../text/shell-arg.mjs';
25
36
 
26
37
  /**
27
38
  * Whether the nudge counts `issue` and points to doctor for it. A provider
28
39
  * conflict carries the specific message that `doctor integration validate`
29
- * would not explain, so the nudge prints it instead.
30
- * @param {{code: string}} issue
40
+ * would not explain, so the nudge prints it instead. So does an issue that
41
+ * compares a component with Core components (`needsCore`) where doctor reads
42
+ * no Core (outside a project, or in a project with no Core installed): doctor
43
+ * cannot name one there.
44
+ * @param {{code: string, needsCore?: boolean}} issue
45
+ * @param {{doctorReadsCore?: boolean}} [where]
31
46
  * @returns {boolean}
32
47
  */
33
- export function pointsToDoctor(issue) {
34
- return issue.code !== 'duplicate_provider';
48
+ export function pointsToDoctor(issue, {doctorReadsCore = true} = {}) {
49
+ if (issue.code === 'duplicate_provider') return false;
50
+ return doctorReadsCore || issue.needsCore !== true;
35
51
  }
36
52
 
37
53
  /**
38
- * For each configured (already-loaded) integration, compute its issues using
39
- * the shared integration validators and, if any exist, print exactly
40
- * ONE line per integration to stderr:
54
+ * Whether doctor outside a project names the issues of `integration`, a
55
+ * record the folder loads: doctor checks the computer there, so only an
56
+ * integration installed for the computer that loads (spec AST-081 FR4, FR12).
57
+ * @param {{__computer?: boolean, __loadError?: string}} integration
58
+ * @returns {boolean}
59
+ */
60
+ export function doctorChecksOutside(integration) {
61
+ return integration.__computer === true && integration.__loadError == null;
62
+ }
63
+
64
+ /**
65
+ * `doctor integration validate` for the integration labelled `pkg`. A local
66
+ * integration whose package.json has no name has a placeholder label, so its
67
+ * command names no package and validates the package in the current folder.
68
+ * Any other label stays, as one shell word, so the command reports what is
69
+ * wrong with it, such as a configured entry that is not a bare package name.
70
+ * @param {string} pkg
71
+ * @param {ReadonlySet<string>} unnamedLocal the placeholder labels
72
+ * @returns {string}
73
+ */
74
+ function validateCommand(pkg, unnamedLocal) {
75
+ return unnamedLocal.has(pkg)
76
+ ? 'doctor integration validate'
77
+ : `doctor integration validate ${shellArg(pkg)}`;
78
+ }
79
+
80
+ /**
81
+ * The labels of the local integrations among `records` whose package.json
82
+ * has no name.
83
+ * @param {ReadonlyArray<{name?: string, __local?: boolean}>} records
84
+ * @returns {Set<string>}
85
+ */
86
+ function unnamedLocalLabels(records) {
87
+ return new Set(
88
+ records.flatMap(record =>
89
+ record?.__local === true &&
90
+ typeof record.name === 'string' &&
91
+ !isPackageName(record.name)
92
+ ? [record.name]
93
+ : [],
94
+ ),
95
+ );
96
+ }
97
+
98
+ /**
99
+ * Print the issues of the loaded integrations to stderr: ONE line per
100
+ * integration with issues, naming the check that shows them,
101
+ *
102
+ * Warning: <pkg> has N integration issue(s). Run: astryx doctor
103
+ *
104
+ * (`doctor integration validate <pkg>` for a bare list of integrations, and
105
+ * outside a project for an integration doctor does not check there), and a
106
+ * line of its own for each issue that check cannot show:
41
107
  *
42
- * Warning: <pkg> has N integration issue(s). Run: astryx doctor integration validate <pkg>
108
+ * Warning: <pkg>: <message>
43
109
  *
44
- * @param {Array<import('./integrations.mjs').LoadedIntegration> | {issues: () => Promise<Array<{package: string, code: string, severity: string, message: string}>>}} source loaded integrations or their Project owner
110
+ * @param {Array<import('./integrations.mjs').LoadedIntegration> | {cwd?: string, loadedIntegrations?: ReadonlyArray<{name?: string, __computer?: boolean, __loadError?: string, __local?: boolean}>, issues: () => Promise<Array<{package: string, code: string, severity: string, message: string, needsCore?: boolean, needsCatalog?: boolean}>>}} source loaded integrations or their Project owner
45
111
  * @param {{json?: boolean}} [options]
46
112
  * @returns {Promise<void>}
47
113
  */
@@ -51,6 +117,8 @@ export async function warnOnIntegrationIssues(source, {json = false} = {}) {
51
117
 
52
118
  /** @type {Map<string, number>} */
53
119
  const issueCounts = new Map();
120
+ /** @type {Set<string>} packages whose line names their own check */
121
+ const checkedAlone = new Set();
54
122
  const fromProject =
55
123
  source != null &&
56
124
  !Array.isArray(source) &&
@@ -58,11 +126,61 @@ export async function warnOnIntegrationIssues(source, {json = false} = {}) {
58
126
 
59
127
  if (fromProject) {
60
128
  const issues = await source.issues();
129
+ const cwd = source.cwd ?? process.cwd();
130
+ // Doctor reads only the project's installed Core, never the one the
131
+ // answering CLI carries. Asked only for an issue that needs a Core.
132
+ /** @type {boolean | undefined} */
133
+ let projectCore;
134
+ const doctorReadsCore = () =>
135
+ (projectCore ??= findProjectCoreDir(cwd) != null);
136
+ // Outside a project doctor checks the computer: of the integrations
137
+ // the folder loads, it names the issues of those installed for the
138
+ // computer that load.
139
+ /** @type {Set<string> | null} */
140
+ let doctorNames = null;
141
+ let scoped = false;
142
+ const doctorCovers = (/** @type {string} */ pkg) => {
143
+ if (!scoped) {
144
+ scoped = true;
145
+ if (isOutsideProject(cwd)) {
146
+ doctorNames = new Set(
147
+ (source.loadedIntegrations ?? []).flatMap(i =>
148
+ doctorChecksOutside(i) && i.name ? [i.name] : [],
149
+ ),
150
+ );
151
+ }
152
+ }
153
+ return doctorNames == null || doctorNames.has(pkg);
154
+ };
155
+ /** @param {{package: string, message: string}} issue */
156
+ const printOwnLine = issue => {
157
+ // Name the package unless the message already does.
158
+ const named = issue.message.includes(issue.package);
159
+ console.error(
160
+ `Warning: ${named ? '' : `${issue.package}: `}${issue.message}`,
161
+ );
162
+ };
61
163
  for (const issue of issues) {
62
- if (!pointsToDoctor(issue)) {
164
+ if (issue.code === 'duplicate_provider') {
63
165
  console.error(`Warning: ${issue.message}`);
64
166
  continue;
65
167
  }
168
+ if (
169
+ issue.needsCore === true &&
170
+ !pointsToDoctor(issue, {doctorReadsCore: doctorReadsCore()})
171
+ ) {
172
+ printOwnLine(issue);
173
+ continue;
174
+ }
175
+ if (!doctorCovers(issue.package)) {
176
+ // `doctor integration validate` does not resolve replacements, so
177
+ // it cannot show a replacement finding.
178
+ if (issue.needsCatalog === true) {
179
+ printOwnLine(issue);
180
+ continue;
181
+ }
182
+ checkedAlone.add(issue.package);
183
+ }
66
184
  issueCounts.set(
67
185
  issue.package,
68
186
  (issueCounts.get(issue.package) ?? 0) + 1,
@@ -89,10 +207,14 @@ export async function warnOnIntegrationIssues(source, {json = false} = {}) {
89
207
  }
90
208
  }
91
209
 
210
+ const unnamedLocal = unnamedLocalLabels(
211
+ Array.isArray(source) ? source : (source?.loadedIntegrations ?? []),
212
+ );
92
213
  for (const [pkg, count] of issueCounts) {
93
- const command = fromProject
94
- ? formatCliCommand('doctor')
95
- : formatCliCommand(`doctor integration validate ${pkg}`);
214
+ const command =
215
+ fromProject && !checkedAlone.has(pkg)
216
+ ? formatCliCommand('doctor')
217
+ : formatCliCommand(validateCommand(pkg, unnamedLocal));
96
218
  console.error(
97
219
  `Warning: ${pkg} has ${count} integration issue(s). Run: ${command}`,
98
220
  );