@astryxdesign/cli 0.7.5-canary.dbcfc30 → 0.7.5-canary.dc5a8cf
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/template/tokenizer-showcase.test.mjs +47 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +190 -95
- package/api/theme/build/build.project-core.test.mjs +63 -8
- package/api/theme/build/build.test.mjs +77 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +82 -1
- package/assets/docs/theme.doc.dense.mjs +8 -0
- package/assets/docs/theme.doc.mjs +16 -0
- package/assets/docs/theme.doc.zh.mjs +11 -0
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
- package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
- package/assets/theme.template.ts +18 -5
- package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
- package/package.json +9 -9
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
|
|
59
59
|
import * as fs from 'node:fs';
|
|
60
60
|
import * as path from 'node:path';
|
|
61
|
-
import {isBuiltin} from 'node:module';
|
|
61
|
+
import {createRequire, isBuiltin} from 'node:module';
|
|
62
62
|
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
63
63
|
import {parse} from '@babel/parser';
|
|
64
64
|
import {createJiti} from 'jiti';
|
|
@@ -306,7 +306,9 @@ function realLocation(target) {
|
|
|
306
306
|
* Core, so building with it keeps the CSS identical; and a CLI run one-off
|
|
307
307
|
* (`npx @astryxdesign/cli`) has no Core beside it at all. Null when there is
|
|
308
308
|
* nothing better than the CLI's own import: no installed Core (the Astryx
|
|
309
|
-
* repository, a bare directory)
|
|
309
|
+
* repository, a bare directory) or the same Core. A Core that is there but
|
|
310
|
+
* does not load, or lacks the functions the build calls, throws, naming it:
|
|
311
|
+
* building with another Core would not match the app's `<Theme>`.
|
|
310
312
|
*
|
|
311
313
|
* @param {string} cwd
|
|
312
314
|
* @param {CoreBindings} cliCore - The CLI's own Core, from {@link loadCliCore}.
|
|
@@ -316,29 +318,36 @@ function realLocation(target) {
|
|
|
316
318
|
*/
|
|
317
319
|
async function loadProjectCore(cwd, cliCore, {projectOnly = false} = {}) {
|
|
318
320
|
// Outside a project, the Core the answering copy carries (spec AST-081 FR3).
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
(projectOnly ? null : fetchCarriedThemeCoreDir(cwd));
|
|
321
|
+
const installed = findInstalledPackage(cwd, '@astryxdesign/core');
|
|
322
|
+
const dir = installed ?? (projectOnly ? null : fetchCarriedThemeCoreDir(cwd));
|
|
322
323
|
const themeFile = dir ? importTarget(dir, './theme') : null;
|
|
323
324
|
if (!dir || !themeFile) return null;
|
|
324
325
|
if (cliCore.themeModule) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
import.meta.resolve('@astryxdesign/core/theme'),
|
|
328
|
-
);
|
|
329
|
-
if (realOrSelf(own) === realOrSelf(themeFile)) return null;
|
|
330
|
-
} catch {
|
|
331
|
-
// The CLI's own Core cannot be located; load the project's.
|
|
332
|
-
}
|
|
326
|
+
const own = cliCoreThemeFile();
|
|
327
|
+
if (own != null && realOrSelf(own) === realOrSelf(themeFile)) return null;
|
|
333
328
|
}
|
|
334
329
|
let themeModule;
|
|
335
330
|
try {
|
|
336
331
|
themeModule = await import(pathToFileURL(themeFile).href);
|
|
337
|
-
} catch {
|
|
338
|
-
|
|
332
|
+
} catch (error) {
|
|
333
|
+
throw new AstryxError(
|
|
334
|
+
installed == null
|
|
335
|
+
? carriedCoreMessage(dir, /** @type {Error} */ (error))
|
|
336
|
+
: coreUnavailableMessage(cwd, /** @type {Error} */ (error)),
|
|
337
|
+
undefined,
|
|
338
|
+
ERROR_CODES.ERR_CORE_NOT_FOUND,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
const missing = ['defineTheme', 'generateThemeRulesSplit'].filter(
|
|
342
|
+
name => typeof themeModule[name] !== 'function',
|
|
343
|
+
);
|
|
344
|
+
if (missing.length > 0) {
|
|
345
|
+
throw new AstryxError(
|
|
346
|
+
`The @astryxdesign/core at ${path.relative(cwd, dir) || '.'} does not export ${missing.join(' or ')} from its \`./theme\` entry, which \`${formatCliCommand('theme build')}\` calls. Update it.`,
|
|
347
|
+
undefined,
|
|
348
|
+
ERROR_CODES.ERR_CORE_INCOMPATIBLE,
|
|
349
|
+
);
|
|
339
350
|
}
|
|
340
|
-
if (!themeModule.defineTheme || !themeModule.generateThemeRulesSplit)
|
|
341
|
-
return null;
|
|
342
351
|
let rootModule = null;
|
|
343
352
|
const rootFile = importTarget(dir, '.');
|
|
344
353
|
if (rootFile) {
|
|
@@ -359,6 +368,40 @@ async function loadProjectCore(cwd, cliCore, {projectOnly = false} = {}) {
|
|
|
359
368
|
};
|
|
360
369
|
}
|
|
361
370
|
|
|
371
|
+
/**
|
|
372
|
+
* The file the CLI's own `@astryxdesign/core/theme` resolves to, or null when
|
|
373
|
+
* the CLI has no Core of its own (a one-off `npx` run).
|
|
374
|
+
* @returns {string | null}
|
|
375
|
+
*/
|
|
376
|
+
function cliCoreThemeFile() {
|
|
377
|
+
try {
|
|
378
|
+
return fileURLToPath(import.meta.resolve('@astryxdesign/core/theme'));
|
|
379
|
+
} catch (error) {
|
|
380
|
+
const {code} = /** @type {NodeJS.ErrnoException} */ (error);
|
|
381
|
+
if (
|
|
382
|
+
code === 'ERR_MODULE_NOT_FOUND' ||
|
|
383
|
+
code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'
|
|
384
|
+
) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
throw error;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* The error for a Core the answering copy carries (outside a project) that
|
|
393
|
+
* does not load.
|
|
394
|
+
* @param {string} dir
|
|
395
|
+
* @param {Error} importError
|
|
396
|
+
* @returns {string}
|
|
397
|
+
*/
|
|
398
|
+
function carriedCoreMessage(dir, importError) {
|
|
399
|
+
return (
|
|
400
|
+
`Could not load the @astryxdesign/core this CLI release carries, at ${dir}.` +
|
|
401
|
+
`\n Import error: ${importError.message}`
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
362
405
|
/** @type {Map<string, Awaited<ReturnType<typeof loadProjectCore>>>} */
|
|
363
406
|
const _projectCores = new Map();
|
|
364
407
|
|
|
@@ -379,7 +422,7 @@ async function selectCore(cwd, {projectOnly = false} = {}) {
|
|
|
379
422
|
// A global or cached copy's own Core is the carried one.
|
|
380
423
|
if (projectOnly && !projectCore && carriesCore() && !cliCoreIsProjects(cwd)) {
|
|
381
424
|
throw new AstryxError(
|
|
382
|
-
"The project's Core isn't installed
|
|
425
|
+
"The project's Core isn't installed.",
|
|
383
426
|
undefined,
|
|
384
427
|
ERROR_CODES.ERR_CORE_NOT_FOUND,
|
|
385
428
|
);
|
|
@@ -405,13 +448,11 @@ function carriesCore() {
|
|
|
405
448
|
function cliCoreIsProjects(cwd) {
|
|
406
449
|
const dir = findProjectCoreDir(cwd);
|
|
407
450
|
if (!dir) return false;
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
return false;
|
|
414
|
-
}
|
|
451
|
+
const own = cliCoreThemeFile();
|
|
452
|
+
const theirs = importTarget(dir, './theme');
|
|
453
|
+
return (
|
|
454
|
+
own != null && theirs != null && realOrSelf(own) === realOrSelf(theirs)
|
|
455
|
+
);
|
|
415
456
|
}
|
|
416
457
|
|
|
417
458
|
/**
|
|
@@ -1103,6 +1144,28 @@ function componentHasAugmentableInterface(pascalName, interfaceName) {
|
|
|
1103
1144
|
return re.test(decl);
|
|
1104
1145
|
}
|
|
1105
1146
|
|
|
1147
|
+
/**
|
|
1148
|
+
* Public augmentable maps whose axis requests artwork instead of styling.
|
|
1149
|
+
* `Icon.variant` selects a theme's icon artwork, so it has no component styling
|
|
1150
|
+
* map (architecture:component-theming-surface INV14): a `components` key on it
|
|
1151
|
+
* never enrolls a value or generates an augmentation of its map.
|
|
1152
|
+
*/
|
|
1153
|
+
const ARTWORK_REQUEST_MAPS = new Set(['IconVariantMap']);
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Whether a theme's component styling keys may enroll values in `interfaceName`
|
|
1157
|
+
* on `@astryxdesign/core/<Component>`.
|
|
1158
|
+
* @param {string} pascalName
|
|
1159
|
+
* @param {string} interfaceName
|
|
1160
|
+
* @returns {boolean}
|
|
1161
|
+
*/
|
|
1162
|
+
function isComponentValueAugmentationPoint(pascalName, interfaceName) {
|
|
1163
|
+
return (
|
|
1164
|
+
!ARTWORK_REQUEST_MAPS.has(interfaceName) &&
|
|
1165
|
+
componentHasAugmentableInterface(pascalName, interfaceName)
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1106
1169
|
/**
|
|
1107
1170
|
* Adaptation values from resolved runtime rules, raw input, or normalized built
|
|
1108
1171
|
* metadata. Built modules intentionally omit `__adaptationRules`, so every CLI
|
|
@@ -1410,7 +1473,7 @@ async function classifyComponentValue(component, prop, value) {
|
|
|
1410
1473
|
const propPascal = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
1411
1474
|
const target = (await resolveAugmentationTargetCandidates(component)).find(
|
|
1412
1475
|
candidate =>
|
|
1413
|
-
|
|
1476
|
+
isComponentValueAugmentationPoint(
|
|
1414
1477
|
candidate.moduleName,
|
|
1415
1478
|
`${candidate.interfacePrefix}${propPascal}Map`,
|
|
1416
1479
|
),
|
|
@@ -1567,7 +1630,7 @@ async function generateVariantDeclarationsAsync(themeDef) {
|
|
|
1567
1630
|
const target = (
|
|
1568
1631
|
await resolveAugmentationTargetCandidates(component)
|
|
1569
1632
|
).find(candidate =>
|
|
1570
|
-
|
|
1633
|
+
isComponentValueAugmentationPoint(
|
|
1571
1634
|
candidate.moduleName,
|
|
1572
1635
|
`${candidate.interfacePrefix}${propPascal}Map`,
|
|
1573
1636
|
),
|
|
@@ -1833,19 +1896,43 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
1833
1896
|
commonJsPatch.undo();
|
|
1834
1897
|
}
|
|
1835
1898
|
} else {
|
|
1836
|
-
mod = await jiti.import(filePath
|
|
1899
|
+
mod = await jiti.import(filePath);
|
|
1837
1900
|
}
|
|
1838
1901
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1902
|
+
// Both loads hand back the module. The theme is read from the module's own
|
|
1903
|
+
// exports, never from the module object itself: jiti's interop answers a
|
|
1904
|
+
// property the module lacks from its default export (and a missing
|
|
1905
|
+
// `default` with the module), so the module can pass for the theme while
|
|
1906
|
+
// its own keys hide the theme's fields.
|
|
1907
|
+
const isModule = mod != null && typeof mod === 'object';
|
|
1908
|
+
const hasDefault = isModule && Object.hasOwn(mod, 'default');
|
|
1909
|
+
const defaultExport = hasDefault ? mod.default : undefined;
|
|
1910
|
+
if (isThemeObject(defaultExport)) {
|
|
1911
|
+
return {theme: defaultExport, exportName: 'default', degraded};
|
|
1912
|
+
}
|
|
1913
|
+
if (isModule) {
|
|
1845
1914
|
for (const [exportName, value] of Object.entries(mod)) {
|
|
1915
|
+
if (exportName === 'default' || exportName === 'module.exports') continue;
|
|
1846
1916
|
if (isThemeObject(value)) return {theme: value, exportName, degraded};
|
|
1847
1917
|
}
|
|
1848
1918
|
}
|
|
1919
|
+
// A plain-object default export is the module's theme even when it has
|
|
1920
|
+
// no tokens of its own (local tokens, typography or component styles may
|
|
1921
|
+
// be all it defines), or no name: the build's validation says what it
|
|
1922
|
+
// lacks.
|
|
1923
|
+
if (isPlainObject(defaultExport)) {
|
|
1924
|
+
return {theme: defaultExport, exportName: 'default', degraded};
|
|
1925
|
+
}
|
|
1926
|
+
// A CommonJS module whose exports are the theme (`module.exports =
|
|
1927
|
+
// theme`) has no default of its own: interop answers `default` with
|
|
1928
|
+
// those exports, and without interop (a family build's loader) the module
|
|
1929
|
+
// is them.
|
|
1930
|
+
if (isModule && !hasDefault) {
|
|
1931
|
+
const exportsObject = mod.default ?? mod;
|
|
1932
|
+
if (isThemeObject(exportsObject)) {
|
|
1933
|
+
return {theme: exportsObject, exportName: 'default', degraded};
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1849
1936
|
|
|
1850
1937
|
throw new Error(
|
|
1851
1938
|
`Could not find a defineTheme() result in ${filePath}.\n` +
|
|
@@ -1853,6 +1940,45 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
1853
1940
|
);
|
|
1854
1941
|
}
|
|
1855
1942
|
|
|
1943
|
+
/**
|
|
1944
|
+
* Whether the theme file's own folder resolves Core's theme entry, as the
|
|
1945
|
+
* theme's own `import ... from '@astryxdesign/core/theme'` would. A theme
|
|
1946
|
+
* outside any project (an empty folder, a fresh clone) does not, and is
|
|
1947
|
+
* handed the Core the CLI answers with instead, as a new project with that
|
|
1948
|
+
* Core would build it (`theme build` runs the same outside a project, spec
|
|
1949
|
+
* AST-081 FR3). Only a Core not installed there (MODULE_NOT_FOUND) reads as
|
|
1950
|
+
* no: an installed Core whose entry does not resolve is the theme's own, and
|
|
1951
|
+
* its load reports that.
|
|
1952
|
+
* @param {string} filePath
|
|
1953
|
+
* @returns {boolean}
|
|
1954
|
+
*/
|
|
1955
|
+
function themeFolderResolvesCore(filePath) {
|
|
1956
|
+
try {
|
|
1957
|
+
createRequire(filePath).resolve('@astryxdesign/core/theme');
|
|
1958
|
+
return true;
|
|
1959
|
+
} catch (error) {
|
|
1960
|
+
const {code} = /** @type {NodeJS.ErrnoException} */ (error);
|
|
1961
|
+
if (code === 'MODULE_NOT_FOUND') return false;
|
|
1962
|
+
if (code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') return true;
|
|
1963
|
+
throw error;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
/**
|
|
1968
|
+
* A plain object, not an array or a module namespace: a theme module's
|
|
1969
|
+
* default export, read as its theme.
|
|
1970
|
+
* @param {any} value
|
|
1971
|
+
* @returns {boolean}
|
|
1972
|
+
*/
|
|
1973
|
+
function isPlainObject(value) {
|
|
1974
|
+
return (
|
|
1975
|
+
value != null &&
|
|
1976
|
+
typeof value === 'object' &&
|
|
1977
|
+
!Array.isArray(value) &&
|
|
1978
|
+
value[Symbol.toStringTag] !== 'Module'
|
|
1979
|
+
);
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1856
1982
|
/**
|
|
1857
1983
|
* @param {any} value
|
|
1858
1984
|
* @returns {boolean}
|
|
@@ -1868,12 +1994,9 @@ function isThemeObject(value) {
|
|
|
1868
1994
|
}
|
|
1869
1995
|
|
|
1870
1996
|
/**
|
|
1871
|
-
* Extract the theme definition from a JS/TS file
|
|
1872
|
-
*
|
|
1873
|
-
*
|
|
1874
|
-
* The legacy fallback needs no interception: it evaluates the `defineTheme()`
|
|
1875
|
-
* ARGUMENT, so what it returns is raw authored input with `adaptations` still
|
|
1876
|
-
* on it — nothing has erased anything yet. It is therefore never degraded.
|
|
1997
|
+
* Extract the theme definition from a JS/TS file, through jiti (full TS
|
|
1998
|
+
* support). A module that does not load fails with its own error: the theme
|
|
1999
|
+
* is never read from the file's text instead.
|
|
1877
2000
|
*
|
|
1878
2001
|
* @param {string} filePath
|
|
1879
2002
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
@@ -1884,18 +2007,12 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
|
|
|
1884
2007
|
try {
|
|
1885
2008
|
return await importThemeModule(filePath, interception, loader);
|
|
1886
2009
|
} catch (jitiError) {
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
const je = /** @type {Error} */ (jitiError);
|
|
1894
|
-
throw new Error(
|
|
1895
|
-
`Failed to load theme from ${filePath}: ${je.message}\n` +
|
|
1896
|
-
`Make sure all imports in the theme file are resolvable.`,
|
|
1897
|
-
);
|
|
1898
|
-
}
|
|
2010
|
+
const je = /** @type {Error} */ (jitiError);
|
|
2011
|
+
throw new Error(
|
|
2012
|
+
`Failed to load theme from ${filePath}: ${je.message}\n` +
|
|
2013
|
+
`Make sure all imports in the theme file are resolvable.`,
|
|
2014
|
+
{cause: jitiError},
|
|
2015
|
+
);
|
|
1899
2016
|
}
|
|
1900
2017
|
}
|
|
1901
2018
|
|
|
@@ -1941,45 +2058,6 @@ export async function validateThemePrivateInputs(
|
|
|
1941
2058
|
}
|
|
1942
2059
|
}
|
|
1943
2060
|
|
|
1944
|
-
/**
|
|
1945
|
-
* Fallback extraction via regex + eval.
|
|
1946
|
-
* Only works for plain object literals — can't follow imports or variables.
|
|
1947
|
-
* Never erase icon references: an unresolved registry must preserve the loader
|
|
1948
|
-
* error instead of turning an incomplete theme into a successful build.
|
|
1949
|
-
* @param {string} filePath
|
|
1950
|
-
* @returns {any}
|
|
1951
|
-
*/
|
|
1952
|
-
function extractThemeDefinitionLegacy(filePath) {
|
|
1953
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
1954
|
-
|
|
1955
|
-
const defineMatch = content.match(/defineTheme\s*\(\s*({[\s\S]*?})\s*\)/);
|
|
1956
|
-
if (!defineMatch) {
|
|
1957
|
-
const defaultMatch = content.match(/export\s+default\s+({[\s\S]*?});/);
|
|
1958
|
-
if (!defaultMatch) {
|
|
1959
|
-
throw new Error(
|
|
1960
|
-
`Could not find defineTheme() call or default export in ${filePath}.\n` +
|
|
1961
|
-
`Expected: defineTheme({ name: '...', tokens: {...} })`,
|
|
1962
|
-
);
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
|
-
return eval(`(${defaultMatch[1]})`);
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
let objStr = defineMatch[1];
|
|
1969
|
-
objStr = objStr.replace(/\s+as\s+const/g, '');
|
|
1970
|
-
|
|
1971
|
-
try {
|
|
1972
|
-
return eval(`(${objStr})`);
|
|
1973
|
-
} catch (e) {
|
|
1974
|
-
const err = /** @type {Error} */ (e);
|
|
1975
|
-
throw new Error(
|
|
1976
|
-
`Failed to parse theme definition in ${filePath}: ${err.message}\n` +
|
|
1977
|
-
`Make sure the defineTheme() argument is a plain object literal.`,
|
|
1978
|
-
{cause: e},
|
|
1979
|
-
);
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
2061
|
/**
|
|
1984
2062
|
* Extract a family member's named registry import from its source file.
|
|
1985
2063
|
* Returns { importPath, exportName } or null when the theme names none.
|
|
@@ -2151,7 +2229,22 @@ function generateBuiltModule(
|
|
|
2151
2229
|
serializeField('__onDark', themeDef.__onDark) +
|
|
2152
2230
|
serializeField('__onLight', themeDef.__onLight) +
|
|
2153
2231
|
serializeField('__adaptations', themeDef.__adaptations) +
|
|
2154
|
-
serializeField('__axes', themeDef.__axes ?? {}, true)
|
|
2232
|
+
serializeField('__axes', themeDef.__axes ?? {}, true) +
|
|
2233
|
+
// An explicit empty list replaces an inherited one, so keep `[]`.
|
|
2234
|
+
serializeField('iconVariants', themeDef.iconVariants, true) +
|
|
2235
|
+
// Each inherited function entry keeps its defining theme's list. JSON
|
|
2236
|
+
// drops `undefined`, so a defining theme with no list is written as `[]`,
|
|
2237
|
+
// which no variant matches either.
|
|
2238
|
+
serializeField(
|
|
2239
|
+
'__iconEntryVariants',
|
|
2240
|
+
themeDef.__iconEntryVariants &&
|
|
2241
|
+
Object.fromEntries(
|
|
2242
|
+
Object.entries(themeDef.__iconEntryVariants).map(([name, list]) => [
|
|
2243
|
+
name,
|
|
2244
|
+
list ?? [],
|
|
2245
|
+
]),
|
|
2246
|
+
),
|
|
2247
|
+
);
|
|
2155
2248
|
|
|
2156
2249
|
return `${iconImport}${iconDeclaration}/**
|
|
2157
2250
|
* ${themeDef.name} theme — built by \`${getCliInvocation()} theme build\`
|
|
@@ -2580,13 +2673,15 @@ async function themeBuildInternal(
|
|
|
2580
2673
|
}
|
|
2581
2674
|
await selectCore(cwd, {projectOnly: projectCore});
|
|
2582
2675
|
|
|
2583
|
-
// Standalone builds
|
|
2584
|
-
// adaptations
|
|
2676
|
+
// Standalone builds need interception when an older Core could erase
|
|
2677
|
+
// adaptations, and when the theme's folder has no Core of its own: its
|
|
2678
|
+
// imports of Core are then handed the Core this build selected, as family
|
|
2679
|
+
// builds' are. Family preparation always supplies the same recorder as its
|
|
2585
2680
|
// shared loader so exact authored parent identity stays CLI-private instead
|
|
2586
2681
|
// of becoming a public DefinedTheme field.
|
|
2587
2682
|
const interception =
|
|
2588
2683
|
options.__familyInterception ??
|
|
2589
|
-
(_generateAdaptationCSS
|
|
2684
|
+
(_generateAdaptationCSS && themeFolderResolvesCore(filePath)
|
|
2590
2685
|
? undefined
|
|
2591
2686
|
: interceptCore(_coreThemeModule, _coreRootModule));
|
|
2592
2687
|
|
|
@@ -7,15 +7,26 @@
|
|
|
7
7
|
* app's `<Theme>` runs on the app's Core either way, so the build loads the
|
|
8
8
|
* project's installed `@astryxdesign/core` when it differs from the CLI's own.
|
|
9
9
|
* When there is no Core to use, the error names the fix for where it ran:
|
|
10
|
-
* install it in an app, build it in the Astryx repository.
|
|
10
|
+
* install it in an app, build it in the Astryx repository. An installed Core
|
|
11
|
+
* that does not load, or lacks the functions the build calls, fails the build,
|
|
12
|
+
* naming it, rather than leave the build to the CLI's own Core.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
|
-
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
15
|
+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
14
16
|
import * as fs from 'node:fs';
|
|
15
17
|
import * as os from 'node:os';
|
|
16
18
|
import * as path from 'node:path';
|
|
17
19
|
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
18
20
|
import {coreUnavailableMessage, themeBuild} from './build.mjs';
|
|
21
|
+
import {fetchCarriedThemeCoreDir} from '../_adapter.mjs';
|
|
22
|
+
|
|
23
|
+
vi.mock('../_adapter.mjs', async importOriginal => {
|
|
24
|
+
const actual = /** @type {Record<string, any>} */ (await importOriginal());
|
|
25
|
+
return {
|
|
26
|
+
...actual,
|
|
27
|
+
fetchCarriedThemeCoreDir: vi.fn(actual.fetchCarriedThemeCoreDir),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
19
30
|
|
|
20
31
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
21
32
|
const REPO_ROOT = path.resolve(HERE, '../../../../..');
|
|
@@ -53,9 +64,10 @@ afterEach(() => {
|
|
|
53
64
|
* entry as it is imported. Its `exports` map lists `source` first, as Core's
|
|
54
65
|
* own does, so the build must skip that condition to find the runtime file.
|
|
55
66
|
* @param {string} dir
|
|
56
|
-
* @param {{broken?: boolean}} [options]
|
|
67
|
+
* @param {{broken?: boolean, themeModule?: string}} [options] `themeModule`
|
|
68
|
+
* replaces the theme entry's source
|
|
57
69
|
*/
|
|
58
|
-
function installCore(dir, {broken = false} = {}) {
|
|
70
|
+
function installCore(dir, {broken = false, themeModule} = {}) {
|
|
59
71
|
const core = path.join(dir, 'node_modules', '@astryxdesign', 'core');
|
|
60
72
|
fs.mkdirSync(core, {recursive: true});
|
|
61
73
|
fs.writeFileSync(
|
|
@@ -82,12 +94,29 @@ function installCore(dir, {broken = false} = {}) {
|
|
|
82
94
|
`globalThis.__astryxProjectCoreLoads = [...(globalThis.__astryxProjectCoreLoads ?? []), '${entry}'];\n`;
|
|
83
95
|
fs.writeFileSync(
|
|
84
96
|
path.join(core, 'theme.mjs'),
|
|
85
|
-
module('theme', 'theme/index.js'),
|
|
97
|
+
themeModule ?? module('theme', 'theme/index.js'),
|
|
86
98
|
);
|
|
87
99
|
fs.writeFileSync(path.join(core, 'root.mjs'), module('root', 'index.js'));
|
|
88
100
|
return core;
|
|
89
101
|
}
|
|
90
102
|
|
|
103
|
+
describe('theme build outside a project, with the Core this CLI release carries', () => {
|
|
104
|
+
it('fails naming a carried Core that does not load, rather than build with the CLI’s own', async () => {
|
|
105
|
+
const carried = installCore(makeDir(), {broken: true});
|
|
106
|
+
vi.mocked(fetchCarriedThemeCoreDir).mockReturnValueOnce(carried);
|
|
107
|
+
const bare = makeDir();
|
|
108
|
+
const build = themeBuild('ocean.mjs', {}, {cwd: bare});
|
|
109
|
+
await expect(build).rejects.toMatchObject({
|
|
110
|
+
code: 'ERR_CORE_NOT_FOUND',
|
|
111
|
+
message: expect.stringContaining(
|
|
112
|
+
`Could not load the @astryxdesign/core this CLI release carries, at ${carried}`,
|
|
113
|
+
),
|
|
114
|
+
});
|
|
115
|
+
await expect(build).rejects.toThrow(/Import error: this Core is broken/);
|
|
116
|
+
expect(fs.existsSync(path.join(bare, 'ocean.css'))).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
91
120
|
describe('theme build generates with the Core the project installed', () => {
|
|
92
121
|
it('loads the app’s installed Core when it differs from the CLI’s own', async () => {
|
|
93
122
|
const app = makeDir();
|
|
@@ -114,11 +143,37 @@ describe('theme build generates with the Core the project installed', () => {
|
|
|
114
143
|
expect(fs.existsSync(path.join(bare, 'ocean.css'))).toBe(true);
|
|
115
144
|
});
|
|
116
145
|
|
|
117
|
-
it('
|
|
146
|
+
it('fails naming an installed Core that does not load, rather than build with the CLI’s own', async () => {
|
|
118
147
|
const app = makeDir();
|
|
119
148
|
installCore(app, {broken: true});
|
|
120
|
-
await themeBuild('ocean.mjs', {}, {cwd: app})
|
|
121
|
-
|
|
149
|
+
await expect(themeBuild('ocean.mjs', {}, {cwd: app})).rejects.toMatchObject(
|
|
150
|
+
{
|
|
151
|
+
code: 'ERR_CORE_NOT_FOUND',
|
|
152
|
+
message: expect.stringContaining(
|
|
153
|
+
`Could not load the @astryxdesign/core installed at ${path.join('node_modules', '@astryxdesign', 'core')}`,
|
|
154
|
+
),
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
await expect(themeBuild('ocean.mjs', {}, {cwd: app})).rejects.toThrow(
|
|
158
|
+
/Import error: this Core is broken/,
|
|
159
|
+
);
|
|
160
|
+
expect(fs.existsSync(path.join(app, 'ocean.css'))).toBe(false);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('fails naming an installed Core without the functions the build calls, rather than build with the CLI’s own', async () => {
|
|
164
|
+
const app = makeDir();
|
|
165
|
+
installCore(app, {
|
|
166
|
+
themeModule: 'export const defineTheme = theme => theme;\n',
|
|
167
|
+
});
|
|
168
|
+
await expect(themeBuild('ocean.mjs', {}, {cwd: app})).rejects.toMatchObject(
|
|
169
|
+
{
|
|
170
|
+
code: 'ERR_CORE_INCOMPATIBLE',
|
|
171
|
+
message: expect.stringContaining(
|
|
172
|
+
'does not export generateThemeRulesSplit',
|
|
173
|
+
),
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
expect(fs.existsSync(path.join(app, 'ocean.css'))).toBe(false);
|
|
122
177
|
});
|
|
123
178
|
});
|
|
124
179
|
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
import {
|
|
28
28
|
themeBuild,
|
|
29
29
|
validateComponentOverridesAgainstRegistry,
|
|
30
|
+
validateThemePrivateInputs,
|
|
30
31
|
} from './build.mjs';
|
|
31
32
|
|
|
32
33
|
// `themeBuild` captures core's generator once at module load. Wrap the two
|
|
@@ -212,6 +213,55 @@ describe('themeBuild() — receipt', () => {
|
|
|
212
213
|
});
|
|
213
214
|
});
|
|
214
215
|
|
|
216
|
+
describe.each(['mjs', 'ts'])('a .%s theme module with no theme export', ext => {
|
|
217
|
+
beforeEach(() => {
|
|
218
|
+
fs.writeFileSync(
|
|
219
|
+
path.join(tmpDir, `none.${ext}`),
|
|
220
|
+
'export const notATheme = 42;\n',
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('fails the build as a module that does not load a theme', async () => {
|
|
225
|
+
const build = themeBuild(`none.${ext}`, {}, {cwd: tmpDir});
|
|
226
|
+
await expect(build).rejects.toThrow(
|
|
227
|
+
/Could not find a defineTheme\(\) result/,
|
|
228
|
+
);
|
|
229
|
+
await expect(build).rejects.toMatchObject({code: 'ERR_THEME_LOAD'});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("fails doctor's private-input check the same way, rather than read its exports as a theme", async () => {
|
|
233
|
+
await expect(
|
|
234
|
+
validateThemePrivateInputs(`none.${ext}`, {cwd: tmpDir}),
|
|
235
|
+
).rejects.toThrow(/Could not find a defineTheme\(\) result/);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe('themeBuild() — a theme module that does not load', () => {
|
|
240
|
+
it('fails with the import error, rather than build the theme from the file text', async () => {
|
|
241
|
+
fs.writeFileSync(
|
|
242
|
+
path.join(tmpDir, 'unresolved.mjs'),
|
|
243
|
+
"import './missing-helper.mjs';\nexport default {name: 'unresolved', tokens: {'--color-bg': '#000'}};\n",
|
|
244
|
+
);
|
|
245
|
+
await expect(
|
|
246
|
+
themeBuild('unresolved.mjs', {}, {cwd: tmpDir}),
|
|
247
|
+
).rejects.toThrow(
|
|
248
|
+
/Failed to load theme from .*unresolved\.mjs: .*missing-helper\.mjs/s,
|
|
249
|
+
);
|
|
250
|
+
expect(fs.existsSync(path.join(tmpDir, 'unresolved.css'))).toBe(false);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('fails with the error the module throws, rather than build the theme from the file text', async () => {
|
|
254
|
+
fs.writeFileSync(
|
|
255
|
+
path.join(tmpDir, 'throws.mjs'),
|
|
256
|
+
"throw new Error('the theme module failed');\nexport default {name: 'throws', tokens: {'--color-bg': '#000'}};\n",
|
|
257
|
+
);
|
|
258
|
+
await expect(themeBuild('throws.mjs', {}, {cwd: tmpDir})).rejects.toThrow(
|
|
259
|
+
/the theme module failed/,
|
|
260
|
+
);
|
|
261
|
+
expect(fs.existsSync(path.join(tmpDir, 'throws.css'))).toBe(false);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
215
265
|
describe('themeBuild() — dropped declarations reach the receipt', () => {
|
|
216
266
|
// Core's generator refuses a declaration whose value would end it early
|
|
217
267
|
// (an unquoted `;` or brace, an unclosed string/comment/url). The runtime
|
|
@@ -599,6 +649,33 @@ describe('themeBuild() — component override validation', () => {
|
|
|
599
649
|
});
|
|
600
650
|
});
|
|
601
651
|
|
|
652
|
+
describe('themeBuild() — Icon size dimensions', () => {
|
|
653
|
+
it('writes width and height on an icon size into the vars the glyph reads, with no warnings', async () => {
|
|
654
|
+
// spec:AST-087 FR10: a built theme sets an Icon size's glyph dimension the
|
|
655
|
+
// way the runtime provider does, through the shared compiler's derived
|
|
656
|
+
// vars. Raw width/height would lose to a consumer's unlayered StyleX.
|
|
657
|
+
const themeFile = path.join(tmpDir, 'iconsizes.mjs');
|
|
658
|
+
fs.writeFileSync(
|
|
659
|
+
themeFile,
|
|
660
|
+
`export default {
|
|
661
|
+
name: 'iconsizes',
|
|
662
|
+
tokens: {'--color-bg': '#0a0a0a'},
|
|
663
|
+
components: {icon: {'size:sm': {width: '18px', height: '22px'}}},
|
|
664
|
+
};\n`,
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
const result = await themeBuild('iconsizes.mjs', {}, {cwd: tmpDir});
|
|
668
|
+
|
|
669
|
+
expect(result?.data.warnings).toEqual([]);
|
|
670
|
+
const css = fs.readFileSync(path.join(tmpDir, 'iconsizes.css'), 'utf8');
|
|
671
|
+
const rule =
|
|
672
|
+
css.match(/\.astryx-icon\[data-size="sm"\]\s*\{([^}]*)\}/)?.[1] ?? '';
|
|
673
|
+
expect(rule).toMatch(/--_icon-width:\s*18px/);
|
|
674
|
+
expect(rule).toMatch(/--_icon-height:\s*22px/);
|
|
675
|
+
expect(rule).not.toMatch(/(^|[\s;])(width|height)\s*:/);
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
|
|
602
679
|
describe('themeBuild() — the shipped theme template', () => {
|
|
603
680
|
// `assets/theme.template.ts` is what `astryx theme template` puts in a
|
|
604
681
|
// consumer's project. It is the one theme file we hand out, so it has to
|
|
@@ -55,9 +55,11 @@ export const docs = {
|
|
|
55
55
|
['tokens', 'Base tokens are copied first, then child tokens override on top.'],
|
|
56
56
|
['components', 'Deep-merged: child component rules override matching keys from the base.'],
|
|
57
57
|
['icons', 'Shallow-merged: child icons override matching names from the base.'],
|
|
58
|
+
['iconVariants', 'Replaced, never merged: a child that sets iconVariants replaces the base list; a child that omits it inherits the list.'],
|
|
58
59
|
['indicators', 'Shallow-merged: child indicators override matching names from the base.'],
|
|
59
60
|
['onDark, onLight', "Deep-merged per surface: the base's resolved surface first, then the child's overrides."],
|
|
60
|
-
['
|
|
61
|
+
['motion', "Field by field: the child's `fast`, `medium` and `ratio` regenerate the fast and medium duration tokens; `slow` and `easing` left unset keep the base theme's tokens, so an inherited slow band stays at the base's ratio."],
|
|
62
|
+
['typography, radius, color', 'Child config replaces base entirely (these are scale inputs, not additive).'],
|
|
61
63
|
['adaptations', 'Width-breakpoint overrides merge by fixed name. Inherited ordered rules keep their relative order; child rules append and re-resolve against the child root axes.'],
|
|
62
64
|
]},
|
|
63
65
|
{type: 'prose', text: "Inheritance is resolved when the theme is defined, so an extended theme is flat: `{@command theme build}` emits one self-contained stylesheet holding everything the child inherited, and the base theme's CSS does not need to be loaded next to it. A base that is not a theme (most often an import that missed) throws when `defineTheme` runs, rather than producing a theme that silently inherits nothing."},
|