@astryxdesign/cli 0.7.15 → 0.7.16-canary.g22213fd

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 (222) hide show
  1. package/README.md +6 -4
  2. package/api/build/_adapter.d.mts +10 -0
  3. package/api/build/_adapter.mjs +24 -0
  4. package/api/build/blocks/blocks.d.mts +1 -0
  5. package/api/build/blocks/blocks.mjs +18 -1
  6. package/api/build/kit/shell.weights.json +1 -0
  7. package/api/build/kit/shellcall.d.mts +26 -0
  8. package/api/build/kit/shellcall.mjs +87 -0
  9. package/api/build/kit/start.mjs +67 -4
  10. package/api/build/kit/weights.d.mts +15 -0
  11. package/api/build/kit/weights.mjs +27 -0
  12. package/api/component/__fixtures__/resolutions/modules.txt +1 -1
  13. package/api/component/_adapter.d.mts +1 -1
  14. package/api/component/_adapter.mjs +28 -1
  15. package/api/doctor/_adapter.d.mts +38 -2
  16. package/api/doctor/_adapter.mjs +76 -1
  17. package/api/doctor/built-checks.mjs +1 -1
  18. package/api/doctor/doctor.d.mts +26 -0
  19. package/api/doctor/doctor.doc.mjs +1 -1
  20. package/api/doctor/doctor.mjs +156 -11
  21. package/api/doctor/theme-checks.mjs +163 -18
  22. package/api/icon/_adapter.d.mts +7 -3
  23. package/api/icon/_adapter.mjs +12 -3
  24. package/api/icon/icon.type.d.mts +15 -0
  25. package/api/icon/icon.type.mjs +10 -3
  26. package/api/icon/iconUse.doc.mjs +19 -5
  27. package/api/icon/list/list.mjs +7 -1
  28. package/api/icon/use/use.d.mts +8 -5
  29. package/api/icon/use/use.mjs +95 -13
  30. package/api/init/run/run.mjs +1 -0
  31. package/api/integration/add-contribution.mjs +3 -3
  32. package/api/integration/pack-check.mjs +14 -8
  33. package/api/integration/validate-integration.mjs +1 -1
  34. package/api/search/_adapter.mjs +15 -16
  35. package/api/search/_entries.d.mts +2 -1
  36. package/api/search/_entries.mjs +28 -1
  37. package/api/swizzle/_moduleGraph.mjs +1 -1
  38. package/api/template/template.type.d.mts +6 -2
  39. package/api/template/template.type.mjs +2 -1
  40. package/api/theme/_adapter.d.mts +5 -2
  41. package/api/theme/_adapter.mjs +59 -14
  42. package/api/theme/_fork.mjs +1 -1
  43. package/api/theme/build/build.d.mts +120 -32
  44. package/api/theme/build/build.mjs +471 -111
  45. package/api/theme/eject/eject.mjs +22 -1
  46. package/api/theme/generateTonalPalette.doc.mjs +2 -2
  47. package/api/theme/palette/generate/generator.mjs +141 -2
  48. package/api/theme/template/template.d.mts +19 -0
  49. package/api/theme/template/template.mjs +102 -25
  50. package/api/theme/theme.type.d.mts +44 -1
  51. package/api/theme/theme.type.mjs +23 -1
  52. package/api/theme/themeBuild.doc.mjs +4 -4
  53. package/api/theme/themeEject.doc.mjs +1 -1
  54. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  55. package/api/theme/themeTemplate.doc.mjs +9 -3
  56. package/api/theme-edit/_adapter.d.mts +33 -2
  57. package/api/theme-edit/_adapter.mjs +276 -41
  58. package/api/theme-edit/_check.d.mts +93 -4
  59. package/api/theme-edit/_check.mjs +1712 -223
  60. package/api/theme-edit/_color.d.mts +2 -8
  61. package/api/theme-edit/_color.mjs +292 -219
  62. package/api/theme-edit/_compiler.d.mts +1 -0
  63. package/api/theme-edit/_compiler.mjs +20 -1
  64. package/api/theme-edit/_context.d.mts +31 -1
  65. package/api/theme-edit/_context.mjs +445 -41
  66. package/api/theme-edit/_css.d.mts +60 -1
  67. package/api/theme-edit/_css.mjs +404 -28
  68. package/api/theme-edit/_edit.d.mts +25 -0
  69. package/api/theme-edit/_edit.mjs +1620 -154
  70. package/api/theme-edit/_how-commands.d.mts +11 -26
  71. package/api/theme-edit/_how-commands.mjs +30 -2
  72. package/api/theme-edit/_how-question.d.mts +15 -0
  73. package/api/theme-edit/_how-question.mjs +1469 -194
  74. package/api/theme-edit/_how.mjs +144 -30
  75. package/api/theme-edit/_marks.d.mts +13 -0
  76. package/api/theme-edit/_marks.mjs +15 -0
  77. package/api/theme-edit/_overview.mjs +2 -0
  78. package/api/theme-edit/_palette.d.mts +38 -0
  79. package/api/theme-edit/_palette.mjs +306 -73
  80. package/api/theme-edit/_parts.d.mts +33 -0
  81. package/api/theme-edit/_parts.mjs +138 -9
  82. package/api/theme-edit/_png.d.mts +18 -0
  83. package/api/theme-edit/_png.mjs +95 -14
  84. package/api/theme-edit/_preview-app.d.mts +55 -1
  85. package/api/theme-edit/_preview-app.mjs +1552 -101
  86. package/api/theme-edit/_preview.d.mts +71 -3
  87. package/api/theme-edit/_preview.mjs +565 -35
  88. package/api/theme-edit/_project.d.mts +15 -0
  89. package/api/theme-edit/_project.mjs +68 -13
  90. package/api/theme-edit/_settings.d.mts +299 -5
  91. package/api/theme-edit/_settings.mjs +2806 -158
  92. package/api/theme-edit/_tables.d.mts +24 -0
  93. package/api/theme-edit/_tables.mjs +212 -150
  94. package/api/theme-edit/_vet.d.mts +42 -0
  95. package/api/theme-edit/_vet.mjs +144 -0
  96. package/api/theme-edit/theme-edit.type.d.mts +31 -2
  97. package/api/theme-edit/theme-edit.type.mjs +10 -2
  98. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  99. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  100. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  101. package/api/upgrade/registry/registry.mjs +6 -1
  102. package/assets/codemods/parse.mjs +2 -2
  103. package/assets/docs/author-a-theme.doc.mjs +1 -1
  104. package/assets/docs/theme.doc.dense.mjs +1 -1
  105. package/assets/docs/theme.doc.mjs +1 -1
  106. package/assets/docs/theme.doc.zh.mjs +4 -3
  107. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  108. package/assets/docs/tree/icon-sets.doc.mjs +63 -8
  109. package/assets/docs/tree/single-component.doc.mjs +11 -2
  110. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  111. package/assets/docs.generated.json +2 -2
  112. package/assets/preview-app/next.config.mjs +7 -1
  113. package/assets/preview-app/package.json +1 -0
  114. package/assets/preview-app/src/app/globals.css +1 -0
  115. package/assets/self-audit.generated.json +1 -1
  116. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
  117. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
  118. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  119. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  120. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  121. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  122. package/assets/templates/components.generated.json +1 -1
  123. package/assets/templates/pages/ai-chat/page.tsx +20 -2
  124. package/assets/templates/pages/dashboard/page.tsx +1 -1
  125. package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
  126. package/authoring/config/config.doc.mjs +8 -0
  127. package/authoring/config/parse.d.mts +1 -0
  128. package/authoring/config/parse.mjs +12 -0
  129. package/authoring/config/type.ts +8 -0
  130. package/authoring/doctypes/_schema.d.mts +52 -5
  131. package/authoring/doctypes/_schema.mjs +62 -7
  132. package/authoring/doctypes/base/type.ts +10 -0
  133. package/authoring/doctypes/component/component.doc.mjs +1 -1
  134. package/authoring/doctypes/function/function.doc.mjs +6 -0
  135. package/authoring/doctypes/function/type.ts +3 -0
  136. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
  137. package/authoring/doctypes/legacy.mjs +5 -1
  138. package/authoring/index.d.ts +1 -0
  139. package/authoring/shadcn/source-variants.d.mts +1 -1
  140. package/authoring/shadcn/source-variants.mjs +32 -10
  141. package/clients/cli/build-id.generated.json +1 -1
  142. package/clients/cli/commands/doctor.doc.mjs +2 -2
  143. package/clients/cli/commands/experimental/icon.mjs +61 -6
  144. package/clients/cli/commands/experimental/theme.mjs +244 -45
  145. package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
  146. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  147. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  148. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  149. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  150. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  151. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  152. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  153. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  154. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  155. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  156. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  157. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  158. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  159. package/clients/cli/commands/theme.doc.mjs +7 -2
  160. package/clients/cli/commands/theme.mjs +222 -55
  161. package/clients/cli/commands.generated.json +1 -1
  162. package/clients/cli/formatters/index.mjs +7 -4
  163. package/clients/cli/index.mjs +25 -5
  164. package/clients/cli/lib/cli-error.mjs +9 -3
  165. package/clients/cli/lib/component-format.mjs +27 -9
  166. package/clients/cli/lib/json-shim.mjs +72 -2
  167. package/clients/cli/manifest.generated.json +1 -1
  168. package/clients/cli/run.mjs +49 -0
  169. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  170. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  171. package/foundation/agent-docs/agent-docs.mjs +4 -3
  172. package/foundation/config/config-writer.d.mts +23 -0
  173. package/foundation/config/config-writer.mjs +152 -58
  174. package/foundation/config/project.mjs +103 -16
  175. package/foundation/discovery/component-discovery.mjs +11 -22
  176. package/foundation/discovery/icon-set-checks.mjs +164 -48
  177. package/foundation/discovery/icon-set-discovery.d.mts +38 -5
  178. package/foundation/discovery/icon-set-discovery.mjs +50 -6
  179. package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
  180. package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
  181. package/foundation/discovery/icon-set-writer.d.mts +2 -3
  182. package/foundation/discovery/icon-set-writer.mjs +58 -17
  183. package/foundation/discovery/module-exports.mjs +1 -15
  184. package/foundation/discovery/template-adapter.mjs +44 -19
  185. package/foundation/discovery/template-icons.d.mts +27 -10
  186. package/foundation/discovery/template-icons.mjs +142 -26
  187. package/foundation/discovery/template-source-tree.mjs +3 -16
  188. package/foundation/discovery/theme-discovery.d.mts +30 -1
  189. package/foundation/discovery/theme-discovery.mjs +109 -50
  190. package/foundation/fs/exact-codec.d.mts +35 -0
  191. package/foundation/fs/exact-codec.mjs +148 -0
  192. package/foundation/fs/gather-cache.d.mts +15 -5
  193. package/foundation/fs/gather-cache.mjs +129 -31
  194. package/foundation/fs/paths.d.mts +39 -0
  195. package/foundation/fs/paths.mjs +44 -11
  196. package/foundation/fs/read-record.mjs +11 -1
  197. package/foundation/integrations/autolink.d.mts +4 -2
  198. package/foundation/integrations/autolink.mjs +4 -2
  199. package/foundation/integrations/cli-requirement.d.mts +16 -5
  200. package/foundation/integrations/cli-requirement.mjs +27 -6
  201. package/foundation/integrations/contribution-fixes.mjs +1 -16
  202. package/foundation/integrations/may-have-integrations.mjs +7 -3
  203. package/foundation/integrations/missing-dependency.d.mts +9 -0
  204. package/foundation/integrations/missing-dependency.mjs +100 -0
  205. package/foundation/integrations/public-imports.mjs +1 -1
  206. package/foundation/render/embedded-imports.mjs +1 -1
  207. package/foundation/render/host-exit.d.mts +8 -0
  208. package/foundation/render/host-exit.mjs +11 -0
  209. package/foundation/render/page-host.mjs +56 -10
  210. package/foundation/render/page-worker.mjs +14 -0
  211. package/foundation/render/render-page.mjs +37 -2
  212. package/foundation/response/error-codes.d.mts +2 -1
  213. package/foundation/response/error-codes.d.ts +1 -0
  214. package/foundation/response/error-codes.doc.mjs +5 -0
  215. package/foundation/response/error-codes.mjs +3 -0
  216. package/foundation/response/json.d.mts +15 -0
  217. package/foundation/response/json.mjs +52 -1
  218. package/foundation/response/response-types.doc.mjs +1 -1
  219. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  220. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  221. package/foundation/xle/browser.d.mts +2 -2
  222. package/package.json +7 -6
@@ -28,6 +28,55 @@
28
28
  * when, in a hosted run, that release's host entry answered
29
29
  */
30
30
  export async function runCli({cliRoot, argv, declinedProjectCli}) {
31
+ // A folder deleted under the shell (another terminal, `git clean`): every
32
+ // command reads the working folder first, so say so once, plainly, in
33
+ // text and in --json, instead of a stack trace.
34
+ try {
35
+ process.cwd();
36
+ } catch (e) {
37
+ if (/** @type {any} */ (e)?.code !== 'ENOENT') throw e;
38
+ const fs = await import('node:fs');
39
+ const path = await import('node:path');
40
+ const os = await import('node:os');
41
+ let up = process.env.PWD ? path.dirname(process.env.PWD) : null;
42
+ while (up && !fs.existsSync(up) && path.dirname(up) !== up)
43
+ up = path.dirname(up);
44
+ const cd = up && fs.existsSync(up) ? up : '~';
45
+ // Help, the version and docs read no folder: run them from an existing
46
+ // one.
47
+ const first = argv.find(a => !a.startsWith('-'));
48
+ if (
49
+ argv.length === 0 ||
50
+ argv.some(a => ['--help', '-h', '--version', '-V'].includes(a)) ||
51
+ first === 'docs' ||
52
+ first === 'help'
53
+ ) {
54
+ process.chdir(cd === '~' ? os.homedir() : cd);
55
+ return runCli({cliRoot, argv, declinedProjectCli});
56
+ }
57
+ const message =
58
+ 'The current folder no longer exists (it was deleted or moved). Nothing was written. cd to an existing folder and run the command again.';
59
+ const {quoteCommandArgument} =
60
+ await import('../../foundation/env/package-manager.mjs');
61
+ const suggestions = [
62
+ {
63
+ name: `cd ${cd === '~' ? cd : quoteCommandArgument(cd)}`,
64
+ reason: 'an existing folder',
65
+ },
66
+ ];
67
+ if (argv.includes('--json')) {
68
+ const {toErrorEnvelope} =
69
+ await import('../../foundation/response/json.mjs');
70
+ fs.writeSync(
71
+ 1,
72
+ `${JSON.stringify(toErrorEnvelope(message, suggestions, 'ERR_PROJECT_REQUIRED'), null, 2)}\n`,
73
+ );
74
+ } else {
75
+ fs.writeSync(2, `Error: ${message}\n ${suggestions[0].name}\n`);
76
+ }
77
+ process.exitCode = 1;
78
+ return undefined;
79
+ }
31
80
  const {startRun} = await import('../../foundation/release/handoff.mjs');
32
81
  const answered = await startRun({cliRoot, argv, declinedProjectCli});
33
82
  if (answered) return answered;
@@ -1,12 +1,6 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
- /**
5
- * `p` resolved, through symlinks when it exists.
6
- * @param {string} p
7
- * @returns {string}
8
- */
9
- export function realDir(p: string): string;
10
4
  /**
11
5
  * Throw {@link AgentDocsHomeError} when `targetDir` is the home folder, or a
12
6
  * settings folder in it outside a project.
@@ -32,6 +26,7 @@ export function resolveAgentDocsRoot(cwd: string): string | null;
32
26
  * @returns {string}
33
27
  */
34
28
  export function agentDocsTargetDir(cwd: string): string;
29
+ export { realDir };
35
30
  /**
36
31
  * Thrown when agent docs would be written into the home folder, or into a
37
32
  * settings folder in it such as `~/.gemini` outside a project. Agents read the
@@ -47,3 +42,4 @@ export class AgentDocsHomeError extends Error {
47
42
  }
48
43
  /** Folders that mark a repository root; the project search stops there. */
49
44
  export const REPOSITORY_MARKERS: string[];
45
+ import { realDir } from '../fs/paths.mjs';
@@ -5,15 +5,20 @@
5
5
  * @input The folder a run starts in, the home folder, and the package.json
6
6
  * files and repository markers above the folder
7
7
  * @output AgentDocsHomeError, assertAgentDocsTarget, resolveAgentDocsRoot and
8
- * agentDocsTargetDir, with the realDir and REPOSITORY_MARKERS helpers
9
- * @position The folder agent docs go to. It imports node builtins only, so the
10
- * per-command setup nudge (clients/cli/index.mjs) loads it without
11
- * agent-docs.mjs's discovery and config. agent-docs.mjs re-exports it.
8
+ * agentDocsTargetDir, with the REPOSITORY_MARKERS helper (and realDir,
9
+ * re-exported from ../fs/paths.mjs)
10
+ * @position The folder agent docs go to. It imports node builtins and the
11
+ * CLI's paths module only, so the per-command setup nudge
12
+ * (clients/cli/index.mjs) loads it without agent-docs.mjs's discovery and
13
+ * config. agent-docs.mjs re-exports it.
12
14
  */
13
15
 
14
16
  import * as fs from 'node:fs';
15
17
  import * as os from 'node:os';
16
18
  import * as path from 'node:path';
19
+ import {realDir} from '../fs/paths.mjs';
20
+
21
+ export {realDir};
17
22
 
18
23
  /**
19
24
  * Thrown when agent docs would be written into the home folder, or into a
@@ -34,19 +39,6 @@ export class AgentDocsHomeError extends Error {
34
39
  }
35
40
  }
36
41
 
37
- /**
38
- * `p` resolved, through symlinks when it exists.
39
- * @param {string} p
40
- * @returns {string}
41
- */
42
- export function realDir(p) {
43
- try {
44
- return fs.realpathSync(path.resolve(p));
45
- } catch {
46
- return path.resolve(p);
47
- }
48
- }
49
-
50
42
  /**
51
43
  * `dir` relative to the home folder, compared without symlinks (and without
52
44
  * case on Windows). null when there is no home folder.
@@ -83,8 +83,9 @@ import {
83
83
  export {discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach};
84
84
 
85
85
  // The folder the docs go to lives in ./agent-docs-target.mjs, with node
86
- // builtins only. So the per-command setup nudge loads it without this
87
- // module's discovery and config. Re-exported here for existing importers.
86
+ // builtins and the CLI's paths module only. So the per-command setup nudge
87
+ // loads it without this module's discovery and config. Re-exported here for
88
+ // existing importers.
88
89
  export {
89
90
  AgentDocsHomeError,
90
91
  agentDocsTargetDir,
@@ -672,7 +673,7 @@ export function generateCompressedIndex(
672
673
  } else {
673
674
  lines.push("- Style with component props first, then tokens (var(--color-*|--spacing-*|--radius-*)). No raw hex/px. No StyleX/Tailwind compiler here — don't use xstyle/utility classes directly. Some templates use StyleX and need a compiler plugin; see `astryx docs styling-overview`.");
674
675
  }
675
- lines.push('- Palettes and custom colors go through the theme, never :root overrides. Run `astryx theme add <slug>` to import; `theme eject <slug>` only forks source. See `astryx docs theme`.');
676
+ lines.push('- THEMES: palettes and custom colors go through the theme, never :root overrides. To make or change a theme (colors, fonts, corners, spacing, a look from a picture), prefer the experimental theme editor over hand-written theme files: `astryx experimental theme editor new <name> --like neutral`, then `editor set <name> <thing> <value>` or `editor how "<what you want>"`; wire it with `astryx theme add <name>`; after each change look at it with `astryx experimental theme editor show <name> --png` and open the PNGs it writes (changes nothing in the app); a theme change is not done until you have looked at the pictures. In code, extend an imported theme to customize it; `theme eject <slug>` only forks source. See `astryx docs theme`.');
676
677
  // Self-check — post-generation pass. Validated via vibe tests (internal/vibe-tests/
677
678
  // prompt-purity-test): on complex multi-step UIs the rules above alone still leave raw
678
679
  // CSS in ~11-13% of runs; a re-read-and-fix pass cuts that ~4x at negligible token cost.
@@ -28,6 +28,24 @@ export function setConfigValue(projectDir: string, key: string, value: string |
28
28
  previous: string | string[] | null;
29
29
  changed: boolean;
30
30
  };
31
+ /**
32
+ * Set several fields of the project's astryx.config in one write. Each value
33
+ * is a string, a list of strings, or `null`, which removes the field; a
34
+ * field the config does not set needs no removal. Either every field is
35
+ * written or, when one cannot be, none is.
36
+ * @param {string} projectDir
37
+ * @param {ReadonlyArray<readonly [string, string | readonly string[] | null]>} fields
38
+ * each a top-level key or a dotted path (`experimental.iconSet`), and its
39
+ * value
40
+ * @returns {{file: string, created: boolean, previous: Array<string | string[] | null>, changed: boolean}}
41
+ * `previous`: each field's value before the write, in the order given
42
+ */
43
+ export function setConfigValues(projectDir: string, fields: ReadonlyArray<readonly [string, string | readonly string[] | null]>): {
44
+ file: string;
45
+ created: boolean;
46
+ previous: Array<string | string[] | null>;
47
+ changed: boolean;
48
+ };
31
49
  /** A protected astryx.config the writer refused to touch. */
32
50
  export class ConfigProtectedError extends Error {
33
51
  /**
@@ -39,3 +57,8 @@ export class ConfigProtectedError extends Error {
39
57
  file: string;
40
58
  protections: import("../fs/file-protection.mjs").FileProtection[];
41
59
  }
60
+ /**
61
+ * The nested objects of a new config: each key's value, or the object a
62
+ * dotted path opens.
63
+ */
64
+ export type ConfigTree = Map<string, string | readonly string[] | ConfigTree>;
@@ -1,10 +1,10 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Write one string field, or one list of strings, in a project's
5
- * astryx.config.
4
+ * @file Write string fields, or lists of strings, in a project's
5
+ * astryx.config, or remove them, in one write.
6
6
  *
7
- * The field is a top-level key or a dotted path into nested object literals
7
+ * A field is a top-level key or a dotted path into nested object literals
8
8
  * (`experimental.iconSet`); a missing object on the path is created.
9
9
  *
10
10
  * Edits the default-exported object literal in place (comments and other
@@ -19,16 +19,16 @@
19
19
  * `ERR_CODEMOD_PROTECTED` naming the protecting declaration, and an unreadable
20
20
  * protection source fails with `ERR_CODEMOD_PROTECTION_SOURCE`.
21
21
  *
22
- * @input A project directory, a field name, and its value: a string or a
23
- * list of strings
24
- * @output The config file written and the value it replaced
22
+ * @input A project directory and fields: each a name and its value, a string,
23
+ * a list of strings, or null to remove it
24
+ * @output The config file written and the values it replaced
25
25
  * @position packages/cli/foundation/config — read by `astryx experimental icon use`
26
26
  */
27
27
 
28
28
  import * as fs from 'node:fs';
29
29
  import * as path from 'node:path';
30
30
  import {randomUUID} from 'node:crypto';
31
- import jscodeshift from 'jscodeshift';
31
+ import {jscodeshift as loadJscodeshift} from '../runtime/lazy-dependencies.mjs';
32
32
  import {
33
33
  findManifestObject,
34
34
  unwrapManifestExpression,
@@ -154,40 +154,104 @@ export function setConfigString(projectDir, key, value) {
154
154
  * @returns {{file: string, created: boolean, previous: string | string[] | null, changed: boolean}}
155
155
  */
156
156
  export function setConfigValue(projectDir, key, value) {
157
- const keys = key.split('.');
158
- const leaf = /** @type {string} */ (keys[keys.length - 1]);
157
+ const result = setConfigValues(projectDir, [[key, value]]);
158
+ return {...result, previous: result.previous[0] ?? null};
159
+ }
160
+
161
+ /**
162
+ * The sentence that tells a person to make the edits by hand: `Set
163
+ * "experimental.iconSet: 'glyphs'"`, with each further edit after `and`.
164
+ * @param {ReadonlyArray<readonly [string, string | readonly string[] | null]>} fields
165
+ */
166
+ function byHand(fields) {
167
+ const edits = fields
168
+ .map(([key, value]) =>
169
+ value == null ? `remove "${key}"` : `set "${key}: ${written(value)}"`,
170
+ )
171
+ .join(' and ');
172
+ return edits[0].toUpperCase() + edits.slice(1);
173
+ }
174
+
175
+ /**
176
+ * The nested objects of a new config: each key's value, or the object a
177
+ * dotted path opens.
178
+ * @typedef {Map<string, string | readonly string[] | ConfigTree>} ConfigTree
179
+ */
180
+
181
+ /**
182
+ * The text of a new astryx.config.mjs that sets the fields: each key on a
183
+ * path opens one nested object (`experimental: {`), shared by the fields
184
+ * under it.
185
+ * @param {ReadonlyArray<readonly [string, string | readonly string[]]>} fields
186
+ */
187
+ function newConfigText(fields) {
188
+ /** @type {ConfigTree} */
189
+ const tree = new Map();
190
+ for (const [key, value] of fields) {
191
+ const keys = key.split('.');
192
+ let node = tree;
193
+ for (const each of keys.slice(0, -1)) {
194
+ let child = node.get(each);
195
+ if (!(child instanceof Map)) {
196
+ child = new Map();
197
+ node.set(each, child);
198
+ }
199
+ node = child;
200
+ }
201
+ node.set(/** @type {string} */ (keys[keys.length - 1]), value);
202
+ }
203
+ /** @param {ConfigTree} node @param {number} depth @returns {string} */
204
+ const render = (node, depth) =>
205
+ [...node]
206
+ .map(([name, value]) =>
207
+ value instanceof Map
208
+ ? `${' '.repeat(depth)}${name}: {\n${render(value, depth + 1)}${' '.repeat(depth)}},\n`
209
+ : `${' '.repeat(depth)}${name}: ${written(value)},\n`,
210
+ )
211
+ .join('');
212
+ return `export default {\n${render(tree, 1)}};\n`;
213
+ }
214
+
215
+ /**
216
+ * Set several fields of the project's astryx.config in one write. Each value
217
+ * is a string, a list of strings, or `null`, which removes the field; a
218
+ * field the config does not set needs no removal. Either every field is
219
+ * written or, when one cannot be, none is.
220
+ * @param {string} projectDir
221
+ * @param {ReadonlyArray<readonly [string, string | readonly string[] | null]>} fields
222
+ * each a top-level key or a dotted path (`experimental.iconSet`), and its
223
+ * value
224
+ * @returns {{file: string, created: boolean, previous: Array<string | string[] | null>, changed: boolean}}
225
+ * `previous`: each field's value before the write, in the order given
226
+ */
227
+ export function setConfigValues(projectDir, fields) {
159
228
  const existing = CONFIG_BASENAMES.map(name =>
160
229
  path.join(projectDir, name),
161
230
  ).find(file => fs.existsSync(file));
231
+ /** @type {Array<readonly [string, string | readonly string[]]>} */
232
+ const set = [];
233
+ for (const [key, value] of fields) {
234
+ if (value != null) set.push([key, value]);
235
+ }
162
236
  if (!existing) {
163
237
  const file = path.join(projectDir, 'astryx.config.mjs');
238
+ const previous = fields.map(() => null);
239
+ if (set.length === 0)
240
+ return {file, created: false, previous, changed: false};
164
241
  assertWritable(projectDir, file);
165
- // Each key on the path opens one nested object: `experimental: {`.
166
- const open = keys
167
- .slice(0, -1)
168
- .map((each, depth) => `${' '.repeat(depth + 1)}${each}: {\n`)
169
- .join('');
170
- const close = keys
171
- .slice(0, -1)
172
- .map((_, depth) => `${' '.repeat(depth + 1)}},\n`)
173
- .reverse()
174
- .join('');
175
- writeAtomically(
176
- file,
177
- `export default {\n${open}${' '.repeat(keys.length)}${leaf}: ${written(value)},\n${close}};\n`,
178
- );
179
- return {file, created: true, previous: null, changed: true};
242
+ writeAtomically(file, newConfigText(set));
243
+ return {file, created: true, previous, changed: true};
180
244
  }
181
245
  assertWritable(projectDir, existing);
182
246
  const source = fs.readFileSync(existing, 'utf-8');
183
- const j = jscodeshift.withParser('tsx');
247
+ const j = loadJscodeshift().withParser('tsx');
184
248
  const ast = j(source);
185
- let object = findManifestObject(j, ast);
249
+ const root = findManifestObject(j, ast);
186
250
  const refuse = () =>
187
251
  new Error(
188
- `Could not update ${path.basename(existing)} safely: its default export is not a static object literal. Set "${key}: ${written(value)}" in it yourself.`,
252
+ `Could not update ${path.basename(existing)} safely: its default export is not a static object literal. ${byHand(fields)} in it yourself.`,
189
253
  );
190
- if (!object) throw refuse();
254
+ if (!root) throw refuse();
191
255
  // A spread on the path can hold the same keys: a key added beside it would
192
256
  // shadow the spread's whole object and drop what it sets, so nothing is
193
257
  // written there (`{...base}` may set `experimental.xle`).
@@ -195,43 +259,73 @@ export function setConfigValue(projectDir, key, value) {
195
259
  const assertNoSpread = (holder, where) => {
196
260
  if (holder.properties.some((/** @type {any} */ each) => isSpread(each))) {
197
261
  throw new Error(
198
- `Could not update ${path.basename(existing)} safely: ${where} spreads another object (\`...\`), whose keys a written "${key}" could replace. Set "${key}: ${written(value)}" in it yourself.`,
262
+ `Could not update ${path.basename(existing)} safely: ${where} spreads another object (\`...\`), whose keys a written ${fields.map(([key]) => `"${key}"`).join(' or ')} could replace. ${byHand(fields)} in it yourself.`,
199
263
  );
200
264
  }
201
265
  };
202
- assertNoSpread(object, 'its default export');
203
- for (const each of keys.slice(0, -1)) {
204
- const holder = object.properties.find((/** @type {any} */ property) =>
205
- propertyNamed(property, each),
206
- );
207
- if (!holder) {
208
- const created = j.objectExpression([]);
209
- object.properties.push(j.objectProperty(j.identifier(each), created));
210
- object = created;
211
- continue;
212
- }
213
- const nested = unwrapManifestExpression(holder.value);
214
- if (!j.ObjectExpression.check(nested)) throw refuse();
215
- assertNoSpread(nested, `its "${each}" object`);
216
- object = nested;
217
- }
218
- const property = object.properties.find((/** @type {any} */ each) =>
219
- propertyNamed(each, leaf),
220
- );
221
- const node =
266
+ /** @param {string | readonly string[]} value */
267
+ const nodeOf = value =>
222
268
  typeof value === 'string'
223
269
  ? j.stringLiteral(value)
224
270
  : j.arrayExpression(value.map(each => j.stringLiteral(each)));
225
- /** @type {string | string[] | null} */
226
- let previous = null;
227
- if (property) {
228
- previous = literalValue(property.value);
229
- if (sameValue(previous, value)) {
230
- return {file: existing, created: false, previous, changed: false};
271
+ /** @type {Array<string | string[] | null>} */
272
+ const previous = [];
273
+ let changed = false;
274
+ for (const [key, value] of fields) {
275
+ const keys = key.split('.');
276
+ const leaf = /** @type {string} */ (keys[keys.length - 1]);
277
+ let object = root;
278
+ assertNoSpread(object, 'its default export');
279
+ let absent = false;
280
+ for (const each of keys.slice(0, -1)) {
281
+ const holder = object.properties.find((/** @type {any} */ property) =>
282
+ propertyNamed(property, each),
283
+ );
284
+ if (!holder) {
285
+ // A field the config does not reach is already removed.
286
+ if (value == null) {
287
+ absent = true;
288
+ break;
289
+ }
290
+ const created = j.objectExpression([]);
291
+ object.properties.push(j.objectProperty(j.identifier(each), created));
292
+ object = created;
293
+ continue;
294
+ }
295
+ const nested = unwrapManifestExpression(holder.value);
296
+ if (!j.ObjectExpression.check(nested)) throw refuse();
297
+ assertNoSpread(nested, `its "${each}" object`);
298
+ object = nested;
299
+ }
300
+ if (absent) {
301
+ previous.push(null);
302
+ continue;
231
303
  }
232
- property.value = node;
233
- } else {
234
- object.properties.push(j.objectProperty(j.identifier(leaf), node));
304
+ const at = object.properties.findIndex((/** @type {any} */ each) =>
305
+ propertyNamed(each, leaf),
306
+ );
307
+ const property = at === -1 ? null : object.properties[at];
308
+ const before = property ? literalValue(property.value) : null;
309
+ previous.push(before);
310
+ if (value == null) {
311
+ if (property) {
312
+ object.properties.splice(at, 1);
313
+ changed = true;
314
+ }
315
+ continue;
316
+ }
317
+ if (property) {
318
+ if (sameValue(before, value)) continue;
319
+ property.value = nodeOf(value);
320
+ } else {
321
+ object.properties.push(
322
+ j.objectProperty(j.identifier(leaf), nodeOf(value)),
323
+ );
324
+ }
325
+ changed = true;
326
+ }
327
+ if (!changed) {
328
+ return {file: existing, created: false, previous, changed: false};
235
329
  }
236
330
  let next = ast.toSource({quote: 'single', reuseWhitespace: true});
237
331
  if (source.endsWith('\n') && !next.endsWith('\n')) next += '\n';
@@ -45,6 +45,7 @@ import {
45
45
  resolveInstalledIntegrationDir,
46
46
  } from '../integrations/integrations.mjs';
47
47
  import {loadAutolinkCandidates} from '../integrations/autolink.mjs';
48
+ import {missingDeclaredDependency} from '../integrations/missing-dependency.mjs';
48
49
  import {
49
50
  computerInstallRoots,
50
51
  loadComputerIntegrations,
@@ -118,6 +119,16 @@ import {
118
119
  const ISSUES_CODEC = {
119
120
  encode: (/** @type {any} */ value) => value,
120
121
  decode: (/** @type {any} */ value) => value,
122
+ /** A list of issue records, each with its code, severity and message. */
123
+ valid: (/** @type {any} */ value) =>
124
+ Array.isArray(value) &&
125
+ value.every(
126
+ issue =>
127
+ issue != null &&
128
+ typeof issue.code === 'string' &&
129
+ typeof issue.severity === 'string' &&
130
+ typeof issue.message === 'string',
131
+ ),
121
132
  };
122
133
 
123
134
  export {CONFIG_BASENAMES, findConfigPath} from './config-path.mjs';
@@ -1077,6 +1088,7 @@ export class Project {
1077
1088
  sets,
1078
1089
  this.#config.experimental?.iconSet,
1079
1090
  withdrawn,
1091
+ this.#config.experimental?.iconVariant,
1080
1092
  );
1081
1093
  return {sets: orderIconSets(sets, choice), withdrawn, choice};
1082
1094
  });
@@ -1320,6 +1332,63 @@ export class Project {
1320
1332
  return integration?.issuesUrl;
1321
1333
  }
1322
1334
 
1335
+ /**
1336
+ * The passes that find every integration issue: template and component
1337
+ * replacement validity (over Core plus every integration), then each
1338
+ * integration's own checks.
1339
+ */
1340
+ async #runIssuePasses() {
1341
+ // Template replacement validity depends on the combined Core +
1342
+ // integration catalog. Resolve it first so issue results never depend
1343
+ // on which discovery method the caller happened to invoke earlier. Only
1344
+ // an integration's own templates can replace one, so with none, Core's
1345
+ // templates stay unread.
1346
+ if (this.#loadedIntegrations.some(hasTemplatesRoot)) {
1347
+ await this.templates();
1348
+ }
1349
+ // Component replacement validity likewise depends on Core plus every
1350
+ // integration's components.
1351
+ await this.componentReplacements();
1352
+ for (const integration of this.#loadedIntegrations) {
1353
+ await this.#collectIssues(integration);
1354
+ }
1355
+ // An installed dependency whose manifest could not be loaded for want of
1356
+ // a package leaves no loaded record, so nothing above sees it: report it
1357
+ // here, as a package named in astryx.config that fails to load is.
1358
+ for (const failed of this.#unloadedDependencies()) {
1359
+ this.#pushIssue(failed.spec, {
1360
+ code: 'integration_error',
1361
+ severity: 'error',
1362
+ message: failed.error,
1363
+ });
1364
+ }
1365
+ }
1366
+
1367
+ /**
1368
+ * The installed dependencies, linked without a config entry, whose manifest
1369
+ * could not be loaded because a package that the importing package requires
1370
+ * (a dependency or a required peer) is missing, with the load error. That is a broken install, which the
1371
+ * project can fix by installing again; a dependency's own packaging bug (a
1372
+ * manifest that throws, does not validate, or imports what it does not
1373
+ * declare) stays out of the project's issues, since the project cannot fix
1374
+ * it.
1375
+ * @returns {Array<{spec: string, error: string}>}
1376
+ */
1377
+ #unloadedDependencies() {
1378
+ return [...(PROVIDER_LEDGERS.get(this)?.values() ?? [])].flatMap(entry =>
1379
+ entry.outcome === 'load-failed' &&
1380
+ entry.candidate.source === 'autolinked' &&
1381
+ missingDeclaredDependency(entry.error ?? '') != null
1382
+ ? [
1383
+ {
1384
+ spec: entry.candidate.spec ?? entry.label,
1385
+ error: entry.error ?? 'its manifest could not be loaded',
1386
+ },
1387
+ ]
1388
+ : [],
1389
+ );
1390
+ }
1391
+
1323
1392
  /**
1324
1393
  * The accumulated integration issues (deduped by package, code, message).
1325
1394
  * When called directly, also validates any configured integration not yet
@@ -1330,22 +1399,40 @@ export class Project {
1330
1399
  async issues() {
1331
1400
  // Each issue these passes find belongs to an integration, because Core's
1332
1401
  // templates and components declare no replacement. A project with no
1333
- // integration skips them.
1334
- if (this.#loadedIntegrations.length > 0) {
1335
- // Template replacement validity depends on the combined Core +
1336
- // integration catalog. Resolve it first so issue results never depend
1337
- // on which discovery method the caller happened to invoke earlier. Only
1338
- // an integration's own templates can replace one, so with none, Core's
1339
- // templates stay unread.
1340
- if (this.#loadedIntegrations.some(hasTemplatesRoot)) {
1341
- await this.templates();
1342
- }
1343
- // Component replacement validity likewise depends on Core plus every
1344
- // integration's components.
1345
- await this.componentReplacements();
1346
- for (const integration of this.#loadedIntegrations) {
1347
- await this.#collectIssues(integration);
1348
- }
1402
+ // integration skips them (one whose manifest failed to load counts).
1403
+ if (
1404
+ this.#loadedIntegrations.length > 0 ||
1405
+ this.#unloadedDependencies().length > 0
1406
+ ) {
1407
+ // A function of the files the passes read and of the issues already
1408
+ // found (which the key holds): the kept gather stamps the files, so a
1409
+ // later run with every one unchanged reads the whole list back and
1410
+ // skips the passes, discovery included.
1411
+ const before = this.#issues.map(i => ({...i}));
1412
+ const all = await persistedGather(
1413
+ [
1414
+ 'project-issues',
1415
+ this.#cwd,
1416
+ // The Core the replacement pass reads: a carried Core for everyday
1417
+ // commands, the project's own for doctor.
1418
+ this.#core,
1419
+ this.coreDir() ?? null,
1420
+ this.#loadedIntegrations.map(
1421
+ integration => integration.__packageDir ?? integration.name ?? null,
1422
+ ),
1423
+ Boolean(this.#config.experimental?.iconSet),
1424
+ this.#unloadedDependencies(),
1425
+ before,
1426
+ ],
1427
+ async () => {
1428
+ await this.#runIssuePasses();
1429
+ return this.#issues.map(i => ({...i}));
1430
+ },
1431
+ ISSUES_CODEC,
1432
+ );
1433
+ this.#issues = all.map((/** @type {ProjectIntegrationIssue} */ i) => ({
1434
+ ...i,
1435
+ }));
1349
1436
  }
1350
1437
  // Return a stable copy so callers can't mutate internal state.
1351
1438
  return this.#issues.map(i => ({...i}));
@@ -5,7 +5,6 @@
5
5
  */
6
6
 
7
7
  import * as fs from 'node:fs';
8
- import {createRequire} from 'node:module';
9
8
  import * as path from 'node:path';
10
9
  import {DOC_EXPORTS} from '../doc-compiler/read.mjs';
11
10
  import {
@@ -25,12 +24,8 @@ import {
25
24
  moduleExportsName,
26
25
  staticExportObject,
27
26
  } from './module-exports.mjs';
28
- import {
29
- inspectPackageExport,
30
- sourceExportTarget,
31
- } from './package-exports.mjs';
32
-
33
- const require = createRequire(import.meta.url);
27
+ import {inspectPackageExport, sourceExportTarget} from './package-exports.mjs';
28
+ import {babelParser} from '../runtime/lazy-dependencies.mjs';
34
29
 
35
30
  const SKIP_DIRS = new Set(['hooks', 'utils', '__tests__', 'node_modules']);
36
31
 
@@ -176,9 +171,6 @@ function readDocMeta(docPath) {
176
171
  }
177
172
  }
178
173
 
179
- /** @type {typeof import('@babel/parser') | undefined} */
180
- let babelParser;
181
-
182
174
  /**
183
175
  * A property of an object literal, by its plain key.
184
176
  * @param {any} object - an ObjectExpression node
@@ -211,13 +203,9 @@ function docMemberNames(source) {
211
203
  /** @type {any} */
212
204
  let ast;
213
205
  try {
214
- babelParser ??= require('@babel/parser');
215
- ast = /** @type {typeof import('@babel/parser')} */ (babelParser).parse(
216
- source,
217
- {
218
- sourceType: 'module',
219
- },
220
- );
206
+ ast = babelParser().parse(source, {
207
+ sourceType: 'module',
208
+ });
221
209
  } catch {
222
210
  return [];
223
211
  }
@@ -693,11 +681,12 @@ function ownSourceFile(coreDir, name) {
693
681
  if (found) return found;
694
682
  }
695
683
 
696
- // Search nested (component might be under a parent dir)
697
- const entries = listDirEntries(srcDir);
698
- for (const entry of entries) {
699
- if (!entry.isDirectory()) continue;
700
- const nestedDir = path.join(srcDir, entry.name, name);
684
+ // Search nested (component might be under a parent dir): only the folders
685
+ // whose listing holds the name, in listing order.
686
+ const nested = foldersHolding(srcDir, listDirEntries(srcDir), [name]).map(
687
+ entry => path.join(srcDir, entry.name, name),
688
+ );
689
+ for (const nestedDir of nested) {
701
690
  if (existsCaseExact(nestedDir, srcDir)) {
702
691
  const found = searchDir(nestedDir);
703
692
  if (found) return found;