@astryxdesign/cli 0.7.17-canary.g6ecaa86 → 0.7.17-canary.g8d3e010
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/theme/build/build.d.mts +50 -4
- package/api/theme/build/build.mjs +175 -32
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +10 -0
- package/api/theme/build/font-warning.d.mts +16 -3
- package/api/theme/build/font-warning.mjs +37 -5
- package/api/theme/build/icon-imports.mjs +25 -2
- package/api/theme-edit/_adapter.d.mts +42 -3
- package/api/theme-edit/_adapter.mjs +215 -50
- package/api/theme-edit/_catalog.mjs +19 -4
- package/api/theme-edit/_check.d.mts +23 -2
- package/api/theme-edit/_check.mjs +619 -207
- package/api/theme-edit/_compiler.mjs +80 -6
- package/api/theme-edit/_context.mjs +59 -11
- package/api/theme-edit/_edit.d.mts +14 -1
- package/api/theme-edit/_edit.mjs +935 -236
- package/api/theme-edit/_how-commands.d.mts +7 -1
- package/api/theme-edit/_how-commands.mjs +130 -12
- package/api/theme-edit/_how-question.d.mts +0 -7
- package/api/theme-edit/_how-question.mjs +1410 -333
- package/api/theme-edit/_how.d.mts +2 -1
- package/api/theme-edit/_how.mjs +100 -15
- package/api/theme-edit/_normal.d.mts +44 -9
- package/api/theme-edit/_normal.mjs +256 -54
- package/api/theme-edit/_part-words.d.mts +31 -0
- package/api/theme-edit/_part-words.mjs +126 -0
- package/api/theme-edit/_parts.d.mts +9 -1
- package/api/theme-edit/_parts.mjs +79 -32
- package/api/theme-edit/_preview-app.mjs +276 -54
- package/api/theme-edit/_preview.mjs +33 -2
- package/api/theme-edit/_project.d.mts +4 -0
- package/api/theme-edit/_project.mjs +3 -1
- package/api/theme-edit/_settings.d.mts +129 -71
- package/api/theme-edit/_settings.mjs +770 -576
- package/api/theme-edit/_tables.d.mts +9 -0
- package/api/theme-edit/_tables.mjs +19 -0
- package/api/theme-edit/_vet.d.mts +3 -1
- package/api/theme-edit/_vet.mjs +19 -6
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/theme.mjs +208 -48
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +179 -110
- package/clients/cli/lib/json-shim.mjs +16 -1
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/discovery/template-adapter.d.mts +1 -1
- package/foundation/discovery/theme-discovery.mjs +28 -2
- package/foundation/fs/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/gather-cache.mjs +27 -12
- package/foundation/fs/stop-cleanup.d.mts +12 -0
- package/foundation/fs/stop-cleanup.mjs +66 -0
- package/foundation/render/render-page.mjs +353 -82
- package/package.json +6 -6
|
@@ -183,16 +183,47 @@ export function importSpecifier(relDir: string, base: string): string;
|
|
|
183
183
|
* build selects, the same loader and interception) and name the export the
|
|
184
184
|
* build reads. Callers that must agree with the build on which theme a
|
|
185
185
|
* module defines read it here, never from the module's text.
|
|
186
|
+
*
|
|
187
|
+
* With `base`, also whether the theme extends that module's export, by
|
|
188
|
+
* identity, anywhere up its `extends` chain (`extendsBase`): the module is
|
|
189
|
+
* loaded once, and the theme module's imports of it (by any of
|
|
190
|
+
* `base.specifiers`) are handed that one load, so the answer is about the
|
|
191
|
+
* very object, not one that only looks like it.
|
|
186
192
|
* @param {string} file
|
|
187
|
-
* @param {{cwd?: string}} [ctx]
|
|
188
|
-
* @returns {Promise<{theme: any, exportName: string}>}
|
|
193
|
+
* @param {{cwd?: string, base?: {file: string, exportName: string, specifiers: string[]}}} [ctx]
|
|
194
|
+
* @returns {Promise<{theme: any, exportName: string, extendsBase?: boolean}>}
|
|
189
195
|
*/
|
|
190
|
-
export function loadThemeExport(file: string, { cwd }?: {
|
|
196
|
+
export function loadThemeExport(file: string, { cwd, base }?: {
|
|
191
197
|
cwd?: string;
|
|
198
|
+
base?: {
|
|
199
|
+
file: string;
|
|
200
|
+
exportName: string;
|
|
201
|
+
specifiers: string[];
|
|
202
|
+
};
|
|
192
203
|
}): Promise<{
|
|
193
204
|
theme: any;
|
|
194
205
|
exportName: string;
|
|
206
|
+
extendsBase?: boolean;
|
|
195
207
|
}>;
|
|
208
|
+
/**
|
|
209
|
+
* The input a theme module gives `defineTheme()` for the theme a build of
|
|
210
|
+
* it reads, evaluated as the build evaluates the module (an import, an
|
|
211
|
+
* expression, a spread or a computed key is its value), with the theme Core
|
|
212
|
+
* made of it. When Core refuses the input, the input the module gave for
|
|
213
|
+
* the named theme (else its last) and Core's error; null when the module
|
|
214
|
+
* does not load at all.
|
|
215
|
+
* @param {string} file
|
|
216
|
+
* @param {{cwd?: string, name?: string}} [ctx]
|
|
217
|
+
* @returns {Promise<{input: any, theme: any, error: Error | null} | null>}
|
|
218
|
+
*/
|
|
219
|
+
export function loadThemeInput(file: string, { cwd, name }?: {
|
|
220
|
+
cwd?: string;
|
|
221
|
+
name?: string;
|
|
222
|
+
}): Promise<{
|
|
223
|
+
input: any;
|
|
224
|
+
theme: any;
|
|
225
|
+
error: Error | null;
|
|
226
|
+
} | null>;
|
|
196
227
|
/**
|
|
197
228
|
* A one-mode `colorModes` value (`['light']` or `['dark']`), or null for
|
|
198
229
|
* anything else: a theme with both modes needs no export.
|
|
@@ -417,9 +448,13 @@ export type ThemeBuildTrailer = {
|
|
|
417
448
|
*/
|
|
418
449
|
unloadedFonts: string[];
|
|
419
450
|
/**
|
|
420
|
-
* One notice per unloaded font family.
|
|
451
|
+
* One notice per unloaded font family, as printed.
|
|
421
452
|
*/
|
|
422
453
|
fontNotices: string[];
|
|
454
|
+
/**
|
|
455
|
+
* How the caller loads fonts, when it does.
|
|
456
|
+
*/
|
|
457
|
+
fontHelp?: FontHelp | null | undefined;
|
|
423
458
|
};
|
|
424
459
|
/**
|
|
425
460
|
* What the CLI hands a build beyond themeBuild's options. CLI-internal, never
|
|
@@ -448,5 +483,16 @@ export type ThemeBuildHandOff = {
|
|
|
448
483
|
build: string;
|
|
449
484
|
};
|
|
450
485
|
colorModes?: ["light"] | ["dark"] | null;
|
|
486
|
+
fontHelp?: FontHelp | null;
|
|
487
|
+
loadedFonts?: ((family: string) => boolean) | null;
|
|
488
|
+
};
|
|
489
|
+
/**
|
|
490
|
+
* How a caller that loads a theme's fonts itself (the editor's app copy)
|
|
491
|
+
* says to load a family: the notice per family and the recipe in place of
|
|
492
|
+
* the generic one.
|
|
493
|
+
*/
|
|
494
|
+
export type FontHelp = {
|
|
495
|
+
notice: (family: string) => string;
|
|
496
|
+
recipe: (families: string[]) => string;
|
|
451
497
|
};
|
|
452
498
|
import { AstryxError } from '../../error.mjs';
|
|
@@ -329,7 +329,9 @@ function importTarget(dir, subpath) {
|
|
|
329
329
|
/** @param {string} file @returns {string} its real path, or itself */
|
|
330
330
|
function realOrSelf(file) {
|
|
331
331
|
try {
|
|
332
|
-
|
|
332
|
+
// The native form spells a path as the disk does (its own case on a
|
|
333
|
+
// case-insensitive disk), so two spellings of one file compare equal.
|
|
334
|
+
return fs.realpathSync.native(file);
|
|
333
335
|
} catch {
|
|
334
336
|
return file;
|
|
335
337
|
}
|
|
@@ -1206,7 +1208,14 @@ function assertThemeSourceFile(filePath, cwd, mode = {}) {
|
|
|
1206
1208
|
* `familyInterception` make the build a family member's plan.
|
|
1207
1209
|
* `colorModes` is the one color mode a calling command knows the theme has
|
|
1208
1210
|
* (the theme editor, from its settings), written into the built module.
|
|
1209
|
-
* @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}, colorModes?: ['light'] | ['dark'] | null}} ThemeBuildHandOff
|
|
1211
|
+
* @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}, colorModes?: ['light'] | ['dark'] | null, fontHelp?: FontHelp | null, loadedFonts?: ((family: string) => boolean) | null}} ThemeBuildHandOff
|
|
1212
|
+
*/
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* How a caller that loads a theme's fonts itself (the editor's app copy)
|
|
1216
|
+
* says to load a family: the notice per family and the recipe in place of
|
|
1217
|
+
* the generic one.
|
|
1218
|
+
* @typedef {{notice: (family: string) => string, recipe: (families: string[]) => string}} FontHelp
|
|
1210
1219
|
*/
|
|
1211
1220
|
|
|
1212
1221
|
/**
|
|
@@ -1336,11 +1345,12 @@ export function buildSuggestion(source, mode, cwd, words, shape = {}) {
|
|
|
1336
1345
|
* @param {Array<{dest: string}>} writes
|
|
1337
1346
|
* @param {string} filePath the theme source
|
|
1338
1347
|
* @param {string} cwd
|
|
1339
|
-
* @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void}} [options]
|
|
1348
|
+
* @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void, onWarning?: (message: string) => void}} [options]
|
|
1340
1349
|
* `claimed`: outputs written earlier in this run, by the source that wrote
|
|
1341
1350
|
* them; `rerun`: this build's command with another --out, or without one;
|
|
1342
1351
|
* `elsewhere`: the option that moves the outputs; `onEditorFolder`: takes
|
|
1343
|
-
* the editor-folder warning instead of the logger (a watcher prints it
|
|
1352
|
+
* the editor-folder warning instead of the logger (a watcher prints it
|
|
1353
|
+
* once); `onWarning`: each warning's message too, for the result
|
|
1344
1354
|
*/
|
|
1345
1355
|
function assertOutputsReplaceable(
|
|
1346
1356
|
writes,
|
|
@@ -1352,6 +1362,7 @@ function assertOutputsReplaceable(
|
|
|
1352
1362
|
refuseUnmarked = false,
|
|
1353
1363
|
elsewhere = '--out',
|
|
1354
1364
|
onEditorFolder,
|
|
1365
|
+
onWarning,
|
|
1355
1366
|
} = {},
|
|
1356
1367
|
) {
|
|
1357
1368
|
const rel = (/** @type {string} */ file) => path.relative(cwd, file);
|
|
@@ -1433,7 +1444,7 @@ function assertOutputsReplaceable(
|
|
|
1433
1444
|
// It is printed after every output passes, so it names a replacement
|
|
1434
1445
|
// that happens.
|
|
1435
1446
|
if (warnedOtherSource) continue;
|
|
1436
|
-
warnedOtherSource =
|
|
1447
|
+
warnedOtherSource = `${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
|
|
1437
1448
|
} else if (otherSource) {
|
|
1438
1449
|
throw new AstryxError(
|
|
1439
1450
|
`${rel(write.dest)} is the build output of another theme source, ${otherSource}, so this build does not replace it. Pick another ${elsewhere}.`,
|
|
@@ -1470,12 +1481,16 @@ function assertOutputsReplaceable(
|
|
|
1470
1481
|
}
|
|
1471
1482
|
// Warned only once nothing refuses the build, so it names a write that
|
|
1472
1483
|
// happens.
|
|
1473
|
-
if (warnedOtherSource)
|
|
1484
|
+
if (warnedOtherSource) {
|
|
1485
|
+
logger.warn(`Warning: ${warnedOtherSource}`);
|
|
1486
|
+
onWarning?.(warnedOtherSource);
|
|
1487
|
+
}
|
|
1474
1488
|
if (editorFolder) {
|
|
1475
1489
|
const dir = path.dirname(writes[0].dest);
|
|
1476
|
-
const
|
|
1477
|
-
if (onEditorFolder) onEditorFolder(
|
|
1478
|
-
else logger.warn(
|
|
1490
|
+
const message = `${rel(dir) || '.'} is a folder the theme editor made, and ${rel(filePath)} is outside it; the build writes there anyway. Build beside the source, or pick another ${elsewhere}, to keep the editor's folder to its own theme.`;
|
|
1491
|
+
if (onEditorFolder) onEditorFolder(`Warning: ${message}`);
|
|
1492
|
+
else logger.warn(`Warning: ${message}`);
|
|
1493
|
+
onWarning?.(message);
|
|
1479
1494
|
}
|
|
1480
1495
|
}
|
|
1481
1496
|
|
|
@@ -1567,7 +1582,31 @@ function writeBuildOutputs(writes) {
|
|
|
1567
1582
|
})),
|
|
1568
1583
|
);
|
|
1569
1584
|
} catch (error) {
|
|
1570
|
-
const
|
|
1585
|
+
const e = /** @type {NodeJS.ErrnoException} */ (error);
|
|
1586
|
+
// A place the outputs cannot be written: name it and its fix (the
|
|
1587
|
+
// writes go through temporary files beside each output, whose names
|
|
1588
|
+
// help nobody).
|
|
1589
|
+
if (e.code === 'EACCES' || e.code === 'EPERM' || e.code === 'EROFS') {
|
|
1590
|
+
const failed = e.path ? path.resolve(e.path) : null;
|
|
1591
|
+
const output = writes.find(w => path.resolve(w.dest) === failed);
|
|
1592
|
+
const place = output
|
|
1593
|
+
? output.dest
|
|
1594
|
+
: failed
|
|
1595
|
+
? path.dirname(failed)
|
|
1596
|
+
: path.dirname(writes[0].dest);
|
|
1597
|
+
const shownPlace = path.relative(process.cwd(), place) || place;
|
|
1598
|
+
throw new AstryxError(
|
|
1599
|
+
`Could not write the theme's outputs: ${shownPlace} is not writable (${e.code}). Give yourself write permission on it (chmod u+w ${shellWord(shownPlace)}), then build again. Nothing was changed.`,
|
|
1600
|
+
[
|
|
1601
|
+
{
|
|
1602
|
+
name: `ls -ld ${shellWord(shownPlace)}`,
|
|
1603
|
+
reason: 'see its permissions',
|
|
1604
|
+
},
|
|
1605
|
+
],
|
|
1606
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
const message = `Failed to write theme outputs: ${e.message}`;
|
|
1571
1610
|
throw new AstryxError(message, undefined, ERROR_CODES.ERR_WRITE_FAILED);
|
|
1572
1611
|
}
|
|
1573
1612
|
}
|
|
@@ -2763,7 +2802,7 @@ function isSyncLoaderLimitation(error) {
|
|
|
2763
2802
|
* @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes: ["light"] | ["dark"] | null}>}
|
|
2764
2803
|
*/
|
|
2765
2804
|
// prettier-ignore
|
|
2766
|
-
async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
2805
|
+
async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined, /** @type {string | undefined} */ pick = undefined) {
|
|
2767
2806
|
const jiti =
|
|
2768
2807
|
loader ??
|
|
2769
2808
|
createJiti(import.meta.url, {
|
|
@@ -2830,6 +2869,12 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
2830
2869
|
);
|
|
2831
2870
|
const hasDefault = isModule && Object.hasOwn(mod, 'default');
|
|
2832
2871
|
const defaultExport = hasDefault ? mod.default : undefined;
|
|
2872
|
+
// A caller that already knows which export a build reads (from a load
|
|
2873
|
+
// as the build loads it) reads that one.
|
|
2874
|
+
if (pick !== undefined && isModule && Object.hasOwn(mod, pick)) {
|
|
2875
|
+
if (isThemeObject(mod[pick]))
|
|
2876
|
+
return {theme: mod[pick], exportName: pick, degraded, colorModes};
|
|
2877
|
+
}
|
|
2833
2878
|
if (isThemeObject(defaultExport)) {
|
|
2834
2879
|
return {theme: defaultExport, exportName: 'default', degraded, colorModes};
|
|
2835
2880
|
}
|
|
@@ -2940,9 +2985,9 @@ function isThemeObject(value) {
|
|
|
2940
2985
|
* @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes?: ['light'] | ['dark'] | null}>}
|
|
2941
2986
|
*/
|
|
2942
2987
|
// prettier-ignore
|
|
2943
|
-
async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
2988
|
+
async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined, /** @type {string | undefined} */ pick = undefined) {
|
|
2944
2989
|
try {
|
|
2945
|
-
return await importThemeModule(filePath, interception, loader);
|
|
2990
|
+
return await importThemeModule(filePath, interception, loader, pick);
|
|
2946
2991
|
} catch (jitiError) {
|
|
2947
2992
|
const je = /** @type {Error} */ (jitiError);
|
|
2948
2993
|
throw new Error(
|
|
@@ -2970,18 +3015,86 @@ function standaloneInterception(filePath) {
|
|
|
2970
3015
|
* build selects, the same loader and interception) and name the export the
|
|
2971
3016
|
* build reads. Callers that must agree with the build on which theme a
|
|
2972
3017
|
* module defines read it here, never from the module's text.
|
|
3018
|
+
*
|
|
3019
|
+
* With `base`, also whether the theme extends that module's export, by
|
|
3020
|
+
* identity, anywhere up its `extends` chain (`extendsBase`): the module is
|
|
3021
|
+
* loaded once, and the theme module's imports of it (by any of
|
|
3022
|
+
* `base.specifiers`) are handed that one load, so the answer is about the
|
|
3023
|
+
* very object, not one that only looks like it.
|
|
2973
3024
|
* @param {string} file
|
|
2974
|
-
* @param {{cwd?: string}} [ctx]
|
|
2975
|
-
* @returns {Promise<{theme: any, exportName: string}>}
|
|
3025
|
+
* @param {{cwd?: string, base?: {file: string, exportName: string, specifiers: string[]}}} [ctx]
|
|
3026
|
+
* @returns {Promise<{theme: any, exportName: string, extendsBase?: boolean}>}
|
|
2976
3027
|
*/
|
|
2977
|
-
export async function loadThemeExport(file, {cwd = process.cwd()} = {}) {
|
|
3028
|
+
export async function loadThemeExport(file, {cwd = process.cwd(), base} = {}) {
|
|
2978
3029
|
const filePath = path.resolve(cwd, file);
|
|
2979
3030
|
await selectCore(cwd, {projectOnly: false});
|
|
2980
|
-
const {theme, exportName} = await extractThemeDefinition(
|
|
3031
|
+
const {theme, exportName = 'default'} = await extractThemeDefinition(
|
|
2981
3032
|
filePath,
|
|
2982
3033
|
standaloneInterception(filePath),
|
|
2983
3034
|
);
|
|
2984
|
-
return {theme, exportName
|
|
3035
|
+
if (!base) return {theme, exportName};
|
|
3036
|
+
const recorder = interceptCore(_coreThemeModule, _coreRootModule);
|
|
3037
|
+
const shared = (
|
|
3038
|
+
await extractThemeDefinition(
|
|
3039
|
+
path.resolve(cwd, base.file),
|
|
3040
|
+
recorder,
|
|
3041
|
+
undefined,
|
|
3042
|
+
base.exportName,
|
|
3043
|
+
)
|
|
3044
|
+
).theme;
|
|
3045
|
+
const withBase = {
|
|
3046
|
+
...recorder,
|
|
3047
|
+
modules: {
|
|
3048
|
+
...recorder.modules,
|
|
3049
|
+
...Object.fromEntries(
|
|
3050
|
+
base.specifiers.map(s => [s, {[base.exportName]: shared}]),
|
|
3051
|
+
),
|
|
3052
|
+
},
|
|
3053
|
+
};
|
|
3054
|
+
const again = await extractThemeDefinition(
|
|
3055
|
+
filePath,
|
|
3056
|
+
withBase,
|
|
3057
|
+
undefined,
|
|
3058
|
+
exportName,
|
|
3059
|
+
);
|
|
3060
|
+
let extendsBase = false;
|
|
3061
|
+
for (
|
|
3062
|
+
let at = recorder.parentOf(again.theme), depth = 0;
|
|
3063
|
+
at && depth < 64;
|
|
3064
|
+
at = recorder.parentOf(at), depth++
|
|
3065
|
+
)
|
|
3066
|
+
if (at === shared) {
|
|
3067
|
+
extendsBase = true;
|
|
3068
|
+
break;
|
|
3069
|
+
}
|
|
3070
|
+
return {theme, exportName, extendsBase};
|
|
3071
|
+
}
|
|
3072
|
+
|
|
3073
|
+
/**
|
|
3074
|
+
* The input a theme module gives `defineTheme()` for the theme a build of
|
|
3075
|
+
* it reads, evaluated as the build evaluates the module (an import, an
|
|
3076
|
+
* expression, a spread or a computed key is its value), with the theme Core
|
|
3077
|
+
* made of it. When Core refuses the input, the input the module gave for
|
|
3078
|
+
* the named theme (else its last) and Core's error; null when the module
|
|
3079
|
+
* does not load at all.
|
|
3080
|
+
* @param {string} file
|
|
3081
|
+
* @param {{cwd?: string, name?: string}} [ctx]
|
|
3082
|
+
* @returns {Promise<{input: any, theme: any, error: Error | null} | null>}
|
|
3083
|
+
*/
|
|
3084
|
+
export async function loadThemeInput(file, {cwd = process.cwd(), name} = {}) {
|
|
3085
|
+
const filePath = path.resolve(cwd, file);
|
|
3086
|
+
await selectCore(cwd, {projectOnly: false});
|
|
3087
|
+
const interception = interceptCore(_coreThemeModule, _coreRootModule);
|
|
3088
|
+
try {
|
|
3089
|
+
const {theme} = await extractThemeDefinition(filePath, interception);
|
|
3090
|
+
return {input: interception.inputOf(theme) ?? null, theme, error: null};
|
|
3091
|
+
} catch (e) {
|
|
3092
|
+
const given = interception.inputs;
|
|
3093
|
+
const input =
|
|
3094
|
+
given.filter(x => x && typeof x === 'object' && x.name === name).at(-1) ??
|
|
3095
|
+
given.at(-1);
|
|
3096
|
+
return input ? {input, theme: null, error: /** @type {Error} */ (e)} : null;
|
|
3097
|
+
}
|
|
2985
3098
|
}
|
|
2986
3099
|
|
|
2987
3100
|
/**
|
|
@@ -4580,9 +4693,10 @@ async function themeBuildInternal(
|
|
|
4580
4693
|
.join(path.dirname(options.out), `${stem}.css`)
|
|
4581
4694
|
.split(path.sep)
|
|
4582
4695
|
.join('/');
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
);
|
|
4696
|
+
// The result's warnings say it too, as text does.
|
|
4697
|
+
const w = `--out names the stylesheet, which is CSS; give it a .css name such as ${fixed}.`;
|
|
4698
|
+
warningMessages.push(w);
|
|
4699
|
+
logger.warn(`Warning: ${w}`);
|
|
4586
4700
|
}
|
|
4587
4701
|
// A build keeps the explicit output inside the write root, relative or
|
|
4588
4702
|
// absolute. Check mode writes nothing, so it refuses only a relative path
|
|
@@ -4672,6 +4786,8 @@ async function themeBuildInternal(
|
|
|
4672
4786
|
? `export declare const colorModes: readonly [${JSON.stringify(colorModes[0])}];\n`
|
|
4673
4787
|
: '');
|
|
4674
4788
|
|
|
4789
|
+
// A family the caller knows the app loads (a font stylesheet it writes
|
|
4790
|
+
// for the theme) is not named as unloaded.
|
|
4675
4791
|
const unloadedFonts = [
|
|
4676
4792
|
...new Set([
|
|
4677
4793
|
...collectUnloadedFonts(resolvedTheme),
|
|
@@ -4679,7 +4795,7 @@ async function themeBuildInternal(
|
|
|
4679
4795
|
(/** @type {any} */ value) => collectUnloadedFonts(value),
|
|
4680
4796
|
),
|
|
4681
4797
|
]),
|
|
4682
|
-
];
|
|
4798
|
+
].filter(family => !handOff.loadedFonts?.(family));
|
|
4683
4799
|
|
|
4684
4800
|
if (handOff.prepareFamily) {
|
|
4685
4801
|
return {
|
|
@@ -4732,6 +4848,8 @@ async function themeBuildInternal(
|
|
|
4732
4848
|
rerun,
|
|
4733
4849
|
refuseUnmarked: Boolean(options.out),
|
|
4734
4850
|
onEditorFolder: editorFolderListener ?? undefined,
|
|
4851
|
+
// The result's warnings carry what text prints.
|
|
4852
|
+
onWarning: message => warningMessages.push(message),
|
|
4735
4853
|
});
|
|
4736
4854
|
}
|
|
4737
4855
|
|
|
@@ -4822,12 +4940,19 @@ async function themeBuildInternal(
|
|
|
4822
4940
|
// permanently in violation of its own "compiles with no warnings" guard).
|
|
4823
4941
|
// Adaptation rules are resolved theme writes in their own right, so a family
|
|
4824
4942
|
// named only inside one needs the same notice as one named at the root.
|
|
4943
|
+
// The result names the recipe's command bare, as every machine-read
|
|
4944
|
+
// command is; the printed note starts it the way this project runs the CLI.
|
|
4945
|
+
/** @param {string} family @param {string} recipe */
|
|
4946
|
+
const fontNotice = (family, recipe) =>
|
|
4947
|
+
handOff.fontHelp?.notice(family) ??
|
|
4948
|
+
`Font "${family}" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: ${recipe})`;
|
|
4825
4949
|
/** @type {string[]} */
|
|
4826
4950
|
const fontNotices = [];
|
|
4827
4951
|
for (const family of unloadedFonts) {
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4952
|
+
noticeMessages.push(fontNotice(family, 'astryx docs typography'));
|
|
4953
|
+
fontNotices.push(
|
|
4954
|
+
fontNotice(family, formatCliCommand('docs typography', cwd)),
|
|
4955
|
+
);
|
|
4831
4956
|
}
|
|
4832
4957
|
|
|
4833
4958
|
/** @type {ThemeBuildTrailer} */
|
|
@@ -4838,6 +4963,7 @@ async function themeBuildInternal(
|
|
|
4838
4963
|
cssImport,
|
|
4839
4964
|
unloadedFonts,
|
|
4840
4965
|
fontNotices,
|
|
4966
|
+
fontHelp: handOff.fontHelp ?? null,
|
|
4841
4967
|
};
|
|
4842
4968
|
// A batch or compact report prints this once for the whole run instead.
|
|
4843
4969
|
if (report.trailers) report.trailers.push(trailer);
|
|
@@ -4874,7 +5000,8 @@ async function themeBuildInternal(
|
|
|
4874
5000
|
* @property {string} jsImport Import specifier of the built JS module.
|
|
4875
5001
|
* @property {string} cssImport Import specifier of the built CSS.
|
|
4876
5002
|
* @property {string[]} unloadedFonts Font families the theme names but does not load.
|
|
4877
|
-
* @property {string[]} fontNotices One notice per unloaded font family.
|
|
5003
|
+
* @property {string[]} fontNotices One notice per unloaded font family, as printed.
|
|
5004
|
+
* @property {FontHelp | null} [fontHelp] How the caller loads fonts, when it does.
|
|
4878
5005
|
*/
|
|
4879
5006
|
|
|
4880
5007
|
/**
|
|
@@ -4905,7 +5032,13 @@ Or with a <link> tag:
|
|
|
4905
5032
|
`);
|
|
4906
5033
|
for (const msg of trailer.fontNotices) logger.log(` note: ${msg}`);
|
|
4907
5034
|
if (trailer.unloadedFonts.length > 0) {
|
|
4908
|
-
logger.log(
|
|
5035
|
+
logger.log(
|
|
5036
|
+
formatFontLoadingHelp(
|
|
5037
|
+
trailer.themeName,
|
|
5038
|
+
trailer.unloadedFonts,
|
|
5039
|
+
trailer.fontHelp?.recipe,
|
|
5040
|
+
),
|
|
5041
|
+
);
|
|
4909
5042
|
}
|
|
4910
5043
|
}
|
|
4911
5044
|
|
|
@@ -4948,7 +5081,10 @@ Or with a <link> tag:
|
|
|
4948
5081
|
}
|
|
4949
5082
|
}
|
|
4950
5083
|
const fonts = groupUnloadedFonts(trailers);
|
|
4951
|
-
|
|
5084
|
+
// One caller's recipe serves the batch only when every theme takes it.
|
|
5085
|
+
const help = trailers.every(t => t.fontHelp) ? trailers[0].fontHelp : null;
|
|
5086
|
+
if (fonts.length > 0)
|
|
5087
|
+
logger.log(formatBatchFontLoadingHelp(fonts, help?.recipe));
|
|
4952
5088
|
}
|
|
4953
5089
|
|
|
4954
5090
|
/**
|
|
@@ -5503,11 +5639,18 @@ Or load the same stylesheet natively:
|
|
|
5503
5639
|
const unloadedFonts = [
|
|
5504
5640
|
...new Set(members.flatMap(member => member.unloadedFonts)),
|
|
5505
5641
|
];
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5642
|
+
/** @param {string} family @param {string} recipe */
|
|
5643
|
+
const familyNotice = (family, recipe) =>
|
|
5644
|
+
`Font "${family}" is named by this theme family but not loaded; add a <link> or @font-face in your app (recipe: ${recipe})`;
|
|
5645
|
+
// The result names the command bare; the printed note as this project
|
|
5646
|
+
// runs the CLI.
|
|
5647
|
+
const notices = unloadedFonts.map(family =>
|
|
5648
|
+
familyNotice(family, 'astryx docs typography'),
|
|
5509
5649
|
);
|
|
5510
|
-
for (const
|
|
5650
|
+
for (const family of unloadedFonts)
|
|
5651
|
+
logger.log(
|
|
5652
|
+
` note: ${familyNotice(family, formatCliCommand('docs typography', cwd))}`,
|
|
5653
|
+
);
|
|
5511
5654
|
return {
|
|
5512
5655
|
type: 'theme.build',
|
|
5513
5656
|
data: {
|
|
@@ -57,6 +57,16 @@ export type CoreInterception = {
|
|
|
57
57
|
* - Exact authored `extends` value.
|
|
58
58
|
*/
|
|
59
59
|
parentOf: (theme: any) => any;
|
|
60
|
+
/**
|
|
61
|
+
* - The raw `defineTheme()` argument
|
|
62
|
+
* that produced a theme, or undefined.
|
|
63
|
+
*/
|
|
64
|
+
inputOf: (theme: any) => any;
|
|
65
|
+
/**
|
|
66
|
+
* - Every `defineTheme()` argument in call order,
|
|
67
|
+
* recorded before Core reads it, so an input Core refuses is seen too.
|
|
68
|
+
*/
|
|
69
|
+
inputs: any[];
|
|
60
70
|
/**
|
|
61
71
|
* - Every raw input that fed a
|
|
62
72
|
* theme, following its own `extends` chain and spread provenance.
|
|
@@ -95,6 +95,10 @@ const retainedLineageByReference = new WeakMap();
|
|
|
95
95
|
* @property {(theme: any) => boolean} observed - Whether authored input was captured.
|
|
96
96
|
* @property {(theme: any) => void} retain - Retain capture before stripping.
|
|
97
97
|
* @property {(theme: any) => any} parentOf - Exact authored `extends` value.
|
|
98
|
+
* @property {(theme: any) => any} inputOf - The raw `defineTheme()` argument
|
|
99
|
+
* that produced a theme, or undefined.
|
|
100
|
+
* @property {any[]} inputs - Every `defineTheme()` argument in call order,
|
|
101
|
+
* recorded before Core reads it, so an input Core refuses is seen too.
|
|
98
102
|
* @property {(theme: any) => any[]} lineageOf - Every raw input that fed a
|
|
99
103
|
* theme, following its own `extends` chain and spread provenance.
|
|
100
104
|
* @property {(theme: any) => any[]} unobservedIn - Lineage members this
|
|
@@ -243,6 +247,8 @@ function mergeGenerativeAxes(inherited, own) {
|
|
|
243
247
|
export function interceptCore(coreThemeModule, coreRootModule) {
|
|
244
248
|
/** @type {WeakMap<object, ThemeLineage>} */
|
|
245
249
|
const byReference = new WeakMap();
|
|
250
|
+
/** @type {any[]} */
|
|
251
|
+
const inputs = [];
|
|
246
252
|
|
|
247
253
|
/** @param {any} value @param {ThemeLineage} lineage */
|
|
248
254
|
const mark = (value, lineage) => {
|
|
@@ -281,6 +287,7 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
281
287
|
...namespace,
|
|
282
288
|
/** @param {any} input */
|
|
283
289
|
defineTheme(input) {
|
|
290
|
+
inputs.push(input);
|
|
284
291
|
const result = real.call(namespace, input);
|
|
285
292
|
mark(result, {input, result});
|
|
286
293
|
return result;
|
|
@@ -317,6 +324,9 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
317
324
|
|
|
318
325
|
return {
|
|
319
326
|
modules,
|
|
327
|
+
inputs,
|
|
328
|
+
// prettier-ignore
|
|
329
|
+
inputOf(theme) { return lineageFor(theme)?.input; },
|
|
320
330
|
|
|
321
331
|
// prettier-ignore
|
|
322
332
|
observed(theme) { return wasObserved(theme, byReference); },
|
|
@@ -8,9 +8,18 @@
|
|
|
8
8
|
* @returns {string[]}
|
|
9
9
|
*/
|
|
10
10
|
export function namedFontFamilies(value: string): string[];
|
|
11
|
+
/**
|
|
12
|
+
* The family list of a CSS `font` shorthand: what follows its size (and
|
|
13
|
+
* line height), as the shorthand's grammar puts it last. A system font
|
|
14
|
+
* keyword (`caption`, `menu`, ...) or a value with no size names none.
|
|
15
|
+
* @param {string} value
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
export function fontShorthandFamilyList(value: string): string;
|
|
11
19
|
/**
|
|
12
20
|
* Collect the font families a resolved theme names but does not load —
|
|
13
|
-
* every `--font-family-*` token plus every component-override `fontFamily
|
|
21
|
+
* every `--font-family-*` token plus every component-override `fontFamily`
|
|
22
|
+
* and the families of a `font` shorthand,
|
|
14
23
|
* minus generics, CSS-wide keywords, `var()` references, and known system
|
|
15
24
|
* families. Source order, first-seen casing, deduped case-insensitively.
|
|
16
25
|
*
|
|
@@ -42,17 +51,21 @@ export function collectUnloadedFonts(resolvedTheme: {
|
|
|
42
51
|
*
|
|
43
52
|
* @param {string} themeName
|
|
44
53
|
* @param {string[]} families
|
|
54
|
+
* @param {(families: string[]) => string} [recipe] the caller's own way to
|
|
55
|
+
* load them, in place of the generic recipe
|
|
45
56
|
* @returns {string}
|
|
46
57
|
*/
|
|
47
|
-
export function formatFontLoadingHelp(themeName: string, families: string[]): string;
|
|
58
|
+
export function formatFontLoadingHelp(themeName: string, families: string[], recipe?: (families: string[]) => string): string;
|
|
48
59
|
/**
|
|
49
60
|
* The same fix once for a batch build: each family the built themes name but
|
|
50
61
|
* do not load, with the themes that name it, then one recipe for all of them.
|
|
51
62
|
*
|
|
52
63
|
* @param {Array<{family: string, themes: string[]}>} entries
|
|
64
|
+
* @param {(families: string[]) => string} [recipe] the caller's own way to
|
|
65
|
+
* load them, in place of the generic recipe
|
|
53
66
|
* @returns {string}
|
|
54
67
|
*/
|
|
55
68
|
export function formatBatchFontLoadingHelp(entries: Array<{
|
|
56
69
|
family: string;
|
|
57
70
|
themes: string[];
|
|
58
|
-
}
|
|
71
|
+
}>, recipe?: (families: string[]) => string): string;
|
|
@@ -146,9 +146,27 @@ export function namedFontFamilies(value) {
|
|
|
146
146
|
);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
/**
|
|
150
|
+
* The family list of a CSS `font` shorthand: what follows its size (and
|
|
151
|
+
* line height), as the shorthand's grammar puts it last. A system font
|
|
152
|
+
* keyword (`caption`, `menu`, ...) or a value with no size names none.
|
|
153
|
+
* @param {string} value
|
|
154
|
+
* @returns {string}
|
|
155
|
+
*/
|
|
156
|
+
export function fontShorthandFamilyList(value) {
|
|
157
|
+
// A size has a unit (a bare number is a weight); a line height may
|
|
158
|
+
// follow it after a slash.
|
|
159
|
+
const size =
|
|
160
|
+
/(?<=^|\s)(?:[+-]?(?:\d+\.?\d*|\.\d+)(?:[a-z]+|%)|xx-small|x-small|small|medium|large|x-large|xx-large|xxx-large|larger|smaller|(?:calc|clamp|min|max|var)\([^)]*\))(?:\s*\/\s*\S+)?\s+(?=\S)/i;
|
|
161
|
+
// The first size: a family name after it may hold anything.
|
|
162
|
+
const m = size.exec(String(value));
|
|
163
|
+
return m ? String(value).slice(m.index + m[0].length) : '';
|
|
164
|
+
}
|
|
165
|
+
|
|
149
166
|
/**
|
|
150
167
|
* Collect the font families a resolved theme names but does not load —
|
|
151
|
-
* every `--font-family-*` token plus every component-override `fontFamily
|
|
168
|
+
* every `--font-family-*` token plus every component-override `fontFamily`
|
|
169
|
+
* and the families of a `font` shorthand,
|
|
152
170
|
* minus generics, CSS-wide keywords, `var()` references, and known system
|
|
153
171
|
* families. Source order, first-seen casing, deduped case-insensitively.
|
|
154
172
|
*
|
|
@@ -202,6 +220,9 @@ export function collectUnloadedFonts(resolvedTheme) {
|
|
|
202
220
|
if (!node || typeof node !== 'object') return;
|
|
203
221
|
for (const [key, value] of Object.entries(node)) {
|
|
204
222
|
if (key === 'fontFamily') consider(value);
|
|
223
|
+
// A `font` shorthand names its families last.
|
|
224
|
+
else if (key === 'font' && typeof value === 'string')
|
|
225
|
+
consider(fontShorthandFamilyList(value));
|
|
205
226
|
else walk(value);
|
|
206
227
|
}
|
|
207
228
|
};
|
|
@@ -217,13 +238,19 @@ export function collectUnloadedFonts(resolvedTheme) {
|
|
|
217
238
|
*
|
|
218
239
|
* @param {string} themeName
|
|
219
240
|
* @param {string[]} families
|
|
241
|
+
* @param {(families: string[]) => string} [recipe] the caller's own way to
|
|
242
|
+
* load them, in place of the generic recipe
|
|
220
243
|
* @returns {string}
|
|
221
244
|
*/
|
|
222
|
-
export function formatFontLoadingHelp(
|
|
245
|
+
export function formatFontLoadingHelp(
|
|
246
|
+
themeName,
|
|
247
|
+
families,
|
|
248
|
+
recipe = fontLoadingRecipe,
|
|
249
|
+
) {
|
|
223
250
|
const named = families.map(f => `"${f}"`).join(', ');
|
|
224
251
|
return `
|
|
225
252
|
[note] Theme "${themeName}" names fonts it does not load: ${named}
|
|
226
|
-
${
|
|
253
|
+
${recipe(families)}`;
|
|
227
254
|
}
|
|
228
255
|
|
|
229
256
|
/**
|
|
@@ -231,16 +258,21 @@ ${fontLoadingRecipe(families)}`;
|
|
|
231
258
|
* do not load, with the themes that name it, then one recipe for all of them.
|
|
232
259
|
*
|
|
233
260
|
* @param {Array<{family: string, themes: string[]}>} entries
|
|
261
|
+
* @param {(families: string[]) => string} [recipe] the caller's own way to
|
|
262
|
+
* load them, in place of the generic recipe
|
|
234
263
|
* @returns {string}
|
|
235
264
|
*/
|
|
236
|
-
export function formatBatchFontLoadingHelp(
|
|
265
|
+
export function formatBatchFontLoadingHelp(
|
|
266
|
+
entries,
|
|
267
|
+
recipe = fontLoadingRecipe,
|
|
268
|
+
) {
|
|
237
269
|
const named = entries
|
|
238
270
|
.map(({family, themes}) => ` "${family}" (${themes.join(', ')})`)
|
|
239
271
|
.join('\n');
|
|
240
272
|
return `
|
|
241
273
|
[note] The built themes name fonts they do not load:
|
|
242
274
|
${named}
|
|
243
|
-
${
|
|
275
|
+
${recipe(entries.map(entry => entry.family))}`;
|
|
244
276
|
}
|
|
245
277
|
|
|
246
278
|
/**
|
|
@@ -160,6 +160,19 @@ export async function resolveIconImports(
|
|
|
160
160
|
const defaultName = staticSlots ? 'themeComponentIcons' : 'themeIcons';
|
|
161
161
|
/** @param {string} [name] @param {string} [reason] @returns {never} */
|
|
162
162
|
const invalidRegistry = (name, reason) => registryError(name, reason, field);
|
|
163
|
+
/**
|
|
164
|
+
* A theme written as an expression the build does not follow (a call to
|
|
165
|
+
* a helper, a conditional): where its icons come from cannot be read.
|
|
166
|
+
* @param {any} node
|
|
167
|
+
* @returns {never}
|
|
168
|
+
*/
|
|
169
|
+
const untraceableTheme = node => {
|
|
170
|
+
throw new AstryxError(
|
|
171
|
+
`The build carries a theme's ${field === 'icons' ? 'icon registry' : 'componentIcons'} from the source that writes it, and follows a theme only through its name, an import of it, or defineTheme({...}); here a theme is written as ${node?.type === 'CallExpression' ? 'a call to a helper' : node?.type === 'ConditionalExpression' ? 'a conditional' : 'an expression'}, which it cannot follow. Write each theme as defineTheme({...}), and the theme it extends by its name (extends: neutralTheme).`,
|
|
172
|
+
undefined,
|
|
173
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
174
|
+
);
|
|
175
|
+
};
|
|
163
176
|
|
|
164
177
|
if (exportName === undefined) {
|
|
165
178
|
if (!hasIcons) return null;
|
|
@@ -797,10 +810,20 @@ export async function resolveIconImports(
|
|
|
797
810
|
if (ref) return themeReference(ref, rejectOpaque);
|
|
798
811
|
}
|
|
799
812
|
if (node?.type === 'CallExpression') {
|
|
800
|
-
if (!isDefineTheme(module, node.callee)
|
|
801
|
-
|
|
813
|
+
if (!isDefineTheme(module, node.callee)) untraceableTheme(node);
|
|
814
|
+
if (node.arguments.length !== 1) invalidRegistry();
|
|
802
815
|
node = unwrap(node.arguments[0]);
|
|
803
816
|
}
|
|
817
|
+
// Any other expression (a helper's call, a conditional) is a theme the
|
|
818
|
+
// build cannot read from the source: it does not say the theme sets a
|
|
819
|
+
// registry, only that it cannot be followed.
|
|
820
|
+
if (
|
|
821
|
+
node &&
|
|
822
|
+
node.type !== 'ObjectExpression' &&
|
|
823
|
+
node.type !== 'Identifier' &&
|
|
824
|
+
node.type !== 'MemberExpression'
|
|
825
|
+
)
|
|
826
|
+
untraceableTheme(node);
|
|
804
827
|
const config = await fields(module, node);
|
|
805
828
|
const baseField = config.get('extends');
|
|
806
829
|
// A built module keeps its functions in `__icons` (or `__componentIcons`)
|