@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
@@ -269,7 +269,7 @@ function isCoreSource(dir) {
269
269
  * @param {string} p
270
270
  * @returns {string}
271
271
  */
272
- function realDir(p) {
272
+ export function realDir(p) {
273
273
  try {
274
274
  return fs.realpathSync(path.resolve(p));
275
275
  } catch {
@@ -282,7 +282,7 @@ function realDir(p) {
282
282
  *
283
283
  * @returns {string|null}
284
284
  */
285
- function homeFolder() {
285
+ export function homeFolder() {
286
286
  try {
287
287
  const home = os.homedir();
288
288
  return home ? realDir(home) : null;
@@ -339,6 +339,31 @@ export function findPackageRoot(startDir) {
339
339
  return null;
340
340
  }
341
341
 
342
+ /**
343
+ * A path a command writes in a project, read the same way by every theme
344
+ * command: from the working folder when given, from the project root (the
345
+ * nearest folder with a package.json, else the working folder) when not,
346
+ * and with a backslash as a folder separator on every platform.
347
+ * @param {string} cwd
348
+ * @param {string | undefined} typed the path as given, or undefined
349
+ * @param {string} fallback the path from the project root when none is given
350
+ * @returns {{projectDir: string, typed: string | undefined, relative: string}}
351
+ * `typed`: the path as given with `/`; `relative`: from the project root
352
+ */
353
+ export function projectWritePath(cwd, typed, fallback) {
354
+ const projectDir = findPackageRoot(cwd) ?? path.resolve(cwd);
355
+ const given = typed == null ? undefined : String(typed).replace(/\\/g, '/');
356
+ const absolute =
357
+ given == null ? path.join(projectDir, fallback) : path.resolve(cwd, given);
358
+ return {
359
+ projectDir,
360
+ typed: given,
361
+ relative: path.isAbsolute(given ?? '')
362
+ ? /** @type {string} */ (given)
363
+ : path.relative(projectDir, absolute) || '.',
364
+ };
365
+ }
366
+
342
367
  /**
343
368
  * The Astryx project `startDir` belongs to: the nearest folder at or above it
344
369
  * whose package.json declares an Astryx package (`@astryxdesign/*`, or the
@@ -374,8 +399,22 @@ export function findAstryxProject(startDir) {
374
399
  * @returns {string}
375
400
  */
376
401
  export function findWorkspaceRoot(startDir) {
377
- /** @type {string|null} */
378
- let nearestPackage = null;
402
+ return (
403
+ findDeclaredWorkspaceRoot(startDir) ??
404
+ findPackageRoot(startDir) ??
405
+ path.resolve(startDir)
406
+ );
407
+ }
408
+
409
+ /**
410
+ * The nearest directory at or above `startDir` that declares a workspace,
411
+ * by a `pnpm-workspace.yaml` or a package.json `workspaces` field; null
412
+ * outside a workspace.
413
+ *
414
+ * @param {string} startDir
415
+ * @returns {string|null}
416
+ */
417
+ export function findDeclaredWorkspaceRoot(startDir) {
379
418
  for (const dir of foldersUpFrom(startDir)) {
380
419
  if (
381
420
  fs.existsSync(path.join(dir, 'pnpm-workspace.yaml')) ||
@@ -383,14 +422,8 @@ export function findWorkspaceRoot(startDir) {
383
422
  ) {
384
423
  return dir;
385
424
  }
386
- if (
387
- nearestPackage == null &&
388
- fs.existsSync(path.join(dir, 'package.json'))
389
- ) {
390
- nearestPackage = dir;
391
- }
392
425
  }
393
- return nearestPackage ?? path.resolve(startDir);
426
+ return null;
394
427
  }
395
428
 
396
429
  /**
@@ -233,7 +233,17 @@ export function recordStates(states) {
233
233
  const runs = reads.getStore();
234
234
  if (!runs) return;
235
235
  for (const [file, state] of states) {
236
- for (const seen of runs) if (!seen.has(file)) seen.set(file, state);
236
+ for (const seen of runs) {
237
+ const had = seen.get(file);
238
+ // A folder this run only probed, which the kept read listed: the
239
+ // listing counts, as when this run lists it itself (see `note`).
240
+ if (
241
+ had === undefined ||
242
+ (had.startsWith('dir:') && !state.startsWith('dir:'))
243
+ ) {
244
+ seen.set(file, state);
245
+ }
246
+ }
237
247
  }
238
248
  }
239
249
 
@@ -74,8 +74,10 @@ export function loadAutolinkCandidates({ projectDir, loaded, fresh, }: {
74
74
  * rest of that package's contributions — including the load-error marker
75
75
  * `loadIntegrations` returns for it. A CONFIGURED integration is the opposite
76
76
  * case: the project named it, so its failure is an issue the project owns and
77
- * can act on. An autolinked one is a dependency's own packaging bug, which the
78
- * consuming project can neither fix nor silence, and which
77
+ * can act on. An autolinked one is dropped here either way; the project reports
78
+ * it only when a package the dependency requires is missing (a broken install
79
+ * it can repair, INV14). Otherwise it is the dependency's own packaging bug,
80
+ * which the consuming project can neither fix nor silence, and which
79
81
  * `astryx doctor integration validate <package>` reports on demand.
80
82
  *
81
83
  * One package reached twice (an alias beside the package it aliases, at the
@@ -218,8 +218,10 @@ export async function loadAutolinkCandidates({
218
218
  * rest of that package's contributions — including the load-error marker
219
219
  * `loadIntegrations` returns for it. A CONFIGURED integration is the opposite
220
220
  * case: the project named it, so its failure is an issue the project owns and
221
- * can act on. An autolinked one is a dependency's own packaging bug, which the
222
- * consuming project can neither fix nor silence, and which
221
+ * can act on. An autolinked one is dropped here either way; the project reports
222
+ * it only when a package the dependency requires is missing (a broken install
223
+ * it can repair, INV14). Otherwise it is the dependency's own packaging bug,
224
+ * which the consuming project can neither fix nor silence, and which
223
225
  * `astryx doctor integration validate <package>` reports on demand.
224
226
  *
225
227
  * One package reached twice (an alias beside the package it aliases, at the
@@ -129,15 +129,18 @@ export function templateIconsCliProblem(pkg: any): string | null;
129
129
  * refused by a CLI it may run, or null when the `@astryxdesign/cli` range it
130
130
  * declares (in dependencies, devDependencies, optionalDependencies, or
131
131
  * peerDependencies) admits only CLIs that read the key. A list value needs a
132
- * later release than a string. A project that declares no range, or one that
133
- * is not a version range (`workspace:`, `file:`, `link:`), gets null: nothing
134
- * says which CLI it runs.
132
+ * later release than a string, and `experimental.iconVariant` a later
133
+ * release than either. A project that declares no range, or one that is not
134
+ * a version range (`workspace:`, `file:`, `link:`), gets null: nothing says
135
+ * which CLI it runs.
135
136
  * @param {any} pkg the project's package.json
136
- * @param {{list?: boolean}} [options] `list`: the value is a list
137
+ * @param {{list?: boolean, variant?: boolean}} [options] `list`: the value is
138
+ * a list; `variant`: the config also sets `experimental.iconVariant`
137
139
  * @returns {string | null}
138
140
  */
139
- export function projectIconSetCliWarning(pkg: any, { list }?: {
141
+ export function projectIconSetCliWarning(pkg: any, { list, variant }?: {
140
142
  list?: boolean;
143
+ variant?: boolean;
141
144
  }): string | null;
142
145
  export const CLI_PACKAGE: "@astryxdesign/cli";
143
146
  /**
@@ -233,3 +236,11 @@ export const CONFIG_ICON_SET_CLI: "0.7.4";
233
236
  * a list (a main set and backups). Earlier releases refuse the list form.
234
237
  */
235
238
  export const CONFIG_ICON_SET_LIST_CLI: "0.7.12";
239
+ /**
240
+ * The first stable CLI release that reads `experimental.iconVariant`, the
241
+ * look the project's icon sets draw. Earlier releases refuse an astryx.config
242
+ * that sets it ("Unrecognized key").
243
+ *
244
+ * Tied to the next patch slot.
245
+ */
246
+ export const CONFIG_ICON_VARIANT_CLI: "0.7.16";
@@ -410,19 +410,33 @@ export const CONFIG_ICON_SET_CLI = '0.7.4';
410
410
  */
411
411
  export const CONFIG_ICON_SET_LIST_CLI = '0.7.12';
412
412
 
413
+ /**
414
+ * The first stable CLI release that reads `experimental.iconVariant`, the
415
+ * look the project's icon sets draw. Earlier releases refuse an astryx.config
416
+ * that sets it ("Unrecognized key").
417
+ *
418
+ * Tied to the next patch slot.
419
+ */
420
+ export const CONFIG_ICON_VARIANT_CLI = '0.7.16';
421
+
413
422
  /**
414
423
  * Why an app project whose astryx.config sets `experimental.iconSet` would be
415
424
  * refused by a CLI it may run, or null when the `@astryxdesign/cli` range it
416
425
  * declares (in dependencies, devDependencies, optionalDependencies, or
417
426
  * peerDependencies) admits only CLIs that read the key. A list value needs a
418
- * later release than a string. A project that declares no range, or one that
419
- * is not a version range (`workspace:`, `file:`, `link:`), gets null: nothing
420
- * says which CLI it runs.
427
+ * later release than a string, and `experimental.iconVariant` a later
428
+ * release than either. A project that declares no range, or one that is not
429
+ * a version range (`workspace:`, `file:`, `link:`), gets null: nothing says
430
+ * which CLI it runs.
421
431
  * @param {any} pkg the project's package.json
422
- * @param {{list?: boolean}} [options] `list`: the value is a list
432
+ * @param {{list?: boolean, variant?: boolean}} [options] `list`: the value is
433
+ * a list; `variant`: the config also sets `experimental.iconVariant`
423
434
  * @returns {string | null}
424
435
  */
425
- export function projectIconSetCliWarning(pkg, {list = false} = {}) {
436
+ export function projectIconSetCliWarning(
437
+ pkg,
438
+ {list = false, variant = false} = {},
439
+ ) {
426
440
  const field = [
427
441
  'dependencies',
428
442
  'devDependencies',
@@ -432,11 +446,18 @@ export function projectIconSetCliWarning(pkg, {list = false} = {}) {
432
446
  if (!field) return null;
433
447
  const range = pkg[field][CLI_PACKAGE];
434
448
  if (range.includes(':')) return null;
435
- const needed = list ? CONFIG_ICON_SET_LIST_CLI : CONFIG_ICON_SET_CLI;
449
+ const needed = variant
450
+ ? CONFIG_ICON_VARIANT_CLI
451
+ : list
452
+ ? CONFIG_ICON_SET_LIST_CLI
453
+ : CONFIG_ICON_SET_CLI;
436
454
  const lowest = lowestAdmitted(range);
437
455
  if (lowest != null && semverCompare(lowest, needed) >= 0) {
438
456
  return null;
439
457
  }
458
+ if (variant) {
459
+ return `The project's ${CLI_PACKAGE} range "${range}" (${field}) admits a release before ${needed}, which refuses an astryx.config that sets \`experimental.iconVariant\` ("Unrecognized key"), so commands that load the project configuration, such as \`doctor\` and \`discover\`, fail there. Require "${CLI_PACKAGE}": ">=${needed}".`;
460
+ }
440
461
  if (list) {
441
462
  return `The project's ${CLI_PACKAGE} range "${range}" (${field}) admits a release before ${needed}, which refuses \`experimental.iconSet\` written as a list, so commands that load the project configuration, such as \`doctor\` and \`discover\`, fail there. Require "${CLI_PACKAGE}": ">=${needed}".`;
442
463
  }
@@ -20,7 +20,6 @@
20
20
 
21
21
  import * as fs from 'node:fs';
22
22
  import * as path from 'node:path';
23
- import {createRequire} from 'node:module';
24
23
  import {isValidSemver} from '../env/semver.mjs';
25
24
  import {
26
25
  isThemeFolder as readsAsTheme,
@@ -28,6 +27,7 @@ import {
28
27
  THEME_MODULE_EXTENSIONS,
29
28
  THEME_SLUG_RE,
30
29
  } from '../discovery/theme-discovery.mjs';
30
+ import {jscodeshift} from '../runtime/lazy-dependencies.mjs';
31
31
 
32
32
  /** @typedef {'components' | 'templates' | 'docs' | 'themes'} MetadataRoot */
33
33
 
@@ -88,24 +88,9 @@ const ROOT_HOLDS = /** @type {Record<MetadataRoot, string>} */ ({
88
88
  themes: 'themes',
89
89
  });
90
90
 
91
- const require = createRequire(import.meta.url);
92
- /** @type {typeof import('jscodeshift').default | undefined} */
93
- let jscodeshiftModule;
94
91
  /** @type {ReturnType<typeof import('jscodeshift').default['withParser']> | undefined} */
95
92
  let tsxParser;
96
93
 
97
- /**
98
- * jscodeshift, loaded at its first use: it is a large module, and a run that
99
- * checks no contribution file never needs it.
100
- * @returns {typeof import('jscodeshift').default}
101
- */
102
- function jscodeshift() {
103
- jscodeshiftModule ??= require('jscodeshift');
104
- return /** @type {typeof import('jscodeshift').default} */ (
105
- jscodeshiftModule
106
- );
107
- }
108
-
109
94
  /** jscodeshift with the TypeScript parser, made once. */
110
95
  function tsx() {
111
96
  tsxParser ??= jscodeshift().withParser('tsx');
@@ -11,9 +11,13 @@
11
11
  * integrations installed beside the running CLI load, spec AST-081 FR12),
12
12
  * so no configured, self-resolved, autolinked or computer-level integration
13
13
  * can load.
14
- * @position Read by foundation/fs/gather-cache.mjs: `component`, `template`,
15
- * `theme` and `discover` record a run only for their integrations' kept
16
- * check results, so a project with none skips the recorder entirely. A true
14
+ * @position Read by clients/cli/index.mjs, which loads the project before
15
+ * help and before each command only where an integration can load (to read
16
+ * the commands integrations declare), and by foundation/fs/gather-cache.mjs:
17
+ * `component`, `template`, `theme`, `discover` and `docs` record a run only
18
+ * for what is worth keeping where
19
+ * an integration can load (its kept check results, and template
20
+ * discovery's records), so a project with none skips the recorder entirely. A true
17
21
  * answer only means the run records, so a check that says true too often
18
22
  * costs time, never an answer.
19
23
  */
@@ -0,0 +1,9 @@
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 missing package's name when the package that imports it declares it.
6
+ * @param {string} message
7
+ * @returns {string | null}
8
+ */
9
+ export function missingDeclaredDependency(message: string): string | null;
@@ -0,0 +1,100 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Whether a module load error is a broken install: a package that the
5
+ * importing package declares is missing.
6
+ * @input A load error's message, as Node words it for an ES module ("Cannot
7
+ * find package 'x' imported from /file") or for CommonJS ("Cannot find
8
+ * module 'x'" with its require stack).
9
+ * @output `missingDeclaredDependency(message)`: the missing package's name
10
+ * when the package holding the importing file declares it as a package its
11
+ * consumers' install must hold (dependencies, or a peerDependencies entry
12
+ * not marked optional in peerDependenciesMeta), else null. A dev dependency
13
+ * is never installed for a consumer and an optional one may be skipped by
14
+ * design, so a manifest that needs either has a packaging bug, which
15
+ * reinstalling does not clear. A package listed both as a dependency and
16
+ * as an optional one is optional, as npm reads it.
17
+ * @position Read by the project (foundation/config/project.mjs) to tell an
18
+ * install the user can repair from a dependency's own packaging bug, which
19
+ * stays out of the project's issues.
20
+ */
21
+
22
+ import * as fs from 'node:fs';
23
+ import * as path from 'node:path';
24
+ import {fileURLToPath} from 'node:url';
25
+
26
+ /**
27
+ * Whether a package.json declares `name` as a package its consumers' install
28
+ * must hold: a dependency, or a peer not marked optional.
29
+ * @param {any} pkg
30
+ * @param {string} name
31
+ * @returns {boolean}
32
+ */
33
+ function requires(pkg, name) {
34
+ /** @param {unknown} field */
35
+ const has = field =>
36
+ field != null && typeof field === 'object' && Object.hasOwn(field, name);
37
+ // npm treats a package listed in both as optional (fsevents, say).
38
+ if (has(pkg.optionalDependencies)) return false;
39
+ if (has(pkg.dependencies)) return true;
40
+ return (
41
+ has(pkg.peerDependencies) &&
42
+ pkg.peerDependenciesMeta?.[name]?.optional !== true
43
+ );
44
+ }
45
+
46
+ /**
47
+ * The missing package and the file that imported it, from a load error.
48
+ * @param {string} message
49
+ * @returns {{name: string, importer: string} | null}
50
+ */
51
+ function parse(message) {
52
+ const esm =
53
+ /Cannot find (?:package|module) '([^']+)' imported from ([^\n]+)/.exec(
54
+ message,
55
+ );
56
+ const cjs =
57
+ /Cannot find module '([^']+)'\s*\nRequire stack:\n- ([^\n]+)/.exec(message);
58
+ const hit = esm ?? cjs;
59
+ if (!hit) return null;
60
+ const [, spec, found] = hit;
61
+ const from = found.trim();
62
+ if (spec.startsWith('.') || path.isAbsolute(spec) || spec.startsWith('node:'))
63
+ return null;
64
+ const parts = spec.split('/');
65
+ const name = spec.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
66
+ let importer = from;
67
+ try {
68
+ if (from.startsWith('file:')) importer = fileURLToPath(from);
69
+ } catch {
70
+ return null;
71
+ }
72
+ return {name, importer};
73
+ }
74
+
75
+ /**
76
+ * The missing package's name when the package that imports it declares it.
77
+ * @param {string} message
78
+ * @returns {string | null}
79
+ */
80
+ export function missingDeclaredDependency(message) {
81
+ const found = parse(message);
82
+ if (!found) return null;
83
+ let dir = path.dirname(found.importer);
84
+ for (;;) {
85
+ const file = path.join(dir, 'package.json');
86
+ if (fs.existsSync(file)) {
87
+ try {
88
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
89
+ if (typeof pkg?.name === 'string') {
90
+ return requires(pkg, found.name) ? found.name : null;
91
+ }
92
+ } catch {
93
+ return null;
94
+ }
95
+ }
96
+ const parent = path.dirname(dir);
97
+ if (parent === dir) return null;
98
+ dir = parent;
99
+ }
100
+ }
@@ -30,7 +30,7 @@
30
30
 
31
31
  import * as fs from 'node:fs';
32
32
  import * as path from 'node:path';
33
- import {parse} from '@babel/parser';
33
+ import {babelParse as parse} from '../runtime/lazy-dependencies.mjs';
34
34
  import {findProjectCoreDir} from '../fs/paths.mjs';
35
35
  import {normalizeProviderId} from '../identity/provider-identity.mjs';
36
36
  import {
@@ -15,7 +15,7 @@
15
15
 
16
16
  import * as fs from 'node:fs';
17
17
  import * as path from 'node:path';
18
- import {parse} from '@babel/parser';
18
+ import {babelParse as parse} from '../runtime/lazy-dependencies.mjs';
19
19
  import {PAGE_EXTENSIONS} from './embedded-files.mjs';
20
20
  import postcss from 'postcss';
21
21
  import {matchPath, readPathsIn} from './ts-paths.mjs';
@@ -0,0 +1,8 @@
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
+ export namespace HOST_EXIT {
5
+ let disconnected: number;
6
+ let timeout: number;
7
+ let noChannel: number;
8
+ }
@@ -0,0 +1,11 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The exit codes of the render's host process (page-host.mjs) for each
5
+ * way it ends without sending an answer. render-page.mjs reads them to say
6
+ * why.
7
+ * @position foundation/render — imported by page-host.mjs and render-page.mjs
8
+ */
9
+
10
+ /** Exit codes for each way the host ends without sending an answer. */
11
+ export const HOST_EXIT = {disconnected: 70, timeout: 71, noChannel: 72};
@@ -9,26 +9,53 @@
9
9
  * when the CLI goes away (the IPC channel closes) or when its own time limit
10
10
  * passes, so a page that never finishes never outlives the CLI.
11
11
  *
12
+ * When the page ends without an answer, the host says why: the last stage the
13
+ * page reported, how long it ran, the memory left, and the last lines the page
14
+ * wrote to stderr. Each way the host itself ends without an answer has its own
15
+ * exit code (HOST_EXIT), so none of them reads as a clean exit.
16
+ *
12
17
  * @input argv[2]: JSON {entry, root, served, withoutSegmenter, timeoutMs}
13
- * @output one IPC message: the worker's answer, or {hostError: message}, or
14
- * {hostExit: code}
18
+ * @output one IPC message: the worker's answer, or {hostError, stage}, or
19
+ * {hostExit, reason, stage, elapsedMs, rssMb, freeMb, stderrTail}
15
20
  * @position foundation/render — started by render-page.mjs
16
21
  */
17
22
 
23
+ import * as os from 'node:os';
18
24
  import {Worker} from 'node:worker_threads';
25
+ import {HOST_EXIT} from './host-exit.mjs';
19
26
 
20
27
  /** @type {{entry: string, root: string, served: {dir: string, integrations: string[]} | null, withoutSegmenter: boolean, timeoutMs: number}} */
21
28
  const input = JSON.parse(process.argv[2] ?? '{}');
29
+ const started = Date.now();
30
+ let stage = 'starting';
31
+ let stderrTail = '';
32
+ let answered = false;
22
33
 
23
34
  /** @param {unknown} message */
24
35
  function answer(message) {
25
- if (!process.connected) process.exit(0);
36
+ if (answered) return;
37
+ answered = true;
38
+ if (!process.connected) process.exit(HOST_EXIT.noChannel);
26
39
  process.send?.(message, () => process.exit(0));
27
40
  }
28
41
 
29
- process.once('disconnect', () => process.exit(0));
42
+ /** What the page was doing and what it had left, for an end without an answer. */
43
+ function state() {
44
+ return {
45
+ stage,
46
+ elapsedMs: Date.now() - started,
47
+ rssMb: Math.round(process.memoryUsage().rss / 2 ** 20),
48
+ freeMb: Math.round(os.freemem() / 2 ** 20),
49
+ stderrTail: stderrTail.trim().split('\n').slice(-5).join('\n'),
50
+ };
51
+ }
52
+
53
+ process.once('disconnect', () => process.exit(HOST_EXIT.disconnected));
30
54
  // A margin past the CLI's own limit, so the CLI reports the timeout first.
31
- setTimeout(() => process.exit(0), input.timeoutMs + 5000);
55
+ setTimeout(() => {
56
+ answer({hostExit: null, reason: 'host-timeout', ...state()});
57
+ setTimeout(() => process.exit(HOST_EXIT.timeout), 1000).unref();
58
+ }, input.timeoutMs + 5000);
32
59
 
33
60
  const worker = new Worker(new URL('./page-worker.mjs', import.meta.url), {
34
61
  workerData: input,
@@ -37,9 +64,28 @@ const worker = new Worker(new URL('./page-worker.mjs', import.meta.url), {
37
64
  stderr: true,
38
65
  resourceLimits: {maxOldGenerationSizeMb: 4096},
39
66
  });
40
- // The page's own writes to stdout/stderr never reach the CLI's output.
67
+ // The page's own writes to stdout/stderr never reach the CLI's output; the
68
+ // last stderr lines go into the reason for an end without an answer.
41
69
  worker.stdout.resume();
42
- worker.stderr.resume();
43
- worker.once('message', answer);
44
- worker.once('error', (/** @type {any} */ error) => answer({hostError: String(error?.message ?? error)}));
45
- worker.once('exit', code => answer({hostExit: code}));
70
+ worker.stderr.setEncoding('utf8');
71
+ worker.stderr.on('data', (/** @type {string} */ chunk) => {
72
+ stderrTail = (stderrTail + chunk).slice(-4000);
73
+ });
74
+ worker.on('message', (/** @type {any} */ message) => {
75
+ // A progress note, not the answer.
76
+ if (
77
+ message &&
78
+ typeof message.stage === 'string' &&
79
+ Object.keys(message).length === 1
80
+ ) {
81
+ stage = message.stage;
82
+ return;
83
+ }
84
+ answer(message);
85
+ });
86
+ worker.once('error', (/** @type {any} */ error) =>
87
+ answer({hostError: String(error?.message ?? error), stage}),
88
+ );
89
+ worker.once('exit', code =>
90
+ answer({hostExit: code, reason: 'worker-ended', ...state()}),
91
+ );
@@ -835,10 +835,20 @@ function classify(e) {
835
835
  return fail('ERR_RENDER_FAILED', `The page threw while rendering: ${message.split('\n')[0]}`);
836
836
  }
837
837
 
838
+ /**
839
+ * Tell the host what the page is doing, so an end without an answer can say
840
+ * where it ended.
841
+ * @param {string} name
842
+ */
843
+ function reach(name) {
844
+ parentPort?.postMessage({stage: name});
845
+ }
846
+
838
847
  try {
839
848
  /** @type {any} */
840
849
  let mod;
841
850
  try {
851
+ reach('importing the page');
842
852
  mod = await jiti.import(entry);
843
853
  } catch (e) {
844
854
  classify(e);
@@ -857,6 +867,7 @@ try {
857
867
  /** @type {any} */
858
868
  let server;
859
869
  try {
870
+ reach('loading React');
860
871
  React = await jiti.import('react');
861
872
  createElement = React.createElement;
862
873
  useContext = React.useContext;
@@ -874,11 +885,13 @@ try {
874
885
  /** @type {false | 'error' | 'changed' | 'rerendered'} */
875
886
  let chartsAlone = false;
876
887
  try {
888
+ reach('rendering on the server');
877
889
  markup = server.renderToStaticMarkup(React.createElement(Page));
878
890
  if (charts.length > 0) {
879
891
  // Drawing the page again re-runs its code: what it prints then was
880
892
  // already reported by the server render.
881
893
  const printed = logs.length;
894
+ reach('drawing charts');
882
895
  ({markup, failed: chartsFailed, alone: chartsAlone} = await drawCharts(markup, Page));
883
896
  logs.length = printed;
884
897
  }
@@ -893,6 +906,7 @@ try {
893
906
  /** @type {string} */
894
907
  let css = '';
895
908
  if (stylexRules.length > 0) {
909
+ reach('compiling styles');
896
910
  css = stylexPlugin.processStylexRules(stylexRules, {useLayers: false});
897
911
  }
898
912
  parentPort?.postMessage({
@@ -27,6 +27,7 @@ import {sourceBlock} from './source-block.mjs';
27
27
  import {embeddedPathProblem} from './embedded-files.mjs';
28
28
  import {resolveServed} from './served-packages.mjs';
29
29
  import {CHART_CSS} from './charts.mjs';
30
+ import {HOST_EXIT} from './host-exit.mjs';
30
31
 
31
32
  /** How long one page may take to render before it is stopped. */
32
33
  export const RENDER_TIMEOUT_MS = 60_000;
@@ -273,6 +274,40 @@ function crashError(how, {crashed, withoutSegmenter}) {
273
274
  );
274
275
  }
275
276
 
277
+ /**
278
+ * The error for a page that ended without an answer, with why: the stage it
279
+ * reported last, how long it ran, the memory left, and its last stderr line.
280
+ * @param {any} message the host's {hostExit, reason, stage, elapsedMs, rssMb, freeMb, stderrTail}
281
+ */
282
+ function noAnswerError({hostExit, reason, stage, elapsedMs, rssMb, freeMb, stderrTail}) {
283
+ const detail = {reason, exit: hostExit, stage, elapsedMs, rssMb, freeMb, ...(stderrTail ? {stderrTail} : {})};
284
+ const where = stage ? ` while ${stage}` : '';
285
+ const seconds = Math.round((elapsedMs ?? 0) / 1000);
286
+ if (reason === 'host-timeout') {
287
+ return new RenderError('ERR_RENDER_TIMEOUT', `The page's process stopped at its own time limit${where}, after ${seconds} seconds, before this process read an answer.`, detail);
288
+ }
289
+ const last = stderrTail ? ` Its last output: ${String(stderrTail).split('\n').at(-1)}` : '';
290
+ return new RenderError(
291
+ 'ERR_RENDER_FAILED',
292
+ `The page stopped rendering without an answer (exit ${hostExit})${where}, after ${seconds} seconds, with ${freeMb} MB of memory free.${last}`,
293
+ detail,
294
+ );
295
+ }
296
+
297
+ /** The error for a host process that ended, without a signal, before it answered. */
298
+ function hostEndError(/** @type {number | null} */ code) {
299
+ if (code === HOST_EXIT.disconnected) {
300
+ return new RenderError('ERR_RENDER_FAILED', "The page's process lost its channel to this process and stopped without an answer.", {reason: 'disconnected', exit: code});
301
+ }
302
+ if (code === HOST_EXIT.noChannel) {
303
+ return new RenderError('ERR_RENDER_FAILED', "The page's process had no channel left to send its answer on.", {reason: 'no-channel', exit: code});
304
+ }
305
+ if (code === HOST_EXIT.timeout) {
306
+ return new RenderError('ERR_RENDER_TIMEOUT', "The page's process stopped at its own time limit before this process read an answer.", {reason: 'host-timeout', exit: code});
307
+ }
308
+ return new RenderError('ERR_RENDER_FAILED', `The page's process ended without an answer (exit ${code}).`, {reason: 'host-ended', exit: code});
309
+ }
310
+
276
311
  /**
277
312
  * Run the page in a host process (page-host.mjs), stopping it after
278
313
  * `timeoutMs`. The host runs the page in a worker thread, and it exits when
@@ -325,7 +360,7 @@ function runWorker(input, timeoutMs) {
325
360
  : new RenderError('ERR_RENDER_FAILED', `The page could not be rendered: ${text.split('\n')[0]}`),
326
361
  );
327
362
  } else if (message?.hostExit !== undefined) {
328
- reject(new RenderError('ERR_RENDER_FAILED', `The page stopped rendering without an answer (exit ${message.hostExit}).`));
363
+ reject(noAnswerError(message));
329
364
  } else {
330
365
  resolve(message);
331
366
  }
@@ -339,7 +374,7 @@ function runWorker(input, timeoutMs) {
339
374
  const crash = crashOf(code, signal);
340
375
  if (crash) resolve({crashed: crash});
341
376
  else if (signal) reject(crashError(signal, {crashed: false, withoutSegmenter: input.withoutSegmenter}));
342
- else reject(new RenderError('ERR_RENDER_FAILED', `The page stopped rendering without an answer (exit ${code}).`));
377
+ else reject(hostEndError(code));
343
378
  });
344
379
  });
345
380
  });