@astryxdesign/cli 0.7.5-canary.67dc45f → 0.7.5-canary.6906beb
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 +134 -75
- package/api/theme/build/build.test.mjs +77 -0
- package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -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/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- 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/templates/pages/dashboard-alert-rail/page.tsx +3 -3
- package/assets/templates/pages/table-comparison/page.tsx +12 -3
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
- package/assets/templates/themes/butter/butterTheme.ts +47 -44
- package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
- package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
- package/assets/templates/themes/stone/stoneTheme.ts +46 -21
- package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
- package/assets/theme.template.ts +18 -5
- package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
- 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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Contract test for the Tokenizer showcase block.
|
|
5
|
+
* @input The shipped TokenizerShowcase block source.
|
|
6
|
+
* @output Guards the block's search source: typing in the showcase must list
|
|
7
|
+
* matching tags rather than an empty menu.
|
|
8
|
+
* @position CLI template regression coverage; runs in the node test project.
|
|
9
|
+
* The block is the hero example of the Tokenizer docs page. Like the other
|
|
10
|
+
* template contract tests here it reads the block's source instead of
|
|
11
|
+
* importing it, so it needs no built `@astryxdesign/core`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import {fileURLToPath} from 'node:url';
|
|
17
|
+
import {describe, expect, it} from 'vitest';
|
|
18
|
+
|
|
19
|
+
const sourcePath = path.resolve(
|
|
20
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
21
|
+
'../../assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx',
|
|
22
|
+
);
|
|
23
|
+
const source = fs.readFileSync(sourcePath, 'utf8');
|
|
24
|
+
|
|
25
|
+
// Evaluate the block's tag list and search source on their own, with the
|
|
26
|
+
// type annotations removed, so the test exercises the shipped logic.
|
|
27
|
+
function loadSearchSource() {
|
|
28
|
+
const tags = source.match(/const tags[^=]*=\s*(\[[\s\S]*?\n\]);/)?.[1];
|
|
29
|
+
const searchSource = source.match(
|
|
30
|
+
/const source[^=]*=\s*(\{[\s\S]*?\n\});/,
|
|
31
|
+
)?.[1];
|
|
32
|
+
if (tags == null || searchSource == null) {
|
|
33
|
+
throw new Error('TokenizerShowcase no longer declares `tags` and `source`');
|
|
34
|
+
}
|
|
35
|
+
const untyped = searchSource.replace(/\((\w+):\s*string\)/g, '($1)');
|
|
36
|
+
return new Function(`const tags = ${tags}; return ${untyped};`)();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('Tokenizer showcase block', () => {
|
|
40
|
+
it('lists the tags that match a typed query, ignoring case', async () => {
|
|
41
|
+
const {search, bootstrap} = loadSearchSource();
|
|
42
|
+
const labels = async query => (await search(query)).map(tag => tag.label);
|
|
43
|
+
expect(await labels('mar')).toEqual(['Marketing']);
|
|
44
|
+
expect(await labels('A')).toEqual(['Marketing', 'Research', 'Sales']);
|
|
45
|
+
expect((await bootstrap()).length).toBeGreaterThan(0);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -86,6 +86,10 @@ describe('values the root accepts without enrollment are accepted rule-only', ()
|
|
|
86
86
|
// case. It must NOT be an adaptation-specific exception; it is simply
|
|
87
87
|
// whatever root does.
|
|
88
88
|
['an unresolved domain', 'avatar-group', 'size:not-a-real-avatar-size'],
|
|
89
|
+
// `IconVariantMap` is public and augmentable, but `Icon.variant` selects
|
|
90
|
+
// artwork and has no component styling map (component-theming-surface
|
|
91
|
+
// INV14), so a styling key on it never enrolls a value.
|
|
92
|
+
['an artwork-request axis', 'icon', 'variant:filled'],
|
|
89
93
|
])('accepts %s on both surfaces', async (_label, component, key) => {
|
|
90
94
|
const rootReceipt = await buildWithRootValue('root-ok', component, key);
|
|
91
95
|
expect(rootReceipt?.type).toBe('theme.build');
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Built and runtime themes pass an inherited icon entry the same variants.
|
|
5
|
+
* @input Real themeBuild calls on a base theme with a function icon entry and a
|
|
6
|
+
* child that extends it with a wider `iconVariants` list.
|
|
7
|
+
* @output A native ESM load renders `<Icon variant>` under the built child and
|
|
8
|
+
* under the runtime child and compares the variant each entry received.
|
|
9
|
+
* @position `architecture:theme-compilation` INV15 for `spec:AST-087` FR4: an
|
|
10
|
+
* inherited entry keeps its defining theme's list, so a variant only the
|
|
11
|
+
* child lists never reaches it, built or runtime. The node project's global
|
|
12
|
+
* setup supplies the compiled core package.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {expect, it} from 'vitest';
|
|
16
|
+
import {execFileSync} from 'node:child_process';
|
|
17
|
+
import * as fs from 'node:fs';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import {themeBuild} from './build.mjs';
|
|
20
|
+
|
|
21
|
+
it('passes an inherited entry only its defining theme variants in a built child, as at runtime', async () => {
|
|
22
|
+
const tmpDir = fs.mkdtempSync(
|
|
23
|
+
path.resolve(import.meta.dirname, '../../..', '.tmp-icon-entry-variants-'),
|
|
24
|
+
);
|
|
25
|
+
try {
|
|
26
|
+
for (const directory of ['base', 'child', 'unlisted']) {
|
|
27
|
+
fs.mkdirSync(path.join(tmpDir, directory));
|
|
28
|
+
}
|
|
29
|
+
const write = (file, source) =>
|
|
30
|
+
fs.writeFileSync(path.join(tmpDir, file), source);
|
|
31
|
+
|
|
32
|
+
write(
|
|
33
|
+
'base/icons.mjs',
|
|
34
|
+
`import {createElement} from 'react';
|
|
35
|
+
export const icons = {
|
|
36
|
+
info: ({variant}) => createElement('svg', {'data-variant': variant ?? 'normal'}),
|
|
37
|
+
};
|
|
38
|
+
`,
|
|
39
|
+
);
|
|
40
|
+
write(
|
|
41
|
+
'base/source.mjs',
|
|
42
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
43
|
+
import {icons} from './icons.mjs';
|
|
44
|
+
export const baseTheme = defineTheme({
|
|
45
|
+
name: 'entry-variants-base', tokens: {}, iconVariants: ['outline'], icons,
|
|
46
|
+
});
|
|
47
|
+
`,
|
|
48
|
+
);
|
|
49
|
+
write(
|
|
50
|
+
'child/source.mjs',
|
|
51
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
52
|
+
import {baseTheme} from '../base/source.mjs';
|
|
53
|
+
export default defineTheme({
|
|
54
|
+
name: 'entry-variants-child', extends: baseTheme, tokens: {},
|
|
55
|
+
iconVariants: ['outline', 'filled'],
|
|
56
|
+
});
|
|
57
|
+
`,
|
|
58
|
+
);
|
|
59
|
+
// A defining theme with no list: the built module writes it as `[]`.
|
|
60
|
+
write(
|
|
61
|
+
'unlisted/base.mjs',
|
|
62
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
63
|
+
import {icons} from '../base/icons.mjs';
|
|
64
|
+
export const unlistedBase = defineTheme({
|
|
65
|
+
name: 'entry-variants-unlisted-base', tokens: {}, icons,
|
|
66
|
+
});
|
|
67
|
+
`,
|
|
68
|
+
);
|
|
69
|
+
write(
|
|
70
|
+
'unlisted/source.mjs',
|
|
71
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
72
|
+
import {unlistedBase} from './base.mjs';
|
|
73
|
+
export default defineTheme({
|
|
74
|
+
name: 'entry-variants-unlisted-child', extends: unlistedBase, tokens: {},
|
|
75
|
+
iconVariants: ['filled'],
|
|
76
|
+
});
|
|
77
|
+
`,
|
|
78
|
+
);
|
|
79
|
+
for (const source of ['child/source.mjs', 'unlisted/source.mjs']) {
|
|
80
|
+
const receipt = await themeBuild(source, {}, {cwd: tmpDir});
|
|
81
|
+
expect(receipt?.type).toBe('theme.build');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const output = execFileSync(
|
|
85
|
+
process.execPath,
|
|
86
|
+
[
|
|
87
|
+
'--input-type=module',
|
|
88
|
+
'--eval',
|
|
89
|
+
`import {createElement} from 'react';
|
|
90
|
+
import {renderToStaticMarkup} from 'react-dom/server';
|
|
91
|
+
import {Icon} from '@astryxdesign/core/Icon';
|
|
92
|
+
import {Theme} from '@astryxdesign/core/theme';
|
|
93
|
+
import {entryVariantsChildTheme as built} from './child/entry-variants-child.js';
|
|
94
|
+
import runtime from './child/source.mjs';
|
|
95
|
+
import {entryVariantsUnlistedChildTheme as unlistedBuilt} from './unlisted/entry-variants-unlisted-child.js';
|
|
96
|
+
import unlistedRuntime from './unlisted/source.mjs';
|
|
97
|
+
const received = (theme, variant) => {
|
|
98
|
+
const html = renderToStaticMarkup(
|
|
99
|
+
createElement(Theme, {theme}, createElement(Icon, {icon: 'info', variant})),
|
|
100
|
+
);
|
|
101
|
+
return /data-variant="([^"]+)"/.exec(html)?.[1] ?? null;
|
|
102
|
+
};
|
|
103
|
+
const result = {};
|
|
104
|
+
for (const [label, theme] of [
|
|
105
|
+
['built', built],
|
|
106
|
+
['runtime', runtime],
|
|
107
|
+
['unlistedBuilt', unlistedBuilt],
|
|
108
|
+
['unlistedRuntime', unlistedRuntime],
|
|
109
|
+
]) {
|
|
110
|
+
result[label] = {
|
|
111
|
+
filled: received(theme, 'filled'),
|
|
112
|
+
outline: received(theme, 'outline'),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
process.stdout.write(JSON.stringify(result));`,
|
|
116
|
+
],
|
|
117
|
+
{cwd: tmpDir, stdio: ['ignore', 'pipe', 'pipe'], timeout: 20000},
|
|
118
|
+
);
|
|
119
|
+
const result = JSON.parse(String(output));
|
|
120
|
+
|
|
121
|
+
// The base never listed 'filled', so its entry draws normal artwork for
|
|
122
|
+
// it in the child; 'outline' is listed by both and reaches the entry.
|
|
123
|
+
expect(result.runtime).toEqual({filled: 'normal', outline: 'outline'});
|
|
124
|
+
expect(result.built).toEqual(result.runtime);
|
|
125
|
+
// A base with no list passes its entry no variant, even one its child lists.
|
|
126
|
+
expect(result.unlistedRuntime).toEqual({
|
|
127
|
+
filled: 'normal',
|
|
128
|
+
outline: 'normal',
|
|
129
|
+
});
|
|
130
|
+
expect(result.unlistedBuilt).toEqual(result.unlistedRuntime);
|
|
131
|
+
} finally {
|
|
132
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A built theme keeps its `iconVariants` list.
|
|
5
|
+
*
|
|
6
|
+
* `architecture:theme-compilation` (System model item 7): a built theme carries
|
|
7
|
+
* its `iconVariants` list in its JavaScript, so the built theme, and a theme
|
|
8
|
+
* that `extends` it, read the same list as the runtime theme
|
|
9
|
+
* (`spec:AST-087` FR2, FR18).
|
|
10
|
+
*
|
|
11
|
+
* `themeBuild` compiles via @astryxdesign/core, so it needs a built core — the
|
|
12
|
+
* `node` project's globalSetup builds it once before workers fork.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as os from 'node:os';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import {pathToFileURL} from 'node:url';
|
|
20
|
+
import {defineTheme} from '@astryxdesign/core/theme';
|
|
21
|
+
import {themeBuild} from './build.mjs';
|
|
22
|
+
|
|
23
|
+
vi.setConfig({testTimeout: 30000});
|
|
24
|
+
|
|
25
|
+
let tmpDir;
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-icon-variants-'));
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Build a raw theme source and import the generated module's theme.
|
|
35
|
+
* @param {Record<string, unknown>} source
|
|
36
|
+
*/
|
|
37
|
+
async function buildAndImport(source) {
|
|
38
|
+
const name = String(source.name);
|
|
39
|
+
fs.writeFileSync(
|
|
40
|
+
path.join(tmpDir, `${name}.mjs`),
|
|
41
|
+
`export default ${JSON.stringify({tokens: {}, ...source})};\n`,
|
|
42
|
+
);
|
|
43
|
+
await themeBuild(`${name}.mjs`, {}, {cwd: tmpDir});
|
|
44
|
+
const mod = await import(pathToFileURL(path.join(tmpDir, `${name}.js`)).href);
|
|
45
|
+
const [theme] = Object.values(mod);
|
|
46
|
+
return /** @type {any} */ (theme);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('theme build keeps the iconVariants list', () => {
|
|
50
|
+
it('writes the list a theme sets, as the runtime theme reads it', async () => {
|
|
51
|
+
const source = {name: 'listed-icons', iconVariants: ['outline', 'filled']};
|
|
52
|
+
const built = await buildAndImport(source);
|
|
53
|
+
|
|
54
|
+
expect(built.__built).toBe(true);
|
|
55
|
+
expect(built.iconVariants).toEqual(['outline', 'filled']);
|
|
56
|
+
expect(built.iconVariants).toEqual(defineTheme(source).iconVariants);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('lets a child of the built theme inherit or replace the list, as at runtime', async () => {
|
|
60
|
+
const source = {name: 'base-icons', iconVariants: ['outline', 'filled']};
|
|
61
|
+
const built = await buildAndImport(source);
|
|
62
|
+
const runtime = defineTheme(source);
|
|
63
|
+
|
|
64
|
+
const inherits = defineTheme({name: 'inherits', extends: built});
|
|
65
|
+
const replaces = defineTheme({
|
|
66
|
+
name: 'replaces',
|
|
67
|
+
extends: built,
|
|
68
|
+
iconVariants: ['bold'],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(inherits.iconVariants).toEqual(['outline', 'filled']);
|
|
72
|
+
expect(replaces.iconVariants).toEqual(['bold']);
|
|
73
|
+
expect(inherits.iconVariants).toEqual(
|
|
74
|
+
defineTheme({name: 'inherits-runtime', extends: runtime}).iconVariants,
|
|
75
|
+
);
|
|
76
|
+
expect(replaces.iconVariants).toEqual(
|
|
77
|
+
defineTheme({
|
|
78
|
+
name: 'replaces-runtime',
|
|
79
|
+
extends: runtime,
|
|
80
|
+
iconVariants: ['bold'],
|
|
81
|
+
}).iconVariants,
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('keeps an explicit empty list, which replaces an inherited one', async () => {
|
|
86
|
+
const built = await buildAndImport({
|
|
87
|
+
name: 'emptied-icons',
|
|
88
|
+
iconVariants: [],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(built.iconVariants).toEqual([]);
|
|
92
|
+
expect(
|
|
93
|
+
defineTheme({name: 'emptied-child', extends: built}).iconVariants,
|
|
94
|
+
).toEqual([]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('writes no list for a theme without one', async () => {
|
|
98
|
+
const built = await buildAndImport({name: 'unlisted-icons'});
|
|
99
|
+
|
|
100
|
+
expect('iconVariants' in built).toBe(false);
|
|
101
|
+
expect(
|
|
102
|
+
defineTheme({name: 'unlisted-child', extends: built}).iconVariants,
|
|
103
|
+
).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -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';
|
|
@@ -1103,6 +1103,28 @@ function componentHasAugmentableInterface(pascalName, interfaceName) {
|
|
|
1103
1103
|
return re.test(decl);
|
|
1104
1104
|
}
|
|
1105
1105
|
|
|
1106
|
+
/**
|
|
1107
|
+
* Public augmentable maps whose axis requests artwork instead of styling.
|
|
1108
|
+
* `Icon.variant` selects a theme's icon artwork, so it has no component styling
|
|
1109
|
+
* map (architecture:component-theming-surface INV14): a `components` key on it
|
|
1110
|
+
* never enrolls a value or generates an augmentation of its map.
|
|
1111
|
+
*/
|
|
1112
|
+
const ARTWORK_REQUEST_MAPS = new Set(['IconVariantMap']);
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* Whether a theme's component styling keys may enroll values in `interfaceName`
|
|
1116
|
+
* on `@astryxdesign/core/<Component>`.
|
|
1117
|
+
* @param {string} pascalName
|
|
1118
|
+
* @param {string} interfaceName
|
|
1119
|
+
* @returns {boolean}
|
|
1120
|
+
*/
|
|
1121
|
+
function isComponentValueAugmentationPoint(pascalName, interfaceName) {
|
|
1122
|
+
return (
|
|
1123
|
+
!ARTWORK_REQUEST_MAPS.has(interfaceName) &&
|
|
1124
|
+
componentHasAugmentableInterface(pascalName, interfaceName)
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1106
1128
|
/**
|
|
1107
1129
|
* Adaptation values from resolved runtime rules, raw input, or normalized built
|
|
1108
1130
|
* metadata. Built modules intentionally omit `__adaptationRules`, so every CLI
|
|
@@ -1410,7 +1432,7 @@ async function classifyComponentValue(component, prop, value) {
|
|
|
1410
1432
|
const propPascal = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
1411
1433
|
const target = (await resolveAugmentationTargetCandidates(component)).find(
|
|
1412
1434
|
candidate =>
|
|
1413
|
-
|
|
1435
|
+
isComponentValueAugmentationPoint(
|
|
1414
1436
|
candidate.moduleName,
|
|
1415
1437
|
`${candidate.interfacePrefix}${propPascal}Map`,
|
|
1416
1438
|
),
|
|
@@ -1567,7 +1589,7 @@ async function generateVariantDeclarationsAsync(themeDef) {
|
|
|
1567
1589
|
const target = (
|
|
1568
1590
|
await resolveAugmentationTargetCandidates(component)
|
|
1569
1591
|
).find(candidate =>
|
|
1570
|
-
|
|
1592
|
+
isComponentValueAugmentationPoint(
|
|
1571
1593
|
candidate.moduleName,
|
|
1572
1594
|
`${candidate.interfacePrefix}${propPascal}Map`,
|
|
1573
1595
|
),
|
|
@@ -1833,19 +1855,43 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
1833
1855
|
commonJsPatch.undo();
|
|
1834
1856
|
}
|
|
1835
1857
|
} else {
|
|
1836
|
-
mod = await jiti.import(filePath
|
|
1858
|
+
mod = await jiti.import(filePath);
|
|
1837
1859
|
}
|
|
1838
1860
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1861
|
+
// Both loads hand back the module. The theme is read from the module's own
|
|
1862
|
+
// exports, never from the module object itself: jiti's interop answers a
|
|
1863
|
+
// property the module lacks from its default export (and a missing
|
|
1864
|
+
// `default` with the module), so the module can pass for the theme while
|
|
1865
|
+
// its own keys hide the theme's fields.
|
|
1866
|
+
const isModule = mod != null && typeof mod === 'object';
|
|
1867
|
+
const hasDefault = isModule && Object.hasOwn(mod, 'default');
|
|
1868
|
+
const defaultExport = hasDefault ? mod.default : undefined;
|
|
1869
|
+
if (isThemeObject(defaultExport)) {
|
|
1870
|
+
return {theme: defaultExport, exportName: 'default', degraded};
|
|
1871
|
+
}
|
|
1872
|
+
if (isModule) {
|
|
1845
1873
|
for (const [exportName, value] of Object.entries(mod)) {
|
|
1874
|
+
if (exportName === 'default' || exportName === 'module.exports') continue;
|
|
1846
1875
|
if (isThemeObject(value)) return {theme: value, exportName, degraded};
|
|
1847
1876
|
}
|
|
1848
1877
|
}
|
|
1878
|
+
// A plain-object default export is the module's theme even when it has
|
|
1879
|
+
// no tokens of its own (local tokens, typography or component styles may
|
|
1880
|
+
// be all it defines), or no name: the build's validation says what it
|
|
1881
|
+
// lacks.
|
|
1882
|
+
if (isPlainObject(defaultExport)) {
|
|
1883
|
+
return {theme: defaultExport, exportName: 'default', degraded};
|
|
1884
|
+
}
|
|
1885
|
+
// A CommonJS module whose exports are the theme (`module.exports =
|
|
1886
|
+
// theme`) has no default of its own: interop answers `default` with
|
|
1887
|
+
// those exports, and without interop (a family build's loader) the module
|
|
1888
|
+
// is them.
|
|
1889
|
+
if (isModule && !hasDefault) {
|
|
1890
|
+
const exportsObject = mod.default ?? mod;
|
|
1891
|
+
if (isThemeObject(exportsObject)) {
|
|
1892
|
+
return {theme: exportsObject, exportName: 'default', degraded};
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1849
1895
|
|
|
1850
1896
|
throw new Error(
|
|
1851
1897
|
`Could not find a defineTheme() result in ${filePath}.\n` +
|
|
@@ -1853,6 +1899,45 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
|
|
|
1853
1899
|
);
|
|
1854
1900
|
}
|
|
1855
1901
|
|
|
1902
|
+
/**
|
|
1903
|
+
* Whether the theme file's own folder resolves Core's theme entry, as the
|
|
1904
|
+
* theme's own `import ... from '@astryxdesign/core/theme'` would. A theme
|
|
1905
|
+
* outside any project (an empty folder, a fresh clone) does not, and is
|
|
1906
|
+
* handed the Core the CLI answers with instead, as a new project with that
|
|
1907
|
+
* Core would build it (`theme build` runs the same outside a project, spec
|
|
1908
|
+
* AST-081 FR3). Only a Core not installed there (MODULE_NOT_FOUND) reads as
|
|
1909
|
+
* no: an installed Core whose entry does not resolve is the theme's own, and
|
|
1910
|
+
* its load reports that.
|
|
1911
|
+
* @param {string} filePath
|
|
1912
|
+
* @returns {boolean}
|
|
1913
|
+
*/
|
|
1914
|
+
function themeFolderResolvesCore(filePath) {
|
|
1915
|
+
try {
|
|
1916
|
+
createRequire(filePath).resolve('@astryxdesign/core/theme');
|
|
1917
|
+
return true;
|
|
1918
|
+
} catch (error) {
|
|
1919
|
+
const {code} = /** @type {NodeJS.ErrnoException} */ (error);
|
|
1920
|
+
if (code === 'MODULE_NOT_FOUND') return false;
|
|
1921
|
+
if (code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') return true;
|
|
1922
|
+
throw error;
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
/**
|
|
1927
|
+
* A plain object, not an array or a module namespace: a theme module's
|
|
1928
|
+
* default export, read as its theme.
|
|
1929
|
+
* @param {any} value
|
|
1930
|
+
* @returns {boolean}
|
|
1931
|
+
*/
|
|
1932
|
+
function isPlainObject(value) {
|
|
1933
|
+
return (
|
|
1934
|
+
value != null &&
|
|
1935
|
+
typeof value === 'object' &&
|
|
1936
|
+
!Array.isArray(value) &&
|
|
1937
|
+
value[Symbol.toStringTag] !== 'Module'
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1856
1941
|
/**
|
|
1857
1942
|
* @param {any} value
|
|
1858
1943
|
* @returns {boolean}
|
|
@@ -1868,12 +1953,9 @@ function isThemeObject(value) {
|
|
|
1868
1953
|
}
|
|
1869
1954
|
|
|
1870
1955
|
/**
|
|
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.
|
|
1956
|
+
* Extract the theme definition from a JS/TS file, through jiti (full TS
|
|
1957
|
+
* support). A module that does not load fails with its own error: the theme
|
|
1958
|
+
* is never read from the file's text instead.
|
|
1877
1959
|
*
|
|
1878
1960
|
* @param {string} filePath
|
|
1879
1961
|
* @param {import('./core-interception.mjs').CoreInterception} [interception]
|
|
@@ -1884,18 +1966,12 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
|
|
|
1884
1966
|
try {
|
|
1885
1967
|
return await importThemeModule(filePath, interception, loader);
|
|
1886
1968
|
} 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
|
-
}
|
|
1969
|
+
const je = /** @type {Error} */ (jitiError);
|
|
1970
|
+
throw new Error(
|
|
1971
|
+
`Failed to load theme from ${filePath}: ${je.message}\n` +
|
|
1972
|
+
`Make sure all imports in the theme file are resolvable.`,
|
|
1973
|
+
{cause: jitiError},
|
|
1974
|
+
);
|
|
1899
1975
|
}
|
|
1900
1976
|
}
|
|
1901
1977
|
|
|
@@ -1941,45 +2017,6 @@ export async function validateThemePrivateInputs(
|
|
|
1941
2017
|
}
|
|
1942
2018
|
}
|
|
1943
2019
|
|
|
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
2020
|
/**
|
|
1984
2021
|
* Extract a family member's named registry import from its source file.
|
|
1985
2022
|
* Returns { importPath, exportName } or null when the theme names none.
|
|
@@ -2151,7 +2188,22 @@ function generateBuiltModule(
|
|
|
2151
2188
|
serializeField('__onDark', themeDef.__onDark) +
|
|
2152
2189
|
serializeField('__onLight', themeDef.__onLight) +
|
|
2153
2190
|
serializeField('__adaptations', themeDef.__adaptations) +
|
|
2154
|
-
serializeField('__axes', themeDef.__axes ?? {}, true)
|
|
2191
|
+
serializeField('__axes', themeDef.__axes ?? {}, true) +
|
|
2192
|
+
// An explicit empty list replaces an inherited one, so keep `[]`.
|
|
2193
|
+
serializeField('iconVariants', themeDef.iconVariants, true) +
|
|
2194
|
+
// Each inherited function entry keeps its defining theme's list. JSON
|
|
2195
|
+
// drops `undefined`, so a defining theme with no list is written as `[]`,
|
|
2196
|
+
// which no variant matches either.
|
|
2197
|
+
serializeField(
|
|
2198
|
+
'__iconEntryVariants',
|
|
2199
|
+
themeDef.__iconEntryVariants &&
|
|
2200
|
+
Object.fromEntries(
|
|
2201
|
+
Object.entries(themeDef.__iconEntryVariants).map(([name, list]) => [
|
|
2202
|
+
name,
|
|
2203
|
+
list ?? [],
|
|
2204
|
+
]),
|
|
2205
|
+
),
|
|
2206
|
+
);
|
|
2155
2207
|
|
|
2156
2208
|
return `${iconImport}${iconDeclaration}/**
|
|
2157
2209
|
* ${themeDef.name} theme — built by \`${getCliInvocation()} theme build\`
|
|
@@ -2580,13 +2632,15 @@ async function themeBuildInternal(
|
|
|
2580
2632
|
}
|
|
2581
2633
|
await selectCore(cwd, {projectOnly: projectCore});
|
|
2582
2634
|
|
|
2583
|
-
// Standalone builds
|
|
2584
|
-
// adaptations
|
|
2635
|
+
// Standalone builds need interception when an older Core could erase
|
|
2636
|
+
// adaptations, and when the theme's folder has no Core of its own: its
|
|
2637
|
+
// imports of Core are then handed the Core this build selected, as family
|
|
2638
|
+
// builds' are. Family preparation always supplies the same recorder as its
|
|
2585
2639
|
// shared loader so exact authored parent identity stays CLI-private instead
|
|
2586
2640
|
// of becoming a public DefinedTheme field.
|
|
2587
2641
|
const interception =
|
|
2588
2642
|
options.__familyInterception ??
|
|
2589
|
-
(_generateAdaptationCSS
|
|
2643
|
+
(_generateAdaptationCSS && themeFolderResolvesCore(filePath)
|
|
2590
2644
|
? undefined
|
|
2591
2645
|
: interceptCore(_coreThemeModule, _coreRootModule));
|
|
2592
2646
|
|
|
@@ -2870,10 +2924,15 @@ async function themeBuildInternal(
|
|
|
2870
2924
|
/** @type {string[]} */
|
|
2871
2925
|
const droppedDeclarations = [];
|
|
2872
2926
|
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
droppedDeclarations
|
|
2876
|
-
)
|
|
2927
|
+
let themeRules;
|
|
2928
|
+
try {
|
|
2929
|
+
themeRules = _generateThemeRulesSplit(resolvedTheme, droppedDeclarations);
|
|
2930
|
+
} catch (error) {
|
|
2931
|
+
const message =
|
|
2932
|
+
error instanceof Error ? error.message : 'Theme normalization failed.';
|
|
2933
|
+
throw new AstryxError(message, undefined, ERROR_CODES.ERR_THEME_INVALID);
|
|
2934
|
+
}
|
|
2935
|
+
const {component, prose} = themeRules;
|
|
2877
2936
|
const cssParts = [];
|
|
2878
2937
|
// Prose element defaults always ship — the `<Theme>` runtime
|
|
2879
2938
|
// (generateThemeCSS) always emits them, so the build must too, or the
|