@astryxdesign/cli 0.3.0-canary.ccb5ca9 → 0.3.0-canary.cd0b9f6
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/assets/codemods/transforms/next/__tests__/next-codemods.test.mjs +92 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/rename-dropdown-menu-radio-dot-target.mjs +152 -0
- package/assets/docs/getting-started.doc.mjs +3 -3
- package/authoring/doctypes/base/type.ts +15 -0
- package/clients/cli/commands/build-theme.registry.test.mjs +10 -0
- package/package.json +9 -9
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Unit tests for the staged (next-release) codemods.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors v0.3.0/__tests__/next-codemods.test.mjs, which covers the codemods
|
|
7
|
+
* after promotion. Keeping a copy here means a staged transform is tested from
|
|
8
|
+
* the day it is written rather than the day it is released.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {describe, expect, it} from 'vitest';
|
|
12
|
+
import jscodeshift from 'jscodeshift';
|
|
13
|
+
|
|
14
|
+
const j = jscodeshift.withParser('tsx');
|
|
15
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
16
|
+
|
|
17
|
+
async function apply(name, source) {
|
|
18
|
+
const {default: transform} = await import(`../${name}.mjs`);
|
|
19
|
+
return transform({source, path: 'test.tsx'}, api) ?? source;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const TRANSFORM = 'rename-dropdown-menu-radio-dot-target';
|
|
23
|
+
|
|
24
|
+
describe('rename-dropdown-menu-radio-dot-target', () => {
|
|
25
|
+
it('renames the theme target key in a defineTheme components map', async () => {
|
|
26
|
+
const input = `import {defineTheme} from '@astryxdesign/core/theme';
|
|
27
|
+
export const theme = defineTheme({
|
|
28
|
+
name: 'brand',
|
|
29
|
+
components: {
|
|
30
|
+
'dropdown-menu-radio-dot': {base: {backgroundColor: 'var(--color-accent)'}},
|
|
31
|
+
},
|
|
32
|
+
});`;
|
|
33
|
+
const output = await apply(TRANSFORM, input);
|
|
34
|
+
expect(output).toContain("'radio-indicator-dot':");
|
|
35
|
+
// The old name survives only inside the TODO comment the rename attaches.
|
|
36
|
+
expect(output).not.toContain("'dropdown-menu-radio-dot':");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('warns that the new target is app-wide, not menu-only', async () => {
|
|
40
|
+
const input = `const components = {
|
|
41
|
+
'dropdown-menu-radio-dot': {base: {width: '10px'}},
|
|
42
|
+
};`;
|
|
43
|
+
const output = await apply(TRANSFORM, input);
|
|
44
|
+
// The rename cannot preserve scope — there is no menu-only dot element
|
|
45
|
+
// left — so the author has to decide, and must be told.
|
|
46
|
+
expect(output).toContain('TODO(astryx upgrade)');
|
|
47
|
+
expect(output).toContain('EVERY radio dot');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('renames the rendered class inside a selector string', async () => {
|
|
51
|
+
const input = `const sel = '.astryx-dropdown-menu-radio-dot';
|
|
52
|
+
const nested = '.astryx-dropdown-menu-radio .astryx-dropdown-menu-radio-dot';`;
|
|
53
|
+
const output = await apply(TRANSFORM, input);
|
|
54
|
+
expect(output).toContain("'.astryx-radio-indicator-dot'");
|
|
55
|
+
expect(output).toContain(
|
|
56
|
+
'.astryx-dropdown-menu-radio .astryx-radio-indicator-dot',
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renames the class inside a template literal', async () => {
|
|
61
|
+
const input =
|
|
62
|
+
'const css = `.astryx-dropdown-menu-radio-dot { background: ${c}; }`;';
|
|
63
|
+
const output = await apply(TRANSFORM, input);
|
|
64
|
+
expect(output).toContain('.astryx-radio-indicator-dot {');
|
|
65
|
+
expect(output).not.toContain('astryx-dropdown-menu-radio-dot');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('leaves the surviving dropdown-menu-radio target alone', async () => {
|
|
69
|
+
// Only the DOT target was removed; the circle still carries the
|
|
70
|
+
// menu-specific target, so a theme keyed on it must not be rewritten.
|
|
71
|
+
const input = `const components = {
|
|
72
|
+
'dropdown-menu-radio': {base: {borderWidth: '2px'}},
|
|
73
|
+
};`;
|
|
74
|
+
const output = await apply(TRANSFORM, input);
|
|
75
|
+
expect(output).toContain("'dropdown-menu-radio'");
|
|
76
|
+
expect(output).not.toContain('radio-indicator');
|
|
77
|
+
expect(output).not.toContain('TODO(astryx upgrade)');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('is a no-op on files that never mention the target', async () => {
|
|
81
|
+
const input = `const components = {button: {base: {fontWeight: '600'}}};`;
|
|
82
|
+
expect(await apply(TRANSFORM, input)).toBe(input);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('is idempotent', async () => {
|
|
86
|
+
const input = `const components = {
|
|
87
|
+
'dropdown-menu-radio-dot': {base: {width: '10px'}},
|
|
88
|
+
};`;
|
|
89
|
+
const once = await apply(TRANSFORM, input);
|
|
90
|
+
expect(await apply(TRANSFORM, once)).toBe(once);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -7,4 +7,14 @@
|
|
|
7
7
|
* this file into the resolved version folder.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import renameDropdownMenuRadioDotTarget, {
|
|
11
|
+
meta as renameDropdownMenuRadioDotTargetMeta,
|
|
12
|
+
} from './rename-dropdown-menu-radio-dot-target.mjs';
|
|
13
|
+
|
|
14
|
+
export default [
|
|
15
|
+
{
|
|
16
|
+
name: 'rename-dropdown-menu-radio-dot-target',
|
|
17
|
+
transform: renameDropdownMenuRadioDotTarget,
|
|
18
|
+
meta: renameDropdownMenuRadioDotTargetMeta,
|
|
19
|
+
},
|
|
20
|
+
];
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Codemod: rename the removed `dropdown-menu-radio-dot` theme target
|
|
5
|
+
*
|
|
6
|
+
* The menu radio's dot is no longer drawn by DropdownMenuRadioItem. That row
|
|
7
|
+
* now renders the shared radio indicator, so its dot is the indicator's dot and
|
|
8
|
+
* carries `radio-indicator-dot` (plus the legacy `radio-dot`) instead of the
|
|
9
|
+
* menu-specific `dropdown-menu-radio-dot`, which is gone.
|
|
10
|
+
*
|
|
11
|
+
* Runtime themes are not validated: a theme keyed on the old target keeps
|
|
12
|
+
* compiling and simply stops matching, with no error anywhere. That silence is
|
|
13
|
+
* why this rename needs a codemod rather than a changelog line.
|
|
14
|
+
*
|
|
15
|
+
* The rename is NOT scope-preserving, and that cannot be fixed here — there is
|
|
16
|
+
* no menu-only dot element left to address. `radio-indicator-dot` reaches every
|
|
17
|
+
* radio dot in the app, including RadioList's. So every rewritten site also
|
|
18
|
+
* gets a TODO comment (api.report is a stub; comments are the only warning
|
|
19
|
+
* channel) telling the author to check whether the rule was meant to be
|
|
20
|
+
* menu-only, and pointing at the containing-target route if it was.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export const meta = {
|
|
24
|
+
title: 'Rename the removed dropdown-menu-radio-dot theme target',
|
|
25
|
+
description:
|
|
26
|
+
'Renames the `dropdown-menu-radio-dot` theme target (and the ' +
|
|
27
|
+
'`astryx-dropdown-menu-radio-dot` class it rendered) to ' +
|
|
28
|
+
'`radio-indicator-dot` / `astryx-radio-indicator-dot`. Menu radios draw ' +
|
|
29
|
+
'the shared radio indicator now, so the menu-specific dot target no ' +
|
|
30
|
+
'longer exists. The new target is app-wide rather than menu-only, so each ' +
|
|
31
|
+
'rewritten site gets a TODO comment to confirm that widening is intended.',
|
|
32
|
+
pr: '#4712',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const OLD_TARGET = 'dropdown-menu-radio-dot';
|
|
36
|
+
const NEW_TARGET = 'radio-indicator-dot';
|
|
37
|
+
const OLD_CLASS = `astryx-${OLD_TARGET}`;
|
|
38
|
+
const NEW_CLASS = `astryx-${NEW_TARGET}`;
|
|
39
|
+
|
|
40
|
+
const TODO_COMMENT =
|
|
41
|
+
' TODO(astryx upgrade): `dropdown-menu-radio-dot` became `radio-indicator-dot`,' +
|
|
42
|
+
' which styles EVERY radio dot, not just the ones in a menu. If this rule was' +
|
|
43
|
+
' meant to be menu-only, scope it under the containing `dropdown-menu-radio`' +
|
|
44
|
+
' target instead of this one. ';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Rewrite one string value, or return null when it holds nothing to rename.
|
|
48
|
+
*
|
|
49
|
+
* Handles the target name on its own (a theme's `components` key) and the
|
|
50
|
+
* rendered class inside a larger string (a selector such as
|
|
51
|
+
* `.astryx-dropdown-menu-radio-dot`, or a className list).
|
|
52
|
+
*
|
|
53
|
+
* @param {string} value
|
|
54
|
+
* @returns {string | null}
|
|
55
|
+
*/
|
|
56
|
+
function renameIn(value) {
|
|
57
|
+
if (value === OLD_TARGET) {
|
|
58
|
+
return NEW_TARGET;
|
|
59
|
+
}
|
|
60
|
+
if (value.includes(OLD_CLASS)) {
|
|
61
|
+
return value.split(OLD_CLASS).join(NEW_CLASS);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
|
|
68
|
+
* @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
|
|
69
|
+
* @returns {string | null | undefined}
|
|
70
|
+
*/
|
|
71
|
+
export default function transformer(file, api) {
|
|
72
|
+
// Cheap bail-out: most files in a consumer repo mention neither name.
|
|
73
|
+
if (!file.source.includes(OLD_TARGET)) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const j = api.jscodeshift;
|
|
78
|
+
const root = j(file.source);
|
|
79
|
+
let hasChanges = false;
|
|
80
|
+
|
|
81
|
+
/** Attach the widening warning once to the nearest statement-ish node. */
|
|
82
|
+
function attachTodo(/** @type {any} */ path) {
|
|
83
|
+
// The property (or its statement) reads better than the bare literal, and
|
|
84
|
+
// matches where a human would look for the note.
|
|
85
|
+
const host =
|
|
86
|
+
path.parent?.node?.type === 'ObjectProperty' ||
|
|
87
|
+
path.parent?.node?.type === 'Property'
|
|
88
|
+
? path.parent.node
|
|
89
|
+
: path.node;
|
|
90
|
+
if (!host.comments) {
|
|
91
|
+
host.comments = [];
|
|
92
|
+
}
|
|
93
|
+
if (
|
|
94
|
+
host.comments.some((/** @type {any} */ c) => c.value === TODO_COMMENT)
|
|
95
|
+
) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
host.comments.push(j.commentBlock(TODO_COMMENT, true, false));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
root
|
|
102
|
+
.find(j.StringLiteral)
|
|
103
|
+
.forEach((/** @type {any} */ path) => {
|
|
104
|
+
const renamed = renameIn(path.node.value);
|
|
105
|
+
if (renamed == null) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
path.node.value = renamed;
|
|
109
|
+
attachTodo(path);
|
|
110
|
+
hasChanges = true;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Older parsers surface string literals as `Literal`.
|
|
114
|
+
root.find(j.Literal).forEach((/** @type {any} */ path) => {
|
|
115
|
+
if (typeof path.node.value !== 'string') {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const renamed = renameIn(path.node.value);
|
|
119
|
+
if (renamed == null) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
path.node.value = renamed;
|
|
123
|
+
if (typeof path.node.raw === 'string') {
|
|
124
|
+
path.node.raw = path.node.raw
|
|
125
|
+
.split(OLD_TARGET)
|
|
126
|
+
.join(NEW_TARGET);
|
|
127
|
+
}
|
|
128
|
+
attachTodo(path);
|
|
129
|
+
hasChanges = true;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Template literals carry the class in CSS strings: `.${OLD_CLASS} > span`.
|
|
133
|
+
root.find(j.TemplateElement).forEach((/** @type {any} */ path) => {
|
|
134
|
+
const cooked = path.node.value?.cooked;
|
|
135
|
+
if (typeof cooked !== 'string') {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const renamed = renameIn(cooked);
|
|
139
|
+
if (renamed == null) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
path.node.value.cooked = renamed;
|
|
143
|
+
path.node.value.raw = path.node.value.raw
|
|
144
|
+
.split(OLD_CLASS)
|
|
145
|
+
.join(NEW_CLASS)
|
|
146
|
+
.split(OLD_TARGET)
|
|
147
|
+
.join(NEW_TARGET);
|
|
148
|
+
hasChanges = true;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return hasChanges ? root.toSource({quote: 'single'}) : undefined;
|
|
152
|
+
}
|
|
@@ -21,7 +21,7 @@ export const docs = {
|
|
|
21
21
|
type: 'code',
|
|
22
22
|
lang: 'text',
|
|
23
23
|
label: 'Paste this into your AI',
|
|
24
|
-
code: 'Install @astryxdesign/core, @astryxdesign/theme-neutral, and @astryxdesign/cli in this project, then run `npx @astryxdesign/cli init` to set up agent docs. Read the generated files to learn the conventions.',
|
|
24
|
+
code: 'Install @astryxdesign/core, @stylexjs/stylex, @astryxdesign/theme-neutral, and @astryxdesign/cli in this project, then run `npx @astryxdesign/cli init` to set up agent docs. Read the generated files to learn the conventions.',
|
|
25
25
|
},
|
|
26
26
|
],
|
|
27
27
|
},
|
|
@@ -34,13 +34,13 @@ export const docs = {
|
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
type: 'prose',
|
|
37
|
-
text: 'Add the core package, a theme
|
|
37
|
+
text: 'Add the core package and its `@stylexjs/stylex` peer dependency, plus a theme and the CLI.',
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
type: 'code',
|
|
41
41
|
lang: 'bash',
|
|
42
42
|
label: 'Terminal',
|
|
43
|
-
code: `npm install @astryxdesign/core @astryxdesign/theme-neutral @astryxdesign/cli`,
|
|
43
|
+
code: `npm install @astryxdesign/core @stylexjs/stylex @astryxdesign/theme-neutral @astryxdesign/cli`,
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
type: 'prose',
|
|
@@ -260,6 +260,8 @@ export interface ComponentSlotElement {
|
|
|
260
260
|
* { property: 'padding', vars: ['--_card-padding'] },
|
|
261
261
|
* ```
|
|
262
262
|
*/
|
|
263
|
+
// SYNC: apps/docsite/scripts/generate-data.mjs (interface DerivedVar) — see the
|
|
264
|
+
// note on ComponentThemingTarget below.
|
|
263
265
|
export interface ComponentThemingDerivedVar {
|
|
264
266
|
/** The standard CSS property name (camelCase) that theme authors write.
|
|
265
267
|
* e.g. `'borderRadius'`, `'padding'`, `'paddingBlock'` */
|
|
@@ -291,6 +293,10 @@ export interface ComponentThemingDerivedVar {
|
|
|
291
293
|
* {className: 'astryx-card'}
|
|
292
294
|
* ```
|
|
293
295
|
*/
|
|
296
|
+
// SYNC: When adding a field here, add it to the docsite's generated-registry
|
|
297
|
+
// copy too — apps/docsite/scripts/generate-data.mjs (interface ThemingTarget).
|
|
298
|
+
// `next build` type-checks the emitted componentRegistry.ts against that copy,
|
|
299
|
+
// so a field present in a .doc.mjs but missing there fails the docsite build.
|
|
294
300
|
export interface ComponentThemingTarget {
|
|
295
301
|
/** The stable CSS class name rendered by the component.
|
|
296
302
|
* Always starts with `astryx-`.
|
|
@@ -310,6 +316,15 @@ export interface ComponentThemingTarget {
|
|
|
310
316
|
* `[data-checked="checked"]`. Legacy state classes are still emitted for
|
|
311
317
|
* compatibility. Omit if the element has no state-driven selectors. */
|
|
312
318
|
states?: string[];
|
|
319
|
+
/** Set when this target has been RENAMED and this entry is the old name.
|
|
320
|
+
* The component still emits the class (via `themeProps`'s `legacyNames`),
|
|
321
|
+
* so existing themes keep working, but the docsite should steer readers to
|
|
322
|
+
* the replacement. The value is the class name that supersedes this one,
|
|
323
|
+
* without the `astryx-` prefix — e.g. `"checkbox-indicator"`.
|
|
324
|
+
*
|
|
325
|
+
* A theme target is public API; renaming one without this is a silent
|
|
326
|
+
* break for every theme styling it. */
|
|
327
|
+
deprecatedFor?: string;
|
|
313
328
|
}
|
|
314
329
|
|
|
315
330
|
/**
|
|
@@ -74,6 +74,16 @@ function renderedClassLiterals() {
|
|
|
74
74
|
classes.add(m[1]);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
// Renamed targets emit their old name too, via themeProps'
|
|
78
|
+
// `legacyNames`. Those classes are just as rendered as the primary
|
|
79
|
+
// one, so a doc entry for the old name is still backed by real output.
|
|
80
|
+
const legacyRe = /legacyNames:\s*\[([^\]]*)\]/g;
|
|
81
|
+
let lm;
|
|
82
|
+
while ((lm = legacyRe.exec(text)) !== null) {
|
|
83
|
+
for (const nm of lm[1].matchAll(/'([^']+)'/g)) {
|
|
84
|
+
classes.add(nm[1]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
89
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.3.0-canary.
|
|
3
|
+
"version": "0.3.0-canary.cd0b9f6",
|
|
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",
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
"zod": "^4.4.3"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
|
-
"@astryxdesign/charts": "0.3.0-canary.
|
|
88
|
-
"@astryxdesign/core": "0.3.0-canary.
|
|
89
|
-
"@astryxdesign/lab": "0.3.0-canary.
|
|
90
|
-
"@astryxdesign/theme-neutral": "0.3.0-canary.
|
|
87
|
+
"@astryxdesign/charts": "0.3.0-canary.cd0b9f6",
|
|
88
|
+
"@astryxdesign/core": "0.3.0-canary.cd0b9f6",
|
|
89
|
+
"@astryxdesign/lab": "0.3.0-canary.cd0b9f6",
|
|
90
|
+
"@astryxdesign/theme-neutral": "0.3.0-canary.cd0b9f6",
|
|
91
91
|
"gpt-tokenizer": "^3.4.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependenciesMeta": {
|
|
@@ -105,10 +105,10 @@
|
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"@astryxdesign/charts": "0.3.0-canary.
|
|
109
|
-
"@astryxdesign/core": "0.3.0-canary.
|
|
110
|
-
"@astryxdesign/lab": "0.3.0-canary.
|
|
111
|
-
"@astryxdesign/theme-neutral": "0.3.0-canary.
|
|
108
|
+
"@astryxdesign/charts": "0.3.0-canary.cd0b9f6",
|
|
109
|
+
"@astryxdesign/core": "0.3.0-canary.cd0b9f6",
|
|
110
|
+
"@astryxdesign/lab": "0.3.0-canary.cd0b9f6",
|
|
111
|
+
"@astryxdesign/theme-neutral": "0.3.0-canary.cd0b9f6",
|
|
112
112
|
"gpt-tokenizer": "^3.4.0"
|
|
113
113
|
},
|
|
114
114
|
"scripts": {
|