@astryxdesign/cli 0.6.5-canary.efac39f → 0.6.5-canary.f27f749
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.mjs +69 -146
- package/api/theme/build/build.test.mjs +1 -190
- package/api/theme/themeBuild.doc.d.mts +1 -4
- package/api/theme/themeBuild.doc.mjs +3 -14
- package/foundation/doc-compiler/doc-loads.test.mjs +1 -1
- package/package.json +9 -9
- package/api/theme/build/build.icon-lineage.test.mjs +0 -117
- package/api/theme/build/build.icon-preservation.test.mjs +0 -639
- package/api/theme/build/icon-imports.d.mts +0 -47
- package/api/theme/build/icon-imports.mjs +0 -691
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +0 -15
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +0 -38
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +0 -20
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +0 -48
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file theme build API — compile standalone themes or one selected family.
|
|
5
|
-
* @input JS/TS theme modules, build/check options, and the installed Core.
|
|
6
|
-
* @output Generated artifacts preserving imported and inherited icon registries.
|
|
7
|
-
* @position CLI theme compiler; standalone icon provenance is icon-imports.mjs.
|
|
8
5
|
*
|
|
9
6
|
* `themeBuild` and `themeBuildFamily` share the same loader, compiler,
|
|
10
7
|
* serializers, check, and writer. They read defineTheme() sources and, via
|
|
@@ -15,14 +12,11 @@
|
|
|
15
12
|
* - A .d.ts (plus an optional .variants.d.ts for custom prop values)
|
|
16
13
|
*
|
|
17
14
|
* It performs the writes and returns a `theme.build` receipt — its `warnings`
|
|
18
|
-
* carry override problems
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* string contents. A registry that cannot be preserved fails before output
|
|
24
|
-
* generation, including in check mode. Errors throw AstryxError (with a stable
|
|
25
|
-
* code). Human progress is emitted through the shared `logger`
|
|
15
|
+
* carry override problems, every declaration core's generator dropped because
|
|
16
|
+
* its value could not stay one CSS declaration, and any fonts the theme names
|
|
17
|
+
* but does not load (font-warning.mjs) — or `null` when the theme produced no
|
|
18
|
+
* CSS (nothing to build). Errors throw AstryxError (with
|
|
19
|
+
* a stable code). Human progress is emitted through the shared `logger`
|
|
26
20
|
* (silent by default), so the CLI keeps its exact output while a programmatic
|
|
27
21
|
* caller stays quiet.
|
|
28
22
|
*
|
|
@@ -73,7 +67,6 @@ import {
|
|
|
73
67
|
import {collectUnloadedFonts, formatFontLoadingHelp} from './font-warning.mjs';
|
|
74
68
|
import {interceptCore} from './core-interception.mjs';
|
|
75
69
|
import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
|
|
76
|
-
import {resolveIconImports} from './icon-imports.mjs';
|
|
77
70
|
|
|
78
71
|
// Import shared theme processing from core. `astryx theme build` MUST produce the
|
|
79
72
|
// exact same CSS as the `<Theme>` runtime, so it has exactly one generation
|
|
@@ -1513,19 +1506,6 @@ async function validateRegistryGraphs(/** @type {Array<{specifier: string, expor
|
|
|
1513
1506
|
if (!(root.exportName in exports)) throw registryGraphError(`Family registry ${root.file} does not export "${root.exportName}".`);
|
|
1514
1507
|
}
|
|
1515
1508
|
}
|
|
1516
|
-
/**
|
|
1517
|
-
* Resolve inherited source with exactly the loader's extension precedence.
|
|
1518
|
-
* This reads module locations only; icon discovery never executes a second load.
|
|
1519
|
-
* @param {string} specifier
|
|
1520
|
-
* @param {string} fromFile
|
|
1521
|
-
* @returns {string}
|
|
1522
|
-
*/
|
|
1523
|
-
function resolveThemeModule(specifier, fromFile) {
|
|
1524
|
-
return createJiti(fromFile, {extensions: THEME_MODULE_EXTENSIONS}).resolve(
|
|
1525
|
-
specifier,
|
|
1526
|
-
);
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
1509
|
/**
|
|
1530
1510
|
* Errors that mean "the synchronous loader cannot evaluate this module", as
|
|
1531
1511
|
* opposed to "this module is broken". Only the former may fall back to the
|
|
@@ -1573,7 +1553,7 @@ function isSyncLoaderLimitation(error) {
|
|
|
1573
1553
|
*
|
|
1574
1554
|
* @param {string} filePath
|
|
1575
1555
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
1576
|
-
* @returns {Promise<{theme: any,
|
|
1556
|
+
* @returns {Promise<{theme: any, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
|
|
1577
1557
|
*/
|
|
1578
1558
|
// prettier-ignore
|
|
1579
1559
|
async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
@@ -1623,14 +1603,12 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
1623
1603
|
mod = await jiti.import(filePath, {default: true});
|
|
1624
1604
|
}
|
|
1625
1605
|
|
|
1626
|
-
if (isThemeObject(mod)) return {theme: mod,
|
|
1606
|
+
if (isThemeObject(mod)) return {theme: mod, degraded};
|
|
1627
1607
|
|
|
1628
1608
|
if (mod && typeof mod === 'object') {
|
|
1629
|
-
if (isThemeObject(mod.default)) {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
for (const [exportName, value] of Object.entries(mod)) {
|
|
1633
|
-
if (isThemeObject(value)) return {theme: value, exportName, degraded};
|
|
1609
|
+
if (isThemeObject(mod.default)) return {theme: mod.default, degraded};
|
|
1610
|
+
for (const value of Object.values(mod)) {
|
|
1611
|
+
if (isThemeObject(value)) return {theme: value, degraded};
|
|
1634
1612
|
}
|
|
1635
1613
|
}
|
|
1636
1614
|
|
|
@@ -1664,7 +1642,7 @@ function isThemeObject(value) {
|
|
|
1664
1642
|
*
|
|
1665
1643
|
* @param {string} filePath
|
|
1666
1644
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
1667
|
-
* @returns {Promise<{theme: any,
|
|
1645
|
+
* @returns {Promise<{theme: any, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
|
|
1668
1646
|
*/
|
|
1669
1647
|
// prettier-ignore
|
|
1670
1648
|
async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined) {
|
|
@@ -1689,8 +1667,6 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
|
|
|
1689
1667
|
/**
|
|
1690
1668
|
* Fallback extraction via regex + eval.
|
|
1691
1669
|
* Only works for plain object literals — can't follow imports or variables.
|
|
1692
|
-
* Never erase icon references: an unresolved registry must preserve the loader
|
|
1693
|
-
* error instead of turning an incomplete theme into a successful build.
|
|
1694
1670
|
* @param {string} filePath
|
|
1695
1671
|
* @returns {any}
|
|
1696
1672
|
*/
|
|
@@ -1712,6 +1688,10 @@ function extractThemeDefinitionLegacy(filePath) {
|
|
|
1712
1688
|
|
|
1713
1689
|
let objStr = defineMatch[1];
|
|
1714
1690
|
objStr = objStr.replace(/\s+as\s+const/g, '');
|
|
1691
|
+
objStr = objStr.replace(
|
|
1692
|
+
/icons:\s*[a-zA-Z_][a-zA-Z0-9_]*/g,
|
|
1693
|
+
'icons: undefined',
|
|
1694
|
+
);
|
|
1715
1695
|
|
|
1716
1696
|
try {
|
|
1717
1697
|
return eval(`(${objStr})`);
|
|
@@ -1726,19 +1706,30 @@ function extractThemeDefinitionLegacy(filePath) {
|
|
|
1726
1706
|
}
|
|
1727
1707
|
|
|
1728
1708
|
/**
|
|
1729
|
-
* Extract
|
|
1730
|
-
* Returns { importPath, exportName } or null
|
|
1731
|
-
* Standalone builds resolve icons through `resolveIconImports` instead.
|
|
1709
|
+
* Extract icon import info from a theme source file.
|
|
1710
|
+
* Returns { importPath, exportName } or null if no icons.
|
|
1732
1711
|
*
|
|
1733
1712
|
* Looks for patterns like:
|
|
1734
1713
|
* import { defaultIconRegistry } from './icons';
|
|
1735
1714
|
* icons: defaultIconRegistry,
|
|
1736
1715
|
* @param {string} filePath
|
|
1737
|
-
* @param {'icons' | 'indicators'} field
|
|
1738
1716
|
* @returns {{exportName: string, importPath: string} | null}
|
|
1739
1717
|
*/
|
|
1740
|
-
function extractRegistryInfo(filePath, field) {
|
|
1718
|
+
function extractRegistryInfo(filePath, field = 'icons', familyMode = false) {
|
|
1741
1719
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
1720
|
+
if (!familyMode) {
|
|
1721
|
+
const fieldMatch = content.match(
|
|
1722
|
+
new RegExp(`${field}:\\s*([a-zA-Z_][a-zA-Z0-9_]*)`),
|
|
1723
|
+
);
|
|
1724
|
+
if (!fieldMatch) return null;
|
|
1725
|
+
const varName = fieldMatch[1];
|
|
1726
|
+
const match = content.match(
|
|
1727
|
+
new RegExp(
|
|
1728
|
+
`import\\s*{[^}]*\\b${varName}\\b[^}]*}\\s*from\\s*['"]([^'"]+)['"]`,
|
|
1729
|
+
),
|
|
1730
|
+
);
|
|
1731
|
+
return match ? {exportName: varName, importPath: match[1]} : null;
|
|
1732
|
+
}
|
|
1742
1733
|
const defineIndex = content.indexOf('defineTheme(');
|
|
1743
1734
|
if (defineIndex < 0) return null;
|
|
1744
1735
|
const themeSource = content.slice(defineIndex);
|
|
@@ -1778,18 +1769,17 @@ function extractRegistryInfo(filePath, field) {
|
|
|
1778
1769
|
* override it had.
|
|
1779
1770
|
*
|
|
1780
1771
|
* The icon registry is imported rather than inlined because it holds React
|
|
1781
|
-
* elements, which cannot be serialized. `
|
|
1782
|
-
*
|
|
1772
|
+
* elements, which cannot be serialized. `extractIconInfo` lifts the specifier
|
|
1773
|
+
* out of the TypeScript source, where an extensionless `./icons` is resolved by
|
|
1783
1774
|
* the TypeScript resolver — but the artifact here is ESM JavaScript, which
|
|
1784
1775
|
* requires a fully specified path. Only the caller knows what its own build
|
|
1785
1776
|
* will emit and under what name, so `iconsSpecifier` lets it say. When it is
|
|
1786
|
-
* not given,
|
|
1787
|
-
* imports are rebased from the base module to the theme entry's directory.
|
|
1777
|
+
* not given, the scraped specifier is emitted unchanged.
|
|
1788
1778
|
*
|
|
1789
1779
|
* @param {any} themeDef
|
|
1790
|
-
* @param {
|
|
1791
|
-
* @param {string} [iconsSpecifier] - Overrides the
|
|
1792
|
-
* @param {{themeBinding?: string, iconsExpression?: string, indicatorsExpression?: string, artifactBaseName?: string, exportIcons?: boolean}} [moduleOptions]
|
|
1780
|
+
* @param {{exportName: string, importPath: string} | null} iconInfo
|
|
1781
|
+
* @param {string} [iconsSpecifier] - Overrides the scraped icon import specifier.
|
|
1782
|
+
* @param {{themeBinding?: string, iconBinding?: string, iconsExpression?: string, indicatorsExpression?: string, artifactBaseName?: string, exportIcons?: boolean}} [moduleOptions]
|
|
1793
1783
|
* @returns {string}
|
|
1794
1784
|
*/
|
|
1795
1785
|
function generateBuiltModule(
|
|
@@ -1800,46 +1790,29 @@ function generateBuiltModule(
|
|
|
1800
1790
|
) {
|
|
1801
1791
|
const themeBinding =
|
|
1802
1792
|
moduleOptions.themeBinding ?? `${toIdentifier(themeDef.name)}Theme`;
|
|
1793
|
+
const iconBinding = moduleOptions.iconBinding ?? iconInfo?.exportName;
|
|
1803
1794
|
const artifactBaseName = moduleOptions.artifactBaseName ?? themeDef.name;
|
|
1804
1795
|
const exportIcons = moduleOptions.exportIcons ?? true;
|
|
1805
|
-
//
|
|
1806
|
-
//
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
: `'${importPath}'`;
|
|
1818
|
-
const imported = /^[$\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u.test(
|
|
1819
|
-
importedName,
|
|
1820
|
-
)
|
|
1821
|
-
? importedName
|
|
1822
|
-
: JSON.stringify(importedName);
|
|
1823
|
-
const binding =
|
|
1824
|
-
importedName === 'default'
|
|
1825
|
-
? localName
|
|
1826
|
-
: importedName === '*'
|
|
1827
|
-
? `* as ${localName}`
|
|
1828
|
-
: `{ ${imported}${importedName === localName ? '' : ` as ${localName}`} }`;
|
|
1829
|
-
return `import ${binding} from ${specifier};\n`;
|
|
1830
|
-
})
|
|
1831
|
-
.join('');
|
|
1832
|
-
const iconDeclaration =
|
|
1833
|
-
iconInfo && iconInfo.expression !== iconInfo.exportName
|
|
1834
|
-
? `const ${iconInfo.exportName} = ${iconInfo.expression};\n`
|
|
1835
|
-
: '';
|
|
1836
|
-
const iconsExpression = moduleOptions.iconsExpression ?? iconInfo?.exportName;
|
|
1796
|
+
// Preserve the historical generated bytes when no override is supplied.
|
|
1797
|
+
// User-provided specifiers need string-literal encoding so quotes and
|
|
1798
|
+
// backslashes cannot produce invalid JavaScript.
|
|
1799
|
+
const renderedSpecifier =
|
|
1800
|
+
iconsSpecifier === undefined
|
|
1801
|
+
? `'${iconInfo?.importPath}'`
|
|
1802
|
+
: JSON.stringify(iconsSpecifier);
|
|
1803
|
+
const iconImport = iconInfo
|
|
1804
|
+
? `import { ${iconInfo.exportName}${iconBinding === iconInfo.exportName ? '' : ` as ${iconBinding}`} } from ${renderedSpecifier};\n`
|
|
1805
|
+
: '';
|
|
1806
|
+
const iconsExpression =
|
|
1807
|
+
moduleOptions.iconsExpression ?? (iconInfo ? iconBinding : undefined);
|
|
1837
1808
|
const iconsField = iconsExpression ? ` icons: ${iconsExpression},` : '';
|
|
1838
1809
|
const indicatorsField = moduleOptions.indicatorsExpression
|
|
1839
1810
|
? `\n indicators: ${moduleOptions.indicatorsExpression},`
|
|
1840
1811
|
: '';
|
|
1841
1812
|
const iconReExport =
|
|
1842
|
-
iconInfo && exportIcons
|
|
1813
|
+
iconInfo && exportIcons
|
|
1814
|
+
? `\nexport { ${iconBinding}${iconBinding === iconInfo.exportName ? '' : ` as ${iconInfo.exportName}`} };\n`
|
|
1815
|
+
: '';
|
|
1843
1816
|
|
|
1844
1817
|
// Resolve token values — tuples become light-dark() strings
|
|
1845
1818
|
/** @type {Record<string, unknown>} */
|
|
@@ -1898,7 +1871,7 @@ function generateBuiltModule(
|
|
|
1898
1871
|
serializeField('__adaptations', themeDef.__adaptations) +
|
|
1899
1872
|
serializeField('__axes', themeDef.__axes ?? {}, true);
|
|
1900
1873
|
|
|
1901
|
-
return `${iconImport}
|
|
1874
|
+
return `${iconImport}/**
|
|
1902
1875
|
* ${themeDef.name} theme — built by \`${getCliInvocation()} theme build\`
|
|
1903
1876
|
* Import the CSS file alongside this module:
|
|
1904
1877
|
*
|
|
@@ -1917,7 +1890,7 @@ ${iconReExport}`;
|
|
|
1917
1890
|
/**
|
|
1918
1891
|
* Generate TypeScript declarations for a built theme module.
|
|
1919
1892
|
* @param {any} themeDef
|
|
1920
|
-
* @param {{exportName: string} | null} iconInfo
|
|
1893
|
+
* @param {{exportName: string, importPath: string} | null} iconInfo
|
|
1921
1894
|
* @param {string | null} variantsFileName
|
|
1922
1895
|
* @param {{themeBinding?: string, includeIconExport?: boolean, includeThemeImport?: boolean}} [typeOptions]
|
|
1923
1896
|
* @returns {string}
|
|
@@ -2343,7 +2316,7 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
|
|
|
2343
2316
|
* `out` overrides the output CSS path; `check` compares against on-disk outputs
|
|
2344
2317
|
* instead of writing. `iconsSpecifier` overrides the icon registry import
|
|
2345
2318
|
* specifier in the generated module (e.g. `./icons.mjs`); when omitted, the
|
|
2346
|
-
*
|
|
2319
|
+
* specifier scraped from the theme source is emitted unchanged.
|
|
2347
2320
|
* @param {{cwd?: string}} [ctx]
|
|
2348
2321
|
* @returns {Promise<any>}
|
|
2349
2322
|
*/
|
|
@@ -2378,8 +2351,6 @@ async function themeBuildInternal(
|
|
|
2378
2351
|
|
|
2379
2352
|
// Extract theme definition
|
|
2380
2353
|
let themeDef;
|
|
2381
|
-
/** The export actually selected by the loader, not the first AST match. */
|
|
2382
|
-
let themeExportName;
|
|
2383
2354
|
/** Paths through the load that interception could not fully observe. */
|
|
2384
2355
|
let loadDegradation;
|
|
2385
2356
|
try {
|
|
@@ -2389,7 +2360,6 @@ async function themeBuildInternal(
|
|
|
2389
2360
|
options.__familyLoader,
|
|
2390
2361
|
);
|
|
2391
2362
|
themeDef = loaded.theme;
|
|
2392
|
-
themeExportName = loaded.exportName;
|
|
2393
2363
|
loadDegradation = loaded.degraded;
|
|
2394
2364
|
} catch (e) {
|
|
2395
2365
|
const err = /** @type {Error} */ (e);
|
|
@@ -2455,25 +2425,6 @@ async function themeBuildInternal(
|
|
|
2455
2425
|
throw err;
|
|
2456
2426
|
}
|
|
2457
2427
|
|
|
2458
|
-
// A generated module must preserve the registry through an import: it may
|
|
2459
|
-
// contain React elements, which cannot be serialized. Validate before CSS
|
|
2460
|
-
// generation so neither the no-CSS return nor --check can bypass the error.
|
|
2461
|
-
// Family preparation keeps its own named-import registry contract, which
|
|
2462
|
-
// themeBuildFamily checks against the selected members' graph.
|
|
2463
|
-
const standaloneIcons = !options.__prepareFamily;
|
|
2464
|
-
const iconResolution = {
|
|
2465
|
-
readSource: (/** @type {string} */ file) => fs.readFileSync(file, 'utf8'),
|
|
2466
|
-
resolveModule: resolveThemeModule,
|
|
2467
|
-
reservedNames: [`${toIdentifier(themeDef.name)}Theme`],
|
|
2468
|
-
rawInput: 'extends' in themeDef,
|
|
2469
|
-
hasIcons:
|
|
2470
|
-
Object.keys(themeDef.icons ?? {}).length > 0 ||
|
|
2471
|
-
Object.keys(themeDef.extends?.icons ?? {}).length > 0,
|
|
2472
|
-
};
|
|
2473
|
-
let iconInfo = standaloneIcons
|
|
2474
|
-
? await resolveIconImports(filePath, themeExportName, iconResolution)
|
|
2475
|
-
: null;
|
|
2476
|
-
|
|
2477
2428
|
// Validate component overrides
|
|
2478
2429
|
const warnings = await validateComponentOverrides(themeDef);
|
|
2479
2430
|
const warningMessages = [];
|
|
@@ -2580,40 +2531,6 @@ async function themeBuildInternal(
|
|
|
2580
2531
|
resolvedTheme = themeDef;
|
|
2581
2532
|
}
|
|
2582
2533
|
|
|
2583
|
-
// Raw object exports can acquire icons only when Core resolves `extends`.
|
|
2584
|
-
// Recheck an unresolved provenance result before any generator runs.
|
|
2585
|
-
if (
|
|
2586
|
-
standaloneIcons &&
|
|
2587
|
-
!iconInfo &&
|
|
2588
|
-
Object.keys(resolvedTheme.icons ?? {}).length > 0
|
|
2589
|
-
) {
|
|
2590
|
-
iconInfo = await resolveIconImports(filePath, themeExportName, {
|
|
2591
|
-
...iconResolution,
|
|
2592
|
-
hasIcons: true,
|
|
2593
|
-
});
|
|
2594
|
-
}
|
|
2595
|
-
// An opaque package base can legitimately have no icons. Its .icons
|
|
2596
|
-
// reference is unnecessary; direct empty registry imports remain intact.
|
|
2597
|
-
if (
|
|
2598
|
-
iconInfo &&
|
|
2599
|
-
iconInfo.iconsSpecifierLocalName === undefined &&
|
|
2600
|
-
Object.keys(resolvedTheme.icons ?? {}).length === 0
|
|
2601
|
-
) {
|
|
2602
|
-
iconInfo = null;
|
|
2603
|
-
}
|
|
2604
|
-
if (
|
|
2605
|
-
iconInfo &&
|
|
2606
|
-
options.iconsSpecifier !== undefined &&
|
|
2607
|
-
iconInfo.iconsSpecifierImportPath === undefined
|
|
2608
|
-
) {
|
|
2609
|
-
throw new AstryxError(
|
|
2610
|
-
'The icon registry is inherited through a theme import. ' +
|
|
2611
|
-
'To use --icons-specifier, import the registry directly and set icons to that binding.',
|
|
2612
|
-
undefined,
|
|
2613
|
-
ERROR_CODES.ERR_THEME_INVALID,
|
|
2614
|
-
);
|
|
2615
|
-
}
|
|
2616
|
-
|
|
2617
2534
|
// Cores that predate adaptations can still resolve typography, color,
|
|
2618
2535
|
// radius, and motion into root tokens, but they do not retain the raw axis
|
|
2619
2536
|
// inputs. Keep the effective metadata captured from the same defineTheme
|
|
@@ -2839,6 +2756,15 @@ async function themeBuildInternal(
|
|
|
2839
2756
|
const jsPath = path.join(outDir, `${baseName}.js`);
|
|
2840
2757
|
const dtsPath = path.join(outDir, `${baseName}.d.ts`);
|
|
2841
2758
|
|
|
2759
|
+
const iconInfo = extractRegistryInfo(
|
|
2760
|
+
filePath,
|
|
2761
|
+
'icons',
|
|
2762
|
+
options.__prepareFamily,
|
|
2763
|
+
);
|
|
2764
|
+
const indicatorInfo = options.__prepareFamily
|
|
2765
|
+
? extractRegistryInfo(filePath, 'indicators', true)
|
|
2766
|
+
: null;
|
|
2767
|
+
|
|
2842
2768
|
// Type augmentation .d.ts if theme has custom prop values. Computed
|
|
2843
2769
|
// before the main .d.ts so the latter can reference it (see below).
|
|
2844
2770
|
const augmentationSource = resolvedTheme || themeDef;
|
|
@@ -2886,8 +2812,8 @@ async function themeBuildInternal(
|
|
|
2886
2812
|
theme: displayTheme,
|
|
2887
2813
|
sourceTheme: themeDef,
|
|
2888
2814
|
sourceParent,
|
|
2889
|
-
iconInfo
|
|
2890
|
-
indicatorInfo
|
|
2815
|
+
iconInfo,
|
|
2816
|
+
indicatorInfo,
|
|
2891
2817
|
variantDecl,
|
|
2892
2818
|
css: cssPlan,
|
|
2893
2819
|
versions,
|
|
@@ -3231,14 +3157,11 @@ export async function themeBuildFamily(
|
|
|
3231
3157
|
const indicatorImport = indicator.info
|
|
3232
3158
|
? `import { ${indicator.info.exportName} as ${ownIndicators} } from ${JSON.stringify(indicator.specifier ?? indicator.info.importPath)};\n`
|
|
3233
3159
|
: '';
|
|
3234
|
-
// The member's own registry import, bound to its family-unique name; a
|
|
3235
|
-
// rebased or overridden specifier replaces the scraped one.
|
|
3236
|
-
// prettier-ignore
|
|
3237
|
-
const iconImports = icon.info && ownIcons ? {imports: [{importPath: icon.info.importPath, importedName: icon.info.exportName, localName: ownIcons}], expression: ownIcons, exportName: ownIcons, iconsSpecifierImportPath: icon.info.importPath, iconsSpecifierLocalName: ownIcons} : null;
|
|
3238
3160
|
return (
|
|
3239
3161
|
indicatorImport +
|
|
3240
|
-
generateBuiltModule(member.theme,
|
|
3162
|
+
generateBuiltModule(member.theme, icon.info, icon.specifier, {
|
|
3241
3163
|
themeBinding,
|
|
3164
|
+
iconBinding: ownIcons ?? undefined,
|
|
3242
3165
|
iconsExpression: expression(ownIcons, inheritedIcons),
|
|
3243
3166
|
indicatorsExpression: expression(ownIndicators, inheritedIndicators),
|
|
3244
3167
|
artifactBaseName: baseName,
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
* end-to-end; these assert the API contract you get calling `themeBuild()` in
|
|
9
9
|
* code: the typed `theme.build` receipt (with files actually written to disk),
|
|
10
10
|
* that it honors the `cwd` option, stays SILENT under the default noopLogger,
|
|
11
|
-
* returns `null` when there is nothing to build
|
|
12
|
-
* registries without creating or changing outputs in build and check modes.
|
|
11
|
+
* and returns `null` when there is nothing to build.
|
|
13
12
|
*
|
|
14
13
|
* `themeBuild` compiles via @astryxdesign/core's generator, so it needs a built
|
|
15
14
|
* core — the `node` project's globalSetup (vitest.global-setup.node.mjs) builds
|
|
@@ -612,194 +611,6 @@ describe('themeBuild() — the shipped theme template', () => {
|
|
|
612
611
|
});
|
|
613
612
|
});
|
|
614
613
|
|
|
615
|
-
describe('themeBuild() — icon registry detection', () => {
|
|
616
|
-
/**
|
|
617
|
-
* The emitted icon import statement, or null. Reads the statement rather
|
|
618
|
-
* than the whole file: the `@generated` header quotes a usage example, so a
|
|
619
|
-
* substring search over the file would match comment text too.
|
|
620
|
-
*/
|
|
621
|
-
function iconImportLine(generated) {
|
|
622
|
-
const match = generated.match(/^import .*$/m);
|
|
623
|
-
return match ? match[0] : null;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
it('emits the import, icons key and re-export for a registry that arrives via an import', async () => {
|
|
627
|
-
fs.writeFileSync(
|
|
628
|
-
path.join(tmpDir, 'icons.mjs'),
|
|
629
|
-
'export const liveIcons = {};\n',
|
|
630
|
-
);
|
|
631
|
-
fs.writeFileSync(
|
|
632
|
-
path.join(tmpDir, 'live.mjs'),
|
|
633
|
-
`import {liveIcons} from './icons';\n` +
|
|
634
|
-
`export default {name: 'live', icons: liveIcons, tokens: {'--color-bg': '#fff'}};\n`,
|
|
635
|
-
);
|
|
636
|
-
|
|
637
|
-
const result = await themeBuild('live.mjs', {}, {cwd: tmpDir});
|
|
638
|
-
|
|
639
|
-
const generated = fs.readFileSync(path.join(tmpDir, 'live.js'), 'utf8');
|
|
640
|
-
expect(iconImportLine(generated)).toBe(
|
|
641
|
-
"import { liveIcons } from './icons';",
|
|
642
|
-
);
|
|
643
|
-
expect(generated).toContain('icons: liveIcons,');
|
|
644
|
-
expect(generated).toContain('export { liveIcons };');
|
|
645
|
-
expect(result?.data.warnings).toEqual([]);
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
it('does not re-emit an import that only appears inside a comment (#5058)', async () => {
|
|
649
|
-
// The reported repro: the registry was inlined into the theme source, and
|
|
650
|
-
// a doc comment kept the old import line for context. The comment's
|
|
651
|
-
// specifier was scraped and emitted as live code in the built module,
|
|
652
|
-
// pointing at a file that no longer exists.
|
|
653
|
-
fs.writeFileSync(
|
|
654
|
-
path.join(tmpDir, 'commented.mjs'),
|
|
655
|
-
`/**\n` +
|
|
656
|
-
` * The scaffold put this in a sibling icons file, so the built module\n` +
|
|
657
|
-
` * carried \`import { ghostIcons } from './icons'\` — which Node\n` +
|
|
658
|
-
` * cannot resolve.\n` +
|
|
659
|
-
` */\n` +
|
|
660
|
-
`const ghostIcons = {close: 'inline'};\n` +
|
|
661
|
-
`export default {name: 'commented', icons: ghostIcons, tokens: {'--color-bg': '#fff'}};\n`,
|
|
662
|
-
);
|
|
663
|
-
|
|
664
|
-
await expect(
|
|
665
|
-
themeBuild('commented.mjs', {}, {cwd: tmpDir}),
|
|
666
|
-
).rejects.toMatchObject({
|
|
667
|
-
code: 'ERR_THEME_INVALID',
|
|
668
|
-
message: expect.stringContaining('icons: ghostIcons'),
|
|
669
|
-
});
|
|
670
|
-
expect(fs.readdirSync(tmpDir)).toEqual(['commented.mjs']);
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
it('scrapes the live import even when a comment quotes a stale one', async () => {
|
|
674
|
-
fs.writeFileSync(
|
|
675
|
-
path.join(tmpDir, 'icons.mjs'),
|
|
676
|
-
'export const realIcons = {};\n',
|
|
677
|
-
);
|
|
678
|
-
fs.writeFileSync(
|
|
679
|
-
path.join(tmpDir, 'both.mjs'),
|
|
680
|
-
`// was: import { realIcons } from './old-icons';\n` +
|
|
681
|
-
`import {realIcons} from './icons';\n` +
|
|
682
|
-
`export default {name: 'both', icons: realIcons, tokens: {'--color-bg': '#fff'}};\n`,
|
|
683
|
-
);
|
|
684
|
-
|
|
685
|
-
const result = await themeBuild('both.mjs', {}, {cwd: tmpDir});
|
|
686
|
-
|
|
687
|
-
// The comment comes first in the source, so the old scan matched it first
|
|
688
|
-
// and emitted `./old-icons` — the live import must win.
|
|
689
|
-
const generated = fs.readFileSync(path.join(tmpDir, 'both.js'), 'utf8');
|
|
690
|
-
expect(iconImportLine(generated)).toBe(
|
|
691
|
-
"import { realIcons } from './icons';",
|
|
692
|
-
);
|
|
693
|
-
expect(generated).not.toContain('old-icons');
|
|
694
|
-
expect(result?.data.warnings).toEqual([]);
|
|
695
|
-
});
|
|
696
|
-
|
|
697
|
-
it('ignores a commented-out icons: field entirely', async () => {
|
|
698
|
-
fs.writeFileSync(
|
|
699
|
-
path.join(tmpDir, 'nofield.mjs'),
|
|
700
|
-
`// icons: retiredIcons,\n` +
|
|
701
|
-
`export default {name: 'nofield', tokens: {'--color-bg': '#fff'}};\n`,
|
|
702
|
-
);
|
|
703
|
-
|
|
704
|
-
const result = await themeBuild('nofield.mjs', {}, {cwd: tmpDir});
|
|
705
|
-
|
|
706
|
-
const generated = fs.readFileSync(path.join(tmpDir, 'nofield.js'), 'utf8');
|
|
707
|
-
expect(iconImportLine(generated)).toBeNull();
|
|
708
|
-
expect(generated).not.toContain('icons:');
|
|
709
|
-
// No icons field means nothing was dropped — no warning either.
|
|
710
|
-
expect(result?.data.warnings).toEqual([]);
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
describe.each([false, true])('unsupported registries (check: %s)', check => {
|
|
714
|
-
it('rejects before the generator can return no CSS', async () => {
|
|
715
|
-
fs.writeFileSync(
|
|
716
|
-
path.join(tmpDir, 'inline.mjs'),
|
|
717
|
-
`const inlineIcons = {chevron: 'stub'};\n` +
|
|
718
|
-
`export default {name: 'inline', icons: inlineIcons, tokens: {}};\n`,
|
|
719
|
-
);
|
|
720
|
-
|
|
721
|
-
await mockGenerateThemeRulesSplit.withImplementation(
|
|
722
|
-
() => ({component: [], prose: []}),
|
|
723
|
-
async () => {
|
|
724
|
-
await mockGenerateOnMediaCSS.withImplementation(
|
|
725
|
-
() => '',
|
|
726
|
-
async () => {
|
|
727
|
-
await expect(
|
|
728
|
-
themeBuild('inline.mjs', {check}, {cwd: tmpDir}),
|
|
729
|
-
).rejects.toMatchObject({code: 'ERR_THEME_INVALID'});
|
|
730
|
-
},
|
|
731
|
-
);
|
|
732
|
-
},
|
|
733
|
-
);
|
|
734
|
-
expect(mockGenerateThemeRulesSplit).not.toHaveBeenCalled();
|
|
735
|
-
expect(fs.readdirSync(tmpDir)).toEqual(['inline.mjs']);
|
|
736
|
-
});
|
|
737
|
-
|
|
738
|
-
it.each([
|
|
739
|
-
['local binding', 'icons: inlineIcons'],
|
|
740
|
-
['object literal', "icons: {chevron: 'stub'}"],
|
|
741
|
-
['shorthand', 'icons'],
|
|
742
|
-
])('rejects a %s without creating output files', async (_label, field) => {
|
|
743
|
-
fs.writeFileSync(
|
|
744
|
-
path.join(tmpDir, 'inline.mjs'),
|
|
745
|
-
`const inlineIcons = {chevron: 'stub'};\n` +
|
|
746
|
-
`const icons = inlineIcons;\n` +
|
|
747
|
-
`export default {name: 'inline', ${field}, tokens: {'--color-bg': '#fff'}};\n`,
|
|
748
|
-
);
|
|
749
|
-
|
|
750
|
-
await expect(
|
|
751
|
-
themeBuild(
|
|
752
|
-
'inline.mjs',
|
|
753
|
-
{check, out: 'dist/inline.css'},
|
|
754
|
-
{cwd: tmpDir},
|
|
755
|
-
),
|
|
756
|
-
).rejects.toMatchObject({
|
|
757
|
-
code: 'ERR_THEME_INVALID',
|
|
758
|
-
message: expect.stringContaining(
|
|
759
|
-
'Move the registry to its own module and import it',
|
|
760
|
-
),
|
|
761
|
-
});
|
|
762
|
-
expect(fs.readdirSync(tmpDir)).toEqual(['inline.mjs']);
|
|
763
|
-
});
|
|
764
|
-
|
|
765
|
-
it('rejects even when committed output already matches the missing-icons result', async () => {
|
|
766
|
-
const themeFile = path.join(tmpDir, 'inline.mjs');
|
|
767
|
-
const withoutIcons =
|
|
768
|
-
`export default {name: 'inline', tokens: {'--color-bg': '#fff'}, ` +
|
|
769
|
-
`components: {button: {'variant:custom': {color: 'red'}}}};\n`;
|
|
770
|
-
fs.writeFileSync(themeFile, withoutIcons);
|
|
771
|
-
const built = await themeBuild('inline.mjs', {}, {cwd: tmpDir});
|
|
772
|
-
expect(built?.data.outputs.variantsDts).toBe('inline.variants.d.ts');
|
|
773
|
-
const outputs = Object.values(built.data.outputs);
|
|
774
|
-
const before = outputs.map(file =>
|
|
775
|
-
fs.readFileSync(path.join(tmpDir, file), 'utf8'),
|
|
776
|
-
);
|
|
777
|
-
// This source used to emit exactly the same output as the icon-free
|
|
778
|
-
// theme, so --check passed after the incomplete artifacts were committed.
|
|
779
|
-
fs.writeFileSync(
|
|
780
|
-
themeFile,
|
|
781
|
-
`const inlineIcons = {chevron: 'stub'};\n` +
|
|
782
|
-
withoutIcons.replace(
|
|
783
|
-
"name: 'inline',",
|
|
784
|
-
"name: 'inline', icons: inlineIcons,",
|
|
785
|
-
),
|
|
786
|
-
);
|
|
787
|
-
const filesBefore = fs.readdirSync(tmpDir).sort();
|
|
788
|
-
|
|
789
|
-
await expect(
|
|
790
|
-
themeBuild('inline.mjs', {check}, {cwd: tmpDir}),
|
|
791
|
-
).rejects.toMatchObject({
|
|
792
|
-
code: 'ERR_THEME_INVALID',
|
|
793
|
-
message: expect.stringContaining('icons: inlineIcons'),
|
|
794
|
-
});
|
|
795
|
-
expect(
|
|
796
|
-
outputs.map(file => fs.readFileSync(path.join(tmpDir, file), 'utf8')),
|
|
797
|
-
).toEqual(before);
|
|
798
|
-
expect(fs.readdirSync(tmpDir).sort()).toEqual(filesBefore);
|
|
799
|
-
});
|
|
800
|
-
});
|
|
801
|
-
});
|
|
802
|
-
|
|
803
614
|
describe('themeBuild() — extends', () => {
|
|
804
615
|
// These fixtures `import {defineTheme} from '@astryxdesign/core/theme'` the
|
|
805
616
|
// way a real theme file does, so they have to sit somewhere that specifier
|
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* @file FunctionDoc for `themeBuild()` / `astryx theme build`. Colocated with
|
|
6
6
|
* the API function it documents; the response-shape source of truth stays in
|
|
7
|
-
* `theme.type.mjs`.
|
|
8
|
-
* of registries that cannot be preserved in build/check modes.
|
|
9
|
-
* @input themeBuild's build/check and icon-import behavior.
|
|
10
|
-
* @output Consumer API documentation for generated theme artifacts.
|
|
7
|
+
* `theme.type.mjs`.
|
|
11
8
|
* @position packages/cli/api/theme — function documentation
|
|
12
9
|
*/
|
|
13
10
|
/** @type {import('@astryxdesign/cli/authoring').FunctionDoc} */
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file FunctionDoc for `themeBuild()` / `astryx theme build`. Colocated with
|
|
5
5
|
* the API function it documents; the response-shape source of truth stays in
|
|
6
|
-
* `theme.type.mjs`.
|
|
7
|
-
* of registries that cannot be preserved in build/check modes.
|
|
8
|
-
* @input themeBuild's build/check and icon-import behavior.
|
|
9
|
-
* @output Consumer API documentation for generated theme artifacts.
|
|
6
|
+
* `theme.type.mjs`.
|
|
10
7
|
* @position packages/cli/api/theme — function documentation
|
|
11
8
|
*/
|
|
12
9
|
|
|
@@ -24,14 +21,6 @@ export const doc = {
|
|
|
24
21
|
'writes a scoped CSS file, a JS module that re-exports the built theme, and a .d.ts ' +
|
|
25
22
|
'(plus an optional .variants.d.ts when the theme adds custom prop values). It uses ' +
|
|
26
23
|
"@astryxdesign/core's own generator, so the CSS matches what the <Theme> runtime emits. " +
|
|
27
|
-
'When another build step emits the icon registry, ' +
|
|
28
|
-
'{iconsSpecifier} declares the fully specified module path for the generated JS import. ' +
|
|
29
|
-
'Real registry imports are preserved, including aliases, default imports, and namespace ' +
|
|
30
|
-
'imports. Icons inherited through extends are retained, with child entries taking precedence. ' +
|
|
31
|
-
'Comment and string contents do not affect import detection. ' +
|
|
32
|
-
'An inline registry that cannot be preserved fails with ERR_THEME_INVALID before any ' +
|
|
33
|
-
'output is written, including in check mode. Move the registry to its own module and ' +
|
|
34
|
-
'import it into the theme file. ' +
|
|
35
24
|
'With {check: true} it writes nothing and instead compares ' +
|
|
36
25
|
'each output against disk, returning the drift: the CI guard for committed, generated theme CSS.',
|
|
37
26
|
importPath: '@astryxdesign/cli/api',
|
|
@@ -71,7 +60,7 @@ export const doc = {
|
|
|
71
60
|
name: 'options.iconsSpecifier',
|
|
72
61
|
type: 'string',
|
|
73
62
|
description:
|
|
74
|
-
'Override the
|
|
63
|
+
'Override the import specifier of the icon registry in the generated JS module, for example ./icons.mjs. Takes effect only when the theme sets icons: to a named import; when omitted, the source specifier is kept.',
|
|
75
64
|
},
|
|
76
65
|
{
|
|
77
66
|
name: 'ctx.cwd',
|
|
@@ -101,7 +90,7 @@ export const doc = {
|
|
|
101
90
|
},
|
|
102
91
|
{
|
|
103
92
|
code: 'ERR_THEME_INVALID',
|
|
104
|
-
when: 'the resolved theme is invalid, for example it has no name, a custom Heading type has no standalone rule with a declaration the compiler can emit
|
|
93
|
+
when: 'the resolved theme is invalid, for example it has no name, or a custom Heading type has no standalone rule with a declaration the compiler can emit',
|
|
105
94
|
},
|
|
106
95
|
{
|
|
107
96
|
code: 'ERR_PATH_TRAVERSAL',
|