@astryxdesign/cli 0.1.4-canary.d3b6700 → 0.1.4-canary.d7c9a39
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/docs/getting-started.doc.mjs +4 -0
- package/docs/migration.doc.mjs +134 -0
- package/docs/styling.doc.mjs +53 -0
- package/docs/working-with-ai.doc.mjs +1 -1
- package/package.json +10 -10
- package/src/codemods/__tests__/registry.test.mjs +1 -0
- package/src/codemods/registry.mjs +1 -0
- package/src/codemods/transforms/v0.1.5/__tests__/rename-switch-label-spacing-default-to-hug.test.mjs +93 -0
- package/src/codemods/transforms/v0.1.5/index.mjs +19 -0
- package/src/codemods/transforms/v0.1.5/rename-switch-label-spacing-default-to-hug.mjs +140 -0
- package/src/commands/agent-docs.mjs +7 -5
- package/src/commands/agent-docs.test.mjs +33 -0
- package/src/commands/build-theme.color-scheme.test.mjs +153 -0
- package/src/commands/build-theme.mjs +8 -1
- package/src/commands/build-theme.variants.test.mjs +7 -18
- package/src/commands/init.mjs +1 -1
- package/src/commands/swizzle.mjs +34 -0
- package/src/commands/swizzle.routing.test.mjs +67 -0
- package/templates/blocks/components/Collapsible/CollapsibleWithoutCard.tsx +25 -23
- package/templates/blocks/components/ContextMenuItem/ContextMenuItemBasic.doc.mjs +14 -0
- package/templates/blocks/components/ContextMenuItem/ContextMenuItemBasic.tsx +44 -0
- package/templates/blocks/components/ContextMenuItem/ContextMenuItemShowcase.doc.mjs +15 -0
- package/templates/blocks/components/ContextMenuItem/ContextMenuItemShowcase.tsx +107 -0
- package/templates/pages/classic-gallery/page.tsx +1 -1
- package/templates/pages/dashboard/page.tsx +1 -1
- package/templates/pages/documentation/page.tsx +1 -1
- package/templates/pages/incident-console/page.tsx +580 -0
- package/templates/pages/incident-console/template.doc.mjs +12 -0
- package/templates/pages/messaging-shell/page.tsx +676 -0
- package/templates/pages/messaging-shell/template.doc.mjs +12 -0
- package/templates/pages/mixed-gallery/page.tsx +1 -1
- package/templates/pages/payment-form/page.tsx +2 -6
- package/templates/pages/product-detail/page.tsx +3 -11
- package/templates/pages/product-gallery/page.tsx +1 -1
- package/templates/pages/settings/page.tsx +1 -1
- package/templates/pages/side-gallery/page.tsx +1 -1
- package/templates/pages/table-page/page.tsx +1 -1
- package/templates/pages/table-page-chart/page.tsx +1 -1
- package/templates/pages/table-page-heatmap-status/page.tsx +1 -1
- package/templates/pages/table-page-shoe-store-heatmap/page.tsx +1 -1
|
@@ -69,6 +69,10 @@ export const docs = {
|
|
|
69
69
|
type: 'prose',
|
|
70
70
|
text: 'Available themes: @astryxdesign/theme-neutral (muted minimal, a good starting point), @astryxdesign/theme-butter, @astryxdesign/theme-chocolate, @astryxdesign/theme-gothic (dark-only), @astryxdesign/theme-matcha, @astryxdesign/theme-stone, and @astryxdesign/theme-y2k. See `npx astryx docs theme` for the full theming guide.',
|
|
71
71
|
},
|
|
72
|
+
{
|
|
73
|
+
type: 'prose',
|
|
74
|
+
text: 'These stylesheets are cascade-layered: the reset loads in @layer reset and component styles in @layer astryx-base. If your project has existing global CSS, a legacy reset, or Tailwind, declare the layer order explicitly and assign every stylesheet to a layer deliberately: unlayered styles and later layers both override astryx-base regardless of specificity. See the Cascade Layer Safety section in `npx astryx docs migration` before building screens.',
|
|
75
|
+
},
|
|
72
76
|
],
|
|
73
77
|
},
|
|
74
78
|
{
|
package/docs/migration.doc.mjs
CHANGED
|
@@ -33,6 +33,7 @@ export const docs = {
|
|
|
33
33
|
'Install the design system and run init so the project has package scripts, theme CSS, and agent docs.',
|
|
34
34
|
'Wrap the app root with Theme and choose the initial light, dark, or system mode behavior.',
|
|
35
35
|
'Make Tailwind and design system CSS layer order explicit before replacing components.',
|
|
36
|
+
'Render the foundation smoke test page and confirm primitives keep their padding before migrating any surface.',
|
|
36
37
|
'Move the persistent frame first: AppShell, TopNav, SideNav, page content, and mobile navigation.',
|
|
37
38
|
'Replace shared primitives: Button, IconButton, TextInput, NumberInput, Switch, CheckboxInput, RadioList, Selector, Tabs, Dialog, AlertDialog, Banner, Toast, Badge, Card, Table, and ListItem.',
|
|
38
39
|
'Replace global workflows: command palette, settings popover, theme toggle, search, filters, create flows, and destructive confirmation dialogs.',
|
|
@@ -125,6 +126,139 @@ export function AppRoot({children}: {children: React.ReactNode}) {
|
|
|
125
126
|
@import "@astryxdesign/core/tailwind-theme.css";
|
|
126
127
|
@import "tailwindcss/utilities.css" layer(utilities);`,
|
|
127
128
|
},
|
|
129
|
+
{
|
|
130
|
+
type: 'prose',
|
|
131
|
+
text: 'On Tailwind v3 there is no preflight.css to import, so wrap the @tailwind base directive in a named layer instead. Keep utilities unlayered so existing app utility classes still win everywhere.',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
type: 'code',
|
|
135
|
+
lang: 'css',
|
|
136
|
+
label: 'Tailwind v3 coexistence',
|
|
137
|
+
code: `@layer reset, tw-preflight, astryx-base, astryx-theme;
|
|
138
|
+
|
|
139
|
+
@import "@astryxdesign/core/reset.css";
|
|
140
|
+
@import "@astryxdesign/core/astryx.css";
|
|
141
|
+
@import "@astryxdesign/theme-neutral/theme.css";
|
|
142
|
+
|
|
143
|
+
@layer tw-preflight {
|
|
144
|
+
@tailwind base; /* layered: astryx-theme now wins over preflight */
|
|
145
|
+
}
|
|
146
|
+
@tailwind components;
|
|
147
|
+
@tailwind utilities; /* unlayered: legacy utility classes keep winning */`,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
title: 'Cascade Layer Safety',
|
|
153
|
+
content: [
|
|
154
|
+
{
|
|
155
|
+
type: 'prose',
|
|
156
|
+
text: 'In a stylesheet with no layers at all, a zero-specificity reset like `* { padding: 0 }` loses to any class selector, so most developers treat resets as harmless. Layers change the rules twice: unlayered styles beat every named layer, and a later layer beats an earlier one, both regardless of specificity. The same reset therefore wins against every component style either by staying unlayered or by landing in a layer declared after astryx-base. Same CSS, opposite outcome, and no error or warning when it happens.',
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: 'prose',
|
|
160
|
+
text: 'This is the most common way an adoption breaks, through one of two @import mechanisms. A top-level @import without the layer() keyword keeps the legacy reset unlayered, where it overrides every design system layer. And an @import nested inside a file that was itself imported into a layer inherits that surrounding layer, so a reset can silently land in a consumer layer above astryx-base. Either way the fix is the same: import the legacy reset into the lowest layer explicitly.',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: 'code',
|
|
164
|
+
lang: 'css',
|
|
165
|
+
label: 'Legacy reset, explicitly layered',
|
|
166
|
+
code: `/* was: @import "./legacy-reset.css"; (unlayered: beats every layer) */
|
|
167
|
+
@import "./legacy-reset.css" layer(reset);`,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
type: 'prose',
|
|
171
|
+
text: 'Audit the layers around the design system with this checklist before building screens.',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
type: 'list',
|
|
175
|
+
style: 'unordered',
|
|
176
|
+
items: [
|
|
177
|
+
'Declare the canonical @layer order once, before any @import. With webpack-based bundlers (including Next.js) the order declaration must live in its own CSS file imported first, such as layers.css, because webpack hoists @import content above the inline CSS that follows it.',
|
|
178
|
+
'Audit every pre-existing global or reset stylesheet and assign each one to a layer deliberately. Top-level imports without layer() stay unlayered and beat every layer; imports nested inside a layered file inherit that layer.',
|
|
179
|
+
'Remove or demote the app legacy reset. The design system ships its own :where() reset in the lowest layer, so any app reset belongs in that same reset layer and never in a layer above astryx-base.',
|
|
180
|
+
'Layer Tailwind preflight. On Tailwind v4, import preflight.css with layer(base). On Tailwind v3, wrap the @tailwind base directive in a named layer (see the snippet in Theme and CSS Setup). Unlayered preflight overrides theme CSS silently.',
|
|
181
|
+
'Set moduleResolution to bundler or node16 and newer so subpath imports like @astryxdesign/core/reset.css resolve.',
|
|
182
|
+
'Theme with defineTheme and the accent family API instead of hand-writing individual color tokens. Derived tokens like --color-on-accent are generated from the accent scale automatically; hand-writing only --color-accent leaves --color-on-accent at its stale white default with no contrast guarantee against the new accent.',
|
|
183
|
+
'Run the foundation smoke test below and view a few components in both light and dark mode before migrating any route.',
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
type: 'prose',
|
|
188
|
+
text: 'One more mental model shift: a className or utility class you write on a component still reaches the DOM either way, but whether it overrides the component is a layer question, not a source order question. Keep app utilities in the utilities layer so they keep winning.',
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
title: 'Foundation Smoke Test',
|
|
194
|
+
content: [
|
|
195
|
+
{
|
|
196
|
+
type: 'prose',
|
|
197
|
+
text: 'A broken layer order fails silently and identically on every page, so catch it before feature work instead of after N migrated screens. Render one throwaway page with a few primitives as the first migration step.',
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
type: 'code',
|
|
201
|
+
lang: 'tsx',
|
|
202
|
+
label: 'Foundation check page',
|
|
203
|
+
code: `import {useState} from 'react';
|
|
204
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
205
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
206
|
+
import {Table} from '@astryxdesign/core/Table';
|
|
207
|
+
import {TextInput} from '@astryxdesign/core/TextInput';
|
|
208
|
+
import {VStack} from '@astryxdesign/core/VStack';
|
|
209
|
+
|
|
210
|
+
export default function FoundationCheck() {
|
|
211
|
+
const [email, setEmail] = useState('');
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<div data-foundation-check>
|
|
215
|
+
<VStack gap={4}>
|
|
216
|
+
<Button label="Primary action" variant="primary" />
|
|
217
|
+
<TextInput
|
|
218
|
+
label="Email"
|
|
219
|
+
placeholder="you@example.com"
|
|
220
|
+
value={email}
|
|
221
|
+
onChange={setEmail}
|
|
222
|
+
/>
|
|
223
|
+
<Card>One card with default padding</Card>
|
|
224
|
+
<Table
|
|
225
|
+
data={[{name: 'Foundation', status: 'ok'}]}
|
|
226
|
+
columns={[
|
|
227
|
+
{key: 'name', header: 'Name'},
|
|
228
|
+
{key: 'status', header: 'Status'},
|
|
229
|
+
]}
|
|
230
|
+
/>
|
|
231
|
+
</VStack>
|
|
232
|
+
</div>
|
|
233
|
+
);
|
|
234
|
+
}`,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
type: 'prose',
|
|
238
|
+
text: 'If the button renders with visible padding, a filled primary background, and the input and card have borders and internal spacing, the foundation is sound. For an assertion that can run in any test runner or a dev-only effect, check that a primitive keeps non-zero padding:',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
type: 'code',
|
|
242
|
+
lang: 'ts',
|
|
243
|
+
label: 'Foundation assertion',
|
|
244
|
+
code: `const button = document.querySelector<HTMLButtonElement>(
|
|
245
|
+
'[data-foundation-check] button',
|
|
246
|
+
);
|
|
247
|
+
if (!button) {
|
|
248
|
+
throw new Error('Foundation check page did not render a button.');
|
|
249
|
+
}
|
|
250
|
+
if (getComputedStyle(button).paddingInline === '0px') {
|
|
251
|
+
throw new Error(
|
|
252
|
+
'Foundation broken: an unlayered reset or a later cascade layer is ' +
|
|
253
|
+
'overriding component styles. Check that no app reset sits outside ' +
|
|
254
|
+
'the reset layer.',
|
|
255
|
+
);
|
|
256
|
+
}`,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: 'prose',
|
|
260
|
+
text: 'When this fails, the fix is almost always in the layer order: find the stylesheet that zeroes padding, and move it into the reset layer or delete it.',
|
|
261
|
+
},
|
|
128
262
|
],
|
|
129
263
|
},
|
|
130
264
|
{
|
package/docs/styling.doc.mjs
CHANGED
|
@@ -338,6 +338,59 @@ const styles = stylex.create({
|
|
|
338
338
|
},
|
|
339
339
|
],
|
|
340
340
|
},
|
|
341
|
+
{
|
|
342
|
+
title: 'StyleX Build Setup (required for swizzled components)',
|
|
343
|
+
category: 'guide',
|
|
344
|
+
content: [
|
|
345
|
+
{
|
|
346
|
+
type: 'prose',
|
|
347
|
+
text: 'Astryx components ship pre-compiled, so consuming the published package needs no StyleX setup. But `astryx swizzle <Component>` copies the raw StyleX *source* into your app, and StyleX source requires a build-time StyleX compiler to produce atomic CSS. Without one the component compiles but renders completely unstyled: no error, no warning. If a swizzled component looks unstyled, a missing StyleX compiler is almost always why. The same applies if you author your own StyleX with `stylex.create()`.',
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
type: 'table',
|
|
351
|
+
headers: ['Bundler', 'StyleX plugin'],
|
|
352
|
+
rows: [
|
|
353
|
+
['Webpack', '@stylexjs/webpack-plugin'],
|
|
354
|
+
['Vite / Rollup', '@stylexjs/rollup-plugin (or a community Vite plugin)'],
|
|
355
|
+
['Babel (any bundler)', '@stylexjs/babel-plugin + @stylexjs/postcss-plugin'],
|
|
356
|
+
['Next.js (App Router, SWC)', 'An SWC-based transform; see the Next.js note below'],
|
|
357
|
+
],
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
type: 'prose',
|
|
361
|
+
text: 'Next.js (App Router) is the sharp edge. StyleX\'s canonical compiler is a Babel plugin, but introducing a Babel config in Next.js disables the SWC compiler, which in turn breaks SWC-dependent features like `next/font`. So the "obvious" Babel setup is actively incompatible with a standard Next 15 App Router app.',
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
type: 'prose',
|
|
365
|
+
text: 'The working path on Next.js is an SWC-based StyleX transform (e.g. the community `@stylexswc/nextjs-plugin`) wired into `next.config`, which keeps SWC and `next/font` intact. See the example app `apps/example-nextjs-stylex` in the repo for a complete, working Next.js + StyleX + SWC configuration.',
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
type: 'code',
|
|
369
|
+
lang: 'js',
|
|
370
|
+
label: 'next.config.mjs: SWC-based StyleX transform (keeps next/font working)',
|
|
371
|
+
code: `import stylexPlugin from '@stylexswc/nextjs-plugin';
|
|
372
|
+
|
|
373
|
+
export default stylexPlugin({
|
|
374
|
+
rsOptions: {
|
|
375
|
+
// Resolve @astryxdesign/core's StyleX so swizzled component source compiles.
|
|
376
|
+
aliases: {'@/*': ['./src/*']},
|
|
377
|
+
unstable_moduleResolution: {type: 'commonJS'},
|
|
378
|
+
},
|
|
379
|
+
})({
|
|
380
|
+
// your existing Next.js config
|
|
381
|
+
});`,
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
type: 'list',
|
|
385
|
+
style: 'unordered',
|
|
386
|
+
items: [
|
|
387
|
+
'Symptom of a missing compiler: swizzled component renders with no styles, but no build or runtime error.',
|
|
388
|
+
'Do NOT add @stylexjs/babel-plugin to a Next.js App Router app; it disables SWC and breaks next/font.',
|
|
389
|
+
'Pure theming (defineTheme + astryx theme build) needs NO StyleX compiler; only swizzled/authored StyleX source does.',
|
|
390
|
+
],
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
},
|
|
341
394
|
{
|
|
342
395
|
title: 'What NOT to Do',
|
|
343
396
|
category: 'guide',
|
|
@@ -125,7 +125,7 @@ If you don't know all three, run \`npx astryx init --features agents\` to genera
|
|
|
125
125
|
lang: 'json',
|
|
126
126
|
label: 'package.json',
|
|
127
127
|
code: `"scripts": {
|
|
128
|
-
"
|
|
128
|
+
"astryx": "node node_modules/@astryxdesign/cli/bin/astryx.mjs"
|
|
129
129
|
}`,
|
|
130
130
|
},
|
|
131
131
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.1.4-canary.
|
|
3
|
+
"version": "0.1.4-canary.d7c9a39",
|
|
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",
|
|
@@ -68,17 +68,17 @@
|
|
|
68
68
|
"CHANGELOG.md"
|
|
69
69
|
],
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@clack/prompts": "^1.
|
|
71
|
+
"@clack/prompts": "^1.7.0",
|
|
72
72
|
"commander": "^12.1.0",
|
|
73
73
|
"jiti": "^2.7.0",
|
|
74
74
|
"jscodeshift": "^17.3.0",
|
|
75
75
|
"zod": "^4.4.3"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@astryxdesign/charts": "0.1.4-canary.
|
|
79
|
-
"@astryxdesign/core": "0.1.4-canary.
|
|
80
|
-
"@astryxdesign/lab": "0.1.4-canary.
|
|
81
|
-
"@astryxdesign/theme-neutral": "0.1.4-canary.
|
|
78
|
+
"@astryxdesign/charts": "0.1.4-canary.d7c9a39",
|
|
79
|
+
"@astryxdesign/core": "0.1.4-canary.d7c9a39",
|
|
80
|
+
"@astryxdesign/lab": "0.1.4-canary.d7c9a39",
|
|
81
|
+
"@astryxdesign/theme-neutral": "0.1.4-canary.d7c9a39",
|
|
82
82
|
"gpt-tokenizer": "^3.4.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependenciesMeta": {
|
|
@@ -96,10 +96,10 @@
|
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
-
"@astryxdesign/charts": "0.1.4-canary.
|
|
100
|
-
"@astryxdesign/core": "0.1.4-canary.
|
|
101
|
-
"@astryxdesign/lab": "0.1.4-canary.
|
|
102
|
-
"@astryxdesign/theme-neutral": "0.1.4-canary.
|
|
99
|
+
"@astryxdesign/charts": "0.1.4-canary.d7c9a39",
|
|
100
|
+
"@astryxdesign/core": "0.1.4-canary.d7c9a39",
|
|
101
|
+
"@astryxdesign/lab": "0.1.4-canary.d7c9a39",
|
|
102
|
+
"@astryxdesign/theme-neutral": "0.1.4-canary.d7c9a39",
|
|
103
103
|
"gpt-tokenizer": "^3.4.0"
|
|
104
104
|
},
|
|
105
105
|
"scripts": {
|
|
@@ -20,6 +20,7 @@ const registry = new Map([
|
|
|
20
20
|
['0.1.0', () => import('./transforms/v0.1.0/index.mjs')],
|
|
21
21
|
['0.1.2', () => import('./transforms/v0.1.2/index.mjs')],
|
|
22
22
|
['0.1.3', () => import('./transforms/v0.1.3/index.mjs')],
|
|
23
|
+
['0.1.5', () => import('./transforms/v0.1.5/index.mjs')],
|
|
23
24
|
]);
|
|
24
25
|
|
|
25
26
|
// Re-export from the shared utility so registry callers and other consumers
|
package/src/codemods/transforms/v0.1.5/__tests__/rename-switch-label-spacing-default-to-hug.test.mjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, it, expect} from 'vitest';
|
|
4
|
+
|
|
5
|
+
async function applyTransform(source) {
|
|
6
|
+
const {default: transform} =
|
|
7
|
+
await import('../rename-switch-label-spacing-default-to-hug.mjs');
|
|
8
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
9
|
+
const j = jscodeshift.withParser('tsx');
|
|
10
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
11
|
+
const file = {source, path: 'test.tsx'};
|
|
12
|
+
const result = transform(file, api);
|
|
13
|
+
return result ?? source;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('rename-switch-label-spacing-default-to-hug', () => {
|
|
17
|
+
it('renames Switch labelSpacing="default" to labelSpacing="hug"', async () => {
|
|
18
|
+
const input = `<Switch label="Notify" value={on} labelSpacing="default" />`;
|
|
19
|
+
const output = await applyTransform(input);
|
|
20
|
+
expect(output).toContain("'hug'");
|
|
21
|
+
expect(output).not.toContain('default');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("renames expression-container labelSpacing={'default'}", async () => {
|
|
25
|
+
const input = `<Switch label="Notify" value={on} labelSpacing={'default'} />`;
|
|
26
|
+
const output = await applyTransform(input);
|
|
27
|
+
expect(output).toContain("'hug'");
|
|
28
|
+
expect(output).not.toContain("'default'");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('renames default inside a ternary labelSpacing expression', async () => {
|
|
32
|
+
const input = `<Switch label="Notify" value={on} labelSpacing={isRow ? 'spread' : 'default'} />`;
|
|
33
|
+
const output = await applyTransform(input);
|
|
34
|
+
expect(output).toContain("'hug'");
|
|
35
|
+
expect(output).toContain("'spread'");
|
|
36
|
+
expect(output).not.toContain("'default'");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('does not change labelSpacing="spread"', async () => {
|
|
40
|
+
const input = `<Switch label="Notify" value={on} labelSpacing="spread" />`;
|
|
41
|
+
const output = await applyTransform(input);
|
|
42
|
+
expect(output).toBe(input);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('does not touch labelSpacing="default" on non-Switch components', async () => {
|
|
46
|
+
const input = `<LegacyToggle labelSpacing="default" />`;
|
|
47
|
+
const output = await applyTransform(input);
|
|
48
|
+
expect(output).toBe(input);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('does not touch other props with a "default" value on Switch', async () => {
|
|
52
|
+
const input = `<Switch label="Notify" value={on} data-variant="default" />`;
|
|
53
|
+
const output = await applyTransform(input);
|
|
54
|
+
expect(output).toBe(input);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('does not touch unrelated "default" string literals', async () => {
|
|
58
|
+
const input = `const theme = {mode: 'default', label: 'Default Mode'};`;
|
|
59
|
+
const output = await applyTransform(input);
|
|
60
|
+
expect(output).toBe(input);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('renames object labelSpacing prop in files importing Switch', async () => {
|
|
64
|
+
const input = `import {Switch} from '@astryxdesign/core/Switch';
|
|
65
|
+
const cfg = {labelSpacing: 'default'};`;
|
|
66
|
+
const output = await applyTransform(input);
|
|
67
|
+
expect(output).toContain("labelSpacing: 'hug'");
|
|
68
|
+
expect(output).not.toContain("'default'");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("renames labelSpacing: 'default' as const in files importing Switch", async () => {
|
|
72
|
+
const input = `import {Switch} from '@astryxdesign/core/Switch';
|
|
73
|
+
const ROWS = [{labelSpacing: 'default' as const, label: 'Adjacent'}];`;
|
|
74
|
+
const output = await applyTransform(input);
|
|
75
|
+
expect(output).toContain("'hug' as const");
|
|
76
|
+
expect(output).not.toContain("'default'");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('does not rename object labelSpacing prop when Switch is not imported', async () => {
|
|
80
|
+
const input = `const cfg = {labelSpacing: 'default'};`;
|
|
81
|
+
const output = await applyTransform(input);
|
|
82
|
+
expect(output).toBe(input);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('renames Storybook argTypes options in files importing Switch', async () => {
|
|
86
|
+
const input = `import {Switch} from '@astryxdesign/core/Switch';
|
|
87
|
+
const meta = {argTypes: {labelSpacing: {control: 'select', options: ['default', 'spread']}}};`;
|
|
88
|
+
const output = await applyTransform(input);
|
|
89
|
+
expect(output).toContain("'hug'");
|
|
90
|
+
expect(output).toContain("'spread'");
|
|
91
|
+
expect(output).not.toContain("'default'");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file v0.1.5 transform manifest
|
|
5
|
+
*
|
|
6
|
+
* Lists all codemods for the v0.1.5 release in the order they should run.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import renameSwitchLabelSpacingDefaultToHug, {
|
|
10
|
+
meta as renameSwitchLabelSpacingDefaultToHugMeta,
|
|
11
|
+
} from './rename-switch-label-spacing-default-to-hug.mjs';
|
|
12
|
+
|
|
13
|
+
export default [
|
|
14
|
+
{
|
|
15
|
+
name: 'rename-switch-label-spacing-default-to-hug',
|
|
16
|
+
transform: renameSwitchLabelSpacingDefaultToHug,
|
|
17
|
+
meta: renameSwitchLabelSpacingDefaultToHugMeta,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Codemod: Rename Switch labelSpacing "default" to "hug"
|
|
5
|
+
* @see https://github.com/facebook/astryx/issues/2889
|
|
6
|
+
*
|
|
7
|
+
* The `labelSpacing="default"` value is renamed to `labelSpacing="hug"` so
|
|
8
|
+
* the name describes the behavior (label and switch hug each other), matching
|
|
9
|
+
* the behavioral register of the sibling `spread` value and the existing
|
|
10
|
+
* `hug`/`fill` layout vocabulary on TabList and SegmentedControl. The old
|
|
11
|
+
* `default` value keeps working as a deprecated alias, so this codemod is a
|
|
12
|
+
* cleanup, not a build fix.
|
|
13
|
+
*
|
|
14
|
+
* Transforms (scoped to Switch):
|
|
15
|
+
* - <Switch labelSpacing="default" /> → <Switch labelSpacing="hug" />
|
|
16
|
+
* - <Switch labelSpacing={'default'} /> → <Switch labelSpacing={'hug'} />
|
|
17
|
+
* - <Switch labelSpacing={cond ? 'default' : x}> → <Switch labelSpacing={cond ? 'hug' : x}>
|
|
18
|
+
* - Storybook argTypes: labelSpacing: { options: [..., 'default', ...] }
|
|
19
|
+
* → replaces 'default' with 'hug' (files importing Switch)
|
|
20
|
+
* - Object properties: { labelSpacing: 'default' } / { labelSpacing: 'default' as const }
|
|
21
|
+
* → { labelSpacing: 'hug' } (files importing Switch)
|
|
22
|
+
*
|
|
23
|
+
* The transform deliberately does NOT touch bare `'default'` strings that are
|
|
24
|
+
* not a `labelSpacing` value (an extremely common string otherwise), so it is
|
|
25
|
+
* safe to run across an entire codebase.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export const meta = {
|
|
29
|
+
title: 'Rename Switch labelSpacing "default" to "hug"',
|
|
30
|
+
description:
|
|
31
|
+
'Renames the `labelSpacing="default"` value to `labelSpacing="hug"` on ' +
|
|
32
|
+
'Switch. The old value keeps working as a deprecated alias. Also updates ' +
|
|
33
|
+
'Storybook labelSpacing argTypes options and object-literal `labelSpacing` ' +
|
|
34
|
+
'props in files that import Switch.',
|
|
35
|
+
pr: '#2889',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const OLD_VALUE = 'default';
|
|
39
|
+
const NEW_VALUE = 'hug';
|
|
40
|
+
|
|
41
|
+
/** Prop whose value is being renamed. */
|
|
42
|
+
const TARGET_PROP = 'labelSpacing';
|
|
43
|
+
|
|
44
|
+
/** Components whose `labelSpacing` prop accepts a SwitchLabelSpacing value. */
|
|
45
|
+
const TARGET_COMPONENTS = new Set(['Switch']);
|
|
46
|
+
|
|
47
|
+
export default function transformer(file, api) {
|
|
48
|
+
const j = api.jscodeshift;
|
|
49
|
+
const root = j(file.source);
|
|
50
|
+
let hasChanges = false;
|
|
51
|
+
|
|
52
|
+
/** Rewrite a string-literal node when it equals the old value. */
|
|
53
|
+
function renameStringLiteral(node) {
|
|
54
|
+
if (!node) return false;
|
|
55
|
+
if (
|
|
56
|
+
(node.type === 'StringLiteral' || node.type === 'Literal') &&
|
|
57
|
+
node.value === OLD_VALUE
|
|
58
|
+
) {
|
|
59
|
+
node.value = NEW_VALUE;
|
|
60
|
+
if (node.raw) node.raw = `'${NEW_VALUE}'`;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Recursively rewrite the old value inside ternary/logical expressions. */
|
|
67
|
+
function renameInExpression(node) {
|
|
68
|
+
if (!node) return false;
|
|
69
|
+
let changed = false;
|
|
70
|
+
if (node.type === 'StringLiteral' || node.type === 'Literal') {
|
|
71
|
+
changed = renameStringLiteral(node) || changed;
|
|
72
|
+
} else if (node.type === 'ConditionalExpression') {
|
|
73
|
+
changed = renameInExpression(node.consequent) || changed;
|
|
74
|
+
changed = renameInExpression(node.alternate) || changed;
|
|
75
|
+
} else if (node.type === 'LogicalExpression') {
|
|
76
|
+
changed = renameInExpression(node.left) || changed;
|
|
77
|
+
changed = renameInExpression(node.right) || changed;
|
|
78
|
+
} else if (node.type === 'TSAsExpression') {
|
|
79
|
+
// `'default' as const` → rewrite the inner expression
|
|
80
|
+
changed = renameInExpression(node.expression) || changed;
|
|
81
|
+
}
|
|
82
|
+
return changed;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// --- 1. JSX attribute: labelSpacing="default" / labelSpacing={'default'} on Switch ---
|
|
86
|
+
root.find(j.JSXOpeningElement).forEach(path => {
|
|
87
|
+
const name = path.node.name;
|
|
88
|
+
const componentName = name.type === 'JSXIdentifier' ? name.name : null;
|
|
89
|
+
if (!componentName || !TARGET_COMPONENTS.has(componentName)) return;
|
|
90
|
+
|
|
91
|
+
path.node.attributes.forEach(attr => {
|
|
92
|
+
if (attr.type !== 'JSXAttribute') return;
|
|
93
|
+
if (!attr.name || attr.name.name !== TARGET_PROP) return;
|
|
94
|
+
|
|
95
|
+
const value = attr.value;
|
|
96
|
+
if (!value) return;
|
|
97
|
+
|
|
98
|
+
if (value.type === 'StringLiteral' || value.type === 'Literal') {
|
|
99
|
+
if (renameStringLiteral(value)) hasChanges = true;
|
|
100
|
+
} else if (value.type === 'JSXExpressionContainer') {
|
|
101
|
+
if (renameInExpression(value.expression)) hasChanges = true;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Object-property / argTypes transforms only run in files that use a target
|
|
107
|
+
// component — keeps unrelated `{ labelSpacing: 'default' }` strings safe.
|
|
108
|
+
const importsTarget =
|
|
109
|
+
root
|
|
110
|
+
.find(j.ImportSpecifier)
|
|
111
|
+
.filter(p => TARGET_COMPONENTS.has(p.node.imported?.name))
|
|
112
|
+
.size() > 0;
|
|
113
|
+
|
|
114
|
+
if (importsTarget) {
|
|
115
|
+
const PropertyType = j.ObjectProperty ?? j.Property;
|
|
116
|
+
|
|
117
|
+
// --- 2. Object property: { labelSpacing: 'default' } / 'default' as const ---
|
|
118
|
+
root.find(PropertyType, {key: {name: TARGET_PROP}}).forEach(path => {
|
|
119
|
+
if (renameInExpression(path.node.value)) hasChanges = true;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// --- 3. Storybook argTypes: labelSpacing: { options: [..., 'default', ...] } ---
|
|
123
|
+
root.find(PropertyType, {key: {name: TARGET_PROP}}).forEach(path => {
|
|
124
|
+
const value = path.node.value;
|
|
125
|
+
if (!value || value.type !== 'ObjectExpression') return;
|
|
126
|
+
|
|
127
|
+
const optionsProp = value.properties.find(
|
|
128
|
+
p => p.key && (p.key.name === 'options' || p.key.value === 'options'),
|
|
129
|
+
);
|
|
130
|
+
if (optionsProp && optionsProp.value.type === 'ArrayExpression') {
|
|
131
|
+
optionsProp.value.elements.forEach(el => {
|
|
132
|
+
if (renameStringLiteral(el)) hasChanges = true;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!hasChanges) return undefined;
|
|
139
|
+
return root.toSource({quote: 'single'});
|
|
140
|
+
}
|
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
* - Claude Code: CLAUDE.md (root) or .claude/CLAUDE.md
|
|
10
10
|
* - Cursor: .cursorrules
|
|
11
11
|
* - Codex/generic: AGENTS.md
|
|
12
|
+
* - Hermes Agent: .hermes.md or HERMES.md (existing), else AGENTS.md
|
|
12
13
|
*
|
|
13
14
|
* Auto-detect: discovers existing files and updates them in place.
|
|
14
15
|
* Default (no existing files): creates .claude/CLAUDE.md.
|
|
15
16
|
*
|
|
16
|
-
* --agent <tool>: target a specific tool preset (claude, cursor, codex, all)
|
|
17
|
+
* --agent <tool>: target a specific tool preset (claude, cursor, codex, hermes, all)
|
|
17
18
|
* --agent-docs-path <path>: explicit file path(s)
|
|
18
19
|
*/
|
|
19
20
|
|
|
@@ -46,6 +47,7 @@ const AGENT_PRESETS = {
|
|
|
46
47
|
claude: [CLAUDE_MD, CLAUDE_DIR_MD],
|
|
47
48
|
cursor: ['.cursorrules', AGENTS_MD],
|
|
48
49
|
codex: [AGENTS_MD],
|
|
50
|
+
hermes: ['.hermes.md', 'HERMES.md', AGENTS_MD],
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -64,7 +66,7 @@ export function discoverAgentDocs(targetDir) {
|
|
|
64
66
|
* Searches for existing files first, falls back to default creation path.
|
|
65
67
|
*
|
|
66
68
|
* @param {string} targetDir
|
|
67
|
-
* @param {string} agent - Preset name: 'claude', 'cursor', 'codex', 'all'
|
|
69
|
+
* @param {string} agent - Preset name: 'claude', 'cursor', 'codex', 'hermes', 'all'
|
|
68
70
|
* @returns {{inject: string[], create: string[]}} Files to inject into vs create fresh
|
|
69
71
|
*/
|
|
70
72
|
export function resolveAgentPaths(targetDir, agent) {
|
|
@@ -386,7 +388,7 @@ export function removeAgentDocs(targetDir) {
|
|
|
386
388
|
* @param {object} [options]
|
|
387
389
|
* @param {boolean} [options.zh]
|
|
388
390
|
* @param {string} [options.lang]
|
|
389
|
-
* @param {string} [options.agent] - Tool preset: 'claude', 'cursor', 'codex', 'all'
|
|
391
|
+
* @param {string} [options.agent] - Tool preset: 'claude', 'cursor', 'codex', 'hermes', 'all'
|
|
390
392
|
* @param {string[]} [options.paths] - Explicit paths (overrides agent/auto-detect)
|
|
391
393
|
* @param {boolean} [options.onlyReplace] - Only update files that already have Astryx markers (for upgrades)
|
|
392
394
|
* @returns {string[]} List of files written
|
|
@@ -468,14 +470,14 @@ export function installAgentDocs(targetDir, {zh = false, lang, agent, paths, onl
|
|
|
468
470
|
return written;
|
|
469
471
|
}
|
|
470
472
|
|
|
471
|
-
const VALID_AGENTS = ['claude', 'cursor', 'codex', 'all'];
|
|
473
|
+
const VALID_AGENTS = ['claude', 'cursor', 'codex', 'hermes', 'all'];
|
|
472
474
|
|
|
473
475
|
export function registerAgentDocs(program) {
|
|
474
476
|
program
|
|
475
477
|
.command('agent-docs')
|
|
476
478
|
.description('Install/update the component index for AI coding agents')
|
|
477
479
|
.option('--remove', 'Remove the design system section from all agent doc files')
|
|
478
|
-
.option('--agent <tool>', 'Target tool: claude, cursor, codex, all')
|
|
480
|
+
.option('--agent <tool>', 'Target tool: claude, cursor, codex, hermes, all')
|
|
479
481
|
.option('--agent-docs-path <path...>', 'Explicit file path(s) to write to')
|
|
480
482
|
.action(options => {
|
|
481
483
|
const targetDir = process.cwd();
|
|
@@ -449,6 +449,17 @@ describe('installAgentDocs', () => {
|
|
|
449
449
|
expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(true);
|
|
450
450
|
});
|
|
451
451
|
|
|
452
|
+
it('respects --agent hermes preset: creates AGENTS.md', () => {
|
|
453
|
+
setupCorePackage(tmpDir);
|
|
454
|
+
|
|
455
|
+
const written = installAgentDocs(tmpDir, {agent: 'hermes'});
|
|
456
|
+
|
|
457
|
+
expect(written).toEqual(['AGENTS.md']);
|
|
458
|
+
const content = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
|
|
459
|
+
expect(content).toContain('<!-- ASTRYX:START -->');
|
|
460
|
+
expect(fs.existsSync(path.join(tmpDir, '.claude'))).toBe(false);
|
|
461
|
+
});
|
|
462
|
+
|
|
452
463
|
it('respects explicit --paths', () => {
|
|
453
464
|
setupCorePackage(tmpDir);
|
|
454
465
|
|
|
@@ -548,4 +559,26 @@ describe('resolveAgentPaths', () => {
|
|
|
548
559
|
expect(result.create).toContain('AGENTS.md');
|
|
549
560
|
expect(result.create).toContain('.claude/CLAUDE.md');
|
|
550
561
|
});
|
|
562
|
+
|
|
563
|
+
it('hermes preset creates AGENTS.md when nothing exists', () => {
|
|
564
|
+
const result = resolveAgentPaths(tmpDir, 'hermes');
|
|
565
|
+
expect(result).toEqual({inject: [], create: ['AGENTS.md']});
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it('hermes preset finds existing .hermes.md', () => {
|
|
569
|
+
fs.writeFileSync(path.join(tmpDir, '.hermes.md'), '');
|
|
570
|
+
const result = resolveAgentPaths(tmpDir, 'hermes');
|
|
571
|
+
expect(result).toEqual({inject: ['.hermes.md'], create: []});
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('hermes preset finds existing HERMES.md when no .hermes.md', () => {
|
|
575
|
+
fs.writeFileSync(path.join(tmpDir, 'HERMES.md'), '');
|
|
576
|
+
const result = resolveAgentPaths(tmpDir, 'hermes');
|
|
577
|
+
expect(result).toEqual({inject: ['HERMES.md'], create: []});
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it('claude preset still creates .claude/CLAUDE.md when nothing exists (hermes is additive)', () => {
|
|
581
|
+
const result = resolveAgentPaths(tmpDir, 'claude');
|
|
582
|
+
expect(result).toEqual({inject: [], create: ['.claude/CLAUDE.md']});
|
|
583
|
+
});
|
|
551
584
|
});
|