@astryxdesign/cli 0.7.10 → 0.7.11-canary.84a2254
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/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/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/integration/pack-check.d.mts +8 -6
- package/api/integration/pack-check.mjs +16 -6
- 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/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/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/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/docs-discovery.mjs +6 -4
- package/foundation/discovery/icon-definition-discovery.mjs +3 -3
- package/foundation/discovery/module-exports.d.mts +91 -4
- package/foundation/discovery/module-exports.mjs +316 -42
- 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/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/string-utils.mjs +25 -25
- package/package.json +6 -6
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
discoverDoctorThemes,
|
|
16
16
|
discoverDoctorUnmigratedCopies,
|
|
17
17
|
findDoctorCoreDir,
|
|
18
|
+
doctorElementPropOrigins,
|
|
19
|
+
doctorStylesheetImports,
|
|
18
20
|
findDoctorInstalledPackage,
|
|
21
|
+
realDoctorFile,
|
|
19
22
|
isLocalThemeOwner,
|
|
20
23
|
listDoctorThemePackages,
|
|
21
24
|
listProjectSourceFiles,
|
|
@@ -135,8 +138,12 @@ function walkAst(value, visit) {
|
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
140
|
|
|
138
|
-
/**
|
|
139
|
-
|
|
141
|
+
/**
|
|
142
|
+
* @param {string} source
|
|
143
|
+
* @param {{runtimeOnly?: boolean}} [options] - skip type-only imports and
|
|
144
|
+
* re-exports, which the build erases
|
|
145
|
+
*/
|
|
146
|
+
function moduleSpecifiers(source, options = {}) {
|
|
140
147
|
const values = new Set();
|
|
141
148
|
walkAst(parseModule(source), node => {
|
|
142
149
|
if (
|
|
@@ -145,7 +152,11 @@ function moduleSpecifiers(source) {
|
|
|
145
152
|
'ExportNamedDeclaration',
|
|
146
153
|
'ExportAllDeclaration',
|
|
147
154
|
].includes(node.type) &&
|
|
148
|
-
typeof node.source?.value === 'string'
|
|
155
|
+
typeof node.source?.value === 'string' &&
|
|
156
|
+
!(
|
|
157
|
+
options.runtimeOnly &&
|
|
158
|
+
(node.importKind === 'type' || node.exportKind === 'type')
|
|
159
|
+
)
|
|
149
160
|
) {
|
|
150
161
|
values.add(node.source.value);
|
|
151
162
|
}
|
|
@@ -406,18 +417,248 @@ function appPackageNamesTheme(cwd) {
|
|
|
406
417
|
return Boolean(pkg?.astryx?.theme);
|
|
407
418
|
}
|
|
408
419
|
|
|
420
|
+
/**
|
|
421
|
+
* Whether one import specifier names a theme's built module or stylesheet.
|
|
422
|
+
* @param {string} specifier
|
|
423
|
+
* @param {string} file - the importing file
|
|
424
|
+
* @param {ResolvedAppTheme} theme
|
|
425
|
+
*/
|
|
426
|
+
function importsTheme(specifier, file, theme) {
|
|
427
|
+
if (theme.source === 'local') {
|
|
428
|
+
return (
|
|
429
|
+
specifierTargets(specifier, file, theme.moduleFile) ||
|
|
430
|
+
specifierTargets(specifier, file, theme.stylesheetFile)
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
return specifier === theme.module || specifier === theme.stylesheet;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const CORE_THEME_SOURCES = new Set([
|
|
437
|
+
'@astryxdesign/core',
|
|
438
|
+
'@astryxdesign/core/theme',
|
|
439
|
+
]);
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* The base a `defineTheme({extends: base})` call extends, for
|
|
443
|
+
* {@link doctorElementPropOrigins}: a theme made that way stands for its base.
|
|
444
|
+
* @param {any} init
|
|
445
|
+
* @returns {any}
|
|
446
|
+
*/
|
|
447
|
+
function definedThemeBase(init) {
|
|
448
|
+
if (
|
|
449
|
+
init?.type !== 'CallExpression' ||
|
|
450
|
+
init.callee?.type !== 'Identifier' ||
|
|
451
|
+
init.callee.name !== 'defineTheme'
|
|
452
|
+
) {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
const options = init.arguments?.[0];
|
|
456
|
+
if (options?.type !== 'ObjectExpression') return null;
|
|
457
|
+
const base = options.properties.find(
|
|
458
|
+
(/** @type {any} */ property) =>
|
|
459
|
+
property.type === 'ObjectProperty' &&
|
|
460
|
+
!property.computed &&
|
|
461
|
+
(property.key?.name ?? property.key?.value) === 'extends',
|
|
462
|
+
);
|
|
463
|
+
return base?.value ?? null;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* The themes the app wires itself, without a generated theme module or a
|
|
468
|
+
* package.json `astryx.theme`. A theme is wired when the app's own source
|
|
469
|
+
* imports its built module or stylesheet ({@link resolveDoctorThemeImports}
|
|
470
|
+
* names them: the imports `theme add` writes), or when the app passes it to
|
|
471
|
+
* Core's `Theme`: {@link doctorElementPropOrigins} follows the `theme` value through
|
|
472
|
+
* module-scope aliases, `defineTheme({extends})`, re-exports and installed
|
|
473
|
+
* packages to where it is declared, which must be inside an installed theme
|
|
474
|
+
* package or be a local theme's built module. Only themes the app can load
|
|
475
|
+
* count: a theme whose package is not installed is never wired. A `theme`
|
|
476
|
+
* value whose origin is anything else (a prop, a function result, a lookup)
|
|
477
|
+
* is reported as unconfirmed, never as missing. The scan reads app source only
|
|
478
|
+
* (no dependencies, build output, links or type-only imports) within the
|
|
479
|
+
* bounded source walk, and executes nothing.
|
|
480
|
+
* @param {string} cwd
|
|
481
|
+
* @returns {Promise<{
|
|
482
|
+
* wired: Array<{slug: string, owner: string, file: string}>,
|
|
483
|
+
* unconfirmed: Array<{file: string}>,
|
|
484
|
+
* }>}
|
|
485
|
+
*/
|
|
486
|
+
export async function themeImportWiring(cwd) {
|
|
487
|
+
const none = {wired: [], unconfirmed: []};
|
|
488
|
+
let state;
|
|
489
|
+
try {
|
|
490
|
+
state = readThemeState(cwd);
|
|
491
|
+
} catch {
|
|
492
|
+
return none;
|
|
493
|
+
}
|
|
494
|
+
// A generated module or `astryx.theme` already decides the result.
|
|
495
|
+
if (state.configured || appPackageNamesTheme(cwd)) return none;
|
|
496
|
+
const projectDir = state.projectDir;
|
|
497
|
+
/** @type {DiscoveredTheme[]} */
|
|
498
|
+
let available;
|
|
499
|
+
try {
|
|
500
|
+
available = await discoverDoctorThemes(projectDir);
|
|
501
|
+
} catch {
|
|
502
|
+
return none;
|
|
503
|
+
}
|
|
504
|
+
const ownerCounts = new Map();
|
|
505
|
+
for (const theme of available) {
|
|
506
|
+
const owner = themeRecordOwner(theme);
|
|
507
|
+
ownerCounts.set(owner, (ownerCounts.get(owner) ?? 0) + 1);
|
|
508
|
+
}
|
|
509
|
+
/** @type {Map<string, string | null>} */
|
|
510
|
+
const installedDirs = new Map();
|
|
511
|
+
const installedDir = (/** @type {string} */ owner) => {
|
|
512
|
+
if (!installedDirs.has(owner)) {
|
|
513
|
+
const dir = findDoctorInstalledPackage(projectDir, owner);
|
|
514
|
+
installedDirs.set(owner, dir ? realDoctorFile(dir) : null);
|
|
515
|
+
}
|
|
516
|
+
return installedDirs.get(owner) ?? null;
|
|
517
|
+
};
|
|
518
|
+
// Only themes the app can load: local themes, and package themes whose
|
|
519
|
+
// package is installed (discovery also lists the CLI's bundled themes).
|
|
520
|
+
/** @type {ResolvedAppTheme[]} */
|
|
521
|
+
const themes = [];
|
|
522
|
+
for (const theme of available) {
|
|
523
|
+
let resolved;
|
|
524
|
+
try {
|
|
525
|
+
resolved = resolveDoctorThemeImports(theme, {
|
|
526
|
+
cwd: projectDir,
|
|
527
|
+
ownerThemeCount: ownerCounts.get(themeRecordOwner(theme)) ?? 1,
|
|
528
|
+
});
|
|
529
|
+
} catch {
|
|
530
|
+
// A theme without built imports cannot be wired by importing them.
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (resolved.source === 'local' || installedDir(resolved.owner)) {
|
|
534
|
+
themes.push(resolved);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
if (themes.length === 0) return none;
|
|
538
|
+
/**
|
|
539
|
+
* The theme a `Theme` value's origin is, or null.
|
|
540
|
+
* @param {{file: string, name: string} | null} origin
|
|
541
|
+
*/
|
|
542
|
+
const themeAt = origin => {
|
|
543
|
+
const file = origin ? realDoctorFile(origin.file) : null;
|
|
544
|
+
if (!origin || !file) return null;
|
|
545
|
+
const local = themes.find(
|
|
546
|
+
theme =>
|
|
547
|
+
theme.source === 'local' && realDoctorFile(theme.moduleFile) === file,
|
|
548
|
+
);
|
|
549
|
+
if (local) return local;
|
|
550
|
+
const owned = themes.filter(theme => {
|
|
551
|
+
const dir = theme.source === 'local' ? null : installedDir(theme.owner);
|
|
552
|
+
return dir != null && file.startsWith(`${dir}${path.sep}`);
|
|
553
|
+
});
|
|
554
|
+
const named = owned.filter(theme => theme.exportName === origin.name);
|
|
555
|
+
if (named.length === 1) return named[0];
|
|
556
|
+
return owned.length === 1 ? owned[0] : null;
|
|
557
|
+
};
|
|
558
|
+
/** @type {Map<string, {slug: string, owner: string, file: string}>} */
|
|
559
|
+
const wired = new Map();
|
|
560
|
+
const keyOf = (/** @type {ResolvedAppTheme} */ theme) =>
|
|
561
|
+
`${theme.owner}\u0000${theme.slug}`;
|
|
562
|
+
/** @type {Set<string>} */
|
|
563
|
+
const unconfirmed = new Set();
|
|
564
|
+
for (const file of listProjectSourceFiles(projectDir, '', {
|
|
565
|
+
stylesheets: true,
|
|
566
|
+
})) {
|
|
567
|
+
let source;
|
|
568
|
+
try {
|
|
569
|
+
source = readTextFile(file);
|
|
570
|
+
} catch {
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
const shown = relative(projectDir, file);
|
|
574
|
+
const candidates = themes.filter(
|
|
575
|
+
theme =>
|
|
576
|
+
!wired.has(keyOf(theme)) &&
|
|
577
|
+
(theme.source === 'local'
|
|
578
|
+
? source.includes(path.basename(theme.moduleFile)) ||
|
|
579
|
+
source.includes(path.basename(theme.stylesheetFile))
|
|
580
|
+
: source.includes(theme.module) || source.includes(theme.stylesheet)),
|
|
581
|
+
);
|
|
582
|
+
if (candidates.length > 0) {
|
|
583
|
+
let specifiers;
|
|
584
|
+
try {
|
|
585
|
+
specifiers =
|
|
586
|
+
path.extname(file) === '.css'
|
|
587
|
+
? doctorStylesheetImports(source)
|
|
588
|
+
: moduleSpecifiers(source, {runtimeOnly: true});
|
|
589
|
+
} catch {
|
|
590
|
+
specifiers = new Set();
|
|
591
|
+
}
|
|
592
|
+
for (const theme of candidates) {
|
|
593
|
+
if ([...specifiers].some(spec => importsTheme(spec, file, theme))) {
|
|
594
|
+
wired.set(keyOf(theme), {
|
|
595
|
+
slug: theme.slug,
|
|
596
|
+
owner: theme.owner,
|
|
597
|
+
file: shown,
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (path.extname(file) === '.css' || !source.includes('theme=')) continue;
|
|
603
|
+
for (const origin of doctorElementPropOrigins(file, {
|
|
604
|
+
sources: CORE_THEME_SOURCES,
|
|
605
|
+
name: 'Theme',
|
|
606
|
+
prop: 'theme',
|
|
607
|
+
unwrap: definedThemeBase,
|
|
608
|
+
})) {
|
|
609
|
+
const theme = themeAt(origin);
|
|
610
|
+
if (!theme) {
|
|
611
|
+
unconfirmed.add(shown);
|
|
612
|
+
} else if (!wired.has(keyOf(theme))) {
|
|
613
|
+
wired.set(keyOf(theme), {
|
|
614
|
+
slug: theme.slug,
|
|
615
|
+
owner: theme.owner,
|
|
616
|
+
file: shown,
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
// In discovery order, so the report does not depend on the file walk.
|
|
622
|
+
return {
|
|
623
|
+
wired: themes.flatMap(theme => {
|
|
624
|
+
const found = wired.get(keyOf(theme));
|
|
625
|
+
return found ? [found] : [];
|
|
626
|
+
}),
|
|
627
|
+
unconfirmed: [...unconfirmed].sort().map(file => ({file})),
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* The pass message's list of themes wired by import, each with the file that
|
|
633
|
+
* imports it.
|
|
634
|
+
* @param {Array<{slug: string, file: string}>} wired
|
|
635
|
+
*/
|
|
636
|
+
function wiredByImportList(wired) {
|
|
637
|
+
const shown = wired.slice(0, 5).map(({slug, file}) => `${slug} (${file})`);
|
|
638
|
+
const more = wired.length - shown.length;
|
|
639
|
+
return more > 0 ? `${shown.join(', ')} and ${more} more` : shown.join(', ');
|
|
640
|
+
}
|
|
641
|
+
|
|
409
642
|
/**
|
|
410
643
|
* The `themes` check that every released doctor report carries. Its id is
|
|
411
644
|
* stable, so it stays beside the app-theme checks. Without a generated theme
|
|
412
645
|
* module it reports what it always has: whether an `@astryxdesign/theme-*`
|
|
413
646
|
* package is installed, and whether the app's package.json names a theme in
|
|
414
|
-
* `astryx.theme
|
|
415
|
-
*
|
|
647
|
+
* `astryx.theme`, or else whether the app's own source imports a theme's built
|
|
648
|
+
* module or stylesheet ({@link themeImportWiring}). With a generated module it
|
|
649
|
+
* reports the overall result of the app-theme checks.
|
|
416
650
|
* @param {string} cwd
|
|
417
651
|
* @param {DoctorCheck[]} appChecks - the checks {@link checkAppThemes} returned
|
|
652
|
+
* @param {{wired: Array<{slug: string, file: string}>, unconfirmed: Array<{file: string}>}} [wiring] -
|
|
653
|
+
* what {@link themeImportWiring} returned
|
|
418
654
|
* @returns {DoctorCheck}
|
|
419
655
|
*/
|
|
420
|
-
export function checkThemes(
|
|
656
|
+
export function checkThemes(
|
|
657
|
+
cwd,
|
|
658
|
+
appChecks,
|
|
659
|
+
wiring = {wired: [], unconfirmed: []},
|
|
660
|
+
) {
|
|
661
|
+
const wiredByImport = wiring.wired;
|
|
421
662
|
const label = 'Theme packages';
|
|
422
663
|
const managed = appChecks.some(
|
|
423
664
|
check => APP_THEME_CHECK_IDS.has(check.id) && check.status !== 'info',
|
|
@@ -475,6 +716,14 @@ export function checkThemes(cwd, appChecks) {
|
|
|
475
716
|
|
|
476
717
|
const run = getCliInvocation(cwd);
|
|
477
718
|
const packages = listDoctorThemePackages(cwd);
|
|
719
|
+
if (packages.length === 0 && wiredByImport.length > 0) {
|
|
720
|
+
return {
|
|
721
|
+
id: 'themes',
|
|
722
|
+
label,
|
|
723
|
+
status: 'pass',
|
|
724
|
+
message: `Themes wired by import: ${wiredByImportList(wiredByImport)}.`,
|
|
725
|
+
};
|
|
726
|
+
}
|
|
478
727
|
if (packages.length === 0) {
|
|
479
728
|
return {
|
|
480
729
|
id: 'themes',
|
|
@@ -485,6 +734,24 @@ export function checkThemes(cwd, appChecks) {
|
|
|
485
734
|
};
|
|
486
735
|
}
|
|
487
736
|
const names = packages.join(', ');
|
|
737
|
+
if (!appPackageNamesTheme(cwd) && wiredByImport.length > 0) {
|
|
738
|
+
return {
|
|
739
|
+
id: 'themes',
|
|
740
|
+
label,
|
|
741
|
+
status: 'pass',
|
|
742
|
+
message: `Theme package(s) installed (${names}); wired by import: ${wiredByImportList(wiredByImport)}.`,
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
if (!appPackageNamesTheme(cwd) && wiring.unconfirmed.length > 0) {
|
|
746
|
+
const files = wiring.unconfirmed.map(({file}) => file).join(', ');
|
|
747
|
+
return {
|
|
748
|
+
id: 'themes',
|
|
749
|
+
label,
|
|
750
|
+
status: 'info',
|
|
751
|
+
message: `Theme package(s) installed (${names}); ${files} pass${wiring.unconfirmed.length === 1 ? 'es' : ''} a theme to Theme that doctor could not trace to a theme import, so it could not confirm which theme is wired.`,
|
|
752
|
+
fix: `If no theme is applied, add one with \`${run} theme add <slug>\`.`,
|
|
753
|
+
};
|
|
754
|
+
}
|
|
488
755
|
if (!appPackageNamesTheme(cwd)) {
|
|
489
756
|
return {
|
|
490
757
|
id: 'themes',
|
package/api/hook/hook.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import {detail as detailLeaf} from './detail/detail.mjs';
|
|
|
19
19
|
import {params as paramsLeaf} from './detail/params/params.mjs';
|
|
20
20
|
import {AstryxError} from '../error.mjs';
|
|
21
21
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
22
|
+
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @param {string} [name]
|
|
@@ -33,6 +34,18 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
|
33
34
|
* @returns {Promise<{type: string, data: unknown}>}
|
|
34
35
|
*/
|
|
35
36
|
export async function hook(name, options = {}) {
|
|
37
|
+
// Each hook's lookup walks the same source tree, so the call reads each
|
|
38
|
+
// directory once.
|
|
39
|
+
return withListingCache(() => hookRead(name, options));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* {@link hook}, without the call's listing cache.
|
|
44
|
+
* @param {string} [name]
|
|
45
|
+
* @param {Parameters<typeof hook>[1]} [options]
|
|
46
|
+
* @returns {ReturnType<typeof hook>}
|
|
47
|
+
*/
|
|
48
|
+
async function hookRead(name, options = {}) {
|
|
36
49
|
const {
|
|
37
50
|
cwd = process.cwd(),
|
|
38
51
|
list: listFlag = false,
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Compare generated theme outputs without making their build directory
|
|
6
|
-
* CLI/Core version look like source drift. Normalization
|
|
7
|
-
*
|
|
8
|
-
* well-formed Source, CLI, and Core line
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Compare generated theme outputs without making their build directory,
|
|
6
|
+
* CLI/Core version, or build command look like source drift. Normalization
|
|
7
|
+
* applies only to a file whose first comment is the generated header with
|
|
8
|
+
* exactly one well-formed Source, CLI, and Core line; it covers those lines
|
|
9
|
+
* and, in a built module, the one `built by` line that names the command
|
|
10
|
+
* (`yarn astryx`, `pnpm exec astryx`, or a host's own). Missing, duplicate,
|
|
11
|
+
* malformed, reordered, or any other bytes stay significant. `theme build
|
|
12
|
+
* --check` deliberately stays strict.
|
|
11
13
|
* @param {string} content
|
|
12
14
|
*/
|
|
13
15
|
export function normalizeThemeVerifyForCompare(content: string): string;
|
|
@@ -99,14 +99,20 @@ const GENERATED_HEADER_LINE =
|
|
|
99
99
|
const SOURCE_LINE = /^( \* Source: )(\S(?:.*\S)?)(\s*)$/u;
|
|
100
100
|
const CLI_VERSION_LINE = /^( \* CLI: @astryxdesign\/cli@)(\S+)(\s*)$/u;
|
|
101
101
|
const CORE_VERSION_LINE = /^( \* Core: @astryxdesign\/core@)(\S+)(\s*)$/u;
|
|
102
|
+
// The built module's own doc comment names the command that built it, which
|
|
103
|
+
// depends on the package manager and host that ran the build.
|
|
104
|
+
const BUILT_BY_LINE =
|
|
105
|
+
/^( \* \S(?:.*\S)? theme — built by `)(\S(?:.*\S)?)( theme build`)(\s*)$/u;
|
|
102
106
|
|
|
103
107
|
/**
|
|
104
|
-
* Compare generated theme outputs without making their build directory
|
|
105
|
-
* CLI/Core version look like source drift. Normalization
|
|
106
|
-
*
|
|
107
|
-
* well-formed Source, CLI, and Core line
|
|
108
|
-
*
|
|
109
|
-
*
|
|
108
|
+
* Compare generated theme outputs without making their build directory,
|
|
109
|
+
* CLI/Core version, or build command look like source drift. Normalization
|
|
110
|
+
* applies only to a file whose first comment is the generated header with
|
|
111
|
+
* exactly one well-formed Source, CLI, and Core line; it covers those lines
|
|
112
|
+
* and, in a built module, the one `built by` line that names the command
|
|
113
|
+
* (`yarn astryx`, `pnpm exec astryx`, or a host's own). Missing, duplicate,
|
|
114
|
+
* malformed, reordered, or any other bytes stay significant. `theme build
|
|
115
|
+
* --check` deliberately stays strict.
|
|
110
116
|
* @param {string} content
|
|
111
117
|
*/
|
|
112
118
|
export function normalizeThemeVerifyForCompare(content) {
|
|
@@ -125,8 +131,12 @@ export function normalizeThemeVerifyForCompare(content) {
|
|
|
125
131
|
if (source.length !== 1 || cli.length !== 1 || core.length !== 1) {
|
|
126
132
|
return normalized;
|
|
127
133
|
}
|
|
134
|
+
const builtBy = lines.filter(line => BUILT_BY_LINE.test(line)).length;
|
|
128
135
|
return lines
|
|
129
136
|
.map((line, index) => {
|
|
137
|
+
if (builtBy === 1 && BUILT_BY_LINE.test(line)) {
|
|
138
|
+
return line.replace(BUILT_BY_LINE, '$1<command>$3$4');
|
|
139
|
+
}
|
|
130
140
|
if (index >= close) return line;
|
|
131
141
|
if (SOURCE_LINE.test(line)) {
|
|
132
142
|
return line.replace(SOURCE_LINE, '$1<source>$3');
|
package/api/render/_adapter.mjs
CHANGED
|
@@ -26,6 +26,10 @@ import {isAstryxMarkup} from '../../foundation/render/html-reader.mjs';
|
|
|
26
26
|
import {rebuildPage} from '../../foundation/render/rebuild.mjs';
|
|
27
27
|
import {cliVersion} from '../../foundation/integrations/cli-peer-version.mjs';
|
|
28
28
|
import {assertWithin, PathSafetyError} from '../../foundation/fs/path-safety.mjs';
|
|
29
|
+
import {requireCoreDir} from '../../foundation/fs/paths.mjs';
|
|
30
|
+
import {runChoice} from '../../foundation/release/run-context.mjs';
|
|
31
|
+
import {isServedPackage} from '../../foundation/render/served-packages.mjs';
|
|
32
|
+
import {hostedRun, recordResolved} from '../../foundation/runtime/package-root.mjs';
|
|
29
33
|
|
|
30
34
|
export {PAGE_EXTENSIONS, embeddedPathProblem};
|
|
31
35
|
|
|
@@ -238,6 +242,29 @@ function asAstryxError(e) {
|
|
|
238
242
|
return e;
|
|
239
243
|
}
|
|
240
244
|
|
|
245
|
+
/**
|
|
246
|
+
* The package set the CLI runs from, for a page outside a project
|
|
247
|
+
* (architecture:cli-surface INV30): the Core it carries, found by the rule of
|
|
248
|
+
* every command that answers from Core outside a project. Inside a project
|
|
249
|
+
* (spec AST-081: a Core or CLI the folder reads, or a package.json that
|
|
250
|
+
* declares one) the project's packages serve the page alone, so this is
|
|
251
|
+
* null.
|
|
252
|
+
* When the carried Core cannot be had, the reason is kept for the error a
|
|
253
|
+
* page that needs it gets (spec AST-081 FR3).
|
|
254
|
+
* @param {string} input absolute path of the page
|
|
255
|
+
* @returns {{dir: string, integrations: readonly string[]} | {unavailable: Error} | null}
|
|
256
|
+
*/
|
|
257
|
+
function servedSet(input) {
|
|
258
|
+
const dir = path.dirname(input);
|
|
259
|
+
if (runChoice(dir).inProject) return null;
|
|
260
|
+
try {
|
|
261
|
+
return {dir: requireCoreDir(dir), integrations: hostedRun()?.integrations ?? []};
|
|
262
|
+
} catch (e) {
|
|
263
|
+
const err = /** @type {any} */ (e);
|
|
264
|
+
return err?.code === ERROR_CODES.ERR_VERSIONS_UNAVAILABLE ? {unavailable: err} : null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
241
268
|
/**
|
|
242
269
|
* Render a page module to one HTML file and write it.
|
|
243
270
|
* @param {{cwd: string, input: string, output: string, title?: string}} args absolute paths
|
|
@@ -249,10 +276,29 @@ export async function renderToFile({cwd, input, output, title}) {
|
|
|
249
276
|
/** @type {import('../../foundation/render/render-page.mjs').RenderedPage} */
|
|
250
277
|
let page;
|
|
251
278
|
try {
|
|
252
|
-
|
|
279
|
+
const set = servedSet(input);
|
|
280
|
+
try {
|
|
281
|
+
page = await renderPage(input, {title, version: cliVersion(), served: set && 'dir' in set ? set : null});
|
|
282
|
+
} catch (e) {
|
|
283
|
+
// A page that needs the Core the CLI could not obtain says why.
|
|
284
|
+
const missing = /** @type {any} */ (e)?.code === 'ERR_RENDER_MISSING_DEPENDENCY' ? /** @type {any} */ (e).detail?.package : null;
|
|
285
|
+
if (set && 'unavailable' in set && typeof missing === 'string' && isServedPackage(missing, hostedRun()?.integrations ?? [])) {
|
|
286
|
+
throw new AstryxError(set.unavailable.message, [], ERROR_CODES.ERR_VERSIONS_UNAVAILABLE);
|
|
287
|
+
}
|
|
288
|
+
throw e;
|
|
289
|
+
}
|
|
253
290
|
} catch (e) {
|
|
254
291
|
throw asAstryxError(e);
|
|
255
292
|
}
|
|
293
|
+
for (const {name, dir} of page.fromSet) {
|
|
294
|
+
let version = null;
|
|
295
|
+
try {
|
|
296
|
+
version = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).version;
|
|
297
|
+
} catch {
|
|
298
|
+
// A package without a readable version is still named.
|
|
299
|
+
}
|
|
300
|
+
recordResolved(name, version, dir, 'package-set');
|
|
301
|
+
}
|
|
256
302
|
refuseProtected([output], cwd);
|
|
257
303
|
// An existing file is replaced only when a render wrote it.
|
|
258
304
|
if (
|
|
@@ -16,7 +16,7 @@ export const doc = {
|
|
|
16
16
|
summary:
|
|
17
17
|
'Render a page to one self-contained HTML file, or turn a rendered file back into a page.',
|
|
18
18
|
description:
|
|
19
|
-
"Renders the page module's default export on the server with the project's own React and Astryx components, and writes ONE static HTML file that needs nothing beside it: the page's own StyleX styles are compiled, Core's stylesheets are cut to the rules the markup uses (layer order, custom properties and keyframes kept), local images become data: URIs, and the page's source is embedded so it can be given back exactly. The file runs no script and loads nothing from the network, so it works inside a sandboxed frame with a strict content security policy, and its colors follow the viewer's light or dark scheme. Warnings name anything that may differ from what the author meant, such as a component that did not render the text it was given. With `reverse`, it writes the embedded source back byte for byte, and only the files a render embeds: the page and the local modules, stylesheets, JSON files and images it imports, into a new folder; a file with Astryx markup but no embedded source is rebuilt from its component class names and data attributes (text and layout only); any other file is refused. Experimental: it may change or be removed in a patch release.",
|
|
19
|
+
"Renders the page module's default export on the server with the project's own React and Astryx components (outside a project, with the Astryx, React and StyleX the CLI runs with), and writes ONE static HTML file that needs nothing beside it: the page's own StyleX styles are compiled, Core's stylesheets are cut to the rules the markup uses (layer order, custom properties and keyframes kept), local images become data: URIs, and the page's source is embedded so it can be given back exactly. The file runs no script and loads nothing from the network, so it works inside a sandboxed frame with a strict content security policy, and its colors follow the viewer's light or dark scheme. Warnings name anything that may differ from what the author meant, such as a component that did not render the text it was given. With `reverse`, it writes the embedded source back byte for byte, and only the files a render embeds: the page and the local modules, stylesheets, JSON files and images it imports, into a new folder; a file with Astryx markup but no embedded source is rebuilt from its component class names and data attributes (text and layout only); any other file is refused. Experimental: it may change or be removed in a patch release.",
|
|
20
20
|
importPath: '@astryxdesign/cli/api/experimental',
|
|
21
21
|
signature:
|
|
22
22
|
'render(file: string, options?: RenderOptions): Promise<RenderPageResponse | RenderReverseResponse>',
|
|
@@ -92,6 +92,7 @@ export const doc = {
|
|
|
92
92
|
{code: 'ERR_RENDER_COMPILE', when: 'the page does not compile, or a stylesheet it imports is not valid CSS (the message names the file)'},
|
|
93
93
|
{code: 'ERR_RENDER_NO_DEFAULT_EXPORT', when: 'the page has no default export'},
|
|
94
94
|
{code: 'ERR_RENDER_MISSING_DEPENDENCY', when: 'the page imports a package that is not installed; the suggestion is its install line'},
|
|
95
|
+
{code: 'ERR_VERSIONS_UNAVAILABLE', when: 'outside a project, the page imports an Astryx package, React or StyleX, and the Core of the release that answers cannot be downloaded'},
|
|
95
96
|
{code: 'ERR_RENDER_BROWSER_API', when: 'the page reads a browser-only API, such as window or document, while rendering'},
|
|
96
97
|
{code: 'ERR_RENDER_ASSET_TOO_LARGE', when: 'a local file the page uses is over 8 MB'},
|
|
97
98
|
{code: 'ERR_RENDER_TIMEOUT', when: 'the page does not finish rendering within 60 seconds'},
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import {discoverExternalPackages} from '../../foundation/fs/paths.mjs';
|
|
11
|
+
import {listDir} from '../../foundation/fs/listing-cache.mjs';
|
|
11
12
|
import {
|
|
12
13
|
discoverComponents,
|
|
13
14
|
discoverValidIntegrationComponents,
|
|
@@ -103,7 +104,7 @@ async function gatherCoreComponents(coreDir) {
|
|
|
103
104
|
// A family doc with no component of its own name (Chat) names members too.
|
|
104
105
|
const srcDir = path.join(coreDir, 'src');
|
|
105
106
|
const listed = new Set(names);
|
|
106
|
-
for (const dir of fs.existsSync(srcDir) ?
|
|
107
|
+
for (const dir of fs.existsSync(srcDir) ? listDir(srcDir) : []) {
|
|
107
108
|
const doc = path.join(srcDir, dir, `${dir}.doc.mjs`);
|
|
108
109
|
if (listed.has(dir) || !fs.existsSync(doc)) continue;
|
|
109
110
|
for (const [n, place] of familyPlaces(await loadModuleDoc(doc)))
|
|
@@ -342,7 +342,11 @@ function confineWrite(target, cwd, options) {
|
|
|
342
342
|
/** @param {string} file */
|
|
343
343
|
function isExcludedFromCopy(file) {
|
|
344
344
|
return (
|
|
345
|
-
file.includes('.test.') ||
|
|
345
|
+
file.includes('.test.') ||
|
|
346
|
+
file.includes('.doc.') ||
|
|
347
|
+
file === 'README.md' ||
|
|
348
|
+
// Browser test harnesses import dev-only packages a consumer cannot resolve.
|
|
349
|
+
/\.spec\.[cm]?[jt]sx?$/.test(file)
|
|
346
350
|
);
|
|
347
351
|
}
|
|
348
352
|
|
|
@@ -925,17 +925,28 @@ async function loadKnownValuesIndex() {
|
|
|
925
925
|
return result;
|
|
926
926
|
};
|
|
927
927
|
|
|
928
|
+
// A component can appear in more than one doc: its own doc declares its
|
|
929
|
+
// props, and a parent doc can list it by name only. Merge every entry, so
|
|
930
|
+
// the result does not depend on the order the docs load in.
|
|
928
931
|
/** @type {Record<string, Record<string, Set<string>>>} */
|
|
929
932
|
const valuesByOwner = {};
|
|
933
|
+
/**
|
|
934
|
+
* @param {string} name
|
|
935
|
+
* @param {any[]} props
|
|
936
|
+
*/
|
|
937
|
+
const addOwnerValues = (name, props) => {
|
|
938
|
+
const owner = (valuesByOwner[targetName(name)] ??= {});
|
|
939
|
+
for (const [prop, values] of Object.entries(valuesFromProps(props))) {
|
|
940
|
+
owner[prop] = new Set([...(owner[prop] ?? []), ...values]);
|
|
941
|
+
}
|
|
942
|
+
};
|
|
930
943
|
for (const doc of docs) {
|
|
931
944
|
if (typeof doc?.name === 'string') {
|
|
932
|
-
|
|
945
|
+
addOwnerValues(doc.name, doc.props);
|
|
933
946
|
}
|
|
934
947
|
for (const component of /** @type {any[]} */ (doc?.components ?? [])) {
|
|
935
948
|
if (typeof component?.name === 'string') {
|
|
936
|
-
|
|
937
|
-
component.props,
|
|
938
|
-
);
|
|
949
|
+
addOwnerValues(component.name, component.props);
|
|
939
950
|
}
|
|
940
951
|
}
|
|
941
952
|
}
|
|
@@ -15,6 +15,8 @@ export const docs = {
|
|
|
15
15
|
title: 'Custom themes',
|
|
16
16
|
content: [
|
|
17
17
|
{type: 'prose', text: "Use an installed built theme as the base for ordinary customization. Import it into your source and pass it as `extends` to `defineTheme({extends: importedTheme, ...})`. Build the result, then add the local slug. Only eject when you need to own and maintain a full source fork."},
|
|
18
|
+
{type: 'prose', text: "A local theme is a folder in `src/themes/<slug>/` holding a `<name>Theme.ts` source that exports `<name>Theme`, and a same-stem `<name>Theme.doc.mjs` descriptor that `theme add` reads. The stem must be a valid export name, so a hyphenated slug drops the hyphen: `brand-dark` lives in `src/themes/brand-dark/brandDarkTheme.ts` exporting `brandDarkTheme`, beside `brandDarkTheme.doc.mjs`. The descriptor's `name` is the folder's slug, and it must declare its type or `theme add` and `theme list` refuse it. {@command docs authoring theme-doc} lists every field."},
|
|
19
|
+
{type: 'code', lang: 'js', label: 'src/themes/brand-dark/brandDarkTheme.doc.mjs', code: "/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */\nexport default {\n type: 'theme',\n name: 'brand-dark',\n displayName: 'Brand Dark',\n description: 'The brand accent, tuned for dark mode.',\n maintained: false,\n};"},
|
|
18
20
|
{type: 'code', lang: 'bash', label: 'Add to use, eject to fork', code: '{@command theme list}\n{@command theme add stone}\n{@command theme eject stone}\n{@command theme build src/themes/stone/stoneTheme.ts}\n{@command theme add stone}'},
|
|
19
21
|
{type: 'prose', text: "For an annotated map of the whole surface (every defineTheme field, the token families, and the component override syntax, each with the CLI command that prints its reference), run `{@command theme template}`. It writes `theme.template.ts` into your project to read and copy from (`{@command init --features theme}` writes it as part of project setup)."},
|
|
20
22
|
{type: 'prose', text: 'To apply a theme you created, see {@link generic:use-a-theme}. To generate colors from seed values, see the Palette section below. Before you eject a package theme instead, see when that fits in {@link generic:use-a-theme}.'},
|
|
@@ -64,6 +64,26 @@ export const docs = {
|
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
id: 'upgrade',
|
|
69
|
+
title: 'Upgrade',
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
type: 'prose',
|
|
73
|
+
text: 'Upgrade every Astryx package your app lists in one command, to the same release. Each theme names the exact Core release it works with, so a theme left on an older release no longer matches the new Core.',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: 'code',
|
|
77
|
+
lang: 'bash',
|
|
78
|
+
label: 'Terminal',
|
|
79
|
+
code: `{@pm install @astryxdesign/core@latest @astryxdesign/theme-neutral@latest @astryxdesign/cli@latest}\n{@command upgrade --from <old Core version> --apply}`,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'prose',
|
|
83
|
+
text: "Add every other Astryx package your app lists to the same command, and pass the Core version you had before to `--from`. If your package manager holds new releases back, exempt the whole `@astryxdesign/*` scope; in pnpm, `minimumReleaseAgeExclude: ['@astryxdesign/*']`. Exempting only some of its packages installs packages from different releases side by side.",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
67
87
|
{
|
|
68
88
|
id: 'install-once',
|
|
69
89
|
title: 'Install once, use everywhere',
|
|
@@ -9,7 +9,7 @@ export const docs = {
|
|
|
9
9
|
placement: {parent: 'namespace:authoring', slot: 'guides', order: 40},
|
|
10
10
|
title: 'Help',
|
|
11
11
|
summary: 'Find a CLI message and how to fix it.',
|
|
12
|
-
keywords: ['help', 'troubleshooting', 'error'],
|
|
12
|
+
keywords: ['authoring', 'help', 'troubleshooting', 'error'],
|
|
13
13
|
slots: {
|
|
14
14
|
guides: {title: 'Help', accepts: {kinds: ['generic']}},
|
|
15
15
|
},
|
|
@@ -44,7 +44,7 @@ export const docs = {
|
|
|
44
44
|
content: [
|
|
45
45
|
{
|
|
46
46
|
type: 'prose',
|
|
47
|
-
text: 'Build the page with Astryx components as usual, then render it. The page module needs a default export; it renders on your machine with the React and Astryx packages your project installed.',
|
|
47
|
+
text: 'Build the page with Astryx components as usual, then render it. The page module needs a default export; it renders on your machine with the React and Astryx packages your project installed. Outside a project (no Astryx Core or CLI installed or declared for the folder), it renders with the Astryx, React and StyleX that the CLI itself runs with, so a single page file renders anywhere, a React app included.',
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
type: 'code',
|