@astryxdesign/cli 0.7.0-canary.4927793 → 0.7.0-canary.4aec44c
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/build/build.mjs +9 -0
- package/api/component/_adapter.d.mts +2 -0
- package/api/component/_adapter.mjs +3 -1
- package/api/component/component.doc.mjs +5 -1
- package/api/docs/compiled-topics.test.mjs +16 -0
- package/api/integration/pack-check.test.mjs +8 -0
- package/api/template/list/list.mjs +23 -2
- package/api/template/list/list.test.mjs +52 -0
- package/api/template/template.doc.mjs +4 -3
- package/api/theme/build/build.d.mts +0 -1
- package/api/theme/build/build.mjs +4 -29
- package/api/theme/build/family.mjs +1 -1
- package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
- package/assets/codemods/transforms/next/index.mjs +8 -0
- package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
- package/assets/docs/author-a-theme.doc.mjs +4 -4
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/page.tsx +1 -1
- package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
- package/assets/templates/pages/payment-form/page.tsx +1 -1
- package/assets/templates/pages/theme-showcase/page.tsx +2 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
- package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
- package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
- package/clients/cli/commands/build.doc.mjs +1 -1
- package/clients/cli/commands/build.mjs +1 -1
- package/clients/cli/commands/component-ownership.test.mjs +2 -2
- package/clients/cli/commands/integration.mjs +2 -1
- package/clients/cli/commands/silent-success-refusals.test.mjs +15 -0
- package/clients/cli/commands/template.doc.mjs +1 -1
- package/package.json +9 -9
package/api/build/build.mjs
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* a query → build.kit (api/build/kit/kit.mjs)
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
import {AstryxError} from '../error.mjs';
|
|
17
|
+
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
16
18
|
import {buildHelp} from './help/help.mjs';
|
|
17
19
|
import {buildKit} from './kit/kit.mjs';
|
|
18
20
|
|
|
@@ -31,5 +33,12 @@ export async function build(query, options = {}) {
|
|
|
31
33
|
if (!query || !String(query).trim()) {
|
|
32
34
|
return buildHelp();
|
|
33
35
|
}
|
|
36
|
+
if (options.limit != null && (!Number.isInteger(options.limit) || options.limit <= 0)) {
|
|
37
|
+
throw new AstryxError(
|
|
38
|
+
`Invalid limit "${options.limit}". Must be a positive integer.`,
|
|
39
|
+
undefined,
|
|
40
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
34
43
|
return buildKit(query, options);
|
|
35
44
|
}
|
|
@@ -149,6 +149,8 @@ export function resolveCoreSourcePath(coreDir: string, dirName: string): string
|
|
|
149
149
|
/**
|
|
150
150
|
* Resolve a bare (unscoped) name to a `.doc.mjs`: core first, then back-compat
|
|
151
151
|
* externals, then a conservative fuzzy search. Throws ERR_UNKNOWN_COMPONENT
|
|
152
|
+
* for a genuinely unknown name, and ERR_AMBIGUOUS_COMPONENT when multiple
|
|
153
|
+
* packages provide the same name
|
|
152
154
|
* (with candidate suggestions when close) or ERR_NO_DOC.
|
|
153
155
|
* @param {string} dirName - bare component name (no `XDS` prefix)
|
|
154
156
|
* @param {{coreDir: string, cwd: string, name: string}} ctx - `name` is the caller's original (prefixed) input, used in error text
|
|
@@ -324,7 +324,7 @@ export class ComponentAmbiguityError extends AstryxError {
|
|
|
324
324
|
super(
|
|
325
325
|
`Component "${dirName}" is provided by multiple packages. Re-run with --package <pkg> to choose one.`,
|
|
326
326
|
owners.map(o => ({name: o.package, reason: 'provides this component'})),
|
|
327
|
-
ERROR_CODES.
|
|
327
|
+
ERROR_CODES.ERR_AMBIGUOUS_COMPONENT,
|
|
328
328
|
);
|
|
329
329
|
this.candidates = owners.map(owner => ({
|
|
330
330
|
package: owner.package,
|
|
@@ -375,6 +375,8 @@ export function resolveCoreSourcePath(coreDir, dirName) {
|
|
|
375
375
|
/**
|
|
376
376
|
* Resolve a bare (unscoped) name to a `.doc.mjs`: core first, then back-compat
|
|
377
377
|
* externals, then a conservative fuzzy search. Throws ERR_UNKNOWN_COMPONENT
|
|
378
|
+
* for a genuinely unknown name, and ERR_AMBIGUOUS_COMPONENT when multiple
|
|
379
|
+
* packages provide the same name
|
|
378
380
|
* (with candidate suggestions when close) or ERR_NO_DOC.
|
|
379
381
|
* @param {string} dirName - bare component name (no `XDS` prefix)
|
|
380
382
|
* @param {{coreDir: string, cwd: string, name: string}} ctx - `name` is the caller's original (prefixed) input, used in error text
|
|
@@ -170,7 +170,11 @@ export const doc = {
|
|
|
170
170
|
},
|
|
171
171
|
{
|
|
172
172
|
code: 'ERR_UNKNOWN_COMPONENT',
|
|
173
|
-
when: 'name is not a string, resolves to no known component,
|
|
173
|
+
when: 'name is not a string, resolves to no known component, or is absent from the requested options.package',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
code: 'ERR_AMBIGUOUS_COMPONENT',
|
|
177
|
+
when: 'the component is provided by multiple packages (pass options.package to disambiguate)',
|
|
174
178
|
},
|
|
175
179
|
{
|
|
176
180
|
code: 'ERR_UNKNOWN_PACKAGE',
|
|
@@ -48,6 +48,22 @@ describe('every shipped topic compiles to plain JSON', () => {
|
|
|
48
48
|
);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
describe('author-a-theme color guidance', () => {
|
|
52
|
+
it('teaches committed generated palette references as the main example', async () => {
|
|
53
|
+
const catalog = await loadDocsCatalog();
|
|
54
|
+
const topic = detailView(
|
|
55
|
+
await compileTopic(catalog, catalog.resolve('author-a-theme')),
|
|
56
|
+
);
|
|
57
|
+
const rendered = JSON.stringify(topic);
|
|
58
|
+
|
|
59
|
+
expect(rendered).toContain("import {palette} from './palette.generated';");
|
|
60
|
+
expect(rendered).toContain('palette.neutral.light[100]');
|
|
61
|
+
expect(rendered).toContain('palette.neutral.dark[15]');
|
|
62
|
+
expect(rendered).toContain('color (existing themes)');
|
|
63
|
+
expect(rendered).not.toContain("color: { accent: ['#7B61FF'");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
51
67
|
describe('reads that share a catalog', () => {
|
|
52
68
|
it(
|
|
53
69
|
'never let one read change another',
|
|
@@ -504,6 +504,14 @@ describe('integrationPackCheck', () => {
|
|
|
504
504
|
message:
|
|
505
505
|
'Theme "ocean" exports @acme/widgets/theme.css without a complete built module and stylesheet pair. Missing partner exports alone do not block packing; add the matching export when the theme should be importable. Every declared export must resolve. Staleness is a warning until the complete importable pair is declared.',
|
|
506
506
|
},
|
|
507
|
+
// A 0.6.5-built stylesheet still carries the root data-color defaults
|
|
508
|
+
// that theme output no longer emits, so it no longer matches its source.
|
|
509
|
+
{
|
|
510
|
+
code: 'theme_stylesheet_stale',
|
|
511
|
+
severity: 'warning',
|
|
512
|
+
message:
|
|
513
|
+
'Theme "ocean" stylesheet does not match themes/ocean/oceanTheme.ts. This incomplete export remains packable, but run `astryx theme build themes/ocean/oceanTheme.ts` before adding its matching export.',
|
|
514
|
+
},
|
|
507
515
|
]);
|
|
508
516
|
const cli = runCliVerify();
|
|
509
517
|
expect(cli.status, cli.stderr).toBe(0);
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import {pkgOf} from '../../../foundation/discovery/template-adapter.mjs';
|
|
13
|
+
import {AstryxError} from '../../error.mjs';
|
|
14
|
+
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Project a discovered template set into the `template.list` envelope.
|
|
@@ -19,10 +21,29 @@ import {pkgOf} from '../../../foundation/discovery/template-adapter.mjs';
|
|
|
19
21
|
*/
|
|
20
22
|
export function templateList(templates, options = {}) {
|
|
21
23
|
const {type, package: packageFilter} = options;
|
|
24
|
+
const VALID_TYPES = ['page', 'block'];
|
|
22
25
|
let filtered = templates;
|
|
23
|
-
if (type)
|
|
24
|
-
|
|
26
|
+
if (type) {
|
|
27
|
+
if (!VALID_TYPES.includes(type)) {
|
|
28
|
+
throw new AstryxError(
|
|
29
|
+
`Unknown template type "${type}". Valid types: ${VALID_TYPES.join(', ')}.`,
|
|
30
|
+
VALID_TYPES.map(t => ({name: t, reason: 'valid type'})),
|
|
31
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
filtered = filtered.filter(t => t.type === type);
|
|
35
|
+
}
|
|
36
|
+
if (packageFilter) {
|
|
37
|
+
const allPackages = [...new Set(templates.map(t => pkgOf(t)))];
|
|
38
|
+
if (!allPackages.includes(packageFilter)) {
|
|
39
|
+
throw new AstryxError(
|
|
40
|
+
`No templates found in package "${packageFilter}".`,
|
|
41
|
+
allPackages.sort().map(p => ({name: p, reason: 'has templates'})),
|
|
42
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
25
45
|
filtered = filtered.filter(t => pkgOf(t) === packageFilter);
|
|
46
|
+
}
|
|
26
47
|
return {
|
|
27
48
|
type: 'template.list',
|
|
28
49
|
data: filtered.map(t => ({
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
import {describe, expect, it} from 'vitest';
|
|
3
|
+
import {templateList} from './list.mjs';
|
|
4
|
+
|
|
5
|
+
const t = (type, dirName, pkg) => ({
|
|
6
|
+
type,
|
|
7
|
+
dirName,
|
|
8
|
+
name: dirName,
|
|
9
|
+
description: dirName,
|
|
10
|
+
...(pkg ? {package: pkg} : {}),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const templates = [
|
|
14
|
+
t('page', 'dashboard'),
|
|
15
|
+
t('block', 'hero'),
|
|
16
|
+
t('block', 'promo', '@acme/blocks'),
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
describe('templateList filters', () => {
|
|
20
|
+
it('returns an empty list for a valid filter that matches nothing', () => {
|
|
21
|
+
// @acme/blocks ships only blocks, so asking it for pages is a valid
|
|
22
|
+
// filter with no match: an empty list, not an error.
|
|
23
|
+
const response = templateList(templates, {
|
|
24
|
+
type: 'page',
|
|
25
|
+
package: '@acme/blocks',
|
|
26
|
+
});
|
|
27
|
+
expect(response.type).toBe('template.list');
|
|
28
|
+
expect(response.data).toEqual([]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('refuses a type outside page or block', () => {
|
|
32
|
+
expect(() => templateList(templates, {type: 'bogus'})).toThrow(
|
|
33
|
+
/Unknown template type "bogus"/,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('refuses a package that provides no templates', () => {
|
|
38
|
+
expect(() => templateList(templates, {package: '@nope/x'})).toThrow(
|
|
39
|
+
/No templates found in package "@nope\/x"/,
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('keeps a matching type and package filter', () => {
|
|
44
|
+
const response = templateList(templates, {
|
|
45
|
+
type: 'block',
|
|
46
|
+
package: '@acme/blocks',
|
|
47
|
+
});
|
|
48
|
+
expect(response.data.map(item => item.id ?? item.dirName)).toEqual([
|
|
49
|
+
'promo',
|
|
50
|
+
]);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -48,7 +48,8 @@ export const doc = {
|
|
|
48
48
|
{
|
|
49
49
|
name: 'options.list',
|
|
50
50
|
type: 'boolean',
|
|
51
|
-
description:
|
|
51
|
+
description:
|
|
52
|
+
'List templates instead of scaffolding; refused with ERR_INVALID_ARGUMENT when a name or path is also given.',
|
|
52
53
|
default: 'false',
|
|
53
54
|
},
|
|
54
55
|
{
|
|
@@ -89,7 +90,7 @@ export const doc = {
|
|
|
89
90
|
type: 'string',
|
|
90
91
|
description:
|
|
91
92
|
'Destination (relative to cwd) to scaffold the template into. Its presence switches a named lookup into a copy. ' +
|
|
92
|
-
|
|
93
|
+
"A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is the file to write; any other path is a directory, which receives page.tsx for a page template or the block's own file name for a block.",
|
|
93
94
|
},
|
|
94
95
|
{
|
|
95
96
|
name: 'options.overwrite',
|
|
@@ -135,7 +136,7 @@ export const doc = {
|
|
|
135
136
|
throws: [
|
|
136
137
|
{
|
|
137
138
|
code: 'ERR_INVALID_ARGUMENT',
|
|
138
|
-
when: '--cdn is combined with <name>, --list, --skeleton, --type, or --package; --list is combined with <name>, <path>, --skeleton, or --overwrite; --skeleton is combined with <path> or --overwrite',
|
|
139
|
+
when: '--cdn is combined with <name>, --list, --skeleton, --type, or --package; --list is combined with <name>, <path>, --skeleton, or --overwrite; --skeleton is combined with <path> or --overwrite; or options.list is set with a type outside page or block, or with a package that provides no templates (a valid filter that matches nothing returns an empty list instead)',
|
|
139
140
|
},
|
|
140
141
|
{
|
|
141
142
|
code: 'ERR_UNKNOWN_TEMPLATE',
|
|
@@ -99,14 +99,12 @@ import {resolveIconImports} from './icon-imports.mjs';
|
|
|
99
99
|
// capability instead, required only by a theme that actually uses it:
|
|
100
100
|
// requiring it unconditionally made every theme build — adaptations or not —
|
|
101
101
|
// fail against an older published core. This is a targeted allowance for that
|
|
102
|
-
// one capability, not a general scheme;
|
|
103
|
-
//
|
|
104
|
-
// ships adaptations' predecessor surface.
|
|
102
|
+
// one capability, not a general scheme; `generateOnMediaCSS` exists in every
|
|
103
|
+
// core that ships adaptations' predecessor surface.
|
|
105
104
|
/** @type {any} */ let _defineTheme = null;
|
|
106
105
|
/** @type {any} */ let _generateThemeRulesSplit = null;
|
|
107
106
|
/** @type {any} */ let _generateOnMediaCSS = null;
|
|
108
107
|
/** @type {any} */ let _generateAdaptationCSS = null;
|
|
109
|
-
/** @type {any} */ let _dataTokenDefaults = null;
|
|
110
108
|
/**
|
|
111
109
|
* The whole `@astryxdesign/core/theme` namespace. A theme file handed a
|
|
112
110
|
* wrapped core must still get every export the installed one has, including
|
|
@@ -129,7 +127,6 @@ try {
|
|
|
129
127
|
_generateThemeRulesSplit = coreTheme.generateThemeRulesSplit;
|
|
130
128
|
_generateOnMediaCSS = coreTheme.generateOnMediaCSS;
|
|
131
129
|
_generateAdaptationCSS = coreTheme.generateAdaptationCSS;
|
|
132
|
-
_dataTokenDefaults = coreTheme.dataTokenDefaults;
|
|
133
130
|
try {
|
|
134
131
|
_coreRootModule = await import('@astryxdesign/core');
|
|
135
132
|
} catch {
|
|
@@ -156,7 +153,6 @@ try {
|
|
|
156
153
|
* generateThemeRulesSplit: any,
|
|
157
154
|
* generateOnMediaCSS: any,
|
|
158
155
|
* generateAdaptationCSS: any,
|
|
159
|
-
* dataTokenDefaults: any,
|
|
160
156
|
* }} CoreBindings
|
|
161
157
|
*/
|
|
162
158
|
|
|
@@ -173,7 +169,6 @@ const _cliCore = {
|
|
|
173
169
|
generateThemeRulesSplit: _generateThemeRulesSplit,
|
|
174
170
|
generateOnMediaCSS: _generateOnMediaCSS,
|
|
175
171
|
generateAdaptationCSS: _generateAdaptationCSS,
|
|
176
|
-
dataTokenDefaults: _dataTokenDefaults,
|
|
177
172
|
};
|
|
178
173
|
|
|
179
174
|
/**
|
|
@@ -188,7 +183,6 @@ function setCore(core) {
|
|
|
188
183
|
_generateThemeRulesSplit = core.generateThemeRulesSplit;
|
|
189
184
|
_generateOnMediaCSS = core.generateOnMediaCSS;
|
|
190
185
|
_generateAdaptationCSS = core.generateAdaptationCSS;
|
|
191
|
-
_dataTokenDefaults = core.dataTokenDefaults;
|
|
192
186
|
}
|
|
193
187
|
|
|
194
188
|
/**
|
|
@@ -295,7 +289,6 @@ async function loadProjectCore(cwd) {
|
|
|
295
289
|
generateThemeRulesSplit: themeModule.generateThemeRulesSplit,
|
|
296
290
|
generateOnMediaCSS: themeModule.generateOnMediaCSS,
|
|
297
291
|
generateAdaptationCSS: themeModule.generateAdaptationCSS,
|
|
298
|
-
dataTokenDefaults: themeModule.dataTokenDefaults,
|
|
299
292
|
};
|
|
300
293
|
}
|
|
301
294
|
|
|
@@ -2739,26 +2732,8 @@ async function themeBuildInternal(
|
|
|
2739
2732
|
logger.log(`${source}No overrides found; nothing to build.`);
|
|
2740
2733
|
return null;
|
|
2741
2734
|
}
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
// public `dataTokenDefaults` export, byte for byte as the `<Theme>`
|
|
2745
|
-
// runtime emits it — build-theme.data-tokens.test.mjs is the drift guard.
|
|
2746
|
-
// Placed after the reset block and before the theme block: a layer's order
|
|
2747
|
-
// is fixed by where it is first declared, so emitting it anywhere else in
|
|
2748
|
-
// the file would invert reset < astryx-base < astryx-theme for a consumer
|
|
2749
|
-
// who imports this stylesheet on its own.
|
|
2750
|
-
const baseCss = _dataTokenDefaults
|
|
2751
|
-
? `:root {\n${Object.entries(_dataTokenDefaults)
|
|
2752
|
-
.map(([name, value]) => ` ${name}: ${value};`)
|
|
2753
|
-
.join('\n')}\n}`
|
|
2754
|
-
: '';
|
|
2755
|
-
if (baseCss) {
|
|
2756
|
-
cssParts.splice(
|
|
2757
|
-
prose.length > 0 ? 1 : 0,
|
|
2758
|
-
0,
|
|
2759
|
-
`@layer astryx-base {\n${baseCss}\n}`,
|
|
2760
|
-
);
|
|
2761
|
-
}
|
|
2735
|
+
cssParts.unshift('@layer reset, astryx-base, astryx-theme;');
|
|
2736
|
+
const baseCss = '';
|
|
2762
2737
|
cssPlan = {
|
|
2763
2738
|
base: baseCss,
|
|
2764
2739
|
prose,
|
|
@@ -438,5 +438,5 @@ export function generateFamilyCSS(members) {
|
|
|
438
438
|
parts.push(`@layer astryx-base {\n${base.join('\n\n')}\n}`);
|
|
439
439
|
if (themed.length > 0)
|
|
440
440
|
parts.push(`@layer astryx-theme {\n${themed.join('\n\n')}\n}`);
|
|
441
|
-
return
|
|
441
|
+
return `@layer reset, astryx-base, astryx-theme;\n\n${parts.join('\n\n')}\n`;
|
|
442
442
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../validate-data-token-ownership.mjs';
|
|
5
|
+
|
|
6
|
+
async function run(source, file = 'test.tsx') {
|
|
7
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
8
|
+
const parser =
|
|
9
|
+
file.endsWith('.ts') || file.endsWith('.tsx') ? 'tsx' : 'babel';
|
|
10
|
+
const api = {
|
|
11
|
+
jscodeshift: jscodeshift.withParser(parser),
|
|
12
|
+
stats: () => {},
|
|
13
|
+
report: () => {},
|
|
14
|
+
};
|
|
15
|
+
return transform({source, path: file}, api);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('validate-data-token-ownership', () => {
|
|
19
|
+
it('reports direct string and static-template consumers with both migration paths', async () => {
|
|
20
|
+
for (const source of [
|
|
21
|
+
`const fill = 'var(--color-data-categorical-green)';`,
|
|
22
|
+
'const fill = `var(--color-data-categorical-green)`;',
|
|
23
|
+
`const border = '1px solid var(--color-data-categorical-green)';`,
|
|
24
|
+
'const border = `${width}px solid var(--color-data-categorical-green)`;',
|
|
25
|
+
]) {
|
|
26
|
+
await expect(run(source)).rejects.toThrow(
|
|
27
|
+
/CSS-capable code imports dataVars.*Canvas.*resolveThemeToken/s,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('leaves fallbacks, dataVars access, and comments unchanged', async () => {
|
|
33
|
+
const source = `
|
|
34
|
+
// var(--color-data-categorical-green)
|
|
35
|
+
const fallback = 'var(--color-data-categorical-green, #008000)';
|
|
36
|
+
const fill = dataVars['--color-data-categorical-green'];
|
|
37
|
+
`;
|
|
38
|
+
expect(await run(source)).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('reports stale generated theme CSS with root data defaults', async () => {
|
|
42
|
+
const source = `/* @generated by \`astryx theme build\` */
|
|
43
|
+
@layer astryx-base {
|
|
44
|
+
:root { --color-data-categorical-green: #008000; }
|
|
45
|
+
}`;
|
|
46
|
+
await expect(run(source, 'theme.css')).rejects.toThrow(
|
|
47
|
+
/Rebuild it with `astryx theme build`/,
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('reports raw stylesheet uses without a fallback', async () => {
|
|
52
|
+
await expect(
|
|
53
|
+
run('.bar { fill: var(--color-data-categorical-green); }', 'chart.css'),
|
|
54
|
+
).rejects.toThrow(/Raw var\(--color-data-categorical-green\).*line 1/s);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('leaves stylesheet uses with a fallback, and comments, unchanged', async () => {
|
|
58
|
+
expect(
|
|
59
|
+
await run(
|
|
60
|
+
`/* var(--color-data-categorical-green) */
|
|
61
|
+
.bar { fill: var(--color-data-categorical-green, #008000); }`,
|
|
62
|
+
'chart.css',
|
|
63
|
+
),
|
|
64
|
+
).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('does not claim ownership of hand-authored CSS or sparse theme overrides', async () => {
|
|
68
|
+
expect(
|
|
69
|
+
await run(
|
|
70
|
+
':root { --color-data-categorical-green: #008000; }',
|
|
71
|
+
'app.css',
|
|
72
|
+
),
|
|
73
|
+
).toBeUndefined();
|
|
74
|
+
expect(
|
|
75
|
+
await run(
|
|
76
|
+
`/* @generated by \`astryx theme build\` */
|
|
77
|
+
@scope ([data-astryx-theme="ocean"]) {
|
|
78
|
+
:scope { --color-data-categorical-green: #008000; }
|
|
79
|
+
}`,
|
|
80
|
+
'theme.css',
|
|
81
|
+
),
|
|
82
|
+
).toBeUndefined();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
import migrateDeprecatedThemeSurface, {
|
|
11
11
|
meta as migrateDeprecatedThemeSurfaceMeta,
|
|
12
12
|
} from './migrate-deprecated-theme-surface.mjs';
|
|
13
|
+
import validateDataTokenOwnership, {
|
|
14
|
+
meta as validateDataTokenOwnershipMeta,
|
|
15
|
+
} from './validate-data-token-ownership.mjs';
|
|
13
16
|
|
|
14
17
|
export default [
|
|
15
18
|
{
|
|
@@ -17,4 +20,9 @@ export default [
|
|
|
17
20
|
transform: migrateDeprecatedThemeSurface,
|
|
18
21
|
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
19
22
|
},
|
|
23
|
+
{
|
|
24
|
+
name: 'validate-data-token-ownership',
|
|
25
|
+
transform: validateDataTokenOwnership,
|
|
26
|
+
meta: validateDataTokenOwnershipMeta,
|
|
27
|
+
},
|
|
20
28
|
];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Report data-token consumers that need an ownership migration.
|
|
5
|
+
*
|
|
6
|
+
* @input Consumer JavaScript/TypeScript source and generated theme CSS
|
|
7
|
+
* @output No rewritten source; actionable upgrade errors for fallback-less
|
|
8
|
+
* `var(--color-data-*)` uses (in JS strings, embedded or whole, and in CSS)
|
|
9
|
+
* and stale generated root-default artifacts
|
|
10
|
+
* @position Next-release upgrade validation for spec:AST-066
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
|
|
15
|
+
export const meta = {
|
|
16
|
+
title: 'Validate data-token ownership',
|
|
17
|
+
description:
|
|
18
|
+
'Reports fallback-less data-token var() uses in source strings and stylesheets for manual CSS/non-CSS migration, and stale generated theme CSS that still owns root defaults.',
|
|
19
|
+
fileExtensions: ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.css'],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// A use without a fallback; `var(--color-data-x, <fallback>)` stays valid.
|
|
23
|
+
const DIRECT_DATA_VAR = /var\(\s*(--color-data-[a-z0-9-]+)\s*\)/u;
|
|
24
|
+
const CSS_COMMENT = /\/\*[\s\S]*?\*\//gu;
|
|
25
|
+
const GENERATED_THEME_HEADER = '@generated by `astryx theme build`';
|
|
26
|
+
const ROOT_DATA_DECLARATION = /:root\s*\{[^}]*--color-data-/su;
|
|
27
|
+
|
|
28
|
+
/** @param {any} node */
|
|
29
|
+
function staticString(node) {
|
|
30
|
+
if (
|
|
31
|
+
(node?.type === 'StringLiteral' || node?.type === 'Literal') &&
|
|
32
|
+
typeof node.value === 'string'
|
|
33
|
+
) {
|
|
34
|
+
return node.value;
|
|
35
|
+
}
|
|
36
|
+
if (node?.type === 'TemplateLiteral') {
|
|
37
|
+
// Each static chunk of the template; a use can sit between expressions.
|
|
38
|
+
return (node.quasis ?? [])
|
|
39
|
+
.map((/** @type {any} */ q) => q?.value?.cooked ?? q?.value?.raw ?? '')
|
|
40
|
+
.join('\u0000');
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
|
|
47
|
+
* @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
|
|
48
|
+
* @returns {undefined}
|
|
49
|
+
*/
|
|
50
|
+
export default function validateDataTokenOwnership(file, api) {
|
|
51
|
+
if (!file.source.includes('--color-data-')) return undefined;
|
|
52
|
+
|
|
53
|
+
if (path.extname(file.path) === '.css') {
|
|
54
|
+
if (
|
|
55
|
+
file.source.includes(GENERATED_THEME_HEADER) &&
|
|
56
|
+
ROOT_DATA_DECLARATION.test(file.source)
|
|
57
|
+
) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults now come from compiled dataVars consumers.',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const uncommented = file.source.replace(CSS_COMMENT, comment =>
|
|
63
|
+
comment.replace(/[^\n]/gu, ' '),
|
|
64
|
+
);
|
|
65
|
+
const cssMatch = DIRECT_DATA_VAR.exec(uncommented);
|
|
66
|
+
if (cssMatch) {
|
|
67
|
+
const line = uncommented.slice(0, cssMatch.index).split('\n').length;
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Raw var(${cssMatch[1]}) without a fallback at line ${line} needs manual migration: compiled dataVars output is not guaranteed in this stylesheet, so add an explicit fallback or style the element from code that imports dataVars from @astryxdesign/core/theme/dataTokens.stylex.`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const j = api.jscodeshift;
|
|
76
|
+
const root = j(file.source);
|
|
77
|
+
/** @type {{token: string, line: number|null}|null} */
|
|
78
|
+
let found = null;
|
|
79
|
+
const inspect = (/** @type {any} */ node) => {
|
|
80
|
+
if (found) return;
|
|
81
|
+
const value = staticString(node);
|
|
82
|
+
const match =
|
|
83
|
+
typeof value === 'string' ? value.match(DIRECT_DATA_VAR) : null;
|
|
84
|
+
if (match) {
|
|
85
|
+
found = {token: match[1], line: node.loc?.start?.line ?? null};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** @param {any} nodePath */
|
|
90
|
+
const inspectPath = nodePath => inspect(nodePath.node);
|
|
91
|
+
root.find(j.StringLiteral).forEach(inspectPath);
|
|
92
|
+
root.find(j.Literal).forEach(inspectPath);
|
|
93
|
+
root.find(j.TemplateLiteral).forEach(inspectPath);
|
|
94
|
+
|
|
95
|
+
if (found) {
|
|
96
|
+
const {token, line} = found;
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Direct var(${token})${line == null ? '' : ` at line ${line}`} needs manual migration: CSS-capable code imports dataVars from @astryxdesign/core/theme/dataTokens.stylex; Canvas and other non-CSS APIs use resolveThemeToken() or useTheme().token().`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
@@ -34,10 +34,10 @@ export const docs = {
|
|
|
34
34
|
{
|
|
35
35
|
title: 'defineTheme',
|
|
36
36
|
content: [
|
|
37
|
-
{type: 'prose', text:
|
|
38
|
-
{type: 'code', lang: 'tsx', label: 'defineTheme with scale configs', code: "import {defineTheme} from '@astryxdesign/core/theme';\n\nconst myTheme = defineTheme({\n name: 'my-theme',\n
|
|
37
|
+
{type: 'prose', text: 'defineTheme creates a theme from explicit token overrides and optional scale configs. Existing themes may use `color` to expand an accent seed into neutral, surface, text, border, and related values; it is not an accent-only edit. Keep that configuration when preserving existing output. For new complete palettes, generate and review a committed palette module, then import its `palette` export and reference stable stops from semantic tokens. This keeps mapped roles coherent when the accepted palette is regenerated; generation itself does not rewrite the theme. Other scale configs generate typography, radius, and motion values from parameters. Explicit token overrides always take precedence over scale-generated values, token by token. When an existing `color` config is in use, overriding `--color-accent` in `tokens` re-points `--color-accent-muted`, `--color-text-accent`, and `--color-icon-accent`, but `--color-on-accent` stays baked from the `color.accent` seed. Prefer a `[light, dark]` tuple for `color.accent` over overriding `--color-accent` alone. localTokens accepts any valid CSS custom-property name; prefixes do not establish ownership.'},
|
|
38
|
+
{type: 'code', lang: 'tsx', label: 'defineTheme with generated palette references and non-color scale configs', code: "import {defineTheme} from '@astryxdesign/core/theme';\nimport {palette} from './palette.generated';\n\nconst myTheme = defineTheme({\n name: 'my-theme',\n typography: {\n scale: { base: 14, ratio: 1.2 },\n body: { family: 'Inter', fallbacks: '-apple-system, sans-serif' },\n },\n radius: { base: 4, multiplier: 1 },\n motion: { fast: 175, medium: 410, ratio: 0.75 },\n tokens: {\n '--color-background-surface': [\n palette.neutral.light[100],\n palette.neutral.dark[15],\n ],\n },\n});"},
|
|
39
39
|
{type: 'table', headers: ['Config', 'Generates', 'Parameters'], rows: [
|
|
40
|
-
['color', '--color-accent, --color-background-*, --color-text-*, --color-border, etc.', 'accent? (hex or [light, dark] tuple
|
|
40
|
+
['color (existing themes)', '--color-accent, --color-background-*, --color-text-*, --color-border, etc.', 'Supported broad scale: accent? (hex or [light, dark] tuple), neutralStyle? (warm|cool|neutral), contrast? (standard|high). Use theme palette generate for new complete palettes.'],
|
|
41
41
|
['typography.scale', '--text-heading-*-size/weight/leading, --text-body-size/weight/leading', 'base (px), ratio'],
|
|
42
42
|
['typography.body/heading/code', '--font-family-body, --font-family-heading, --font-family-code', 'family, fallbacks?, url?, weight?'],
|
|
43
43
|
['radius', '--radius-inner, --radius-element, --radius-container, --radius-page, --radius-chat', 'base (px), multiplier (0–2)'],
|
|
@@ -157,7 +157,7 @@ export const docs = {
|
|
|
157
157
|
{
|
|
158
158
|
title: 'useTheme Hook',
|
|
159
159
|
content: [
|
|
160
|
-
{type: 'prose', text: '`useTheme()` reads the nearest Theme and effective color mode from React context.
|
|
160
|
+
{type: 'prose', text: '`useTheme()` reads the nearest Theme and effective color mode from React context. Prefer `dataVars` for CSS-capable SVG and DOM values. Use this hook for canvas, charts, maps, third-party configuration objects, or an SVG API that requires a concrete JavaScript color instead of a `var(...)` reference.'},
|
|
161
161
|
{type: 'code', lang: 'tsx', label: 'Access resolved token values in React', code: "import {useMemo} from 'react';\nimport {useTheme} from '@astryxdesign/core/theme';\n\nfunction ChartConfig() {\n const {mode, tokens} = useTheme();\n const options = useMemo(() => ({\n mode,\n textColor: tokens['--color-text-primary'],\n gridColor: tokens['--color-border'],\n seriesColor: tokens['--color-data-categorical-blue'],\n }), [mode, tokens]);\n return <Chart options={options} />;\n}"},
|
|
162
162
|
{type: 'prose', text: 'Prefer CSS variables for ordinary styling. See {@link generic:use-a-theme} for the provider setup, and {@link namespace:tokens} for the full token reference.'},
|
|
163
163
|
],
|
|
@@ -17,14 +17,14 @@ export const docs = {
|
|
|
17
17
|
"order": 20
|
|
18
18
|
},
|
|
19
19
|
"category": "foundations",
|
|
20
|
-
"description": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import
|
|
20
|
+
"description": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import dataVars from @astryxdesign/core/theme/dataTokens.stylex for CSS-capable code. Retaining any member emits the complete 56-variable group; an unused graph emits none.",
|
|
21
21
|
"sections": [
|
|
22
22
|
{
|
|
23
23
|
"title": "Data Visualization Tokens",
|
|
24
24
|
"content": [
|
|
25
25
|
{
|
|
26
26
|
"type": "prose",
|
|
27
|
-
"text": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import
|
|
27
|
+
"text": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import dataVars from @astryxdesign/core/theme/dataTokens.stylex for CSS-capable code. Retaining any member emits the complete 56-variable group; an unused graph emits none."
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"type": "table",
|
|
@@ -28,7 +28,7 @@ export const docs = {
|
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"type": "prose",
|
|
31
|
-
"text": "See {@link namespace:styling} for
|
|
31
|
+
"text": "Use `dataVars` for StyleX, DOM styles, and SVG presentation attributes. Canvas and other APIs that require concrete mode-resolved values use `resolveThemeToken()` or `useTheme().token()` instead. Raw CSS may use the stable custom-property names only when compiled dataVars output is guaranteed or the declaration carries an explicit fallback. See {@link namespace:styling} for xstyle, className, and compound component patterns, and {@link generic:author-a-theme} for overriding tokens with defineTheme."
|
|
32
32
|
}
|
|
33
33
|
]
|
|
34
34
|
}
|
|
@@ -871,7 +871,7 @@ export default function FormWizardVerticalPage() {
|
|
|
871
871
|
ref={fieldRefs.cover}
|
|
872
872
|
label="Cover image"
|
|
873
873
|
isLabelHidden
|
|
874
|
-
|
|
874
|
+
controlStyle={hasCover ? dropzoneFill : undefined}
|
|
875
875
|
mode="dropzone"
|
|
876
876
|
accept="image/png,image/jpeg"
|
|
877
877
|
maxSize={5 * 1024 * 1024}
|
|
@@ -500,7 +500,7 @@ function StorePreview({
|
|
|
500
500
|
max={99}
|
|
501
501
|
size="sm"
|
|
502
502
|
width={72}
|
|
503
|
-
|
|
503
|
+
controlStyle={styles.quantityInput}
|
|
504
504
|
/>
|
|
505
505
|
<Button
|
|
506
506
|
label="Add to cart"
|
|
@@ -1143,7 +1143,7 @@ function InventoryCard({
|
|
|
1143
1143
|
value=""
|
|
1144
1144
|
onChange={() => {}}
|
|
1145
1145
|
startIcon={<Search size={16} />}
|
|
1146
|
-
|
|
1146
|
+
controlStyle={styles.searchInput}
|
|
1147
1147
|
/>
|
|
1148
1148
|
<OverflowList
|
|
1149
1149
|
gap={2}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
-
// Generated from
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// Generated from the committed full palette for the stops used by Neutral's
|
|
4
|
+
// theme source. Regenerate with `pnpm generate:neutral-palette-refs`.
|
|
5
|
+
// Keep the complete palette available for authoring and audits without
|
|
6
|
+
// making consumers pay for unused palette stops.
|
|
6
7
|
// prettier-ignore
|
|
7
8
|
export const neutralPaletteRefs = {
|
|
8
9
|
purple: {
|
|
@@ -10,11 +11,11 @@ export const neutralPaletteRefs = {
|
|
|
10
11
|
dark: {25: '#4a2f51', 80: '#eaacf8'},
|
|
11
12
|
},
|
|
12
13
|
green: {
|
|
13
|
-
light: {25: '#00490b', 30: '#0b5615',
|
|
14
|
+
light: {25: '#00490b', 30: '#0b5615', 45: '#2f7d33', 65: '#6ab26b', 75: '#90ca90', 80: '#a4d6a3'},
|
|
14
15
|
dark: {25: '#2b422b', 80: '#aad4a9', 85: '#bce0bb'},
|
|
15
16
|
},
|
|
16
17
|
neutral: {
|
|
17
|
-
light: {0: '#000000', 5: '#111111', 10: '#1b1b1b',
|
|
18
|
+
light: {0: '#000000', 5: '#111111', 10: '#1b1b1b', 30: '#474747', 45: '#6a6a6a', 60: '#919191', 85: '#d4d4d4', 90: '#e2e2e2', 95: '#f1f1f1', 100: '#ffffff'},
|
|
18
19
|
dark: {0: '#000000', 5: '#111111', 10: '#1b1b1b', 15: '#262626', 20: '#303030', 35: '#525252', 65: '#9e9e9e', 85: '#d4d4d4', 90: '#e2e2e2', 95: '#f1f1f1', 100: '#ffffff'},
|
|
19
20
|
},
|
|
20
21
|
orange: {
|
|
@@ -26,11 +27,11 @@ export const neutralPaletteRefs = {
|
|
|
26
27
|
dark: {25: '#253c5a', 65: '#5aa0f8', 75: '#88bcff', 80: '#a1caff'},
|
|
27
28
|
},
|
|
28
29
|
red: {
|
|
29
|
-
light: {25: '#76000c', 30: '#8a0011',
|
|
30
|
+
light: {25: '#76000c', 30: '#8a0011', 55: '#de4745', 65: '#fa6762', 70: '#ff7f77', 80: '#ffaea7', 85: '#ffc4be'},
|
|
30
31
|
dark: {25: '#5b2b28', 65: '#ee736c', 75: '#ff9890', 80: '#ffaea7', 85: '#ffc4be'},
|
|
31
32
|
},
|
|
32
33
|
yellow: {
|
|
33
|
-
light: {25: '#4b3900', 30: '#584400',
|
|
34
|
+
light: {25: '#4b3900', 30: '#584400', 65: '#c29900', 75: '#e2b623', 80: '#eec448', 85: '#f8d36a'},
|
|
34
35
|
dark: {25: '#453a1c', 80: '#e3c36c', 90: '#fae19e'},
|
|
35
36
|
},
|
|
36
37
|
teal: {
|
|
@@ -39,10 +40,10 @@ export const neutralPaletteRefs = {
|
|
|
39
40
|
},
|
|
40
41
|
cyan: {
|
|
41
42
|
dark: {25: '#274046', 65: '#49adc4', 75: '#71c7dd', 80: '#85d5e9', 85: '#9ae2f4'},
|
|
42
|
-
light: {25: '#004351'
|
|
43
|
+
light: {25: '#004351'},
|
|
43
44
|
},
|
|
44
45
|
pink: {
|
|
45
|
-
light: {25: '#70003f',
|
|
46
|
+
light: {25: '#70003f', 70: '#fc78b1', 85: '#ffc0d7'},
|
|
46
47
|
dark: {25: '#572b3d', 75: '#fd92bd', 80: '#ffa9ca'},
|
|
47
48
|
},
|
|
48
49
|
} as const;
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* html[data-theme="dark"] { color-scheme: dark; }
|
|
18
18
|
*
|
|
19
19
|
* Themes that never use `light-dark()` have no `color-scheme` ambiguity to
|
|
20
|
-
* resolve, so none of the three rules should be emitted for them
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* resolve, so none of the three rules should be emitted for them. Canonical data
|
|
21
|
+
* defaults come from StyleX rather than theme output, so this decision continues
|
|
22
|
+
* to read only the theme's authored values.
|
|
23
23
|
*
|
|
24
24
|
* Building `astryx theme build` requires a compiled @astryxdesign/core (there is no in-CLI
|
|
25
25
|
* fallback generator), so this suite builds core once in beforeAll via the
|
|
@@ -35,8 +35,10 @@ import {ensureCoreBuilt} from './ensure-core-built.mjs';
|
|
|
35
35
|
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
36
36
|
|
|
37
37
|
const COLOR_SCHEME_ROOT_DECL = ':root { color-scheme: light dark; }';
|
|
38
|
-
const COLOR_SCHEME_LIGHT_DECL =
|
|
39
|
-
|
|
38
|
+
const COLOR_SCHEME_LIGHT_DECL =
|
|
39
|
+
'html[data-theme="light"] { color-scheme: light; }';
|
|
40
|
+
const COLOR_SCHEME_DARK_DECL =
|
|
41
|
+
'html[data-theme="dark"] { color-scheme: dark; }';
|
|
40
42
|
|
|
41
43
|
function writeTheme(dir, name, tokens) {
|
|
42
44
|
fs.mkdirSync(dir, {recursive: true});
|
|
@@ -58,7 +60,9 @@ beforeAll(() => {
|
|
|
58
60
|
|
|
59
61
|
let tmpDir;
|
|
60
62
|
beforeEach(() => {
|
|
61
|
-
tmpDir = fs.mkdtempSync(
|
|
63
|
+
tmpDir = fs.mkdtempSync(
|
|
64
|
+
path.join(os.tmpdir(), 'astryx-build-theme-color-scheme-'),
|
|
65
|
+
);
|
|
62
66
|
});
|
|
63
67
|
afterEach(() => {
|
|
64
68
|
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
@@ -1,32 +1,17 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* no other token family does. Layer order is fixed by first declaration, so
|
|
10
|
-
* the base block also has to sit after `@layer reset` and before
|
|
11
|
-
* `@layer astryx-theme` for a consumer who imports this stylesheet alone.
|
|
12
|
-
*
|
|
13
|
-
* Building requires a compiled @astryxdesign/core, so this suite builds core
|
|
14
|
-
* once in beforeAll via the shared ensureCoreBuilt() helper.
|
|
15
|
-
*
|
|
16
|
-
* The build formats the defaults block itself, from the public
|
|
17
|
-
* `dataTokenDefaults` export; core formats it for the runtime. This suite is
|
|
18
|
-
* what keeps those two independent formattings byte-identical.
|
|
4
|
+
* @file Verifies `astryx theme build` emits sparse data overrides and no
|
|
5
|
+
* canonical root defaults while preserving explicit cascade-layer order.
|
|
6
|
+
* @input Temporary standalone theme modules compiled through the public CLI
|
|
7
|
+
* @output Structural assertions for AST-066 data-token ownership
|
|
8
|
+
* @position Regression suite for theme-build CSS ownership
|
|
19
9
|
*/
|
|
20
10
|
|
|
21
11
|
import {describe, it, expect, beforeAll, beforeEach, afterEach} from 'vitest';
|
|
22
12
|
import * as fs from 'node:fs';
|
|
23
13
|
import * as path from 'node:path';
|
|
24
14
|
import * as os from 'node:os';
|
|
25
|
-
// Core's own generator, imported from source rather than from the package: it
|
|
26
|
-
// is deliberately not part of `@astryxdesign/core/theme`'s public surface, and
|
|
27
|
-
// this suite is the guard that the build's independent formatting matches it.
|
|
28
|
-
import {generateDataTokenDefaultsCSS} from '../../../../core/src/theme/generateThemeRules';
|
|
29
|
-
import {dataTokenDefaults as sourceDataTokenDefaults} from '../../../../core/src/theme/domainTokens/dataTokens';
|
|
30
15
|
import {ensureCoreBuilt} from './ensure-core-built.mjs';
|
|
31
16
|
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
32
17
|
|
|
@@ -67,78 +52,41 @@ afterEach(() => {
|
|
|
67
52
|
});
|
|
68
53
|
|
|
69
54
|
describe('theme build data token output', () => {
|
|
70
|
-
it('emits
|
|
55
|
+
it('emits no canonical data defaults or raw root data block', async () => {
|
|
71
56
|
const css = await buildTheme(tmpDir, 'charts-untouched', {
|
|
72
57
|
tokens: {'--color-accent': '#0077B6'},
|
|
73
58
|
});
|
|
74
59
|
|
|
75
|
-
|
|
76
|
-
expect(
|
|
77
|
-
|
|
78
|
-
const baseBlock = css.slice(baseStart, css.indexOf('@layer astryx-theme'));
|
|
79
|
-
expect(baseBlock).toContain(':root {');
|
|
80
|
-
expect(baseBlock).toContain('--color-data-categorical-blue:');
|
|
81
|
-
expect(baseBlock).toContain('--color-data-gray-1:');
|
|
82
|
-
expect(css.match(/--color-data-categorical-blue:/g)).toHaveLength(1);
|
|
83
|
-
expect(css.match(/@layer astryx-base/g)).toHaveLength(1);
|
|
60
|
+
expect(css).not.toContain('--color-data-');
|
|
61
|
+
expect(css).not.toMatch(/:root\s*\{[^}]*--color-data-/s);
|
|
62
|
+
expect(css).not.toContain('@layer astryx-base {\n:root {');
|
|
84
63
|
});
|
|
85
64
|
|
|
86
|
-
it('
|
|
65
|
+
it('registers layer order before every emitted layer block', async () => {
|
|
87
66
|
const css = await buildTheme(tmpDir, 'charts-order', {
|
|
88
67
|
tokens: {'--color-accent': '#0077B6'},
|
|
89
68
|
});
|
|
90
69
|
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const theme = css.indexOf('@layer astryx-theme');
|
|
70
|
+
const order = css.indexOf('@layer reset, astryx-base, astryx-theme;');
|
|
71
|
+
const reset = css.indexOf('@layer reset {');
|
|
72
|
+
const theme = css.indexOf('@layer astryx-theme {');
|
|
94
73
|
|
|
95
|
-
expect(
|
|
96
|
-
expect(
|
|
97
|
-
expect(theme).toBeGreaterThan(
|
|
74
|
+
expect(order).toBeGreaterThanOrEqual(0);
|
|
75
|
+
expect(reset).toBeGreaterThan(order);
|
|
76
|
+
expect(theme).toBeGreaterThan(order);
|
|
98
77
|
});
|
|
99
78
|
|
|
100
|
-
it("puts only the theme's
|
|
79
|
+
it("puts only the theme's authored data token in its donut", async () => {
|
|
101
80
|
const css = await buildTheme(tmpDir, 'charts-override', {
|
|
102
81
|
tokens: {'--color-data-categorical-blue': '#00A3FF'},
|
|
103
82
|
});
|
|
104
83
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
expect(themeBlock).not.toContain('--color-data-categorical-orange');
|
|
108
|
-
expect(themeBlock).not.toContain('--color-data-gray-1');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('emits the bytes the runtime generator emits', async () => {
|
|
112
|
-
const css = await buildTheme(tmpDir, 'charts-parity', {
|
|
113
|
-
tokens: {'--color-accent': '#0077B6'},
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// The expectation below comes from core's SOURCE; the stylesheet came from
|
|
117
|
-
// core's dist. ensureCoreBuilt() only checks that dist exists, never that
|
|
118
|
-
// it is current, so a dist older than the source would fail the byte
|
|
119
|
-
// comparison with a colour mismatch that reads as formatter drift. Name
|
|
120
|
-
// that case first.
|
|
121
|
-
const {dataTokenDefaults: builtDataTokenDefaults} = await import(
|
|
122
|
-
'@astryxdesign/core/theme'
|
|
123
|
-
);
|
|
124
|
-
expect(
|
|
125
|
-
builtDataTokenDefaults,
|
|
126
|
-
'packages/core/dist is stale — run `pnpm -F @astryxdesign/core build`',
|
|
127
|
-
).toEqual(sourceDataTokenDefaults);
|
|
128
|
-
|
|
129
|
-
// The build formats this block itself, from the public `dataTokenDefaults`
|
|
130
|
-
// export; the runtime formats it in core. Nothing else holds the two
|
|
131
|
-
// together, so compare the bytes — a changed indent or separator in either
|
|
132
|
-
// one fails here.
|
|
133
|
-
const runtimeBase = generateDataTokenDefaultsCSS();
|
|
134
|
-
const marker = '@layer astryx-base {\n';
|
|
135
|
-
const start = css.indexOf(marker);
|
|
136
|
-
expect(start).toBeGreaterThanOrEqual(0);
|
|
137
|
-
|
|
138
|
-
const bodyStart = start + marker.length;
|
|
139
|
-
expect(css.slice(bodyStart, bodyStart + runtimeBase.length)).toBe(
|
|
140
|
-
runtimeBase,
|
|
84
|
+
expect(css).toContain(
|
|
85
|
+
'@scope ([data-astryx-theme="charts-override"]) to ([data-astryx-theme])',
|
|
141
86
|
);
|
|
142
|
-
expect(css.
|
|
87
|
+
expect(css).toContain('--color-data-categorical-blue: #00A3FF;');
|
|
88
|
+
expect(css.match(/--color-data-/g)).toHaveLength(1);
|
|
89
|
+
expect(css).not.toContain('--color-data-categorical-orange');
|
|
90
|
+
expect(css).not.toContain('--color-data-gray-1');
|
|
143
91
|
});
|
|
144
92
|
});
|
|
@@ -51,7 +51,7 @@ export const doc = {
|
|
|
51
51
|
{code: 0, when: 'success (including zero matches)'},
|
|
52
52
|
{
|
|
53
53
|
code: 1,
|
|
54
|
-
when: 'invalid --type, a
|
|
54
|
+
when: 'invalid --type, a --limit that is not a positive integer, or a query when @astryxdesign/core cannot be found (the playbook needs no core)',
|
|
55
55
|
},
|
|
56
56
|
],
|
|
57
57
|
related: ['search', 'template', 'component', 'hook', 'init'],
|
|
@@ -101,7 +101,7 @@ export function registerBuild(program) {
|
|
|
101
101
|
// throws ERR_INVALID_ARGUMENT, so we pass NaN through rather than
|
|
102
102
|
// pre-rejecting with a generic code here (parity with `search`).
|
|
103
103
|
const limit =
|
|
104
|
-
options.limit != null ? Number
|
|
104
|
+
options.limit != null ? Number(options.limit) : 60;
|
|
105
105
|
|
|
106
106
|
/** @type {import('../../../api/build/build.type.mjs').BuildKitResponse} */
|
|
107
107
|
let result;
|
|
@@ -223,7 +223,7 @@ describe('component() — integration ownership via config', () => {
|
|
|
223
223
|
caught = e;
|
|
224
224
|
}
|
|
225
225
|
expect(caught).toBeTruthy();
|
|
226
|
-
expect(caught.code).toBe('
|
|
226
|
+
expect(caught.code).toBe('ERR_AMBIGUOUS_COMPONENT');
|
|
227
227
|
const pkgs = (caught.suggestions ?? []).map(s => s.name);
|
|
228
228
|
expect(pkgs).toContain(CORE_PACKAGE);
|
|
229
229
|
expect(pkgs).toContain(INTEGRATION_NAME);
|
|
@@ -288,7 +288,7 @@ describe('component() — integration ownership via config', () => {
|
|
|
288
288
|
expect(result.data.results[1]).toMatchObject({
|
|
289
289
|
selector: 'AppShell',
|
|
290
290
|
status: 'ambiguous',
|
|
291
|
-
code: '
|
|
291
|
+
code: 'ERR_AMBIGUOUS_COMPONENT',
|
|
292
292
|
});
|
|
293
293
|
expect(result.data.results[1].candidates).toEqual(
|
|
294
294
|
expect.arrayContaining([
|
|
@@ -101,7 +101,7 @@ export function registerIntegration(program) {
|
|
|
101
101
|
// still parses its own options.
|
|
102
102
|
integration.allowUnknownOption(true);
|
|
103
103
|
|
|
104
|
-
defineCommand(integration, integrationAddCommand, {
|
|
104
|
+
const addCmd = defineCommand(integration, integrationAddCommand, {
|
|
105
105
|
fn: integrationAddFn,
|
|
106
106
|
action: async (kind, name, options) => {
|
|
107
107
|
const json = program.opts().json || false;
|
|
@@ -157,6 +157,7 @@ export function registerIntegration(program) {
|
|
|
157
157
|
return NO_RESULT_SET;
|
|
158
158
|
},
|
|
159
159
|
});
|
|
160
|
+
addCmd.allowExcessArguments(false);
|
|
160
161
|
|
|
161
162
|
defineCommand(integration, integrationVerifyCommand, {
|
|
162
163
|
fn: integrationPackCheckFn,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
3
|
+
import * as fs from 'node:fs'; import * as os from 'node:os'; import * as path from 'node:path';
|
|
4
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
5
|
+
let dir;
|
|
6
|
+
beforeEach(() => { dir = fs.mkdtempSync(path.join(os.tmpdir(),'astryx-ss-')); fs.writeFileSync(path.join(dir,'package.json'),JSON.stringify({name:'s',version:'1.0.0',dependencies:{'@astryxdesign/core':'0.6.3'}})); const c=path.join(dir,'node_modules','@astryxdesign','core'); fs.mkdirSync(c,{recursive:true}); fs.writeFileSync(path.join(c,'package.json'),JSON.stringify({name:'@astryxdesign/core',version:'0.6.3'})); });
|
|
7
|
+
afterEach(() => fs.rmSync(dir, {recursive:true,force:true}));
|
|
8
|
+
const json = async a => { const {status,stdout}=await runCli(['--json',...a],{cwd:dir}); return {status,body:JSON.parse(stdout)}; };
|
|
9
|
+
describe('refuse invalid input (IFIX-0007)', () => {
|
|
10
|
+
it('template --type bogus', async () => { const {status,body}=await json(['template','--list','--type','bogus']); expect(status).toBe(1); expect(body.code).toBe('ERR_INVALID_ARGUMENT'); });
|
|
11
|
+
it('template --package @nope/x', async () => { const {status,body}=await json(['template','--list','--package','@nope/x']); expect(status).toBe(1); expect(body.code).toBe('ERR_INVALID_ARGUMENT'); });
|
|
12
|
+
it('template valid type+package filter keeps the matching templates', async () => { const {status,body}=await json(['template','--list','--type','block','--package','@astryxdesign/core']); expect(status).toBe(0); expect(body.type).toBe('template.list'); expect(body.data.length).toBeGreaterThan(0); expect(body.data.every(t => t.type === 'block')).toBe(true); });
|
|
13
|
+
it('build --limit 2.5', async () => { const {status,body}=await json(['build','pricing','--limit','2.5']); expect(status).toBe(1); expect(body.code).toBe('ERR_INVALID_ARGUMENT'); });
|
|
14
|
+
it('integration add excess args', async () => { fs.writeFileSync(path.join(dir,'package.json'),JSON.stringify({name:'@t/p',version:'1.0.0'})); const {status}=await json(['integration','add','agent-doc','Run','acme','verify']); expect(status).toBe(1); });
|
|
15
|
+
});
|
|
@@ -109,7 +109,7 @@ export const doc = {
|
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
111
|
code: 1,
|
|
112
|
-
when: 'unknown or ambiguous template, no source, a path escape,
|
|
112
|
+
when: 'unknown or ambiguous template, no source, a path escape, an existing target without --overwrite, or --list with a type outside page or block or a package that provides no templates',
|
|
113
113
|
},
|
|
114
114
|
],
|
|
115
115
|
related: ['component', 'search', 'discover', 'init'],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.0-canary.
|
|
3
|
+
"version": "0.7.0-canary.4aec44c",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -101,10 +101,10 @@
|
|
|
101
101
|
"zod": "^4.4.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@astryxdesign/charts": "0.7.0-canary.
|
|
105
|
-
"@astryxdesign/core": "0.7.0-canary.
|
|
106
|
-
"@astryxdesign/lab": "0.7.0-canary.
|
|
107
|
-
"@astryxdesign/theme-neutral": "0.7.0-canary.
|
|
104
|
+
"@astryxdesign/charts": "0.7.0-canary.4aec44c",
|
|
105
|
+
"@astryxdesign/core": "0.7.0-canary.4aec44c",
|
|
106
|
+
"@astryxdesign/lab": "0.7.0-canary.4aec44c",
|
|
107
|
+
"@astryxdesign/theme-neutral": "0.7.0-canary.4aec44c"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@astryxdesign/charts": {
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"@astryxdesign/charts": "0.7.0-canary.
|
|
125
|
-
"@astryxdesign/core": "0.7.0-canary.
|
|
126
|
-
"@astryxdesign/lab": "0.7.0-canary.
|
|
127
|
-
"@astryxdesign/theme-neutral": "0.7.0-canary.
|
|
124
|
+
"@astryxdesign/charts": "0.7.0-canary.4aec44c",
|
|
125
|
+
"@astryxdesign/core": "0.7.0-canary.4aec44c",
|
|
126
|
+
"@astryxdesign/lab": "0.7.0-canary.4aec44c",
|
|
127
|
+
"@astryxdesign/theme-neutral": "0.7.0-canary.4aec44c",
|
|
128
128
|
"@heroicons/react": "^2.2.0",
|
|
129
129
|
"@stylexjs/stylex": "^0.19.0",
|
|
130
130
|
"@types/babel__core": "^7.20.5",
|