@astryxdesign/cli 0.1.4 → 0.1.5-canary.76e6697

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/docs/getting-started.doc.mjs +4 -0
  3. package/docs/migration.doc.mjs +134 -0
  4. package/docs/styling.doc.mjs +53 -0
  5. package/docs/working-with-ai.doc.mjs +1 -1
  6. package/package.json +15 -10
  7. package/src/api/component.mjs +2 -1
  8. package/src/api/doctor.mjs +13 -2
  9. package/src/api/template.mjs +14 -3
  10. package/src/codemods/__tests__/registry.test.mjs +1 -0
  11. package/src/codemods/__tests__/runner.test.mjs +38 -0
  12. package/src/codemods/registry.mjs +1 -0
  13. package/src/codemods/runner.mjs +2 -0
  14. package/src/codemods/transforms/v0.1.5/__tests__/rename-switch-label-spacing-default-to-hug.test.mjs +93 -0
  15. package/src/codemods/transforms/v0.1.5/index.mjs +19 -0
  16. package/src/codemods/transforms/v0.1.5/rename-switch-label-spacing-default-to-hug.mjs +140 -0
  17. package/src/commands/agent-docs.mjs +9 -6
  18. package/src/commands/agent-docs.test.mjs +33 -0
  19. package/src/commands/build-theme.color-scheme.test.mjs +153 -0
  20. package/src/commands/build-theme.mjs +112 -14
  21. package/src/commands/build-theme.variants.test.mjs +193 -0
  22. package/src/commands/component-resolution.test.mjs +4 -4
  23. package/src/commands/doctor.test.mjs +34 -0
  24. package/src/commands/init.mjs +1 -1
  25. package/src/commands/swizzle.mjs +34 -0
  26. package/src/commands/swizzle.routing.test.mjs +67 -0
  27. package/src/lib/component-discovery.mjs +8 -4
  28. package/templates/blocks/components/AspectRatio/AspectRatioCircleImage.tsx +1 -6
  29. package/templates/blocks/components/AspectRatio/AspectRatioImageGallery.tsx +2 -7
  30. package/templates/blocks/components/AspectRatio/AspectRatioShowcase.tsx +2 -5
  31. package/templates/blocks/components/AspectRatio/AspectRatioSquareImage.tsx +1 -6
  32. package/templates/blocks/components/AspectRatio/AspectRatioWidescreen.tsx +1 -6
  33. package/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +14 -0
  34. package/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +58 -0
  35. package/templates/blocks/components/CodeBlock/CodeBlockTerminal.doc.mjs +14 -0
  36. package/templates/blocks/components/CodeBlock/CodeBlockTerminal.tsx +24 -0
  37. package/templates/blocks/components/Collapsible/CollapsibleDividedAccordion.doc.mjs +13 -0
  38. package/templates/blocks/components/Collapsible/CollapsibleDividedAccordion.tsx +33 -0
  39. package/templates/blocks/components/Collapsible/CollapsibleWithoutCard.tsx +25 -23
  40. package/templates/blocks/components/CommandPaletteGroup/CommandPaletteGroupShowcase.tsx +27 -48
  41. package/templates/blocks/components/CommandPaletteInput/CommandPaletteInputBasic.doc.mjs +15 -0
  42. package/templates/blocks/components/CommandPaletteInput/CommandPaletteInputBasic.tsx +39 -0
  43. package/templates/blocks/components/CommandPaletteInput/CommandPaletteInputShowcase.doc.mjs +15 -0
  44. package/templates/blocks/components/CommandPaletteInput/CommandPaletteInputShowcase.tsx +39 -0
  45. package/templates/blocks/components/CommandPaletteItem/CommandPaletteItemShowcase.tsx +31 -54
  46. package/templates/blocks/components/CommandPaletteList/CommandPaletteListBasic.doc.mjs +15 -0
  47. package/templates/blocks/components/CommandPaletteList/CommandPaletteListBasic.tsx +27 -0
  48. package/templates/blocks/components/CommandPaletteList/CommandPaletteListShowcase.doc.mjs +15 -0
  49. package/templates/blocks/components/CommandPaletteList/CommandPaletteListShowcase.tsx +38 -0
  50. package/templates/blocks/components/ContextMenuItem/ContextMenuItemBasic.doc.mjs +14 -0
  51. package/templates/blocks/components/ContextMenuItem/ContextMenuItemBasic.tsx +44 -0
  52. package/templates/blocks/components/ContextMenuItem/ContextMenuItemShowcase.doc.mjs +15 -0
  53. package/templates/blocks/components/ContextMenuItem/ContextMenuItemShowcase.tsx +107 -0
  54. package/templates/blocks/components/NavHeadingMenu/NavHeadingMenuShowcase.doc.mjs +15 -0
  55. package/templates/blocks/components/NavHeadingMenu/NavHeadingMenuShowcase.tsx +47 -0
  56. package/templates/blocks/components/Table/TableGroupedRowsTable.doc.mjs +14 -0
  57. package/templates/blocks/components/Table/TableGroupedRowsTable.tsx +66 -0
  58. package/templates/pages/classic-gallery/page.tsx +1 -1
  59. package/templates/pages/dashboard/page.tsx +1 -1
  60. package/templates/pages/documentation/page.tsx +1 -1
  61. package/templates/pages/incident-console/page.tsx +580 -0
  62. package/templates/pages/incident-console/template.doc.mjs +12 -0
  63. package/templates/pages/kanban-board/page.tsx +37 -13
  64. package/templates/pages/messaging-shell/page.tsx +676 -0
  65. package/templates/pages/messaging-shell/template.doc.mjs +12 -0
  66. package/templates/pages/mixed-gallery/page.tsx +1 -1
  67. package/templates/pages/payment-form/page.tsx +2 -6
  68. package/templates/pages/product-detail/page.tsx +3 -11
  69. package/templates/pages/product-gallery/page.tsx +1 -1
  70. package/templates/pages/settings/page.tsx +1 -1
  71. package/templates/pages/side-gallery/page.tsx +1 -1
  72. package/templates/pages/table-page/page.tsx +1 -1
  73. package/templates/pages/table-page-chart/page.tsx +4 -14
  74. package/templates/pages/table-page-heatmap-status/page.tsx +1 -1
  75. package/templates/pages/table-page-shoe-store-heatmap/page.tsx +5 -19
@@ -0,0 +1,193 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Regression test for the custom-variant type augmentations emitted by
5
+ * `astryx theme build` (#3391 companion: #3371).
6
+ *
7
+ * When a theme declares a custom component prop value (e.g.
8
+ * `button['variant:accentOutline']`), the build emits a `<name>.variants.d.ts`
9
+ * with a module augmentation so the custom value type-checks. This suite pins
10
+ * the two bugs that made that augmentation dead code:
11
+ *
12
+ * 1. The augmentation targeted a non-existent, `XDS`-prefixed interface
13
+ * (`XDSButtonVariantMap`) instead of core's real `ButtonVariantMap`, so it
14
+ * created a new unused interface and never widened the prop union.
15
+ * 2. Props with no augmentation point (closed literal-union types such as
16
+ * Button `size` or Heading `type`/`level`) still got a `declare module`
17
+ * block against a `*Map` interface that doesn't exist.
18
+ * 3. The generated `.variants.d.ts` was never referenced by the main
19
+ * `<name>.d.ts`, so even a correct augmentation never loaded.
20
+ *
21
+ * Building `astryx theme build` requires a compiled @astryxdesign/core, so this
22
+ * suite builds core once in beforeAll (mirrors build-theme.prose.test.mjs).
23
+ */
24
+
25
+ import {describe, it, expect, beforeAll, beforeEach, afterEach} from 'vitest';
26
+ import {execFileSync} from 'node:child_process';
27
+ import * as fs from 'node:fs';
28
+ import * as path from 'node:path';
29
+ import * as os from 'node:os';
30
+ import {fileURLToPath} from 'node:url';
31
+ import {ensureCoreBuilt} from './ensure-core-built.mjs';
32
+
33
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
34
+ const CLI_BIN = path.resolve(__dirname, '../../bin/astryx.mjs');
35
+
36
+ function runCli(args, cwd) {
37
+ try {
38
+ const out = execFileSync('node', [CLI_BIN, ...args], {
39
+ cwd,
40
+ encoding: 'utf-8',
41
+ stdio: ['ignore', 'pipe', 'pipe'],
42
+ env: {...process.env, FORCE_COLOR: '0'},
43
+ });
44
+ return {code: 0, stdout: out, stderr: ''};
45
+ } catch (e) {
46
+ return {
47
+ code: e.status ?? 1,
48
+ stdout: e.stdout?.toString() ?? '',
49
+ stderr: e.stderr?.toString() ?? '',
50
+ };
51
+ }
52
+ }
53
+
54
+ function writeTheme(dir, contents) {
55
+ fs.mkdirSync(dir, {recursive: true});
56
+ const file = path.join(dir, 'variants-theme.mjs');
57
+ fs.writeFileSync(file, contents);
58
+ return file;
59
+ }
60
+
61
+ // Build core through the shared lock helper — this suite previously ran its
62
+ // own unguarded `if (!exists) pnpm -F core build`, and when Vitest scheduled
63
+ // it alongside the other build-theme suites on a fresh checkout, the
64
+ // concurrent builds collided on packages/core/dist (core's build starts by
65
+ // wiping dist), nondeterministically breaking whichever suite was mid-read.
66
+ beforeAll(() => {
67
+ ensureCoreBuilt();
68
+ }, 200_000);
69
+
70
+ let tmpDir;
71
+ beforeEach(() => {
72
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-build-theme-variants-'));
73
+ });
74
+ afterEach(() => {
75
+ fs.rmSync(tmpDir, {recursive: true, force: true});
76
+ });
77
+
78
+ describe('theme build custom-variant augmentations', () => {
79
+ it('targets the real (un-prefixed) core interface for a custom variant', () => {
80
+ const themeFile = writeTheme(
81
+ tmpDir,
82
+ `export default {
83
+ name: 'variants-theme',
84
+ tokens: { '--color-bg': '#fff' },
85
+ components: {
86
+ button: { 'variant:accentOutline': { backgroundColor: 'transparent' } },
87
+ },
88
+ };\n`,
89
+ );
90
+
91
+ const result = runCli(
92
+ ['theme', 'build', path.relative(tmpDir, themeFile)],
93
+ tmpDir,
94
+ );
95
+ expect(result.code).toBe(0);
96
+
97
+ const variantsPath = path.join(tmpDir, 'variants-theme.variants.d.ts');
98
+ expect(fs.existsSync(variantsPath)).toBe(true);
99
+ const dts = fs.readFileSync(variantsPath, 'utf-8');
100
+
101
+ // Targets core's actual augmentation point…
102
+ expect(dts).toContain("declare module '@astryxdesign/core/Button'");
103
+ expect(dts).toMatch(/interface ButtonVariantMap\b/);
104
+ expect(dts).toContain("'accentOutline': true;");
105
+ // …and NOT the old, non-existent XDS-prefixed interface.
106
+ expect(dts).not.toMatch(/XDSButtonVariantMap/);
107
+ });
108
+
109
+ it('skips props with no augmentation point (Button size, Heading type)', () => {
110
+ const themeFile = writeTheme(
111
+ tmpDir,
112
+ `export default {
113
+ name: 'variants-theme',
114
+ tokens: { '--color-bg': '#fff' },
115
+ components: {
116
+ button: {
117
+ 'variant:accentOutline': { backgroundColor: 'transparent' },
118
+ 'size:jumbo': { paddingBlock: '40px' },
119
+ },
120
+ heading: { 'type:hero': { fontSize: '80px' } },
121
+ },
122
+ };\n`,
123
+ );
124
+
125
+ const result = runCli(
126
+ ['theme', 'build', path.relative(tmpDir, themeFile)],
127
+ tmpDir,
128
+ );
129
+ expect(result.code).toBe(0);
130
+
131
+ const variantsPath = path.join(tmpDir, 'variants-theme.variants.d.ts');
132
+ expect(fs.existsSync(variantsPath)).toBe(true);
133
+ const dts = fs.readFileSync(variantsPath, 'utf-8');
134
+
135
+ // The augmentable variant is emitted…
136
+ expect(dts).toMatch(/interface ButtonVariantMap\b/);
137
+ // …but closed literal-union props get no dead augmentation.
138
+ expect(dts).not.toMatch(/ButtonSizeMap/);
139
+ expect(dts).not.toMatch(/HeadingTypeMap/);
140
+ expect(dts).not.toContain("declare module '@astryxdesign/core/Heading'");
141
+ });
142
+
143
+ it('does not emit a .variants.d.ts when every custom value is non-augmentable', () => {
144
+ const themeFile = writeTheme(
145
+ tmpDir,
146
+ `export default {
147
+ name: 'variants-theme',
148
+ tokens: { '--color-bg': '#fff' },
149
+ components: {
150
+ button: { 'size:jumbo': { paddingBlock: '40px' } },
151
+ },
152
+ };\n`,
153
+ );
154
+
155
+ const result = runCli(
156
+ ['theme', 'build', path.relative(tmpDir, themeFile)],
157
+ tmpDir,
158
+ );
159
+ expect(result.code).toBe(0);
160
+ expect(
161
+ fs.existsSync(path.join(tmpDir, 'variants-theme.variants.d.ts')),
162
+ ).toBe(false);
163
+ });
164
+
165
+ it('references the variants file from the main .d.ts so the augmentation loads', () => {
166
+ const themeFile = writeTheme(
167
+ tmpDir,
168
+ `export default {
169
+ name: 'variants-theme',
170
+ tokens: { '--color-bg': '#fff' },
171
+ components: {
172
+ button: { 'variant:accentOutline': { backgroundColor: 'transparent' } },
173
+ },
174
+ };\n`,
175
+ );
176
+
177
+ const result = runCli(
178
+ ['theme', 'build', path.relative(tmpDir, themeFile)],
179
+ tmpDir,
180
+ );
181
+ expect(result.code).toBe(0);
182
+
183
+ const dts = fs.readFileSync(
184
+ path.join(tmpDir, 'variants-theme.d.ts'),
185
+ 'utf-8',
186
+ );
187
+ // A triple-slash reference to the variants file, so importing the theme's
188
+ // types also loads the module augmentation.
189
+ expect(dts).toMatch(
190
+ /\/\/\/\s*<reference path="\.\/variants-theme\.variants\.d\.ts"\s*\/>/,
191
+ );
192
+ });
193
+ });
@@ -78,13 +78,13 @@ describe('findShowcase() priority', () => {
78
78
  it('Badge resolves to Badge dir, not a sibling that uses Badge', async () => {
79
79
  const result = await findShowcase('Badge');
80
80
  expect(result).not.toBeNull();
81
- expect(result.filePath).toMatch(/\/Badge\//);
81
+ expect(result.filePath).toMatch(/[/\\]Badge[/\\]/);
82
82
  });
83
83
 
84
84
  it('Avatar resolves to Avatar dir, not AvatarStatusDot', async () => {
85
85
  const result = await findShowcase('Avatar');
86
86
  expect(result).not.toBeNull();
87
- expect(result.filePath).toMatch(/\/Avatar\//);
87
+ expect(result.filePath).toMatch(/[/\\]Avatar[/\\]/);
88
88
  expect(result.filePath).not.toMatch(/AvatarStatusDot/);
89
89
  });
90
90
 
@@ -92,7 +92,7 @@ describe('findShowcase() priority', () => {
92
92
  const result = await findShowcase('ClickableCard');
93
93
  expect(result).not.toBeNull();
94
94
  expect(result.name).toBe('ClickableCard');
95
- expect(result.filePath).toMatch(/\/Card\//);
95
+ expect(result.filePath).toMatch(/[/\\]Card[/\\]/);
96
96
  });
97
97
 
98
98
  it('SelectableCard resolves via componentsUsed in Card/', async () => {
@@ -104,7 +104,7 @@ describe('findShowcase() priority', () => {
104
104
  it('Stack resolves to Stack dir despite componentsUsed elsewhere', async () => {
105
105
  const result = await findShowcase('Stack');
106
106
  expect(result).not.toBeNull();
107
- expect(result.filePath).toMatch(/\/Stack\//);
107
+ expect(result.filePath).toMatch(/[/\\]Stack[/\\]/);
108
108
  });
109
109
 
110
110
  it('returns null for nonexistent component', async () => {
@@ -63,6 +63,33 @@ function installPkg(name, version = '1.0.0') {
63
63
  return dir;
64
64
  }
65
65
 
66
+ /**
67
+ * Mirror pnpm's layout: the real package lives under node_modules/.pnpm and
68
+ * the entry in the scope directory is a symlink to it.
69
+ */
70
+ function installPkgPnpmStyle(name, version = '1.0.0') {
71
+ const realDir = path.join(
72
+ tmpDir,
73
+ 'node_modules',
74
+ '.pnpm',
75
+ `${name.replace('/', '+')}@${version}`,
76
+ 'node_modules',
77
+ ...name.split('/'),
78
+ );
79
+ fs.mkdirSync(realDir, {recursive: true});
80
+ fs.writeFileSync(
81
+ path.join(realDir, 'package.json'),
82
+ JSON.stringify({name, version, main: 'index.js'}),
83
+ );
84
+ fs.writeFileSync(path.join(realDir, 'index.js'), 'module.exports = {};');
85
+ const linkPath = path.join(tmpDir, 'node_modules', ...name.split('/'));
86
+ fs.mkdirSync(path.dirname(linkPath), {recursive: true});
87
+ // 'junction' keeps this working on Windows without elevated permissions;
88
+ // it is ignored on posix.
89
+ fs.symlinkSync(realDir, linkPath, 'junction');
90
+ return linkPath;
91
+ }
92
+
66
93
  function find(checks, id) {
67
94
  return checks.find(c => c.id === id);
68
95
  }
@@ -119,6 +146,13 @@ describe('doctor — individual checks', () => {
119
146
  expect(res.status).toBe('pass');
120
147
  });
121
148
 
149
+ it('themes: detects pnpm-style symlinked theme packages (#3530)', () => {
150
+ installPkgPnpmStyle('@astryxdesign/theme-neutral', '0.1.2');
151
+ const res = checkThemes({cwd: tmpDir, configTheme: 'default'});
152
+ expect(res.status).toBe('pass');
153
+ expect(res.message).toContain('@astryxdesign/theme-neutral');
154
+ });
155
+
122
156
  it('config: INFO when no astryx.config.mjs', async () => {
123
157
  const res = await checkConfig({cwd: tmpDir, configPath: null});
124
158
  expect(res.status).toBe('info');
@@ -198,7 +198,7 @@ export function registerInit(program) {
198
198
  .option('--features <list>', 'Comma-separated features to install (agents, theme, template)')
199
199
  .option('--all', 'Install all features, no prompts')
200
200
  .option('--remove-agents', 'Remove AI agent docs from all agent doc files')
201
- .option('--agent <tool>', 'Target AI tool for agent docs: claude, cursor, codex, all')
201
+ .option('--agent <tool>', 'Target AI tool for agent docs: claude, cursor, codex, hermes, all')
202
202
  .option('--agent-docs-path <path...>', 'Explicit file path(s) for agent docs')
203
203
  .action(async (options) => {
204
204
  const targetDir = process.cwd();
@@ -26,6 +26,7 @@ import {jsonOut, humanLog} from '../lib/json.mjs';
26
26
  import {cliError} from '../lib/cli-error.mjs';
27
27
  import {ERROR_CODES} from '../lib/error-codes.mjs';
28
28
  import {checkGhCli} from '../utils/github.mjs';
29
+ import {getRunPrefix} from '../utils/package-manager.mjs';
29
30
  import {Project} from '../lib/project.mjs';
30
31
  import {
31
32
  CORE_PACKAGE,
@@ -339,6 +340,10 @@ export function registerSwizzle(program) {
339
340
  // Copy all non-test, non-doc, non-README files
340
341
  const files = fs.readdirSync(componentDir);
341
342
  let copied = 0;
343
+ // Track whether any copied source uses StyleX. Swizzled StyleX source
344
+ // needs a build-time StyleX compiler in the consumer's app or it renders
345
+ // unstyled with no error — so we surface a setup note after copying.
346
+ let usesStyleX = false;
342
347
 
343
348
  for (const file of files) {
344
349
  // Skip test files, doc files, and README
@@ -355,6 +360,13 @@ export function registerSwizzle(program) {
355
360
  content = rewriteImports(content, owner.ownerPackage);
356
361
  }
357
362
 
363
+ if (
364
+ (file.endsWith('.ts') || file.endsWith('.tsx')) &&
365
+ content.includes('@stylexjs/stylex')
366
+ ) {
367
+ usesStyleX = true;
368
+ }
369
+
358
370
  fs.writeFileSync(path.join(outputDir, file), content);
359
371
  copied++;
360
372
  }
@@ -376,6 +388,7 @@ export function registerSwizzle(program) {
376
388
  outputDir: relOutput,
377
389
  filesCopied: copied,
378
390
  files: copiedFiles.map(f => f),
391
+ usesStyleX,
379
392
  };
380
393
  if (feedback) payload.feedback = feedback;
381
394
  return jsonOut('swizzle.copy', payload);
@@ -387,6 +400,27 @@ export function registerSwizzle(program) {
387
400
  );
388
401
  humanLog('You can now customize the component source freely.\n');
389
402
 
403
+ // StyleX build requirement. Swizzled components ship raw StyleX source,
404
+ // which needs a build-time StyleX compiler in the consumer's app to
405
+ // produce atomic CSS. Without it the component compiles but renders
406
+ // unstyled, with no error — a confusing silent failure, so call it out.
407
+ if (usesStyleX) {
408
+ humanLog(
409
+ '⚠ These components use StyleX and require a StyleX compiler in your build.',
410
+ );
411
+ humanLog(
412
+ ' Without one they render unstyled (no error). See setup per framework:',
413
+ );
414
+ humanLog(` ${getRunPrefix()} astryx docs styling`);
415
+ humanLog(
416
+ ' Next.js note: the StyleX Babel plugin disables SWC and breaks next/font —',
417
+ );
418
+ humanLog(
419
+ ' use an SWC-based StyleX transform instead (covered in the guide).',
420
+ );
421
+ humanLog('');
422
+ }
423
+
390
424
  // Maintainer feedback note. If we couldn't swizzle cleanly, the team
391
425
  // wants to know — point users at the issue tracker. Skipped when the
392
426
  // owning package ships no issues URL.
@@ -277,3 +277,70 @@ describe('swizzle — ambiguous ownership', () => {
277
277
  expect(out).toContain(`from '@astryxdesign/core/theme'`);
278
278
  });
279
279
  });
280
+
281
+ /**
282
+ * Build a fake @astryxdesign/core with a component that imports StyleX directly
283
+ * (so the swizzle StyleX-build note should fire) and one that doesn't.
284
+ */
285
+ function buildStyleXCore(project) {
286
+ const core = path.join(project, 'node_modules', '@astryxdesign', 'core');
287
+ // StyleX component.
288
+ const styledDir = path.join(core, 'src', 'Styled');
289
+ fs.mkdirSync(styledDir, {recursive: true});
290
+ fs.writeFileSync(
291
+ path.join(core, 'package.json'),
292
+ '{"name":"@astryxdesign/core","version":"0.0.13"}',
293
+ );
294
+ fs.writeFileSync(
295
+ path.join(styledDir, 'Styled.tsx'),
296
+ [
297
+ `import * as stylex from '@stylexjs/stylex';`,
298
+ `const styles = stylex.create({base: {color: 'red'}});`,
299
+ `export const Styled = () => null;`,
300
+ '',
301
+ ].join('\n'),
302
+ );
303
+ // Plain component (no StyleX).
304
+ const plainDir = path.join(core, 'src', 'Plain');
305
+ fs.mkdirSync(plainDir, {recursive: true});
306
+ fs.writeFileSync(
307
+ path.join(plainDir, 'Plain.tsx'),
308
+ `export const Plain = () => null;\n`,
309
+ );
310
+ return core;
311
+ }
312
+
313
+ describe('swizzle — StyleX build setup note (#3373)', () => {
314
+ it('reports usesStyleX and prints a setup note for StyleX components', () => {
315
+ buildStyleXCore(project);
316
+ writeProjectPackageJson(project);
317
+
318
+ // JSON payload carries the machine-readable flag.
319
+ const jsonResult = runCli(['--json', 'swizzle', 'Styled', '-f'], project);
320
+ expect(jsonResult.code).toBe(0);
321
+ const env = JSON.parse(jsonResult.stdout);
322
+ expect(env.data.usesStyleX).toBe(true);
323
+
324
+ // Human output surfaces the compiler requirement + Next.js caveat.
325
+ const humanResult = runCli(['swizzle', 'Styled', '-f'], project);
326
+ expect(humanResult.code).toBe(0);
327
+ expect(humanResult.stdout).toMatch(/StyleX compiler/i);
328
+ expect(humanResult.stdout).toMatch(/unstyled/i);
329
+ expect(humanResult.stdout).toMatch(/next\/font/i);
330
+ expect(humanResult.stdout).toMatch(/astryx docs styling/);
331
+ });
332
+
333
+ it('does not print the StyleX note for components without StyleX', () => {
334
+ buildStyleXCore(project);
335
+ writeProjectPackageJson(project);
336
+
337
+ const jsonResult = runCli(['--json', 'swizzle', 'Plain', '-f'], project);
338
+ expect(jsonResult.code).toBe(0);
339
+ const env = JSON.parse(jsonResult.stdout);
340
+ expect(env.data.usesStyleX).toBe(false);
341
+
342
+ const humanResult = runCli(['swizzle', 'Plain', '-f'], project);
343
+ expect(humanResult.code).toBe(0);
344
+ expect(humanResult.stdout).not.toMatch(/StyleX compiler/i);
345
+ });
346
+ });
@@ -335,10 +335,13 @@ export function resolveImportPath(coreDir, componentName) {
335
335
  ? JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
336
336
  : null;
337
337
 
338
+ const exportKeys = Object.keys(pkg?.exports || {});
339
+
338
340
  // Priority 1: exact subpath export matching the component name (e.g. ./Heading)
339
341
  // This allows convenience re-export directories to win over the source directory.
340
- if (pkg?.exports?.[`./${componentName}`]) {
341
- return `@astryxdesign/core/${componentName}`;
342
+ const exactMatch = exportKeys.find(k => k.toLowerCase() === `./${componentName}`.toLowerCase());
343
+ if (exactMatch) {
344
+ return `@astryxdesign/core/${exactMatch.slice(2)}`;
342
345
  }
343
346
 
344
347
  const sourcePath = findComponentSource(coreDir, componentName);
@@ -348,8 +351,9 @@ export function resolveImportPath(coreDir, componentName) {
348
351
  const relToSrc = path.relative(srcDir, sourcePath);
349
352
  const topDir = relToSrc.split(path.sep)[0];
350
353
 
351
- if (pkg?.exports?.[`./${topDir}`]) {
352
- return `@astryxdesign/core/${topDir}`;
354
+ const topMatch = exportKeys.find(k => k.toLowerCase() === `./${topDir}`.toLowerCase());
355
+ if (topMatch) {
356
+ return `@astryxdesign/core/${topMatch.slice(2)}`;
353
357
  }
354
358
 
355
359
  return '@astryxdesign/core';
@@ -8,15 +8,10 @@ import {Center} from '@astryxdesign/core/Center';
8
8
  export default function AspectRatioCircleImage() {
9
9
  return (
10
10
  <Center width={300}>
11
- <AspectRatio ratio={1} shape="ellipse">
11
+ <AspectRatio ratio={1} shape="ellipse" fit="cover">
12
12
  <img
13
13
  src="https://lookaside.facebook.com/assets/astryx/light-home-square-1.png"
14
14
  alt="Circular image"
15
- style={{
16
- width: '100%',
17
- height: '100%',
18
- objectFit: 'cover',
19
- }}
20
15
  />
21
16
  </AspectRatio>
22
17
  </Center>
@@ -25,16 +25,11 @@ export default function AspectRatioImageGallery() {
25
25
  <Center width={600}>
26
26
  <Grid columns={3} gap={4} width="100%">
27
27
  {images.map(({id, alt}) => (
28
- <AspectRatio key={id} ratio={4 / 3}>
28
+ <AspectRatio key={id} ratio={4 / 3} fit="cover">
29
29
  <img
30
30
  src="https://lookaside.facebook.com/assets/astryx/illustrative-horizontal-1.png"
31
31
  alt={alt}
32
- style={{
33
- width: '100%',
34
- height: '100%',
35
- objectFit: 'cover',
36
- borderRadius: 8,
37
- }}
32
+ style={{borderRadius: 8}}
38
33
  />
39
34
  </AspectRatio>
40
35
  ))}
@@ -34,16 +34,13 @@ export default function AspectRatioShowcase() {
34
34
  <VStack key={label} gap={2} hAlign="center">
35
35
  <AspectRatio
36
36
  ratio={ratio}
37
+ fit="cover"
37
38
  style={{
38
39
  height: 120,
39
40
  width: 'auto',
40
41
  borderRadius: 'var(--radius-container)',
41
42
  }}>
42
- <img
43
- src={src}
44
- alt={alt}
45
- style={{width: '100%', height: '100%', objectFit: 'cover'}}
46
- />
43
+ <img src={src} alt={alt} />
47
44
  </AspectRatio>
48
45
  <Text type="supporting" color="secondary">
49
46
  {label}
@@ -8,15 +8,10 @@ import {Center} from '@astryxdesign/core/Center';
8
8
  export default function AspectRatioSquareImage() {
9
9
  return (
10
10
  <Center width={300}>
11
- <AspectRatio ratio={1}>
11
+ <AspectRatio ratio={1} fit="cover">
12
12
  <img
13
13
  src="https://lookaside.facebook.com/assets/astryx/light-home-square-1.png"
14
14
  alt="1:1 square"
15
- style={{
16
- width: '100%',
17
- height: '100%',
18
- objectFit: 'cover',
19
- }}
20
15
  />
21
16
  </AspectRatio>
22
17
  </Center>
@@ -8,15 +8,10 @@ import {Center} from '@astryxdesign/core/Center';
8
8
  export default function AspectRatioWidescreen() {
9
9
  return (
10
10
  <Center width={600}>
11
- <AspectRatio ratio={16 / 9}>
11
+ <AspectRatio ratio={16 / 9} fit="cover">
12
12
  <img
13
13
  src="https://lookaside.facebook.com/assets/astryx/light-scene-horizontal-1.png"
14
14
  alt="16:9 widescreen"
15
- style={{
16
- width: '100%',
17
- height: '100%',
18
- objectFit: 'cover',
19
- }}
20
15
  />
21
16
  </AspectRatio>
22
17
  </Center>
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('../../../../../core/src/docs-types').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'BaseTypeahead',
7
+ name: 'BaseTypeahead — Custom Search Bar',
8
+ displayName: 'BaseTypeahead — Custom Search Bar',
9
+ description:
10
+ 'BaseTypeahead embedded inside a custom-styled wrapper. The wrapper provides its own border and icon chrome; anchorRef positions the dropdown relative to it. Use this pattern when Typeahead\'s built-in field layout does not fit your composition.',
11
+ isReady: true,
12
+ aspectRatio: 16 / 9,
13
+ componentsUsed: ['BaseTypeahead', 'Icon', 'Layout', 'Text'],
14
+ };
@@ -0,0 +1,58 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useRef, useState} from 'react';
6
+ import {BaseTypeahead, createStaticSource} from '@astryxdesign/core/Typeahead';
7
+ import type {SearchableItem} from '@astryxdesign/core/Typeahead';
8
+ import {Icon} from '@astryxdesign/core/Icon';
9
+ import {HStack, VStack} from '@astryxdesign/core/Layout';
10
+ import {Text} from '@astryxdesign/core/Text';
11
+ import {MagnifyingGlassIcon} from '@heroicons/react/24/outline';
12
+
13
+ const frameworks: SearchableItem[] = [
14
+ {id: 'react', label: 'React'},
15
+ {id: 'vue', label: 'Vue'},
16
+ {id: 'angular', label: 'Angular'},
17
+ {id: 'svelte', label: 'Svelte'},
18
+ {id: 'solid', label: 'SolidJS'},
19
+ {id: 'remix', label: 'Remix'},
20
+ {id: 'next', label: 'Next.js'},
21
+ {id: 'nuxt', label: 'Nuxt'},
22
+ ];
23
+
24
+ const source = createStaticSource(frameworks);
25
+
26
+ export default function BaseTypeaheadCustomSearch() {
27
+ const [value, setValue] = useState<SearchableItem | null>(null);
28
+ const wrapperRef = useRef<HTMLElement>(null);
29
+
30
+ return (
31
+ <VStack gap={3} style={{width: 320}}>
32
+ <HStack
33
+ ref={wrapperRef}
34
+ gap={2}
35
+ vAlign="center"
36
+ style={{
37
+ border: '1px solid var(--color-border)',
38
+ borderRadius: 'var(--radius-control)',
39
+ padding: '6px 10px',
40
+ background: 'var(--color-surface)',
41
+ }}>
42
+ <Icon icon={MagnifyingGlassIcon} size="sm" color="secondary" />
43
+ <BaseTypeahead
44
+ searchSource={source}
45
+ value={value}
46
+ onChange={setValue}
47
+ anchorRef={wrapperRef}
48
+ placeholder="Search frameworks…"
49
+ hasEntriesOnFocus
50
+ debounceMs={0}
51
+ />
52
+ </HStack>
53
+ <Text type="supporting" color="secondary">
54
+ {value != null ? `Selected: ${value.label}` : 'No selection'}
55
+ </Text>
56
+ </VStack>
57
+ );
58
+ }
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('../../../../../core/src/docs-types').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'CodeBlock',
7
+ name: 'Code — Terminal',
8
+ displayName: 'Code — Terminal',
9
+ description:
10
+ 'A dark terminal-style command block: a bash CodeBlock wrapped in SyntaxTheme with the GitHub Dark preset, copy button on, and no line numbers. Use for shell sessions or CLI output that should read as a terminal even on light pages. Reach for a dark syntax preset instead of hand-rolling a dark box with custom CSS.',
11
+ isReady: true,
12
+ aspectRatio: 16 / 9,
13
+ componentsUsed: ['CodeBlock', 'SyntaxTheme'],
14
+ };
@@ -0,0 +1,24 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {SyntaxTheme} from '@astryxdesign/core/theme';
6
+ import {githubDark} from '@astryxdesign/core/theme/syntax';
7
+ import {CodeBlock} from '@astryxdesign/core/CodeBlock';
8
+
9
+ const commands = `$ astryx init --features agents
10
+ ✓ AI agent docs installed → .claude/CLAUDE.md
11
+ $ pnpm astryx component CodeBlock --dense`;
12
+
13
+ export default function CodeBlockTerminal() {
14
+ return (
15
+ <SyntaxTheme theme={githubDark}>
16
+ <CodeBlock
17
+ code={commands}
18
+ language="bash"
19
+ hasCopyButton
20
+ style={{width: '100%', maxWidth: 480}}
21
+ />
22
+ </SyntaxTheme>
23
+ );
24
+ }