@astryxdesign/cli 0.7.10 → 0.7.11-canary.143a5de
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/api/build/blocks/blocks.weights.json +1 -1
- package/api/build/build.doc.mjs +1 -1
- package/api/build/kit/rank.mjs +21 -4
- package/api/build/kit/signals.mjs +9 -3
- package/api/build/kit/start.d.mts +19 -0
- package/api/build/kit/start.mjs +49 -2
- package/api/build/kit/weights.d.mts +12 -0
- package/api/build/kit/weights.mjs +52 -16
- package/api/build/kit/words.d.mts +1 -0
- package/api/build/kit/words.mjs +1 -1
- package/api/docs/_adapter.mjs +2 -1
- package/api/doctor/_adapter.d.mts +28 -1
- package/api/doctor/_adapter.mjs +39 -2
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +9 -2
- package/api/doctor/theme-checks.d.mts +44 -3
- package/api/doctor/theme-checks.mjs +273 -6
- package/api/hook/hook.mjs +13 -0
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +8 -2
- package/api/icon/_authoring.d.mts +1 -0
- package/api/icon/_authoring.mjs +362 -38
- package/api/icon/_default-look.d.mts +155 -0
- package/api/icon/_default-look.mjs +474 -0
- package/api/icon/_records.d.mts +1 -1
- package/api/icon/_records.mjs +1 -0
- package/api/icon/add/add.mjs +224 -38
- package/api/icon/icon.type.d.mts +7 -2
- package/api/icon/icon.type.mjs +4 -2
- package/api/icon/iconAdd.doc.mjs +2 -2
- package/api/icon/iconNewDefinition.doc.mjs +3 -2
- package/api/icon/iconNewSet.doc.mjs +4 -4
- package/api/icon/search/search.mjs +10 -9
- package/api/integration/add-helpers.d.mts +2 -1
- package/api/integration/add-helpers.mjs +5 -2
- package/api/integration/authoring-checks.d.mts +0 -2
- package/api/integration/authoring-checks.mjs +1 -6
- package/api/integration/pack-check.d.mts +8 -6
- package/api/integration/pack-check.mjs +16 -6
- package/api/logger.mjs +2 -1
- package/api/render/_adapter.mjs +47 -1
- package/api/render/render.doc.mjs +2 -1
- package/api/search/_gather-components.mjs +2 -1
- package/api/swizzle/copy/copy.mjs +5 -1
- package/api/theme/build/build.mjs +15 -4
- package/assets/docs/author-a-theme.doc.mjs +2 -0
- package/assets/docs/getting-started.doc.mjs +20 -0
- package/assets/docs/tree/building-blocks.doc.mjs +1 -0
- package/assets/docs/tree/global-integrations.doc.mjs +1 -0
- package/assets/docs/tree/help.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +9 -3
- package/assets/docs/tree/quick-start.doc.mjs +1 -0
- package/assets/docs/tree/render-pages.doc.mjs +1 -1
- package/assets/docs/tree/ship.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +2 -2
- package/assets/templates/blocks/components/Table/TableLeadingMarkSelection.doc.mjs +15 -0
- package/assets/templates/blocks/components/Table/TableLeadingMarkSelection.tsx +134 -0
- package/assets/templates/pages/theme-showcase/page.tsx +724 -792
- package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
- package/authoring/doctypes/_schema.d.mts +1 -1
- package/clients/cli/commands/build.doc.mjs +3 -2
- package/clients/cli/commands/build.mjs +34 -5
- package/clients/cli/commands/experimental/icon.mjs +31 -10
- package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
- package/clients/cli/index.mjs +36 -7
- package/foundation/discovery/authoring-self-docs.mjs +8 -3
- package/foundation/discovery/cli-self-docs.mjs +2 -1
- package/foundation/discovery/component-discovery.mjs +16 -0
- package/foundation/discovery/doc-types.mjs +9 -2
- package/foundation/discovery/docs-discovery.mjs +6 -4
- package/foundation/discovery/icon-definition-discovery.mjs +3 -3
- package/foundation/discovery/icon-ranking.d.mts +27 -3
- package/foundation/discovery/icon-ranking.mjs +125 -8
- package/foundation/discovery/icon-set-checks.mjs +40 -20
- package/foundation/discovery/icon-set-writer.d.mts +210 -16
- package/foundation/discovery/icon-set-writer.mjs +619 -79
- package/foundation/discovery/module-exports.d.mts +92 -4
- package/foundation/discovery/module-exports.mjs +410 -61
- package/foundation/discovery/template-adapter.mjs +5 -7
- package/foundation/discovery/theme-discovery.mjs +8 -10
- package/foundation/doc-compiler/tree.mjs +2 -2
- package/foundation/env/package-manager.d.mts +12 -4
- package/foundation/env/package-manager.mjs +15 -6
- package/foundation/env/semver.mjs +41 -9
- package/foundation/fs/listing-cache.d.mts +3 -1
- package/foundation/fs/listing-cache.mjs +63 -11
- package/foundation/fs/paths.mjs +2 -1
- package/foundation/release/notices.d.mts +16 -0
- package/foundation/release/notices.mjs +27 -6
- package/foundation/render/embedded-imports.d.mts +7 -0
- package/foundation/render/embedded-imports.mjs +1 -1
- package/foundation/render/page-worker.mjs +109 -4
- package/foundation/render/render-page.d.mts +16 -1
- package/foundation/render/render-page.mjs +25 -18
- package/foundation/render/served-packages.d.mts +33 -0
- package/foundation/render/served-packages.mjs +75 -0
- package/foundation/render/single-copy-hooks.d.mts +18 -0
- package/foundation/render/single-copy-hooks.mjs +44 -0
- package/foundation/text/shell-arg.d.mts +14 -0
- package/foundation/text/shell-arg.mjs +17 -0
- package/foundation/text/string-utils.mjs +25 -25
- package/package.json +6 -6
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
* It runs in a worker thread so a page that never finishes rendering can be
|
|
9
9
|
* stopped, and so nothing the page prints reaches the CLI's own output.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* Outside a project, the Astryx packages the page's folder lacks resolve
|
|
12
|
+
* from the package set the CLI runs from (served-packages.mjs), and React and
|
|
13
|
+
* StyleX always come from that set, so the page loads one copy of each.
|
|
14
|
+
*
|
|
15
|
+
* @input workerData {entry, root, served}
|
|
12
16
|
* @output one message: {ok: true, markup, css, files, texts, logs} or
|
|
13
17
|
* {ok: false, error: {code, message, detail?}}
|
|
14
18
|
* @position foundation/render — started by render-page.mjs
|
|
@@ -16,17 +20,23 @@
|
|
|
16
20
|
|
|
17
21
|
import * as fs from 'node:fs';
|
|
18
22
|
import * as path from 'node:path';
|
|
19
|
-
import {createRequire} from 'node:module';
|
|
23
|
+
import Module, {createRequire, register} from 'node:module';
|
|
24
|
+
import {pathToFileURL} from 'node:url';
|
|
20
25
|
import {format} from 'node:util';
|
|
21
26
|
import {parentPort, workerData} from 'node:worker_threads';
|
|
22
27
|
import {transformSync} from '@babel/core';
|
|
23
28
|
import {createJiti} from 'jiti';
|
|
24
29
|
import {assetDataUri, isAssetPath} from './assets.mjs';
|
|
30
|
+
import {SINGLE_COPY, isServedPackage, packageOf} from './served-packages.mjs';
|
|
31
|
+
import {findNodeModulesPackage} from '../fs/paths.mjs';
|
|
25
32
|
|
|
26
33
|
/** @typedef {{level: string, text: string}} PageLog */
|
|
27
34
|
|
|
28
|
-
/** @type {{entry: string, root: string}} */
|
|
35
|
+
/** @type {{entry: string, root: string, served: {dir: string, integrations: string[]} | null}} */
|
|
29
36
|
const {entry, root} = workerData;
|
|
37
|
+
|
|
38
|
+
/** The package set, for a page outside a project whose folder has no Core of its own. */
|
|
39
|
+
const served = workerData.served && findNodeModulesPackage(path.dirname(entry), '@astryxdesign/core') === null ? workerData.served : null;
|
|
30
40
|
const ROOT_PREFIX = root.endsWith(path.sep) ? root : root + path.sep;
|
|
31
41
|
|
|
32
42
|
/** @type {PageLog[]} */
|
|
@@ -348,6 +358,96 @@ const resolveAlias = spec => {
|
|
|
348
358
|
return spec;
|
|
349
359
|
};
|
|
350
360
|
|
|
361
|
+
/** Packages the page took from the package set, by name: their folders. */
|
|
362
|
+
/** @type {Map<string, string>} */
|
|
363
|
+
const fromSet = new Map();
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The folder of the package that holds `file`.
|
|
367
|
+
* @param {string} file
|
|
368
|
+
* @param {string} name
|
|
369
|
+
* @returns {string}
|
|
370
|
+
*/
|
|
371
|
+
function packageDirOf(file, name) {
|
|
372
|
+
for (let d = path.dirname(file); path.dirname(d) !== d; d = path.dirname(d)) {
|
|
373
|
+
try {
|
|
374
|
+
if (JSON.parse(fs.readFileSync(path.join(d, 'package.json'), 'utf8')).name === name) return d;
|
|
375
|
+
} catch {
|
|
376
|
+
// No package.json here, or one that does not parse: look further up.
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return path.dirname(file);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const moduleApi = /** @type {any} */ (Module);
|
|
383
|
+
|
|
384
|
+
/** A module at the served Core's folder: what resolves as the Core would. */
|
|
385
|
+
const servedParent = served ? new moduleApi(path.join(served.dir, 'package.json')) : null;
|
|
386
|
+
if (servedParent && served) {
|
|
387
|
+
servedParent.filename = servedParent.id;
|
|
388
|
+
servedParent.paths = moduleApi._nodeModulePaths(served.dir);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* When the page's folder has no copy of a served package, take the one the
|
|
393
|
+
* package set holds. Node's resolver keeps each package's `exports`.
|
|
394
|
+
*/
|
|
395
|
+
function serveFromSet() {
|
|
396
|
+
if (!served || !servedParent) return;
|
|
397
|
+
const resolveFilename = moduleApi._resolveFilename;
|
|
398
|
+
moduleApi._resolveFilename = function (/** @type {string} */ request, /** @type {any[]} */ ...rest) {
|
|
399
|
+
// React, React DOM and StyleX come from the set for every module, a
|
|
400
|
+
// library in the page's folder included, so the page runs on one copy.
|
|
401
|
+
if (!request.startsWith('.') && !path.isAbsolute(request) && packageOf(request) in SINGLE_COPY_ALIASES) {
|
|
402
|
+
try {
|
|
403
|
+
return resolveFilename.call(this, request, servedParent, false);
|
|
404
|
+
} catch {
|
|
405
|
+
// The set has no such file: the importer's own copy serves.
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
return resolveFilename.call(this, request, ...rest);
|
|
410
|
+
} catch (e) {
|
|
411
|
+
const name = /** @type {any} */ (e)?.code === 'MODULE_NOT_FOUND' && !request.startsWith('.') && !path.isAbsolute(request)
|
|
412
|
+
? packageOf(request)
|
|
413
|
+
: null;
|
|
414
|
+
if (!name || !isServedPackage(name, served.integrations)) throw e;
|
|
415
|
+
const file = resolveFilename.call(this, request, servedParent, false);
|
|
416
|
+
if (!fromSet.has(name)) fromSet.set(name, packageDirOf(file, name));
|
|
417
|
+
return file;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* React and StyleX keep state per copy, and the packages from the set load
|
|
424
|
+
* the set's copy. So outside a project the page's own modules load that copy
|
|
425
|
+
* too, even when its folder holds another one.
|
|
426
|
+
* @returns {Record<string, string>}
|
|
427
|
+
*/
|
|
428
|
+
function singleCopyAliases() {
|
|
429
|
+
/** @type {Record<string, string>} */
|
|
430
|
+
const alias = {};
|
|
431
|
+
if (!servedParent) return alias;
|
|
432
|
+
for (const name of SINGLE_COPY) {
|
|
433
|
+
try {
|
|
434
|
+
alias[name] = path.dirname(moduleApi._resolveFilename(`${name}/package.json`, servedParent, false));
|
|
435
|
+
} catch {
|
|
436
|
+
// The set has no copy: the page's own copy, if any, serves.
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return alias;
|
|
440
|
+
}
|
|
441
|
+
const SINGLE_COPY_ALIASES = singleCopyAliases();
|
|
442
|
+
serveFromSet();
|
|
443
|
+
// ES modules follow the same rule through resolve hooks (CommonJS goes
|
|
444
|
+
// through serveFromSet).
|
|
445
|
+
if (servedParent && Object.keys(SINGLE_COPY_ALIASES).length > 0) {
|
|
446
|
+
register(new URL('./single-copy-hooks.mjs', import.meta.url), {
|
|
447
|
+
data: {parent: pathToFileURL(servedParent.filename).href, names: Object.keys(SINGLE_COPY_ALIASES)},
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
351
451
|
const plain = createJiti(entry, {fsCache: false, jsx: {runtime: 'automatic'}});
|
|
352
452
|
|
|
353
453
|
const jiti = createJiti(entry, {
|
|
@@ -356,7 +456,7 @@ const jiti = createJiti(entry, {
|
|
|
356
456
|
extensions: ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx', '.mts', '.cts', '.json'],
|
|
357
457
|
moduleCache: true,
|
|
358
458
|
interopDefault: true,
|
|
359
|
-
alias: ALIASES,
|
|
459
|
+
alias: {...SINGLE_COPY_ALIASES, ...ALIASES},
|
|
360
460
|
jsx: {runtime: 'automatic'},
|
|
361
461
|
transform(opts) {
|
|
362
462
|
const filename = opts.filename ?? '';
|
|
@@ -495,6 +595,10 @@ try {
|
|
|
495
595
|
classify(e);
|
|
496
596
|
throw null;
|
|
497
597
|
}
|
|
598
|
+
// The render always runs on React; StyleX only when the page uses it.
|
|
599
|
+
for (const [name, dir] of Object.entries(SINGLE_COPY_ALIASES)) {
|
|
600
|
+
if (name !== '@stylexjs/stylex' || packages.has(name)) fromSet.set(name, dir);
|
|
601
|
+
}
|
|
498
602
|
/** @type {string} */
|
|
499
603
|
let css = '';
|
|
500
604
|
if (stylexRules.length > 0) {
|
|
@@ -508,6 +612,7 @@ try {
|
|
|
508
612
|
packages: [...packages],
|
|
509
613
|
packageCss,
|
|
510
614
|
skippedCss,
|
|
615
|
+
fromSet: [...fromSet].map(([name, dir]) => ({name, dir})),
|
|
511
616
|
assets: [...assetsInlined],
|
|
512
617
|
files: localFiles,
|
|
513
618
|
texts,
|
|
@@ -4,13 +4,16 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* Render a page module to one self-contained HTML file.
|
|
6
6
|
* @param {string} entry absolute path of the page module
|
|
7
|
-
* @param {{title?: string, timeoutMs?: number, version?: string}} [options]
|
|
7
|
+
* @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null}} [options]
|
|
8
|
+
* `served`: the Core of the package set the CLI runs from, for the packages
|
|
9
|
+
* the page's folder has no copy of
|
|
8
10
|
* @returns {Promise<RenderedPage>}
|
|
9
11
|
*/
|
|
10
12
|
export function renderPage(entry: string, options?: {
|
|
11
13
|
title?: string;
|
|
12
14
|
timeoutMs?: number;
|
|
13
15
|
version?: string;
|
|
16
|
+
served?: ServedSet | null;
|
|
14
17
|
}): Promise<RenderedPage>;
|
|
15
18
|
/** How long one page may take to render before it is stopped. */
|
|
16
19
|
export const RENDER_TIMEOUT_MS: 60000;
|
|
@@ -30,6 +33,7 @@ export { PAGE_EXTENSIONS } from "./embedded-files.mjs";
|
|
|
30
33
|
* @property {number} markupBytes - Bytes of rendered markup.
|
|
31
34
|
* @property {number} images - Local files inlined as data: URIs.
|
|
32
35
|
* @property {RenderWarning[]} warnings
|
|
36
|
+
* @property {{name: string, dir: string}[]} fromSet - Packages that came from the package set the CLI runs from, not the page's folder.
|
|
33
37
|
*/
|
|
34
38
|
/** An error carrying a render error code. */
|
|
35
39
|
export class RenderError extends Error {
|
|
@@ -42,6 +46,10 @@ export class RenderError extends Error {
|
|
|
42
46
|
code: string;
|
|
43
47
|
detail: Record<string, unknown> | undefined;
|
|
44
48
|
}
|
|
49
|
+
export type ServedSet = {
|
|
50
|
+
dir: string;
|
|
51
|
+
integrations: readonly string[];
|
|
52
|
+
};
|
|
45
53
|
export type RenderWarning = {
|
|
46
54
|
/**
|
|
47
55
|
* - What kind of problem.
|
|
@@ -82,4 +90,11 @@ export type RenderedPage = {
|
|
|
82
90
|
*/
|
|
83
91
|
images: number;
|
|
84
92
|
warnings: RenderWarning[];
|
|
93
|
+
/**
|
|
94
|
+
* - Packages that came from the package set the CLI runs from, not the page's folder.
|
|
95
|
+
*/
|
|
96
|
+
fromSet: {
|
|
97
|
+
name: string;
|
|
98
|
+
dir: string;
|
|
99
|
+
}[];
|
|
85
100
|
};
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
|
|
19
19
|
import * as fs from 'node:fs';
|
|
20
20
|
import * as path from 'node:path';
|
|
21
|
-
import {createRequire} from 'node:module';
|
|
22
21
|
import {Worker} from 'node:worker_threads';
|
|
23
22
|
import postcss from 'postcss';
|
|
24
23
|
import {assetDataUri, isAssetBytes, isAssetPath, RenderAssetError} from './assets.mjs';
|
|
25
24
|
import {classesIn, cutCss, layerOrderOf} from './css-cut.mjs';
|
|
26
25
|
import {sourceBlock} from './source-block.mjs';
|
|
27
26
|
import {embeddedPathProblem} from './embedded-files.mjs';
|
|
27
|
+
import {resolveServed} from './served-packages.mjs';
|
|
28
28
|
|
|
29
29
|
/** How long one page may take to render before it is stopped. */
|
|
30
30
|
export const RENDER_TIMEOUT_MS = 60_000;
|
|
@@ -47,6 +47,7 @@ export {PAGE_EXTENSIONS} from './embedded-files.mjs';
|
|
|
47
47
|
* @property {number} markupBytes - Bytes of rendered markup.
|
|
48
48
|
* @property {number} images - Local files inlined as data: URIs.
|
|
49
49
|
* @property {RenderWarning[]} warnings
|
|
50
|
+
* @property {{name: string, dir: string}[]} fromSet - Packages that came from the package set the CLI runs from, not the page's folder.
|
|
50
51
|
*/
|
|
51
52
|
|
|
52
53
|
/** An error carrying a render error code. */
|
|
@@ -128,7 +129,7 @@ function importParams(params) {
|
|
|
128
129
|
* cut.
|
|
129
130
|
* @param {string} file the stylesheet's own path
|
|
130
131
|
* @param {string} css its text
|
|
131
|
-
* @param {{warnings: RenderWarning[], carried: Set<string>, included: Set<string>, packageSheets: string[], seen?: Set<string>}} ctx
|
|
132
|
+
* @param {{warnings: RenderWarning[], carried: Set<string>, included: Set<string>, packageSheets: string[], served: ServedSet | null, seen?: Set<string>}} ctx
|
|
132
133
|
* `included`: stylesheet files already in the page (Core's, say), never
|
|
133
134
|
* inlined twice; `packageSheets`: package stylesheets this pulled in
|
|
134
135
|
* @returns {string}
|
|
@@ -170,12 +171,8 @@ function expandImports(file, css, ctx) {
|
|
|
170
171
|
if (/^\.{1,2}\//.test(url) || fs.existsSync(relative)) {
|
|
171
172
|
target = fs.existsSync(relative) ? relative : null;
|
|
172
173
|
} else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
fromPackage = true;
|
|
176
|
-
} catch {
|
|
177
|
-
target = null;
|
|
178
|
-
}
|
|
174
|
+
target = resolveServed(url.replace(/^~/, ''), file, ctx.served);
|
|
175
|
+
fromPackage = target !== null;
|
|
179
176
|
}
|
|
180
177
|
if (!target) {
|
|
181
178
|
ctx.warnings.push({
|
|
@@ -221,17 +218,20 @@ function expandImports(file, css, ctx) {
|
|
|
221
218
|
return root.toString();
|
|
222
219
|
}
|
|
223
220
|
|
|
221
|
+
/** @typedef {{dir: string, integrations: readonly string[]}} ServedSet */
|
|
222
|
+
|
|
224
223
|
/**
|
|
225
224
|
* Run the page in a worker, stopping it after `timeoutMs`.
|
|
226
225
|
* @param {string} entry
|
|
227
226
|
* @param {string} root
|
|
228
227
|
* @param {number} timeoutMs
|
|
228
|
+
* @param {ServedSet | null} served
|
|
229
229
|
* @returns {Promise<any>}
|
|
230
230
|
*/
|
|
231
|
-
function runWorker(entry, root, timeoutMs) {
|
|
231
|
+
function runWorker(entry, root, timeoutMs, served) {
|
|
232
232
|
return new Promise((resolve, reject) => {
|
|
233
233
|
const worker = new Worker(new URL('./page-worker.mjs', import.meta.url), {
|
|
234
|
-
workerData: {entry, root},
|
|
234
|
+
workerData: {entry, root, served: served ? {dir: served.dir, integrations: [...served.integrations]} : null},
|
|
235
235
|
execArgv: [],
|
|
236
236
|
stdout: true,
|
|
237
237
|
stderr: true,
|
|
@@ -361,13 +361,16 @@ const SCHEME_CSS =
|
|
|
361
361
|
/**
|
|
362
362
|
* Render a page module to one self-contained HTML file.
|
|
363
363
|
* @param {string} entry absolute path of the page module
|
|
364
|
-
* @param {{title?: string, timeoutMs?: number, version?: string}} [options]
|
|
364
|
+
* @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null}} [options]
|
|
365
|
+
* `served`: the Core of the package set the CLI runs from, for the packages
|
|
366
|
+
* the page's folder has no copy of
|
|
365
367
|
* @returns {Promise<RenderedPage>}
|
|
366
368
|
*/
|
|
367
369
|
export async function renderPage(entry, options = {}) {
|
|
368
370
|
const dir = path.dirname(entry);
|
|
369
371
|
const root = projectRootOf(dir);
|
|
370
|
-
const
|
|
372
|
+
const served = options.served ?? null;
|
|
373
|
+
const message = await runWorker(entry, root, options.timeoutMs ?? RENDER_TIMEOUT_MS, served);
|
|
371
374
|
/** @type {RenderWarning[]} */
|
|
372
375
|
const warnings = [];
|
|
373
376
|
if (!message.ok) {
|
|
@@ -378,7 +381,6 @@ export async function renderPage(entry, options = {}) {
|
|
|
378
381
|
|
|
379
382
|
// Stylesheets: Core's reset and components, plus each official package's
|
|
380
383
|
// own stylesheet the page imports from.
|
|
381
|
-
const req = createRequire(entry);
|
|
382
384
|
/** @type {string[]} */
|
|
383
385
|
const sheets = [];
|
|
384
386
|
/** @type {string[]} */
|
|
@@ -388,7 +390,8 @@ export async function renderPage(entry, options = {}) {
|
|
|
388
390
|
/** @param {string} spec */
|
|
389
391
|
const addSheet = spec => {
|
|
390
392
|
try {
|
|
391
|
-
const file =
|
|
393
|
+
const file = resolveServed(spec, entry, served);
|
|
394
|
+
if (!file) return false;
|
|
392
395
|
sheets.push(spec);
|
|
393
396
|
sheetText.push(fs.readFileSync(file, 'utf8'));
|
|
394
397
|
sheetFiles.push(file);
|
|
@@ -402,8 +405,9 @@ export async function renderPage(entry, options = {}) {
|
|
|
402
405
|
// Package stylesheets the page imports itself, such as a theme's.
|
|
403
406
|
for (const {spec, from} of /** @type {{spec: string, from: string}[]} */ (message.packageCss ?? [])) {
|
|
404
407
|
if (sheets.includes(spec)) continue;
|
|
408
|
+
const file = resolveServed(spec, from, served);
|
|
405
409
|
try {
|
|
406
|
-
|
|
410
|
+
if (!file) throw new Error('not found');
|
|
407
411
|
sheets.push(spec);
|
|
408
412
|
sheetText.push(fs.readFileSync(file, 'utf8'));
|
|
409
413
|
sheetFiles.push(file);
|
|
@@ -422,8 +426,10 @@ export async function renderPage(entry, options = {}) {
|
|
|
422
426
|
if (!hasCore) {
|
|
423
427
|
warnings.push({
|
|
424
428
|
code: 'no-astryx-styles',
|
|
425
|
-
|
|
426
|
-
|
|
429
|
+
// Outside a project the page would have taken the CLI's own Core.
|
|
430
|
+
message: served
|
|
431
|
+
? '@astryxdesign/core is not installed where the page is, and the CLI runs without one, so the page has no Astryx styles; install it, or render from inside the project.'
|
|
432
|
+
: '@astryxdesign/core is not installed where the page is, so the page has no Astryx styles; install it, or render from inside the project.',
|
|
427
433
|
});
|
|
428
434
|
}
|
|
429
435
|
|
|
@@ -468,7 +474,7 @@ export async function renderPage(entry, options = {}) {
|
|
|
468
474
|
/** A stylesheet's rules cut to the page, with its own imports inlined. @param {string} file @param {string} text */
|
|
469
475
|
const sheet = (file, text) => {
|
|
470
476
|
try {
|
|
471
|
-
const own = expandImports(file, text, {warnings, carried: carriedCss, included, packageSheets});
|
|
477
|
+
const own = expandImports(file, text, {warnings, carried: carriedCss, included, packageSheets, served});
|
|
472
478
|
return inlineAssets(cutCss(own, used), 'css', {...ctx, dir: path.dirname(file)});
|
|
473
479
|
} catch (e) {
|
|
474
480
|
if (e instanceof RenderAssetError || e instanceof RenderError) throw e;
|
|
@@ -608,5 +614,6 @@ export async function renderPage(entry, options = {}) {
|
|
|
608
614
|
...(message.assets ?? []),
|
|
609
615
|
]).size,
|
|
610
616
|
warnings,
|
|
617
|
+
fromSet: message.fromSet ?? [],
|
|
611
618
|
};
|
|
612
619
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 package a bare specifier names.
|
|
6
|
+
* @param {string} spec
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
export function packageOf(spec: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether a render may take `name` from the package set.
|
|
12
|
+
* @param {string} name
|
|
13
|
+
* @param {readonly string[]} integrations the integrations the host approves
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
export function isServedPackage(name: string, integrations: readonly string[]): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve `spec` the way `from` sees it; when that fails and the package is
|
|
19
|
+
* one the set serves, the way the served Core's folder sees it.
|
|
20
|
+
* @param {string} spec
|
|
21
|
+
* @param {string} from the importing file
|
|
22
|
+
* @param {{dir: string, integrations: readonly string[]} | null} served
|
|
23
|
+
* @returns {string | null}
|
|
24
|
+
*/
|
|
25
|
+
export function resolveServed(spec: string, from: string, served: {
|
|
26
|
+
dir: string;
|
|
27
|
+
integrations: readonly string[];
|
|
28
|
+
} | null): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* React and StyleX hold state per copy, so a page outside a project loads
|
|
31
|
+
* the set's copy of each, as the packages from the set do.
|
|
32
|
+
*/
|
|
33
|
+
export const SINGLE_COPY: string[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Which packages a render may take from the package set the CLI runs
|
|
5
|
+
* from when the page is outside a project (architecture:cli-surface INV30):
|
|
6
|
+
* the Astryx packages, the React and StyleX they run with, and the
|
|
7
|
+
* integrations the host approves. Inside a project the set is never used.
|
|
8
|
+
*
|
|
9
|
+
* @input A specifier, the file that imports it, and the served Core's folder.
|
|
10
|
+
* @output The file it resolves to, or null.
|
|
11
|
+
* @position foundation/render — read by render-page.mjs and page-worker.mjs.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as path from 'node:path';
|
|
15
|
+
import {createRequire} from 'node:module';
|
|
16
|
+
|
|
17
|
+
/** Packages every Astryx package runs with, besides its own scope. */
|
|
18
|
+
const RUNTIME = ['react', 'react-dom', '@stylexjs/stylex'];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* React and StyleX hold state per copy, so a page outside a project loads
|
|
22
|
+
* the set's copy of each, as the packages from the set do.
|
|
23
|
+
*/
|
|
24
|
+
export const SINGLE_COPY = RUNTIME;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The package a bare specifier names.
|
|
28
|
+
* @param {string} spec
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
export function packageOf(spec) {
|
|
32
|
+
return spec.startsWith('@')
|
|
33
|
+
? spec.split('/').slice(0, 2).join('/')
|
|
34
|
+
: spec.split('/')[0];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether a render may take `name` from the package set.
|
|
39
|
+
* @param {string} name
|
|
40
|
+
* @param {readonly string[]} integrations the integrations the host approves
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
export function isServedPackage(name, integrations) {
|
|
44
|
+
return (
|
|
45
|
+
name.startsWith('@astryxdesign/') ||
|
|
46
|
+
RUNTIME.includes(name) ||
|
|
47
|
+
integrations.includes(name)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve `spec` the way `from` sees it; when that fails and the package is
|
|
53
|
+
* one the set serves, the way the served Core's folder sees it.
|
|
54
|
+
* @param {string} spec
|
|
55
|
+
* @param {string} from the importing file
|
|
56
|
+
* @param {{dir: string, integrations: readonly string[]} | null} served
|
|
57
|
+
* @returns {string | null}
|
|
58
|
+
*/
|
|
59
|
+
export function resolveServed(spec, from, served) {
|
|
60
|
+
try {
|
|
61
|
+
return createRequire(from).resolve(spec);
|
|
62
|
+
} catch {
|
|
63
|
+
if (!served || !isServedPackage(packageOf(spec), served.integrations)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
return createRequire(path.join(served.dir, 'package.json')).resolve(
|
|
68
|
+
spec,
|
|
69
|
+
{paths: [served.dir]},
|
|
70
|
+
);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* @param {{parent: string, names: string[]}} data
|
|
6
|
+
*/
|
|
7
|
+
export function initialize(data: {
|
|
8
|
+
parent: string;
|
|
9
|
+
names: string[];
|
|
10
|
+
}): void;
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} specifier
|
|
13
|
+
* @param {{parentURL?: string}} context
|
|
14
|
+
* @param {(specifier: string, context?: object) => Promise<unknown>} nextResolve
|
|
15
|
+
*/
|
|
16
|
+
export function resolve(specifier: string, context: {
|
|
17
|
+
parentURL?: string;
|
|
18
|
+
}, nextResolve: (specifier: string, context?: object) => Promise<unknown>): Promise<unknown>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Module resolve hooks for a render outside a project: every ES module
|
|
5
|
+
* the page loads, a library in the page's folder included, takes React,
|
|
6
|
+
* React DOM and StyleX from the package set the CLI runs from, so the page
|
|
7
|
+
* runs on one copy of each. CommonJS goes through the same rule in
|
|
8
|
+
* page-worker.mjs.
|
|
9
|
+
*
|
|
10
|
+
* @input `initialize` data: `parent`, the URL to resolve from (the served
|
|
11
|
+
* Core's package.json), and `names`, the packages to take from there.
|
|
12
|
+
* @output A `resolve` hook.
|
|
13
|
+
* @position foundation/render — registered by page-worker.mjs.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @type {string} */
|
|
17
|
+
let parent = '';
|
|
18
|
+
/** @type {string[]} */
|
|
19
|
+
let names = [];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {{parent: string, names: string[]}} data
|
|
23
|
+
*/
|
|
24
|
+
export function initialize(data) {
|
|
25
|
+
parent = data.parent;
|
|
26
|
+
names = data.names;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} specifier
|
|
31
|
+
* @param {{parentURL?: string}} context
|
|
32
|
+
* @param {(specifier: string, context?: object) => Promise<unknown>} nextResolve
|
|
33
|
+
*/
|
|
34
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
35
|
+
const named = names.some(name => specifier === name || specifier.startsWith(`${name}/`));
|
|
36
|
+
if (named) {
|
|
37
|
+
try {
|
|
38
|
+
return await nextResolve(specifier, {...context, parentURL: parent});
|
|
39
|
+
} catch {
|
|
40
|
+
// The set has no such file: the importer's own copy serves.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return nextResolve(specifier, context);
|
|
44
|
+
}
|
|
@@ -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
|
+
/**
|
|
5
|
+
* @file One command-line word for a printed command: a value as written when
|
|
6
|
+
* the shell reads it as one plain word, else single-quoted, so a printed
|
|
7
|
+
* command runs as printed and never substitutes anything.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A value as one shell word.
|
|
11
|
+
* @param {string} value
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
export function shellArg(value: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file One command-line word for a printed command: a value as written when
|
|
5
|
+
* the shell reads it as one plain word, else single-quoted, so a printed
|
|
6
|
+
* command runs as printed and never substitutes anything.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A value as one shell word.
|
|
11
|
+
* @param {string} value
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
export function shellArg(value) {
|
|
15
|
+
if (/^[A-Za-z0-9@/._-]+$/.test(value)) return value;
|
|
16
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
17
|
+
}
|
|
@@ -58,7 +58,9 @@ export function findClosestComponents(name, components, maxDistance = 3) {
|
|
|
58
58
|
*/
|
|
59
59
|
export async function searchComponents(needle, coreDir, components) {
|
|
60
60
|
const {readDocView} = await import('../doc-compiler/read.mjs');
|
|
61
|
-
const
|
|
61
|
+
const {listDirEntries, oncePerListing, pathExists} = await import(
|
|
62
|
+
'../fs/listing-cache.mjs'
|
|
63
|
+
);
|
|
62
64
|
const path = await import('node:path');
|
|
63
65
|
|
|
64
66
|
const term = needle.toLowerCase();
|
|
@@ -111,32 +113,30 @@ export async function searchComponents(needle, coreDir, components) {
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
// --- Pass 2: Keyword + description matching (async, reads doc files) ---
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const srcDir = path.join(coreDir, 'src');
|
|
117
|
+
/**
|
|
118
|
+
* The doc that Pass 2 reads for `comp`, or null.
|
|
119
|
+
* @param {string} comp
|
|
120
|
+
* @returns {string | null}
|
|
121
|
+
*/
|
|
122
|
+
function docPathOf(comp) {
|
|
118
123
|
const direct = path.join(srcDir, comp, comp + '.doc.mjs');
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (!
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
if (pathExists(direct)) return direct;
|
|
125
|
+
const xdsDirect = path.join(srcDir, comp, 'XDS' + comp + '.doc.mjs');
|
|
126
|
+
if (pathExists(xdsDirect)) return xdsDirect;
|
|
127
|
+
if (!pathExists(srcDir)) return null;
|
|
128
|
+
for (const entry of listDirEntries(srcDir)) {
|
|
129
|
+
if (!entry.isDirectory()) continue;
|
|
130
|
+
const nested = path.join(srcDir, entry.name, comp, comp + '.doc.mjs');
|
|
131
|
+
if (pathExists(nested)) return nested;
|
|
127
132
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
// Each search probes the same paths, so one operation finds each doc once.
|
|
136
|
+
for (const comp of allNames) {
|
|
137
|
+
const docPath = oncePerListing(`search-doc\0${srcDir}\0${comp}`, () =>
|
|
138
|
+
docPathOf(comp),
|
|
139
|
+
);
|
|
140
140
|
if (!docPath) continue;
|
|
141
141
|
|
|
142
142
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.11-canary.143a5de",
|
|
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",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
"zod": "^4.4.3"
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
|
-
"@astryxdesign/core": "
|
|
127
|
+
"@astryxdesign/core": "0.7.11-canary.143a5de"
|
|
128
128
|
},
|
|
129
129
|
"peerDependenciesMeta": {
|
|
130
130
|
"@astryxdesign/core": {
|
|
@@ -132,10 +132,10 @@
|
|
|
132
132
|
}
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
|
-
"@astryxdesign/charts": "
|
|
136
|
-
"@astryxdesign/core": "
|
|
137
|
-
"@astryxdesign/lab": "
|
|
138
|
-
"@astryxdesign/theme-neutral": "
|
|
135
|
+
"@astryxdesign/charts": "0.7.11-canary.143a5de",
|
|
136
|
+
"@astryxdesign/core": "0.7.11-canary.143a5de",
|
|
137
|
+
"@astryxdesign/lab": "0.7.11-canary.143a5de",
|
|
138
|
+
"@astryxdesign/theme-neutral": "0.7.11-canary.143a5de",
|
|
139
139
|
"@heroicons/react": "^2.2.0",
|
|
140
140
|
"@stylexjs/stylex": "^0.19.0",
|
|
141
141
|
"@types/babel__core": "^7.20.5",
|