@astryxdesign/cli 0.7.5-canary.b58ca63 → 0.7.5-canary.b8c5e4a
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 +199 -99
- package/api/theme/build/build.project-core.test.mjs +63 -8
- 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
|
+
});
|