@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e
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.
- package/README.md +5 -3
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/pack-check.mjs +13 -7
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +64 -27
- package/api/theme/build/build.mjs +341 -69
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +33 -0
- package/api/theme-edit/_adapter.mjs +208 -31
- package/api/theme-edit/_check.d.mts +38 -0
- package/api/theme-edit/_check.mjs +1326 -211
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +29 -0
- package/api/theme-edit/_context.mjs +329 -30
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +1025 -126
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +11 -0
- package/api/theme-edit/_palette.mjs +194 -65
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +59 -7
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.d.mts +3 -0
- package/api/theme-edit/_preview-app.mjs +843 -45
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +310 -29
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +178 -5
- package/api/theme-edit/_settings.mjs +2035 -86
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +211 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/package.json +1 -0
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/dashboard/page.tsx +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +190 -37
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +168 -45
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +40 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/config/project.mjs +50 -14
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +24 -3
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +79 -15
- package/foundation/fs/paths.d.mts +31 -0
- package/foundation/fs/paths.mjs +43 -10
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +7 -6
|
@@ -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
|
|
14
|
-
* {hostExit
|
|
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 (
|
|
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
|
-
|
|
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(() =>
|
|
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.
|
|
43
|
-
worker.
|
|
44
|
-
|
|
45
|
-
|
|
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(
|
|
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(
|
|
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");
|
|
@@ -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
|
-
|
|
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}),
|
|
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',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.16-canary.g54dd64e",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -111,6 +111,7 @@
|
|
|
111
111
|
"@babel/parser": "7.29.8",
|
|
112
112
|
"@babel/plugin-transform-typescript": "7.29.7",
|
|
113
113
|
"@babel/types": "7.29.8",
|
|
114
|
+
"@csstools/css-syntax-patches-for-csstree": "1.1.6",
|
|
114
115
|
"@stylexjs/babel-plugin": "^0.19.1",
|
|
115
116
|
"ast-types": "0.16.3",
|
|
116
117
|
"commander": "^12.1.0",
|
|
@@ -126,7 +127,7 @@
|
|
|
126
127
|
"zod": "^4.6.7"
|
|
127
128
|
},
|
|
128
129
|
"peerDependencies": {
|
|
129
|
-
"@astryxdesign/core": "
|
|
130
|
+
"@astryxdesign/core": "0.7.16-canary.g54dd64e"
|
|
130
131
|
},
|
|
131
132
|
"peerDependenciesMeta": {
|
|
132
133
|
"@astryxdesign/core": {
|
|
@@ -134,10 +135,10 @@
|
|
|
134
135
|
}
|
|
135
136
|
},
|
|
136
137
|
"devDependencies": {
|
|
137
|
-
"@astryxdesign/charts": "
|
|
138
|
-
"@astryxdesign/core": "
|
|
139
|
-
"@astryxdesign/lab": "
|
|
140
|
-
"@astryxdesign/theme-neutral": "
|
|
138
|
+
"@astryxdesign/charts": "0.7.16-canary.g54dd64e",
|
|
139
|
+
"@astryxdesign/core": "0.7.16-canary.g54dd64e",
|
|
140
|
+
"@astryxdesign/lab": "0.7.16-canary.g54dd64e",
|
|
141
|
+
"@astryxdesign/theme-neutral": "0.7.16-canary.g54dd64e",
|
|
141
142
|
"@heroicons/react": "^2.2.0",
|
|
142
143
|
"@stylexjs/stylex": "^0.19.1",
|
|
143
144
|
"@types/babel__core": "^7.20.5",
|