@astryxdesign/cli 0.7.17 → 0.7.18-canary.g32556bb

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 (261) 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/template/template.type.d.mts +3 -3
  48. package/api/template/template.type.mjs +3 -3
  49. package/api/theme/_adapter.mjs +48 -12
  50. package/api/theme/build/build.d.mts +4 -0
  51. package/api/theme/build/build.mjs +69 -18
  52. package/api/theme/build/style-keys.mjs +4 -5
  53. package/api/theme/build/theme-object.mjs +5 -0
  54. package/api/theme/palette/generate/color.d.mts +47 -0
  55. package/api/theme/palette/generate/color.mjs +58 -1
  56. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  57. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  58. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  59. package/api/theme/palette/generate/editor-look.mjs +550 -0
  60. package/api/theme/palette/generate/mapping.d.mts +94 -9
  61. package/api/theme/palette/generate/mapping.mjs +94 -22
  62. package/api/theme-edit/_adapter.mjs +13 -2
  63. package/api/theme-edit/_catalog.d.mts +13 -13
  64. package/api/theme-edit/_catalog.mjs +66 -28
  65. package/api/theme-edit/_check.d.mts +82 -6
  66. package/api/theme-edit/_check.mjs +1270 -238
  67. package/api/theme-edit/_color.d.mts +74 -0
  68. package/api/theme-edit/_color.mjs +168 -3
  69. package/api/theme-edit/_compiler.d.mts +3 -5
  70. package/api/theme-edit/_compiler.mjs +122 -23
  71. package/api/theme-edit/_context.d.mts +55 -12
  72. package/api/theme-edit/_context.mjs +114 -60
  73. package/api/theme-edit/_css.d.mts +11 -0
  74. package/api/theme-edit/_css.mjs +40 -0
  75. package/api/theme-edit/_edit.d.mts +15 -2
  76. package/api/theme-edit/_edit.mjs +1469 -133
  77. package/api/theme-edit/_how-commands.d.mts +116 -0
  78. package/api/theme-edit/_how-commands.mjs +227 -115
  79. package/api/theme-edit/_how-question.d.mts +74 -29
  80. package/api/theme-edit/_how-question.mjs +8514 -1256
  81. package/api/theme-edit/_how-sides.d.mts +22 -0
  82. package/api/theme-edit/_how-sides.mjs +173 -0
  83. package/api/theme-edit/_how-steps.d.mts +42 -0
  84. package/api/theme-edit/_how-steps.mjs +208 -0
  85. package/api/theme-edit/_how-values.d.mts +29 -0
  86. package/api/theme-edit/_how-values.mjs +111 -0
  87. package/api/theme-edit/_how-words.d.mts +15 -0
  88. package/api/theme-edit/_how-words.mjs +239 -0
  89. package/api/theme-edit/_how.d.mts +1 -1
  90. package/api/theme-edit/_how.mjs +422 -37
  91. package/api/theme-edit/_missed.d.mts +2 -1
  92. package/api/theme-edit/_missed.mjs +125 -13
  93. package/api/theme-edit/_normal.d.mts +5 -3
  94. package/api/theme-edit/_normal.mjs +54 -14
  95. package/api/theme-edit/_palette.d.mts +204 -4
  96. package/api/theme-edit/_palette.mjs +901 -25
  97. package/api/theme-edit/_part-pieces.d.mts +54 -0
  98. package/api/theme-edit/_part-pieces.mjs +179 -0
  99. package/api/theme-edit/_part-words.mjs +33 -5
  100. package/api/theme-edit/_parts.d.mts +133 -0
  101. package/api/theme-edit/_parts.mjs +599 -10
  102. package/api/theme-edit/_picture-traits.d.mts +259 -0
  103. package/api/theme-edit/_picture-traits.mjs +1030 -0
  104. package/api/theme-edit/_preview.d.mts +95 -4
  105. package/api/theme-edit/_preview.mjs +284 -31
  106. package/api/theme-edit/_project.d.mts +14 -4
  107. package/api/theme-edit/_project.mjs +95 -26
  108. package/api/theme-edit/_resolved.d.mts +46 -0
  109. package/api/theme-edit/_resolved.mjs +800 -0
  110. package/api/theme-edit/_set-line.d.mts +29 -0
  111. package/api/theme-edit/_set-line.mjs +100 -0
  112. package/api/theme-edit/_settings.d.mts +625 -28
  113. package/api/theme-edit/_settings.mjs +4867 -888
  114. package/api/theme-edit/_tables.d.mts +25 -1
  115. package/api/theme-edit/_tables.mjs +115 -11
  116. package/api/theme-edit/_text-looks.d.mts +78 -0
  117. package/api/theme-edit/_text-looks.mjs +376 -0
  118. package/api/theme-edit/_vet.d.mts +3 -26
  119. package/api/theme-edit/_vet.mjs +5 -89
  120. package/api/theme-edit/how/how.d.mts +1 -1
  121. package/api/theme-edit/how/how.mjs +1 -1
  122. package/api/theme-edit/show/show.d.mts +4 -3
  123. package/api/theme-edit/show/show.mjs +3 -2
  124. package/api/theme-edit/theme-edit.type.d.mts +117 -1
  125. package/api/theme-edit/theme-edit.type.mjs +46 -3
  126. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  128. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  129. package/api/theme-edit/themeEditShow.doc.mjs +22 -3
  130. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  131. package/assets/component-list.generated.json +1 -1
  132. package/assets/docs/author-a-theme.doc.mjs +7 -4
  133. package/assets/docs/icons.doc.mjs +7 -6
  134. package/assets/docs/theme.doc.dense.mjs +10 -0
  135. package/assets/docs/theme.doc.mjs +10 -0
  136. package/assets/docs/theme.doc.zh.mjs +10 -0
  137. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  138. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  139. package/assets/docs/use-a-theme.doc.mjs +89 -17
  140. package/assets/docs-routes.generated.json +1 -1
  141. package/assets/docs.generated.json +2 -2
  142. package/assets/icons/definitions/article.doc.mjs +9 -0
  143. package/assets/icons/template-icons.json +5 -0
  144. package/assets/search-catalog.generated.json +2 -2
  145. package/assets/self-audit.generated.json +1 -1
  146. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  147. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  148. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  149. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  150. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  151. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  152. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  153. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  154. package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +9 -1
  155. package/assets/templates/blocks/components/SideNavCollapseButton/SideNavCollapseButtonShowcase.doc.mjs +9 -2
  156. package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.doc.mjs +3 -2
  157. package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.tsx +2 -1
  158. package/assets/templates/blocks/components/SideNavItem/SideNavItemShowcase.doc.mjs +3 -2
  159. package/assets/templates/blocks/components/SideNavSection/SideNavSectionShowcase.doc.mjs +2 -1
  160. package/assets/templates/components.generated.json +1 -1
  161. package/assets/templates/pages/ide/page.tsx +5 -10
  162. package/assets/templates/pages/payment-form/page.tsx +16 -60
  163. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  164. package/authoring/config/parse.mjs +1 -1
  165. package/authoring/debug/parse.d.mts +1 -1
  166. package/authoring/doctypes/_schema.d.mts +13 -13
  167. package/authoring/doctypes/icon-definition/parse.mjs +2 -2
  168. package/authoring/doctypes/icon-set/parse.mjs +1 -1
  169. package/authoring/doctypes/template/parse.mjs +1 -4
  170. package/authoring/gap-report/parse.d.mts +1 -1
  171. package/clients/cli/build-id.generated.json +1 -1
  172. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  173. package/clients/cli/commands/experimental/icon.mjs +7 -7
  174. package/clients/cli/commands/experimental/theme.mjs +175 -13
  175. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  176. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  177. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  178. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  179. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +15 -5
  180. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  181. package/clients/cli/commands/hook.mjs +7 -0
  182. package/clients/cli/commands/template.mjs +1 -1
  183. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  184. package/clients/cli/index.mjs +6 -2
  185. package/clients/cli/lib/hook-format.mjs +41 -1
  186. package/clients/cli/lib/json-shim.mjs +34 -14
  187. package/clients/cli/lib/other-cli-words.mjs +7 -0
  188. package/clients/cli/lib/unknown-command.mjs +345 -46
  189. package/clients/cli/manifest.generated.json +1 -1
  190. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  191. package/foundation/agent-docs/agent-docs.mjs +51 -8
  192. package/foundation/config/project.d.mts +11 -1
  193. package/foundation/config/project.mjs +11 -2
  194. package/foundation/discovery/component-replacement.d.mts +5 -8
  195. package/foundation/discovery/component-replacement.mjs +12 -14
  196. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  197. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  198. package/foundation/discovery/core-elements.d.mts +6 -0
  199. package/foundation/discovery/core-elements.mjs +10 -2
  200. package/foundation/discovery/core-prop-types.d.mts +5 -0
  201. package/foundation/discovery/core-prop-types.mjs +10 -3
  202. package/foundation/discovery/core-props.d.mts +8 -0
  203. package/foundation/discovery/core-props.mjs +29 -13
  204. package/foundation/discovery/icon-ranking.d.mts +5 -2
  205. package/foundation/discovery/icon-ranking.mjs +101 -18
  206. package/foundation/discovery/icon-set-checks.mjs +1 -1
  207. package/foundation/discovery/icon-set-writer.mjs +1 -1
  208. package/foundation/discovery/official-list.d.mts +17 -0
  209. package/foundation/discovery/official-list.mjs +77 -0
  210. package/foundation/discovery/template-icon-notes.mjs +3 -3
  211. package/foundation/discovery/template-icons.mjs +2 -2
  212. package/foundation/discovery/template-placeholders.mjs +1 -1
  213. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  214. package/foundation/discovery/unknown-core-props.mjs +601 -0
  215. package/foundation/discovery/written-prop-values.d.mts +35 -0
  216. package/foundation/discovery/written-prop-values.mjs +258 -0
  217. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  218. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  219. package/foundation/fs/package-name.d.mts +10 -0
  220. package/foundation/fs/package-name.mjs +37 -0
  221. package/foundation/fs/project-source-files.d.mts +27 -0
  222. package/foundation/fs/project-source-files.mjs +115 -0
  223. package/foundation/fs/project-sources.d.mts +25 -0
  224. package/foundation/fs/project-sources.mjs +83 -0
  225. package/foundation/fs/read-record.d.mts +18 -0
  226. package/foundation/fs/read-record.mjs +36 -2
  227. package/foundation/integrations/integration-warnings.d.mts +39 -7
  228. package/foundation/integrations/integration-warnings.mjs +141 -19
  229. package/foundation/integrations/missing-dependency.d.mts +11 -0
  230. package/foundation/integrations/missing-dependency.mjs +20 -5
  231. package/foundation/release/folder-lock.d.mts +5 -2
  232. package/foundation/release/folder-lock.mjs +9 -3
  233. package/foundation/release/notices.mjs +2 -8
  234. package/foundation/render/cut-short.d.mts +8 -2
  235. package/foundation/render/cut-short.mjs +50 -5
  236. package/foundation/render/drawn-contrast.d.mts +40 -0
  237. package/foundation/render/drawn-contrast.mjs +355 -0
  238. package/foundation/render/file-header.mjs +4 -0
  239. package/foundation/render/layers.d.mts +2 -1
  240. package/foundation/render/layers.mjs +22 -1
  241. package/foundation/render/package-resolve-hooks.d.mts +38 -9
  242. package/foundation/render/package-resolve-hooks.mjs +124 -32
  243. package/foundation/render/page-worker.mjs +95 -23
  244. package/foundation/render/part-boxes.d.mts +27 -0
  245. package/foundation/render/part-boxes.mjs +45 -0
  246. package/foundation/render/picture-chrome.mjs +36 -4
  247. package/foundation/render/picture-playwright.mjs +26 -2
  248. package/foundation/render/picture-window.d.mts +29 -2
  249. package/foundation/render/picture-window.mjs +99 -1
  250. package/foundation/render/render-page.d.mts +39 -6
  251. package/foundation/render/render-page.mjs +26 -10
  252. package/foundation/render/ts-paths.mjs +2 -1
  253. package/foundation/response/error-codes.doc.mjs +1 -1
  254. package/foundation/response/error-codes.mjs +1 -1
  255. package/foundation/response/response-types.doc.mjs +9 -5
  256. package/foundation/suggest/other-command.mjs +25 -1
  257. package/foundation/text/icon-set-next.d.mts +1 -1
  258. package/foundation/text/icon-set-next.mjs +2 -2
  259. package/foundation/text/written-string.d.mts +4 -1
  260. package/foundation/text/written-string.mjs +4 -1
  261. package/package.json +8 -7
@@ -0,0 +1,601 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The props pages give Core components that the component does not
5
+ * take.
6
+ * @input The props pages give Core components (core-props.mjs), a reader of
7
+ * each component's documented props, and the project's TypeScript.
8
+ * @output Each prop the component does not take, with a documented prop that
9
+ * has the same words; or why the props were not checked.
10
+ * @position Shared by `astryx doctor` (api/doctor/_adapter.mjs), which reads
11
+ * every page of the project, and `astryx experimental export`
12
+ * (api/render/_adapter.mjs), which reads the page it exports.
13
+ */
14
+
15
+ import * as fs from 'node:fs';
16
+ import * as path from 'node:path';
17
+ export {OTHER_JSX_RUNTIME} from './core-elements.mjs';
18
+ import {projectAugmentations} from './core-augmentation-points.mjs';
19
+ import {
20
+ findInstalledPackage,
21
+ findPackageRoot,
22
+ findWorkspaceRoot,
23
+ } from '../fs/paths.mjs';
24
+ import {
25
+ listProjectSourceFiles,
26
+ SOURCE_FILE_LIMIT,
27
+ } from '../fs/project-source-files.mjs';
28
+ import {compilerOptionsFor, projectMapsImport} from '../render/ts-paths.mjs';
29
+ import {nameWords, orderByAffinity} from '../text/suggest-order.mjs';
30
+ import {compareText} from '../text/compare-text.mjs';
31
+ import {
32
+ resolveProjectTypeScript,
33
+ TYPESCRIPT_FIX,
34
+ unusableTypeScriptReason,
35
+ } from './project-typescript.mjs';
36
+
37
+ /** What to do when Core's types cannot be read without Core installed. */
38
+ const CORE_FIX =
39
+ 'Install `@astryxdesign/core` in the project that holds the pages.';
40
+
41
+ /**
42
+ * The project's own TypeScript, found from the first of `dirs` that has one,
43
+ * or why the props cannot be checked without it and what to install. Doctor
44
+ * and the export say the same thing.
45
+ * @param {string[]} dirs
46
+ * @returns {{ts: any} | {skipped: string, reason: string}} `reason` is the
47
+ * same reason worded for a folder outside a project, with no install step
48
+ */
49
+ export function projectTypeScript(dirs) {
50
+ const compiler = resolveProjectTypeScript(dirs);
51
+ if (compiler === null) {
52
+ return {
53
+ skipped: `TypeScript is not installed in this project, so the props were not checked. ${TYPESCRIPT_FIX}`,
54
+ reason:
55
+ 'TypeScript is not installed here, so the props were not checked.',
56
+ };
57
+ }
58
+ if (compiler.ts === null)
59
+ return {
60
+ skipped: unusableTypeScriptReason(
61
+ compiler.version,
62
+ 'the props were not checked',
63
+ ),
64
+ reason: unusableTypeScriptReason(
65
+ compiler.version,
66
+ 'the props were not checked',
67
+ {here: true},
68
+ ),
69
+ };
70
+ return {ts: compiler.ts};
71
+ }
72
+
73
+ /**
74
+ * A TypeScript module that may widen what JSX gives every component: one
75
+ * that augments React or the global scope (where `JSX` lives), or that loads
76
+ * a library's `css` prop types.
77
+ */
78
+ const JSX_DECLARATION =
79
+ /\bdeclare\s+(?:module\s+['"]react(?:\/jsx-runtime)?['"]|global\b)|\bnamespace\s+JSX\b|styled-components\/cssprop|@emotion\/react\/types\/css-prop/;
80
+
81
+ /**
82
+ * The JSX runtime other than React's that compiler options name: a
83
+ * `jsxImportSource` other than `react`, or a `jsxFactory` other than
84
+ * `React.createElement`. Null for React's.
85
+ * @param {Record<string, unknown>} options
86
+ * @returns {string | null}
87
+ */
88
+ function otherJsxRuntime(options) {
89
+ const {jsxImportSource: source, jsxFactory: factory} = options;
90
+ if (typeof source === 'string' && source !== 'react') return source;
91
+ if (typeof factory === 'string' && factory !== 'React.createElement')
92
+ return factory;
93
+ return null;
94
+ }
95
+
96
+ /**
97
+ * A build config, by file name, that can set how JSX compiles: Babel, SWC,
98
+ * Vite, Vitest, esbuild, webpack, Rspack, Rsbuild, Next.js or tsup.
99
+ */
100
+ const BUILD_CONFIG =
101
+ /^(?:\.babelrc(?:\.[cm]?js|\.json)?|babel\.config\.(?:[cm]?[jt]s|json)|\.swcrc|(?:vite|vitest|webpack|rspack|rsbuild|next|esbuild|tsup)\.config\.[cm]?[jt]s)$/;
102
+
103
+ /**
104
+ * A build setting that compiles JSX other than as React does: a runtime
105
+ * (`jsxImportSource`, `importSource`) other than `react`; a classic factory
106
+ * (`jsxFactory`, `pragma`, a name such as `jsx` or `h`) other than
107
+ * `React.createElement`; or Next.js's `styledComponents` compiler option,
108
+ * which compiles a `css` prop, when it is not `false`.
109
+ */
110
+ const BUILD_JSX_RUNTIME =
111
+ /\b(?:jsxImportSource|importSource)['"]?\s*[:=]\s*['"](?!react['"])[^'"\s]+['"]|\b(?:jsxFactory|pragma)['"]?\s*[:=]\s*['"](?!React\.createElement['"])[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*['"]|\bstyledComponents['"]?\s*:(?!\s*false\b)/;
112
+
113
+ /**
114
+ * The packages that compile a `css` prop at build time, whatever name the
115
+ * build config gives them (Babel reads `styled-components` as
116
+ * `babel-plugin-styled-components`): a config can use one only when the
117
+ * project depends on it, or when it is installed through another package
118
+ * (`gatsby-plugin-emotion` brings emotion's preset).
119
+ */
120
+ const CSS_PROP_TRANSFORMS = new Set([
121
+ '@emotion/babel-preset-css-prop',
122
+ 'gatsby-plugin-emotion',
123
+ 'babel-plugin-styled-components',
124
+ '@swc/plugin-styled-components',
125
+ '@compiled/babel-plugin',
126
+ '@compiled/webpack-loader',
127
+ '@compiled/vite-plugin',
128
+ '@compiled/parcel-config',
129
+ '@compiled/parcel-transformer',
130
+ ]);
131
+
132
+ /**
133
+ * What compiles the JSX of a page other than as React does, in the folder of
134
+ * the page or a folder above it, up to the project's workspace root (as
135
+ * `findWorkspaceRoot` reads it): a build config
136
+ * that sets another runtime or factory (a config file, or the `babel` key of
137
+ * a `package.json`), a `package.json` that depends on a transform that
138
+ * compiles a `css` prop, or such a transform installed where the project
139
+ * finds packages. Null when nothing does.
140
+ * @param {string[]} pages
141
+ * @param {string} projectDir
142
+ * @returns {{file: string, transform: string | null, installed?: boolean} | null}
143
+ * the config, and the transform it depends on or has installed
144
+ */
145
+ function buildJsxRuntime(pages, projectDir) {
146
+ const top = findWorkspaceRoot(projectDir);
147
+ /** @type {Map<string, {file: string, transform: string | null, installed?: boolean} | null>} */
148
+ const configIn = new Map();
149
+ const read = (/** @type {string} */ dir) => {
150
+ /** @type {string[]} */
151
+ let names;
152
+ try {
153
+ names = fs.readdirSync(dir).sort();
154
+ } catch {
155
+ return null;
156
+ }
157
+ for (const name of names) {
158
+ const file = path.join(dir, name);
159
+ /** @type {string | null} */
160
+ let text = null;
161
+ try {
162
+ if (BUILD_CONFIG.test(name)) text = fs.readFileSync(file, 'utf-8');
163
+ else if (name === 'package.json') {
164
+ const manifest = JSON.parse(fs.readFileSync(file, 'utf-8'));
165
+ for (const field of [
166
+ 'dependencies',
167
+ 'devDependencies',
168
+ 'peerDependencies',
169
+ 'optionalDependencies',
170
+ ]) {
171
+ const transform = Object.keys(manifest?.[field] ?? {}).find(
172
+ dependency => CSS_PROP_TRANSFORMS.has(dependency),
173
+ );
174
+ if (transform) return {file, transform};
175
+ }
176
+ text =
177
+ manifest?.babel == null ? null : JSON.stringify(manifest.babel);
178
+ }
179
+ } catch {
180
+ continue;
181
+ }
182
+ if (text != null && BUILD_JSX_RUNTIME.test(text))
183
+ return {file, transform: null};
184
+ }
185
+ return null;
186
+ };
187
+ for (const page of pages) {
188
+ for (let dir = path.dirname(page); ; dir = path.dirname(dir)) {
189
+ if (!configIn.has(dir)) configIn.set(dir, read(dir));
190
+ const found = configIn.get(dir);
191
+ if (found) return found;
192
+ if (
193
+ dir === top ||
194
+ path.relative(top, dir).startsWith('..') ||
195
+ dir === path.dirname(dir)
196
+ )
197
+ break;
198
+ }
199
+ }
200
+ // A transform installed where a page finds packages: the project's own
201
+ // folders, or a workspace member's.
202
+ const pageDirs = [
203
+ ...new Set([projectDir, ...pages.map(page => path.dirname(page))]),
204
+ ];
205
+ for (const transform of [...CSS_PROP_TRANSFORMS].sort()) {
206
+ for (const dir of pageDirs) {
207
+ const installed = findInstalledPackage(dir, transform, Infinity);
208
+ if (installed) return {file: installed, transform, installed: true};
209
+ }
210
+ }
211
+ return null;
212
+ }
213
+
214
+ /**
215
+ * The configs TypeScript reads for the pages; pages that share a config
216
+ * share one read.
217
+ * @param {string[]} pages
218
+ */
219
+ function readConfigs(pages) {
220
+ /** @type {Map<string, {file: string, options: Record<string, unknown>}>} */
221
+ const configs = new Map();
222
+ /** @type {Map<string, string>} */
223
+ const configOf = new Map();
224
+ for (const file of pages) {
225
+ const config = compilerOptionsFor(file) ?? {file: '', options: {}};
226
+ configs.set(config.file, config);
227
+ configOf.set(file, config.file);
228
+ }
229
+ return {configs, configOf};
230
+ }
231
+
232
+ /**
233
+ * The configs TypeScript reads for the pages, or why their props are not
234
+ * judged: a config or build that compiles JSX with another runtime, or a
235
+ * `css` prop, can give every component props of its own.
236
+ * @param {string[]} pages every page that imports Core
237
+ * @param {string} projectDir
238
+ * @returns {ReturnType<typeof readConfigs> | {skipped: string}}
239
+ */
240
+ function jsxRuntimeCheck(pages, projectDir) {
241
+ const read = readConfigs(pages);
242
+ for (const {options} of read.configs.values()) {
243
+ const runtime = otherJsxRuntime(options);
244
+ if (runtime)
245
+ return {
246
+ skipped: `the project compiles JSX with \`${runtime}\`, which can give every component props of its own`,
247
+ };
248
+ }
249
+ const build = buildJsxRuntime(pages, projectDir);
250
+ if (build?.transform) {
251
+ return {
252
+ skipped: `${build.installed ? `\`${build.transform}\` is installed` : `the project depends on \`${build.transform}\``}, which compiles a \`css\` prop that every component can take`,
253
+ };
254
+ }
255
+ if (build) {
256
+ const shown = path
257
+ .relative(projectDir, build.file)
258
+ .split(path.sep)
259
+ .join('/');
260
+ return {
261
+ skipped: `the build config \`${shown}\` sets another JSX runtime or compiles a \`css\` prop, which can give every component props of its own`,
262
+ };
263
+ }
264
+ return read;
265
+ }
266
+
267
+ /**
268
+ * For each component that Core's docs describe, its documented props as
269
+ * `astryx component <Name> --props` prints them, read in batches from the
270
+ * Core of the folder `cwd`. Doctor and the export read the docs through this
271
+ * one reader.
272
+ * @param {(names: string[], options: {cwd: string, package: string, props: boolean}) => Promise<unknown>} answer
273
+ * the component read (`component` of api/component), which this layer
274
+ * cannot import
275
+ * @param {string[]} names
276
+ * @param {string} cwd
277
+ * @param {number} batchLimit the most components one read takes
278
+ * @returns {Promise<Map<string, any[]>>}
279
+ */
280
+ export async function readCoreDocs(answer, names, cwd, batchLimit) {
281
+ /** @type {Map<string, any[]>} */
282
+ const documented = new Map();
283
+ for (let start = 0; start < names.length; start += batchLimit) {
284
+ const batch = names.slice(start, start + batchLimit);
285
+ const read = /** @type {any} */ (
286
+ await answer(batch, {cwd, package: '@astryxdesign/core', props: true})
287
+ );
288
+ for (const each of read?.data?.results ?? []) {
289
+ const props = each?.status === 'found' ? each.result?.data : null;
290
+ if (Array.isArray(props)) documented.set(each.selector, props);
291
+ }
292
+ }
293
+ return documented;
294
+ }
295
+
296
+ /**
297
+ * The names of a component's documented props, as `readCoreDocs` gives them.
298
+ * @param {any[]} props
299
+ * @returns {string[]}
300
+ */
301
+ export function propNamesOf(props) {
302
+ return props.map(prop => prop?.name).filter(Boolean);
303
+ }
304
+
305
+ /**
306
+ * @typedef {import('./core-props.mjs').CorePropUse & {file: string, path: string}} PageCorePropUse
307
+ * a prop a page gives a Core component, with the page as the caller shows
308
+ * it (`file`) and its absolute path
309
+ */
310
+
311
+ /**
312
+ * @typedef {object} UnknownCoreProp
313
+ * @property {string} file as the caller shows it
314
+ * @property {number} line
315
+ * @property {number} column
316
+ * @property {string} component
317
+ * @property {string} prop
318
+ * @property {string | null} suggestion a documented prop with the same
319
+ * words, when there is one
320
+ */
321
+
322
+ /**
323
+ * The files of a project that may widen what JSX gives every component (see
324
+ * `JSX_DECLARATION`); null when the project has more source files than the
325
+ * walk reads, since a declaration beyond them could add a prop to every
326
+ * component.
327
+ * @param {string} projectDir
328
+ * @returns {string[] | null}
329
+ */
330
+ function jsxDeclarationFiles(projectDir) {
331
+ const files = listProjectSourceFiles(projectDir, '');
332
+ if (files.length >= SOURCE_FILE_LIMIT) return null;
333
+ return files.filter(file => {
334
+ try {
335
+ return widensJsx(file, fs.readFileSync(file, 'utf-8'));
336
+ } catch {
337
+ return false;
338
+ }
339
+ });
340
+ }
341
+
342
+ /**
343
+ * Whether a TypeScript module may widen what JSX gives every component (see
344
+ * `JSX_DECLARATION`). Doctor, which reads each file once, asks it of every
345
+ * file it reads.
346
+ * @param {string} file
347
+ * @param {string} text
348
+ */
349
+ export function widensJsx(file, text) {
350
+ return /\.[cm]?tsx?$/.test(file) && JSX_DECLARATION.test(text);
351
+ }
352
+
353
+ /**
354
+ * The props pages give Core components that the component does not take. A
355
+ * prop is a candidate when Core's docs for the component (the props
356
+ * `astryx component <Name> --package @astryxdesign/core` lists) leave it out,
357
+ * and it is reported only when TypeScript, reading Core's own published types
358
+ * as the pages see them, says the component's props do not take it either;
359
+ * the project's own modules that widen React's JSX are read with Core's
360
+ * types. A prop name React's types give an HTML or SVG element is never
361
+ * reported, since a component may pass it on to the element it renders, and
362
+ * neither is a prop JSX gives every component. A component with no docs, one
363
+ * TypeScript cannot read, a generic one, and a page whose config or build
364
+ * compiles JSX with another runtime or a `css` prop are not judged. Each page
365
+ * is judged with the config TypeScript reads for it. Only the docs are read
366
+ * while every prop is documented: TypeScript, configs and the project's
367
+ * files are read for candidates alone. `skipped` says why the candidates
368
+ * were not judged.
369
+ * @param {object} input
370
+ * @param {string} input.projectDir the folder of the pages' project
371
+ * @param {PageCorePropUse[]} input.uses
372
+ * @param {string[]} input.pages every page that imports Core, the pages of
373
+ * `uses` among them
374
+ * @param {(names: string[], cwd: string) => Promise<Map<string, any[]>>} input.readDocs
375
+ * for each component the docs describe, its documented props (`readCoreDocs`),
376
+ * read from the Core of the folder `cwd`
377
+ * @param {() => {ts: any} | {skipped: string, reason?: string}} input.typescript
378
+ * the compiler to read Core's types with, or why there is none (`reason`
379
+ * worded for a folder outside a project)
380
+ * @param {() => string[] | null} [input.jsxDeclarations] the files that may
381
+ * widen what JSX gives every component (`jsxDeclarationFiles` by default)
382
+ * @param {boolean} [input.runtimeFirst] doctor's order: report pages that
383
+ * find no installed Core, and a project on another JSX runtime
384
+ * (`jsxRuntimeCheck`), before the docs, whatever the props are. By default
385
+ * both are reported for candidates alone, and a page that finds no
386
+ * installed Core still reads the docs of the Core it renders with
387
+ * @returns {Promise<{found: UnknownCoreProp[], skipped: string | null, reason?: string}>}
388
+ * `skipped` ends with what to install when an install fixes it; `reason`,
389
+ * when given, is the same reason without that step, for a folder outside
390
+ * a project, where a project install step does not apply
391
+ */
392
+ export async function judgeCoreProps({
393
+ projectDir,
394
+ uses,
395
+ pages,
396
+ readDocs,
397
+ typescript,
398
+ jsxDeclarations,
399
+ runtimeFirst = false,
400
+ }) {
401
+ const notChecked = (/** @type {string} */ reason, fix = '') => ({
402
+ found: [],
403
+ skipped: `${reason}, so the props were not checked.${fix ? ` ${fix}` : ''}`,
404
+ reason: `${reason}, so the props were not checked.`,
405
+ });
406
+ // Each page is read as TypeScript reads it, with Core and React found from
407
+ // the page's own folder.
408
+ /** @type {Map<string, string | null>} */
409
+ const coreFrom = new Map();
410
+ const coreDirFrom = (/** @type {string} */ dir) => {
411
+ if (!coreFrom.has(dir)) {
412
+ const found = findInstalledPackage(dir, '@astryxdesign/core', Infinity);
413
+ let real = found;
414
+ try {
415
+ real = found ? fs.realpathSync(found) : null;
416
+ } catch {
417
+ // A Core folder that does not resolve is read where it is found.
418
+ }
419
+ coreFrom.set(dir, real);
420
+ }
421
+ return coreFrom.get(dir) ?? null;
422
+ };
423
+ // Pages that import Core and find no installed Core have no types to
424
+ // read. Doctor says so whatever the pages hold; the export says so only
425
+ // for props the docs leave out.
426
+ const noCore = () =>
427
+ notChecked(
428
+ 'Core is not installed where the pages that import it can find it',
429
+ CORE_FIX,
430
+ );
431
+ if (
432
+ runtimeFirst &&
433
+ pages.length > 0 &&
434
+ pages.every(page => !coreDirFrom(path.dirname(page)))
435
+ ) {
436
+ return noCore();
437
+ }
438
+ const early = runtimeFirst ? jsxRuntimeCheck(pages, projectDir) : null;
439
+ if (early && 'skipped' in early) return notChecked(early.skipped);
440
+ // Batched reads of the props the docs of each Core list, as
441
+ // `astryx component <Name> --props` prints them; a component they do not
442
+ // describe is not judged.
443
+ /** @type {Map<string, {from: string, uses: PageCorePropUse[]}>} */
444
+ const byCore = new Map();
445
+ for (const use of uses) {
446
+ const from = path.dirname(use.path);
447
+ const coreDir = coreDirFrom(from);
448
+ if (!coreDir && runtimeFirst) continue;
449
+ // A page without installed Core reads the docs of the Core it renders
450
+ // with, found from its folder.
451
+ const key = coreDir ?? '';
452
+ const group =
453
+ byCore.get(key) ??
454
+ /** @type {any} */ (byCore.set(key, {from, uses: []}).get(key));
455
+ group.uses.push(use);
456
+ }
457
+ /** @type {Map<string, Map<string, string[]>>} */
458
+ const documentedBy = new Map();
459
+ /** @type {PageCorePropUse[]} */
460
+ const candidates = [];
461
+ for (const [coreDir, group] of byCore) {
462
+ const documented = await readDocs(
463
+ [...new Set(group.uses.map(use => use.component))],
464
+ group.from,
465
+ );
466
+ documentedBy.set(
467
+ coreDir,
468
+ new Map(
469
+ [...documented].map(([name, props]) => [name, propNamesOf(props)]),
470
+ ),
471
+ );
472
+ for (const use of group.uses) {
473
+ const props = documentedBy.get(coreDir)?.get(use.component);
474
+ if (props != null && !props.includes(use.prop)) candidates.push(use);
475
+ }
476
+ }
477
+ // A page whose config maps a Core module path elsewhere (`paths`) reads
478
+ // another module, so it is not judged.
479
+ let judged = candidates.filter(
480
+ use => !projectMapsImport(use.source, use.path),
481
+ );
482
+ if (judged.length === 0) return {found: [], skipped: null};
483
+ // A candidate in a file that finds no installed Core is not judged; the
484
+ // line says Core is missing only when no page finds it, as doctor says.
485
+ judged = judged.filter(use => coreDirFrom(path.dirname(use.path)));
486
+ if (judged.length === 0) {
487
+ return pages.some(page => coreDirFrom(path.dirname(page)))
488
+ ? {found: [], skipped: null}
489
+ : noCore();
490
+ }
491
+ const config = early ?? jsxRuntimeCheck(pages, projectDir);
492
+ if ('skipped' in config) return notChecked(config.skipped);
493
+ const {configs, configOf} = config;
494
+ const compiler = typescript();
495
+ if (!('ts' in compiler))
496
+ return {found: [], skipped: compiler.skipped, reason: compiler.reason};
497
+ const declarations = (
498
+ jsxDeclarations ?? (() => jsxDeclarationFiles(projectDir))
499
+ )();
500
+ if (declarations === null)
501
+ return notChecked('the project has more source files than are read');
502
+ /** @type {Map<string, {configFile: string, coreDir: string, from: string, uses: PageCorePropUse[]}>} */
503
+ const groups = new Map();
504
+ for (const use of judged) {
505
+ const from = path.dirname(use.path);
506
+ const coreDir = /** @type {string} */ (coreDirFrom(from));
507
+ const configFile = configOf.get(use.path) ?? '';
508
+ const key = `${configFile}\0${coreDir}`;
509
+ const group =
510
+ groups.get(key) ??
511
+ /** @type {any} */ (
512
+ groups.set(key, {configFile, coreDir, from, uses: []}).get(key)
513
+ );
514
+ group.uses.push(use);
515
+ }
516
+ // Core's types are read for candidates alone.
517
+ const {readCorePropTypes} = await import('./core-prop-types.mjs');
518
+ /** @type {UnknownCoreProp[]} */
519
+ const found = [];
520
+ for (const group of groups.values()) {
521
+ const documented = documentedBy.get(group.coreDir) ?? new Map();
522
+ // What augments Core for a page: the project's files and installed
523
+ // packages, and those of the page's own package, as a workspace member
524
+ // installs its own.
525
+ const memberDir = findPackageRoot(group.from) ?? projectDir;
526
+ const reads = [projectAugmentations(projectDir, group.uses[0].path)];
527
+ if (memberDir !== projectDir)
528
+ reads.push(projectAugmentations(memberDir, group.uses[0].path));
529
+ if (reads.some(read => !read.complete))
530
+ return notChecked(
531
+ "the files that may add to Core's types could not all be read",
532
+ );
533
+ const augmentations = [...new Set(reads.flatMap(read => read.files))];
534
+ /** @type {Map<string, Set<string>>} */
535
+ const asked = new Map();
536
+ /** @type {Map<string, string>} */
537
+ const sources = new Map();
538
+ for (const use of group.uses) {
539
+ (
540
+ asked.get(use.component) ??
541
+ asked.set(use.component, new Set()).get(use.component)
542
+ )?.add(use.prop);
543
+ if (!sources.has(use.component)) sources.set(use.component, use.source);
544
+ }
545
+ const types = readCorePropTypes({
546
+ ts: compiler.ts,
547
+ projectDir: group.from,
548
+ configDir: group.configFile ? path.dirname(group.configFile) : group.from,
549
+ options: configs.get(group.configFile)?.options ?? {},
550
+ augmentations: [...augmentations, ...declarations],
551
+ props: asked,
552
+ sources,
553
+ configFile: group.configFile || undefined,
554
+ });
555
+ if (types.unread) return notChecked(types.unread, types.unreadFix);
556
+ for (const use of group.uses) {
557
+ if (
558
+ types.attributes.has(use.prop) ||
559
+ types.takes.get(use.component)?.get(use.prop) !== false
560
+ )
561
+ continue;
562
+ const {path: _file, source: _source, ...report} = use;
563
+ found.push({
564
+ ...report,
565
+ suggestion: closestProp(use.prop, documented.get(use.component) ?? []),
566
+ });
567
+ }
568
+ }
569
+ found.sort(
570
+ (a, b) =>
571
+ compareText(a.file, b.file) || a.line - b.line || a.column - b.column,
572
+ );
573
+ return {found, skipped: null};
574
+ }
575
+
576
+ /**
577
+ * The documented prop a name means, when one has the same words: in another
578
+ * order or case, with a plural `s`, or with the `is` or `has` that Core puts
579
+ * in front of a yes-or-no prop (`isLabelHidden` for `labelHidden`,
580
+ * `startIcon` for `iconStart`). Words are read as a failed lookup reads them.
581
+ * A name with another word, or a near spelling, can mean something else
582
+ * (`padding` for `paddingX`, `maxWidth` for `minWidth`), so it is not
583
+ * offered. Null when no prop has the same words.
584
+ * @param {string} name
585
+ * @param {string[]} props
586
+ * @returns {string | null}
587
+ */
588
+ function closestProp(name, props) {
589
+ const key = (/** @type {string} */ text) =>
590
+ nameWords(text)
591
+ .filter(word => word !== 'is' && word !== 'has')
592
+ .map(word => (word.length > 3 ? word.replace(/s$/, '') : word))
593
+ .sort()
594
+ .join(' ');
595
+ const wanted = key(name);
596
+ return (
597
+ orderByAffinity(name, props, prop => [prop]).find(
598
+ prop => prop !== name && key(prop) === wanted,
599
+ ) ?? null
600
+ );
601
+ }
@@ -0,0 +1,35 @@
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
+ * @typedef {import('./core-augmentation-points.mjs').ValueKind} ValueKind
6
+ * @typedef {{kinds: ValueKind[], strings: string[] | null}} WrittenValue
7
+ */
8
+ /**
9
+ * What a JSX attribute certainly gives its prop. Every branch of the value
10
+ * must be certain: a literal (a string, a template, a number, a boolean, an
11
+ * object or array literal, `new Date(…)`, a function), a conditional or
12
+ * logical expression of certain branches, a `const` bound to one, or the
13
+ * first value of `useState(<certain value>)`, which is what the first paint
14
+ * gets. A bare attribute (`<Button isDisabled>`) is `true`. A branch that is
15
+ * `null` or `undefined` gives no value. `strings` lists the string values
16
+ * when every string branch is a literal, else null. Null when any branch is
17
+ * not certain: such a prop is not checked.
18
+ * @param {any} attr a JSXAttribute node
19
+ * @param {any} scope the element's Babel scope
20
+ * @returns {WrittenValue | null}
21
+ */
22
+ export function writtenValue(attr: any, scope: any): WrittenValue | null;
23
+ export type ValueKind = import("./core-augmentation-points.mjs").ValueKind;
24
+ export type WrittenValue = {
25
+ kinds: ValueKind[];
26
+ strings: string[] | null;
27
+ };
28
+ /**
29
+ * One value a branch can give. `nullish` is `null` or `undefined`, which
30
+ * gives the prop no value.
31
+ */
32
+ export type Leaf = {
33
+ kind: ValueKind | "nullish";
34
+ text?: string;
35
+ };