@astryxdesign/cli 0.7.15 → 0.7.16-canary.g07c77c0

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 (159) hide show
  1. package/README.md +5 -3
  2. package/api/build/_adapter.d.mts +1 -0
  3. package/api/build/blocks/blocks.d.mts +1 -0
  4. package/api/build/blocks/blocks.mjs +18 -1
  5. package/api/component/_adapter.d.mts +1 -1
  6. package/api/component/_adapter.mjs +28 -1
  7. package/api/doctor/_adapter.d.mts +17 -0
  8. package/api/doctor/_adapter.mjs +43 -0
  9. package/api/doctor/built-checks.mjs +1 -1
  10. package/api/doctor/doctor.mjs +18 -4
  11. package/api/doctor/theme-checks.mjs +1 -1
  12. package/api/integration/add-contribution.mjs +3 -3
  13. package/api/integration/pack-check.mjs +14 -8
  14. package/api/integration/validate-integration.mjs +1 -1
  15. package/api/search/_adapter.mjs +15 -16
  16. package/api/search/_entries.d.mts +2 -1
  17. package/api/search/_entries.mjs +28 -1
  18. package/api/swizzle/_moduleGraph.mjs +1 -1
  19. package/api/theme/_adapter.d.mts +5 -2
  20. package/api/theme/_adapter.mjs +43 -12
  21. package/api/theme/_fork.mjs +1 -1
  22. package/api/theme/build/build.d.mts +116 -32
  23. package/api/theme/build/build.mjs +449 -102
  24. package/api/theme/eject/eject.mjs +22 -1
  25. package/api/theme/template/template.d.mts +19 -0
  26. package/api/theme/template/template.mjs +102 -25
  27. package/api/theme/theme.type.d.mts +5 -1
  28. package/api/theme/theme.type.mjs +2 -1
  29. package/api/theme/themeBuild.doc.mjs +3 -3
  30. package/api/theme/themeEject.doc.mjs +1 -1
  31. package/api/theme/themeTemplate.doc.mjs +9 -3
  32. package/api/theme-edit/_adapter.d.mts +32 -2
  33. package/api/theme-edit/_adapter.mjs +213 -36
  34. package/api/theme-edit/_check.d.mts +69 -3
  35. package/api/theme-edit/_check.mjs +1517 -218
  36. package/api/theme-edit/_color.d.mts +2 -8
  37. package/api/theme-edit/_color.mjs +292 -219
  38. package/api/theme-edit/_compiler.d.mts +1 -0
  39. package/api/theme-edit/_compiler.mjs +20 -1
  40. package/api/theme-edit/_context.d.mts +29 -0
  41. package/api/theme-edit/_context.mjs +426 -40
  42. package/api/theme-edit/_css.d.mts +60 -1
  43. package/api/theme-edit/_css.mjs +404 -28
  44. package/api/theme-edit/_edit.d.mts +9 -0
  45. package/api/theme-edit/_edit.mjs +1300 -135
  46. package/api/theme-edit/_how-commands.d.mts +11 -26
  47. package/api/theme-edit/_how-commands.mjs +30 -2
  48. package/api/theme-edit/_how-question.d.mts +7 -0
  49. package/api/theme-edit/_how-question.mjs +1304 -176
  50. package/api/theme-edit/_how.mjs +144 -30
  51. package/api/theme-edit/_overview.mjs +2 -0
  52. package/api/theme-edit/_palette.d.mts +11 -0
  53. package/api/theme-edit/_palette.mjs +194 -65
  54. package/api/theme-edit/_parts.d.mts +33 -0
  55. package/api/theme-edit/_parts.mjs +138 -9
  56. package/api/theme-edit/_png.d.mts +18 -0
  57. package/api/theme-edit/_png.mjs +95 -14
  58. package/api/theme-edit/_preview-app.d.mts +9 -0
  59. package/api/theme-edit/_preview-app.mjs +1191 -71
  60. package/api/theme-edit/_preview.d.mts +16 -3
  61. package/api/theme-edit/_preview.mjs +335 -30
  62. package/api/theme-edit/_project.d.mts +11 -0
  63. package/api/theme-edit/_project.mjs +46 -12
  64. package/api/theme-edit/_settings.d.mts +240 -5
  65. package/api/theme-edit/_settings.mjs +2561 -115
  66. package/api/theme-edit/_tables.d.mts +24 -0
  67. package/api/theme-edit/_tables.mjs +211 -149
  68. package/api/theme-edit/_vet.d.mts +42 -0
  69. package/api/theme-edit/_vet.mjs +144 -0
  70. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  71. package/api/theme-edit/theme-edit.type.mjs +1 -1
  72. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  73. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  74. package/api/upgrade/registry/registry.mjs +6 -1
  75. package/assets/codemods/parse.mjs +2 -2
  76. package/assets/docs/tree/single-component.doc.mjs +11 -2
  77. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  78. package/assets/docs.generated.json +2 -2
  79. package/assets/preview-app/next.config.mjs +7 -1
  80. package/assets/preview-app/package.json +1 -0
  81. package/assets/preview-app/src/app/globals.css +1 -0
  82. package/assets/self-audit.generated.json +1 -1
  83. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  84. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  85. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  86. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  87. package/assets/templates/components.generated.json +1 -1
  88. package/assets/templates/pages/dashboard/page.tsx +1 -1
  89. package/authoring/doctypes/_schema.d.mts +52 -5
  90. package/authoring/doctypes/_schema.mjs +62 -7
  91. package/authoring/doctypes/base/type.ts +10 -0
  92. package/authoring/doctypes/component/component.doc.mjs +1 -1
  93. package/authoring/doctypes/function/function.doc.mjs +6 -0
  94. package/authoring/doctypes/function/type.ts +3 -0
  95. package/authoring/doctypes/legacy.mjs +5 -1
  96. package/authoring/index.d.ts +1 -0
  97. package/authoring/shadcn/source-variants.d.mts +1 -1
  98. package/authoring/shadcn/source-variants.mjs +32 -10
  99. package/clients/cli/build-id.generated.json +1 -1
  100. package/clients/cli/commands/doctor.doc.mjs +2 -2
  101. package/clients/cli/commands/experimental/theme.mjs +237 -45
  102. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  103. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  104. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  105. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  106. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  108. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  109. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  110. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  111. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  112. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  113. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  114. package/clients/cli/commands/theme.mjs +190 -46
  115. package/clients/cli/formatters/index.mjs +7 -4
  116. package/clients/cli/lib/cli-error.mjs +9 -3
  117. package/clients/cli/lib/component-format.mjs +27 -9
  118. package/clients/cli/lib/json-shim.mjs +72 -2
  119. package/clients/cli/manifest.generated.json +1 -1
  120. package/clients/cli/run.mjs +49 -0
  121. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  122. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  123. package/foundation/agent-docs/agent-docs.mjs +3 -2
  124. package/foundation/config/config-writer.mjs +2 -2
  125. package/foundation/config/project.mjs +60 -14
  126. package/foundation/discovery/component-discovery.mjs +5 -17
  127. package/foundation/discovery/icon-set-writer.mjs +1 -1
  128. package/foundation/discovery/module-exports.mjs +1 -15
  129. package/foundation/discovery/template-adapter.mjs +44 -19
  130. package/foundation/discovery/template-source-tree.mjs +3 -16
  131. package/foundation/discovery/theme-discovery.d.mts +5 -1
  132. package/foundation/discovery/theme-discovery.mjs +30 -35
  133. package/foundation/fs/exact-codec.d.mts +35 -0
  134. package/foundation/fs/exact-codec.mjs +148 -0
  135. package/foundation/fs/gather-cache.d.mts +15 -5
  136. package/foundation/fs/gather-cache.mjs +123 -30
  137. package/foundation/fs/paths.d.mts +39 -0
  138. package/foundation/fs/paths.mjs +44 -11
  139. package/foundation/fs/read-record.mjs +11 -1
  140. package/foundation/integrations/contribution-fixes.mjs +1 -16
  141. package/foundation/integrations/may-have-integrations.mjs +3 -2
  142. package/foundation/integrations/public-imports.mjs +1 -1
  143. package/foundation/render/embedded-imports.mjs +1 -1
  144. package/foundation/render/host-exit.d.mts +8 -0
  145. package/foundation/render/host-exit.mjs +11 -0
  146. package/foundation/render/page-host.mjs +56 -10
  147. package/foundation/render/page-worker.mjs +14 -0
  148. package/foundation/render/render-page.mjs +37 -2
  149. package/foundation/response/error-codes.d.mts +2 -1
  150. package/foundation/response/error-codes.d.ts +1 -0
  151. package/foundation/response/error-codes.doc.mjs +5 -0
  152. package/foundation/response/error-codes.mjs +3 -0
  153. package/foundation/response/json.d.mts +15 -0
  154. package/foundation/response/json.mjs +52 -1
  155. package/foundation/response/response-types.doc.mjs +1 -1
  156. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  157. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  158. package/foundation/xle/browser.d.mts +2 -2
  159. 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
 
@@ -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');
@@ -12,8 +12,9 @@
12
12
  * so no configured, self-resolved, autolinked or computer-level integration
13
13
  * can load.
14
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
15
+ * `theme` and `discover` record a run only for what is worth keeping where
16
+ * an integration can load (its kept check results, and template
17
+ * discovery's records), so a project with none skips the recorder entirely. A true
17
18
  * answer only means the run records, so a check that says true too often
18
19
  * costs time, never an answer.
19
20
  */
@@ -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
  });
@@ -88,6 +88,7 @@ export function allErrorCodes(): string[];
88
88
  * | 'ERR_WRITE_FAILED'
89
89
  * | 'ERR_THEME_INVALID'
90
90
  * | 'ERR_THEME_LOAD'
91
+ * | 'ERR_THEME_STALE'
91
92
  * | 'ERR_PALETTE_GENERATION'
92
93
  * | 'ERR_VERSION_DETECT'
93
94
  * | 'ERR_INVALID_VERSION'
@@ -133,4 +134,4 @@ export const ERROR_CODES: Readonly<Record<ErrorCode, ErrorCode>>;
133
134
  /**
134
135
  * Stable error-code string union. Append-only.
135
136
  */
136
- export type ErrorCode = ("ERR_UNKNOWN" | "ERR_UNKNOWN_COMMAND" | "ERR_UNKNOWN_SUBCOMMAND" | "ERR_INVALID_OPTION" | "ERR_INVALID_ARGUMENT" | "ERR_MISSING_ARGUMENT" | "ERR_INVALID_LANG" | "ERR_INVALID_DETAIL" | "ERR_NODE_VERSION" | "ERR_CORE_NOT_FOUND" | "ERR_CORE_INCOMPATIBLE" | "ERR_UNKNOWN_COMPONENT" | "ERR_UNKNOWN_HOOK" | "ERR_UNKNOWN_TOPIC" | "ERR_UNKNOWN_SECTION" | "ERR_UNKNOWN_CATEGORY" | "ERR_UNKNOWN_TEMPLATE" | "ERR_AMBIGUOUS_TEMPLATE" | "ERR_AMBIGUOUS_COMPONENT" | "ERR_AMBIGUOUS_THEME" | "ERR_UNKNOWN_THEME" | "ERR_INTEGRATION_ROOT_CONFLICT" | "ERR_INTEGRATION_EXPORT_CONFLICT" | "ERR_UNKNOWN_PACKAGE" | "ERR_UNKNOWN_AGENT" | "ERR_UNKNOWN_FEATURE" | "ERR_UNKNOWN_CODEMOD" | "ERR_CODEMOD_FAILED" | "ERR_CODEMOD_PROTECTED" | "ERR_CODEMOD_PROTECTION_SOURCE" | "ERR_NOT_FOUND" | "ERR_NO_DOC" | "ERR_NO_SHOWCASE" | "ERR_NO_SOURCE" | "ERR_INVALID_DOC" | "ERR_FILE_NOT_FOUND" | "ERR_FILE_EXISTS" | "ERR_PATH_TRAVERSAL" | "ERR_WRITE_FAILED" | "ERR_THEME_INVALID" | "ERR_THEME_LOAD" | "ERR_PALETTE_GENERATION" | "ERR_VERSION_DETECT" | "ERR_INVALID_VERSION" | "ERR_DEP_MISSING" | "ERR_GH_CLI" | "ERR_UNKNOWN_POST" | "ERR_FETCH_FAILED" | "ERR_LAYOUT_PARSE" | "ERR_LAYOUT_INVALID" | "ERR_UNCLASSIFIED_EXIT" | "ERR_SIGNAL_TERMINATED" | "ERR_VERSIONS_UNAVAILABLE" | "ERR_PROJECT_REQUIRED" | "ERR_RENDER_COMPILE" | "ERR_RENDER_NO_DEFAULT_EXPORT" | "ERR_RENDER_MISSING_DEPENDENCY" | "ERR_RENDER_BROWSER_API" | "ERR_RENDER_ASSET_TOO_LARGE" | "ERR_RENDER_TIMEOUT" | "ERR_RENDER_FAILED" | "ERR_RENDER_NOT_ASTRYX" | "ERR_RENDER_SOURCE_DAMAGED" | "ERR_THEME_BAD_VALUE" | "ERR_THEME_NO_MODE" | "ERR_THEME_UNKNOWN_PART" | "ERR_THEME_UNKNOWN_VARIANT" | "ERR_THEME_UNKNOWN_STATE" | "ERR_THEME_PRIVATE_TOKEN" | "ERR_THEME_UNKNOWN_TOKEN" | "ERR_THEME_NO_EFFECT" | "ERR_THEME_NOT_CHECKED" | "ERR_THEME_BUSY" | "ERR_THEME_UNKNOWN_THING" | "ERR_THEME_NOT_SET" | "ERR_THEME_NOTHING_TO_UNDO");
137
+ export type ErrorCode = ("ERR_UNKNOWN" | "ERR_UNKNOWN_COMMAND" | "ERR_UNKNOWN_SUBCOMMAND" | "ERR_INVALID_OPTION" | "ERR_INVALID_ARGUMENT" | "ERR_MISSING_ARGUMENT" | "ERR_INVALID_LANG" | "ERR_INVALID_DETAIL" | "ERR_NODE_VERSION" | "ERR_CORE_NOT_FOUND" | "ERR_CORE_INCOMPATIBLE" | "ERR_UNKNOWN_COMPONENT" | "ERR_UNKNOWN_HOOK" | "ERR_UNKNOWN_TOPIC" | "ERR_UNKNOWN_SECTION" | "ERR_UNKNOWN_CATEGORY" | "ERR_UNKNOWN_TEMPLATE" | "ERR_AMBIGUOUS_TEMPLATE" | "ERR_AMBIGUOUS_COMPONENT" | "ERR_AMBIGUOUS_THEME" | "ERR_UNKNOWN_THEME" | "ERR_INTEGRATION_ROOT_CONFLICT" | "ERR_INTEGRATION_EXPORT_CONFLICT" | "ERR_UNKNOWN_PACKAGE" | "ERR_UNKNOWN_AGENT" | "ERR_UNKNOWN_FEATURE" | "ERR_UNKNOWN_CODEMOD" | "ERR_CODEMOD_FAILED" | "ERR_CODEMOD_PROTECTED" | "ERR_CODEMOD_PROTECTION_SOURCE" | "ERR_NOT_FOUND" | "ERR_NO_DOC" | "ERR_NO_SHOWCASE" | "ERR_NO_SOURCE" | "ERR_INVALID_DOC" | "ERR_FILE_NOT_FOUND" | "ERR_FILE_EXISTS" | "ERR_PATH_TRAVERSAL" | "ERR_WRITE_FAILED" | "ERR_THEME_INVALID" | "ERR_THEME_LOAD" | "ERR_THEME_STALE" | "ERR_PALETTE_GENERATION" | "ERR_VERSION_DETECT" | "ERR_INVALID_VERSION" | "ERR_DEP_MISSING" | "ERR_GH_CLI" | "ERR_UNKNOWN_POST" | "ERR_FETCH_FAILED" | "ERR_LAYOUT_PARSE" | "ERR_LAYOUT_INVALID" | "ERR_UNCLASSIFIED_EXIT" | "ERR_SIGNAL_TERMINATED" | "ERR_VERSIONS_UNAVAILABLE" | "ERR_PROJECT_REQUIRED" | "ERR_RENDER_COMPILE" | "ERR_RENDER_NO_DEFAULT_EXPORT" | "ERR_RENDER_MISSING_DEPENDENCY" | "ERR_RENDER_BROWSER_API" | "ERR_RENDER_ASSET_TOO_LARGE" | "ERR_RENDER_TIMEOUT" | "ERR_RENDER_FAILED" | "ERR_RENDER_NOT_ASTRYX" | "ERR_RENDER_SOURCE_DAMAGED" | "ERR_THEME_BAD_VALUE" | "ERR_THEME_NO_MODE" | "ERR_THEME_UNKNOWN_PART" | "ERR_THEME_UNKNOWN_VARIANT" | "ERR_THEME_UNKNOWN_STATE" | "ERR_THEME_PRIVATE_TOKEN" | "ERR_THEME_UNKNOWN_TOKEN" | "ERR_THEME_NO_EFFECT" | "ERR_THEME_NOT_CHECKED" | "ERR_THEME_BUSY" | "ERR_THEME_UNKNOWN_THING" | "ERR_THEME_NOT_SET" | "ERR_THEME_NOTHING_TO_UNDO");
@@ -47,6 +47,7 @@ export type ErrorCode =
47
47
  | 'ERR_WRITE_FAILED'
48
48
  | 'ERR_THEME_INVALID'
49
49
  | 'ERR_THEME_LOAD'
50
+ | 'ERR_THEME_STALE'
50
51
  | 'ERR_VERSION_DETECT'
51
52
  | 'ERR_INVALID_VERSION'
52
53
  | 'ERR_DEP_MISSING'
@@ -219,6 +219,11 @@ export const doc = {
219
219
  description:
220
220
  'A theme file could not be loaded / parsed into a defineTheme result.',
221
221
  },
222
+ {
223
+ value: 'ERR_THEME_STALE',
224
+ description:
225
+ '`theme build --check` found stale or missing outputs: exit 1, in the check result (`code`), not an error.',
226
+ },
222
227
  {
223
228
  value: 'ERR_PALETTE_GENERATION',
224
229
  description:
@@ -77,6 +77,7 @@
77
77
  * | 'ERR_WRITE_FAILED'
78
78
  * | 'ERR_THEME_INVALID'
79
79
  * | 'ERR_THEME_LOAD'
80
+ * | 'ERR_THEME_STALE'
80
81
  * | 'ERR_PALETTE_GENERATION'
81
82
  * | 'ERR_VERSION_DETECT'
82
83
  * | 'ERR_INVALID_VERSION'
@@ -219,6 +220,8 @@ export const ERROR_CODES = Object.freeze({
219
220
  ERR_THEME_INVALID: 'ERR_THEME_INVALID',
220
221
  /** A theme file could not be loaded / parsed into a defineTheme result. */
221
222
  ERR_THEME_LOAD: 'ERR_THEME_LOAD',
223
+ /** `--check` found built outputs stale or missing (a result, exit 1). */
224
+ ERR_THEME_STALE: 'ERR_THEME_STALE',
222
225
 
223
226
  // ── Palette generation ──────────────────────────────────────────
224
227
  /** A palette generation request or its constraints were invalid. */
@@ -84,4 +84,19 @@ export function toErrorEnvelope(err: unknown, suggestions?: import("./base").Sug
84
84
  * done before it failed (see toErrorEnvelope).
85
85
  */
86
86
  export function jsonError(message: string, suggestions?: import("./base").Suggestion[], code?: string, receipt?: Record<string, unknown>): void;
87
+ /**
88
+ * Whether the output on `fd` is captured in process: the console method or
89
+ * the stream's write replaced since this module loaded (a test).
90
+ * @param {number} fd
91
+ */
92
+ export function outputCaptured(fd: number): boolean;
93
+ /**
94
+ * Write `text` to a file descriptor whole, synchronously, waiting while a
95
+ * full pipe drains (a non-blocking pipe answers EAGAIN until its reader
96
+ * reads). Used for a command's last output before it exits, so nothing is
97
+ * lost however slowly the output is read.
98
+ * @param {number} fd 1 (stdout) or 2 (stderr)
99
+ * @param {string} text
100
+ */
101
+ export function writeAllSync(fd: number, text: string): void;
87
102
  export const API_VERSION: 1;
@@ -31,6 +31,7 @@
31
31
  import {ERROR_CODES, isErrorCode} from './error-codes.mjs';
32
32
  import {recordEnvelope, setOutcome} from '../debug/index.mjs';
33
33
  import {answeredBy} from '../release/run-context.mjs';
34
+ import * as fs from 'node:fs';
34
35
 
35
36
  export const API_VERSION = 1;
36
37
 
@@ -171,6 +172,56 @@ export function jsonError(message, suggestions, code, receipt) {
171
172
  const err = toErrorEnvelope(message, suggestions, code, receipt);
172
173
  // No-op when cliError already classified this failure — first outcome wins.
173
174
  setOutcome('error', {exitCode: 1, error: new Error(message), code: err.code});
174
- console.log(JSON.stringify(err, null, 2));
175
+ // Written whole before the exit: a process that exits with output still
176
+ // queued for a pipe (a slow reader, bash `$(…)`) loses all but the first
177
+ // 64 KiB, and a --json caller gets invalid JSON.
178
+ writeAllSync(1, `${JSON.stringify(err, null, 2)}\n`);
175
179
  process.exit(1);
176
180
  }
181
+
182
+ const CONSOLE_LOG = console.log;
183
+ const CONSOLE_ERROR = console.error;
184
+
185
+ /**
186
+ * Whether the output on `fd` is captured in process: the console method or
187
+ * the stream's write replaced since this module loaded (a test).
188
+ * @param {number} fd
189
+ */
190
+ export function outputCaptured(fd) {
191
+ const stream = fd === 2 ? process.stderr : process.stdout;
192
+ return (
193
+ Object.hasOwn(stream, 'write') ||
194
+ (fd === 2 ? console.error !== CONSOLE_ERROR : console.log !== CONSOLE_LOG)
195
+ );
196
+ }
197
+
198
+ /**
199
+ * Write `text` to a file descriptor whole, synchronously, waiting while a
200
+ * full pipe drains (a non-blocking pipe answers EAGAIN until its reader
201
+ * reads). Used for a command's last output before it exits, so nothing is
202
+ * lost however slowly the output is read.
203
+ * @param {number} fd 1 (stdout) or 2 (stderr)
204
+ * @param {string} text
205
+ */
206
+ export function writeAllSync(fd, text) {
207
+ // Output captured in process (a test replaced the console or the
208
+ // stream's write) keeps going through what captures it.
209
+ if (outputCaptured(fd)) {
210
+ (fd === 2 ? console.error : console.log)(text.replace(/\n$/, ''));
211
+ return;
212
+ }
213
+ const buf = Buffer.from(text, 'utf8');
214
+ const pause = new Int32Array(new SharedArrayBuffer(4));
215
+ let off = 0;
216
+ while (off < buf.length) {
217
+ try {
218
+ off += fs.writeSync(fd, buf, off, buf.length - off);
219
+ } catch (e) {
220
+ const code = /** @type {any} */ (e)?.code;
221
+ // A full pipe: wait a moment for its reader, then write the rest.
222
+ if (code === 'EAGAIN') Atomics.wait(pause, 0, 0, 5);
223
+ // The reader is gone (EPIPE) or the fd is closed: nothing to keep.
224
+ else return;
225
+ }
226
+ }
227
+ }
@@ -386,7 +386,7 @@ export const doc = {
386
386
  {
387
387
  value: 'theme.build.check',
388
388
  description:
389
- 'The --check receipt: theme name, an upToDate flag, the stale outputs (each {path, reason: missing | outdated}), and the full list of checked paths. Writes nothing.',
389
+ 'The --check receipt: theme name, an upToDate flag, the stale outputs (each {path, reason: missing | outdated}), the full list of checked paths, and, when any is stale or missing, code ERR_THEME_STALE. Writes nothing.',
390
390
  },
391
391
  {
392
392
  value: 'theme.build.batch',
@@ -0,0 +1,14 @@
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 function babelParser(): typeof import("@babel/parser");
5
+ /** @type {typeof import('@babel/parser').parse} */
6
+ export const babelParse: typeof import("@babel/parser").parse;
7
+ export function babelCore(): typeof import("@babel/core");
8
+ export function jscodeshift(): any;
9
+ export function selectorParser(): typeof import("postcss-selector-parser");
10
+ /**
11
+ * Every package loaded on first use, here and in the ShadCN source variants,
12
+ * for the test that each resolves to one file either way.
13
+ */
14
+ export const LAZY_PACKAGES: string[];