@astryxdesign/cli 0.7.1 → 0.7.2-canary.151434a

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 (51) hide show
  1. package/api/component/component.test.mjs +420 -167
  2. package/api/component/list/list.mjs +42 -4
  3. package/api/integration/pack-check.mjs +10 -10
  4. package/api/search/search.mjs +8 -3
  5. package/api/search/search.test.mjs +36 -0
  6. package/api/template/table-filter-view-tabs.test.mjs +45 -0
  7. package/api/template/template.test.mjs +120 -3
  8. package/api/theme/build/build.core-on-demand.test.mjs +113 -0
  9. package/api/theme/build/build.d.mts +13 -13
  10. package/api/theme/build/build.family.test.mjs +16 -0
  11. package/api/theme/build/build.mjs +149 -55
  12. package/api/theme/themeBuild.doc.mjs +3 -3
  13. package/assets/codemods/transforms/next/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +120 -0
  14. package/assets/codemods/transforms/next/index.mjs +11 -1
  15. package/assets/codemods/transforms/next/migrate-list-edge-compensation-to-edge.mjs +198 -0
  16. package/assets/docs/working-with-ai.doc.mjs +43 -4
  17. package/assets/templates/blocks/components/Drawer/DrawerForm.doc.mjs +24 -0
  18. package/assets/templates/blocks/components/Drawer/DrawerForm.tsx +62 -0
  19. package/assets/templates/blocks/components/Drawer/DrawerScrim.doc.mjs +22 -0
  20. package/assets/templates/blocks/components/Drawer/DrawerScrim.tsx +68 -0
  21. package/assets/templates/blocks/components/Drawer/DrawerShowcase.doc.mjs +22 -0
  22. package/assets/templates/blocks/components/Drawer/DrawerShowcase.tsx +41 -0
  23. package/assets/templates/blocks/components/Drawer/DrawerStart.doc.mjs +21 -0
  24. package/assets/templates/blocks/components/Drawer/DrawerStart.tsx +41 -0
  25. package/assets/templates/blocks/components/Drawer/DrawerWidths.doc.mjs +22 -0
  26. package/assets/templates/blocks/components/Drawer/DrawerWidths.tsx +54 -0
  27. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.doc.mjs +15 -0
  28. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.tsx +73 -0
  29. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.doc.mjs +22 -0
  30. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.tsx +49 -0
  31. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.doc.mjs +21 -0
  32. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.tsx +42 -0
  33. package/assets/templates/pages/detail-page/page.tsx +3 -3
  34. package/assets/templates/pages/table-filter/page.tsx +3 -2
  35. package/assets/templates/pages/table-inbox/page.tsx +10 -8
  36. package/authoring/doctypes/base/type.ts +6 -0
  37. package/authoring/doctypes/component/component.doc.mjs +2 -2
  38. package/clients/cli/commands/build-theme.path-safety.test.mjs +84 -0
  39. package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
  40. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  41. package/clients/cli/lib/component-format.mjs +5 -1
  42. package/foundation/discovery/component-discovery.d.mts +12 -0
  43. package/foundation/discovery/component-discovery.mjs +211 -0
  44. package/foundation/discovery/component-discovery.test.mjs +96 -0
  45. package/foundation/discovery/template-adapter.mjs +74 -5
  46. package/foundation/doc-compiler/doc-loads.test.mjs +5 -1
  47. package/foundation/doc-compiler/inputs.mjs +23 -0
  48. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  49. package/foundation/xle/registry.mjs +4 -0
  50. package/foundation/xle/registry.test.mjs +28 -0
  51. package/package.json +10 -10
@@ -0,0 +1,42 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @input Controlled open state for a modal Drawer
7
+ * @output A Drawer whose DrawerHeader renders a close button because it receives onOpenChange
8
+ * @position Copyable DrawerHeader example
9
+ */
10
+
11
+ import {useState} from 'react';
12
+ import {Drawer, DrawerHeader} from '@astryxdesign/core/Drawer';
13
+ import {Button} from '@astryxdesign/core/Button';
14
+ import {Layout, LayoutContent} from '@astryxdesign/core/Layout';
15
+ import {Text} from '@astryxdesign/core/Text';
16
+
17
+ export default function DrawerHeaderWithCloseButton() {
18
+ const [isOpen, setIsOpen] = useState(false);
19
+
20
+ return (
21
+ <>
22
+ <Button label="Open drawer" onClick={() => setIsOpen(true)} />
23
+ <Drawer
24
+ isOpen={isOpen}
25
+ onOpenChange={setIsOpen}
26
+ label="Details"
27
+ width={360}>
28
+ <Layout
29
+ header={<DrawerHeader title="Details" onOpenChange={setIsOpen} />}
30
+ content={
31
+ <LayoutContent>
32
+ <Text type="body">
33
+ Passing onOpenChange renders the close button, which calls it
34
+ with false.
35
+ </Text>
36
+ </LayoutContent>
37
+ }
38
+ />
39
+ </Drawer>
40
+ </>
41
+ );
42
+ }
@@ -600,9 +600,9 @@ export default function DetailPage2Template() {
600
600
  }
601
601
  end={!isNarrow && showSidePanel ? <RightPanel /> : undefined}
602
602
  />
603
- {/* Mobile: the side panel content opens as a full-screen dialog. (A
604
- side drawer/sheet would be more idiomatic, but Astryx has no Drawer
605
- component yet — #2575 — so we use the fullscreen Dialog variant.) */}
603
+ {/* Mobile: the side-panel content uses the full viewport so order details
604
+ are not squeezed beside narrow page chrome. Drawer remains available
605
+ for side-overlay flows that intentionally preserve page context. */}
606
606
  <Dialog
607
607
  variant="fullscreen"
608
608
  isOpen={isNarrow && isPanelDialogOpen}
@@ -4099,7 +4099,7 @@ export default function TableFilterTemplate() {
4099
4099
  restates the selected tab word for word, and the strip already
4100
4100
  marks which one that is. On a phone that is a line of vertical
4101
4101
  space spent saying it twice. The panel keeps the name for anyone
4102
- not seeing the strip, as its accessible label. */}
4102
+ not seeing the strip: its selected tab labels it. */}
4103
4103
  <TabList
4104
4104
  value={viewSection}
4105
4105
  onChange={value => setViewSection(value as ViewSection)}
@@ -4109,6 +4109,7 @@ export default function TableFilterTemplate() {
4109
4109
  {VIEW_SECTIONS.map(section => (
4110
4110
  <Tab
4111
4111
  key={section.key}
4112
+ id={`${viewPanelId}-tab-${section.key}`}
4112
4113
  value={section.key}
4113
4114
  label={section.label}
4114
4115
  icon={section.icon}
@@ -4126,7 +4127,7 @@ export default function TableFilterTemplate() {
4126
4127
  gap={0}
4127
4128
  id={viewPanelId}
4128
4129
  role="tabpanel"
4129
- aria-label={activeSection?.title}
4130
+ aria-labelledby={`${viewPanelId}-tab-${viewSection}`}
4130
4131
  paddingBlockStart={3}>
4131
4132
  {viewPanelBody()}
4132
4133
  </VStack>
@@ -1652,8 +1652,8 @@ const COMPOSER_TOOLS: {
1652
1652
  /**
1653
1653
  * The compose sheet.
1654
1654
  *
1655
- * **`BottomSheet hasScrim={false}`, which is the only non-modal surface in
1656
- * core.** With the scrim off the sheet opens with `show()` rather than
1655
+ * **`BottomSheet hasScrim={false}` keeps this bottom-edge composer non-modal.**
1656
+ * With the scrim off the sheet opens with `show()` rather than
1657
1657
  * `showModal()`, so it never enters the top layer, never makes the page inert
1658
1658
  * and never locks body scroll: the inbox behind it stays live. That matters
1659
1659
  * more here than anywhere else in this template, because writing a message is
@@ -1661,12 +1661,14 @@ const COMPOSER_TOOLS: {
1661
1661
  * actually said, copy an order number out of a thread. A modal composer
1662
1662
  * answers that with "close me first".
1663
1663
  *
1664
- * The trade is position, and it is worth naming. A sheet rises from the bottom
1665
- * edge, centred: its positioner is `inset-inline: 0` with
1666
- * `justify-content: center`, and there is no anchor, side or width prop. So
1667
- * this cannot be docked to the inline-end corner the way a `Dialog` can be.
1668
- * `Dialog` takes a static `position` and would put the window in that corner —
1669
- * but `Dialog` is always modal, so buying the corner costs the live inbox.
1664
+ * The trade is bottom-edge geometry, and it is worth naming. A non-modal
1665
+ * `Drawer` keeps page context live from an inline edge, but it is a full-height
1666
+ * side panel; this composer intentionally rises from the bottom. A sheet's
1667
+ * positioner is `inset-inline: 0` with `justify-content: center`, and there is
1668
+ * no anchor, side or width prop. So this cannot be docked to the inline-end
1669
+ * corner the way a `Dialog` can be. `Dialog` takes a static `position` and would
1670
+ * put the window in that corner — but `Dialog` is always modal, so buying the
1671
+ * corner costs the live inbox.
1670
1672
  * `ChatComposerDrawer` is a false friend: despite the name it is an in-flow
1671
1673
  * disclosure tray for a ChatComposer's attachments, with no positioning of its
1672
1674
  * own.
@@ -383,6 +383,12 @@ export interface ComponentPropDoc {
383
383
  * ```
384
384
  */
385
385
  slotElements?: ComponentSlotElement[];
386
+ /** Lifecycle marker for a prop outside the stable compatibility promise
387
+ * (spec:AST-017 FR21). Set `'experimental'` on a stable component's
388
+ * optional `experimental` prop object, and say in `description` that its
389
+ * contents may change or be removed in a patch release. Omit for stable
390
+ * props. */
391
+ stability?: 'experimental';
386
392
  }
387
393
 
388
394
  /**
@@ -56,7 +56,7 @@ export const doc = {
56
56
  name: 'replaces',
57
57
  type: 'string',
58
58
  description:
59
- "Integration components only: the exact `name` of the Core ComponentDoc this component takes over for unqualified lookup, so every app that loads the integration gets it from component detail, component lists, search, `swizzle <Name>`, and issue routing; `swizzle --list` keeps listing Core names. The Core original stays reachable with `--package @astryxdesign/core`. It takes effect only when the package's peer range starts at the release that applies it, `\"@astryxdesign/cli\": \">=0.6.7\"` or later; without such a range the component keeps its own name and `doctor integration components` warns. Set it only to intentionally own a Core identity; give an alternative or variant its own name instead.",
59
+ 'Integration components only: the exact `name` of the Core ComponentDoc this component takes over for unqualified lookup, so every app that loads the integration gets it from component detail, component lists, search, `swizzle <Name>`, and issue routing; `swizzle --list` keeps listing Core names. The Core original stays reachable with `--package @astryxdesign/core`. It takes effect only when the package\'s peer range starts at the release that applies it, `"@astryxdesign/cli": ">=0.6.7"` or later; without such a range the component keeps its own name and `doctor integration components` warns. Set it only to intentionally own a Core identity; give an alternative or variant its own name instead.',
60
60
  },
61
61
  {
62
62
  name: 'keywords',
@@ -181,7 +181,7 @@ export const doc = {
181
181
  name: 'props',
182
182
  type: 'ComponentPropDoc[]',
183
183
  description:
184
- 'SingleComponentDoc variant (required there): all public props for the one primary component. Each prop is {name, type, description, default?, required?, slotElements?}. Skip styling props like xstyle/className/style. Also present on SubComponentDoc.',
184
+ 'SingleComponentDoc variant (required there): all public props for the one primary component. Each prop is {name, type, description, default?, required?, slotElements?, stability?}. Skip styling props like xstyle/className/style. Also present on SubComponentDoc.',
185
185
  },
186
186
  {
187
187
  name: 'components',
@@ -9,6 +9,9 @@
9
9
  * - Multi-file write is atomic: if one file fails, none are left behind.
10
10
  * - An `--out` escape, or an output directory that cannot be created, fails
11
11
  * with a registered error code.
12
+ * - Every output stays inside the working directory: an absolute `--out`
13
+ * path or a theme file outside it fails before anything is written, while
14
+ * absolute paths inside it build, also through a symlinked spelling.
12
15
  *
13
16
  * Runs the CLI in-process (shared runCli harness) against a tiny synthetic theme file.
14
17
  */
@@ -129,6 +132,68 @@ describe('theme build output-path failures carry registered codes', () => {
129
132
  expect(fs.existsSync(path.join(tmpDir, 'escaped.css'))).toBe(false);
130
133
  });
131
134
 
135
+ it('reports an absolute --out path outside the project as ERR_PATH_TRAVERSAL, with --check too', async () => {
136
+ const project = path.join(tmpDir, 'project');
137
+ const outside = path.join(tmpDir, 'outside');
138
+ fs.mkdirSync(outside, {recursive: true});
139
+ const themeFile = writeTheme(path.join(project, 'themes'), 'ocean');
140
+ const out = path.join(outside, 'ocean.css');
141
+
142
+ for (const extra of [[], ['--check']]) {
143
+ const {result, envelope} = await buildJson(
144
+ [path.relative(project, themeFile), '--out', out, ...extra],
145
+ project,
146
+ );
147
+
148
+ expect(result.code).toBe(1);
149
+ expect(envelope.code).toBe(ERROR_CODES.ERR_PATH_TRAVERSAL);
150
+ }
151
+ expect(fs.readdirSync(outside)).toEqual([]);
152
+ });
153
+
154
+ it('reports a theme file outside the project as ERR_PATH_TRAVERSAL, because its outputs go beside it', async () => {
155
+ const project = path.join(tmpDir, 'project');
156
+ fs.mkdirSync(project, {recursive: true});
157
+ const shared = path.join(tmpDir, 'shared');
158
+ const themeFile = writeTheme(shared, 'ocean');
159
+
160
+ for (const file of [themeFile, path.relative(project, themeFile)]) {
161
+ const {result, envelope} = await buildJson([file], project);
162
+
163
+ expect(result.code).toBe(1);
164
+ expect(envelope.code).toBe(ERROR_CODES.ERR_PATH_TRAVERSAL);
165
+ }
166
+ expect(fs.readdirSync(shared)).toEqual(['theme.mjs']);
167
+ });
168
+
169
+ it('builds absolute paths inside the project, also when they reach it through a symlink', async () => {
170
+ const project = path.join(tmpDir, 'project');
171
+ const themeFile = writeTheme(path.join(project, 'themes'), 'ocean');
172
+ const alias = path.join(tmpDir, 'alias');
173
+ fs.symlinkSync(project, alias, 'dir');
174
+
175
+ for (const [args, written] of [
176
+ [
177
+ [themeFile, '--out', path.join(project, 'dist', 'direct.css')],
178
+ path.join(project, 'dist', 'direct.css'),
179
+ ],
180
+ [
181
+ [themeFile, '--out', path.join(alias, 'dist', 'aliased.css')],
182
+ path.join(project, 'dist', 'aliased.css'),
183
+ ],
184
+ [
185
+ [path.join(alias, 'themes', 'theme.mjs')],
186
+ path.join(project, 'themes', 'ocean.css'),
187
+ ],
188
+ ]) {
189
+ const {result, envelope} = await buildJson(args, project);
190
+
191
+ expect(result.code).toBe(0);
192
+ expect(envelope.type).toBe('theme.build');
193
+ expect(fs.existsSync(written)).toBe(true);
194
+ }
195
+ });
196
+
132
197
  it('reports an --out path that escapes through a symlink as ERR_PATH_TRAVERSAL', async () => {
133
198
  const project = path.join(tmpDir, 'project');
134
199
  const outside = path.join(tmpDir, 'outside');
@@ -177,4 +242,23 @@ describe('theme build output-path failures carry registered codes', () => {
177
242
  code: ERROR_CODES.ERR_PATH_TRAVERSAL,
178
243
  });
179
244
  });
245
+
246
+ it('themeBuild() rejects an output outside cwd: an absolute out path, or the default beside a theme file outside cwd', async () => {
247
+ const project = path.join(tmpDir, 'project');
248
+ const inside = writeTheme(path.join(project, 'themes'), 'ocean');
249
+ const shared = path.join(tmpDir, 'shared');
250
+ const outsideTheme = writeTheme(shared, 'ocean');
251
+ const outDir = path.join(tmpDir, 'out');
252
+
253
+ for (const [file, options] of [
254
+ [path.relative(project, inside), {out: path.join(outDir, 'ocean.css')}],
255
+ [outsideTheme, {}],
256
+ ]) {
257
+ await expect(
258
+ themeBuild(file, options, {cwd: project}),
259
+ ).rejects.toMatchObject({code: ERROR_CODES.ERR_PATH_TRAVERSAL});
260
+ }
261
+ expect(fs.existsSync(outDir)).toBe(false);
262
+ expect(fs.readdirSync(shared)).toEqual(['theme.mjs']);
263
+ });
180
264
  });
@@ -126,7 +126,10 @@ describe('theme build emits a live TextInput selector (#4109)', () => {
126
126
  `};\n`,
127
127
  );
128
128
 
129
- const result = await runCli(['theme', 'build', themeFile, '-o', outFile]);
129
+ const result = await runCli(
130
+ ['theme', 'build', themeFile, '-o', outFile],
131
+ tmpDir,
132
+ );
130
133
  const css = fs.readFileSync(outFile, 'utf8');
131
134
 
132
135
  expect(result.status).toBe(0);
@@ -148,7 +151,7 @@ describe('theme build emits a live TextInput selector (#4109)', () => {
148
151
  `};\n`,
149
152
  );
150
153
 
151
- await runCli(['theme', 'build', themeFile, '-o', outFile]);
154
+ await runCli(['theme', 'build', themeFile, '-o', outFile], tmpDir);
152
155
  const css = fs.readFileSync(outFile, 'utf8');
153
156
 
154
157
  expect(css).toContain('.astryx-text-input');
@@ -30,7 +30,7 @@ export const doc = {
30
30
  {
31
31
  flag: '--family',
32
32
  description:
33
- 'Build the selected extension family into one keyed CSS, JS, and declaration set. Requires --family-key; refused with --out or --watch (ERR_THEME_INVALID)',
33
+ 'Build the selected extension family into one keyed CSS, JS, and declaration set, written beside the family root theme file, which must be inside the working directory (ERR_PATH_TRAVERSAL). Requires --family-key; refused with --out or --watch (ERR_THEME_INVALID)',
34
34
  },
35
35
  {
36
36
  flag: '--family-key <key>',
@@ -41,7 +41,7 @@ export const doc = {
41
41
  flag: '-o, --out <path>',
42
42
  param: 'options.out',
43
43
  description:
44
- 'Output CSS file path; the .js and .d.ts are written beside it (default: <theme name>.css next to the source). A relative path must stay inside the working directory. Single theme only: refused with more than one file or with --family (ERR_THEME_INVALID)',
44
+ 'Output CSS file path, relative or absolute; the .js and .d.ts are written beside it (default: <theme name>.css next to the source). Every output must resolve inside the working directory, the defaults beside the source too (ERR_PATH_TRAVERSAL). Single theme only: refused with more than one file or with --family (ERR_THEME_INVALID)',
45
45
  },
46
46
  {
47
47
  flag: '--icons-specifier <specifier>',
@@ -68,8 +68,12 @@ function formatPropsTable(props) {
68
68
  for (const p of props) {
69
69
  const def = p.default ? `\`${mdCell(p.default)}\`` : '-';
70
70
  const req = p.required ? ' **(required)**' : '';
71
+ // The text projection of the prop doc's `stability` field: an
72
+ // experimental prop is outside the stable compatibility promise.
73
+ const stability =
74
+ p.stability === 'experimental' ? ' **(experimental)**' : '';
71
75
  lines.push(
72
- `| \`${mdCell(p.name)}\` | \`${mdCell(p.type)}\` | ${def} | ${mdCell(p.description)}${req} |`,
76
+ `| \`${mdCell(p.name)}\` | \`${mdCell(p.type)}\` | ${def} | ${mdCell(p.description)}${req}${stability} |`,
73
77
  );
74
78
  }
75
79
  return lines.join('\n');
@@ -1,8 +1,20 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * The entry a family doc gives `name` in its `components`, when the doc is not
6
+ * the component's own (Stack's doc for VStack); null otherwise.
7
+ * @param {any} docs - a loaded component doc
8
+ * @param {string} name - bare component name
9
+ * @returns {any}
10
+ */
11
+ export function familyMember(docs: any, name: string): any;
4
12
  /**
5
13
  * Auto-discover components by scanning for Astryx*.tsx files in core/src/.
14
+ * A component is listed when a doc documents it: a doc in its folder, or, for a
15
+ * component folder with no doc of its own, the doc `findComponentReadme` finds
16
+ * elsewhere (Heading's doc in the Text folder; HStack and VStack as members of
17
+ * Stack's doc).
6
18
  *
7
19
  * Returns an ordered Record where:
8
20
  * - Grouped components use the group name as key: `'Buttons': ['Button', 'IconButton']`
@@ -5,12 +5,15 @@
5
5
  */
6
6
 
7
7
  import * as fs from 'node:fs';
8
+ import {createRequire} from 'node:module';
8
9
  import * as path from 'node:path';
9
10
  import {listDir, listDirEntries, pathExists} from '../fs/listing-cache.mjs';
10
11
  import {existsCaseExact} from '../fs/paths.mjs';
11
12
  import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
12
13
  import {loadComponentDoc} from './component-loader.mjs';
13
14
 
15
+ const require = createRequire(import.meta.url);
16
+
14
17
  const SKIP_DIRS = new Set(['hooks', 'utils', '__tests__', 'node_modules']);
15
18
 
16
19
  /** The owner package name for built-in (core) components. */
@@ -109,8 +112,193 @@ function readDocMeta(docPath) {
109
112
  }
110
113
  }
111
114
 
115
+ /** @type {typeof import('@babel/parser') | undefined} */
116
+ let babelParser;
117
+
118
+ /**
119
+ * A property of an object literal, by its plain key.
120
+ * @param {any} object - an ObjectExpression node
121
+ * @param {string} key
122
+ * @returns {any}
123
+ */
124
+ function propertyValue(object, key) {
125
+ for (const property of object.properties) {
126
+ if (property.type !== 'ObjectProperty' || property.computed) continue;
127
+ const name =
128
+ property.key.type === 'Identifier'
129
+ ? property.key.name
130
+ : property.key.type === 'StringLiteral'
131
+ ? property.key.value
132
+ : null;
133
+ if (name === key) return property.value;
134
+ }
135
+ return null;
136
+ }
137
+
138
+ /**
139
+ * The names a component doc lists as `components` members, read from its
140
+ * source without running it. Only a static `{name: '<Name>'}` entry in the doc
141
+ * object the loader reads (the `default` export, else `docs`) counts: a name in
142
+ * prose, an example, or `relatedComponents` is not a member.
143
+ * @param {string} source - the doc file's text
144
+ * @returns {string[]}
145
+ */
146
+ function docMemberNames(source) {
147
+ /** @type {any} */
148
+ let ast;
149
+ try {
150
+ babelParser ??= require('@babel/parser');
151
+ ast = /** @type {typeof import('@babel/parser')} */ (babelParser).parse(source, {
152
+ sourceType: 'module',
153
+ });
154
+ } catch {
155
+ return [];
156
+ }
157
+ /** @type {Map<string, any>} */
158
+ const constants = new Map();
159
+ let defaultExport = null;
160
+ let docsExport = null;
161
+ for (const node of ast.program.body) {
162
+ const declaration =
163
+ node.type === 'ExportNamedDeclaration' ? node.declaration : node;
164
+ if (declaration?.type === 'VariableDeclaration') {
165
+ for (const declarator of declaration.declarations) {
166
+ if (declarator.id.type !== 'Identifier' || !declarator.init) continue;
167
+ constants.set(declarator.id.name, declarator.init);
168
+ if (node.type === 'ExportNamedDeclaration' && declarator.id.name === 'docs') {
169
+ docsExport = declarator.init;
170
+ }
171
+ }
172
+ }
173
+ if (node.type === 'ExportDefaultDeclaration') defaultExport = node.declaration;
174
+ }
175
+ let doc = defaultExport ?? docsExport;
176
+ if (doc?.type === 'Identifier') doc = constants.get(doc.name);
177
+ if (doc?.type !== 'ObjectExpression') return [];
178
+ const members = propertyValue(doc, 'components');
179
+ if (members?.type !== 'ArrayExpression') return [];
180
+ return members.elements.flatMap((/** @type {any} */ element) => {
181
+ if (element?.type !== 'ObjectExpression') return [];
182
+ const name = propertyValue(element, 'name');
183
+ return name?.type === 'StringLiteral' ? [name.value] : [];
184
+ });
185
+ }
186
+
187
+ /**
188
+ * Whether `name` has its own component folder in Core: `src/<Name>/<Name>.tsx`
189
+ * (or the `XDS`-prefixed form).
190
+ * @param {string} srcDir
191
+ * @param {string} name
192
+ * @returns {boolean}
193
+ */
194
+ function hasOwnFolder(srcDir, name) {
195
+ return [`${name}.tsx`, `XDS${name}.tsx`].some(file =>
196
+ existsCaseExact(path.join(srcDir, name, file), srcDir),
197
+ );
198
+ }
199
+
200
+ /**
201
+ * Member names read in this process, by doc path, reused while the file keeps
202
+ * its size and mtime.
203
+ * @type {Map<string, {size: number, mtimeMs: number, members: string[]}>}
204
+ */
205
+ const memberReads = new Map();
206
+
207
+ /**
208
+ * The names a doc lists as `components` members (see docMemberNames).
209
+ * @param {string} docPath
210
+ * @returns {string[]}
211
+ */
212
+ function readDocMembers(docPath) {
213
+ let stat;
214
+ try {
215
+ stat = fs.statSync(docPath);
216
+ } catch {
217
+ return [];
218
+ }
219
+ const cached = memberReads.get(docPath);
220
+ if (cached && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs) {
221
+ return cached.members;
222
+ }
223
+ /** @type {string[]} */
224
+ let members;
225
+ try {
226
+ members = docMemberNames(fs.readFileSync(docPath, 'utf-8'));
227
+ } catch {
228
+ members = [];
229
+ }
230
+ memberReads.set(docPath, {size: stat.size, mtimeMs: stat.mtimeMs, members});
231
+ return members;
232
+ }
233
+
234
+ // A sibling component folder named by a relative import or re-export.
235
+ const SIBLING_IMPORT_RE =
236
+ /(?:\bfrom|\bimport\s*\()\s*['"]\.\.\/([A-Za-z0-9_-]+)(?:\/[^'"]*)?['"]/g;
237
+
238
+ /**
239
+ * The Core doc that documents `name` as one of its `components` members: the
240
+ * doc of a component it builds on. HStack and VStack import Stack, and Stack's
241
+ * doc lists them, so each has its own folder and import path but no doc of its
242
+ * own. Only the folders the component's own source imports from are read.
243
+ * @param {string} srcDir
244
+ * @param {string} name
245
+ * @returns {string | null}
246
+ */
247
+ function findFamilyDoc(srcDir, name) {
248
+ const sourcePath = [`${name}.tsx`, `XDS${name}.tsx`]
249
+ .map(file => path.join(srcDir, name, file))
250
+ .find(file => existsCaseExact(file, srcDir));
251
+ if (!sourcePath) return null;
252
+ let source;
253
+ try {
254
+ source = fs.readFileSync(sourcePath, 'utf-8');
255
+ } catch {
256
+ return null;
257
+ }
258
+ const families = [
259
+ ...new Set([...source.matchAll(SIBLING_IMPORT_RE)].map(match => match[1])),
260
+ ]
261
+ .filter(dir => dir !== name && !SKIP_DIRS.has(dir))
262
+ .sort();
263
+ for (const dir of families) {
264
+ const dirPath = path.join(srcDir, dir);
265
+ if (!existsCaseExact(dirPath, srcDir)) continue;
266
+ for (const file of [...listDir(dirPath)].sort()) {
267
+ if (!file.endsWith('.doc.mjs')) continue;
268
+ const docPath = path.join(dirPath, file);
269
+ const members = readDocMembers(docPath);
270
+ if (members.includes(name) || members.includes(`XDS${name}`)) {
271
+ return docPath;
272
+ }
273
+ }
274
+ }
275
+ return null;
276
+ }
277
+
278
+ /**
279
+ * The entry a family doc gives `name` in its `components`, when the doc is not
280
+ * the component's own (Stack's doc for VStack); null otherwise.
281
+ * @param {any} docs - a loaded component doc
282
+ * @param {string} name - bare component name
283
+ * @returns {any}
284
+ */
285
+ export function familyMember(docs, name) {
286
+ if (!docs || docs.name === name || docs.name === `XDS${name}`) return null;
287
+ const members = Array.isArray(docs.components) ? docs.components : [];
288
+ return (
289
+ members.find(
290
+ (/** @type {any} */ member) =>
291
+ member?.name === name || member?.name === `XDS${name}`,
292
+ ) ?? null
293
+ );
294
+ }
295
+
112
296
  /**
113
297
  * Auto-discover components by scanning for Astryx*.tsx files in core/src/.
298
+ * A component is listed when a doc documents it: a doc in its folder, or, for a
299
+ * component folder with no doc of its own, the doc `findComponentReadme` finds
300
+ * elsewhere (Heading's doc in the Text folder; HStack and VStack as members of
301
+ * Stack's doc).
114
302
  *
115
303
  * Returns an ordered Record where:
116
304
  * - Grouped components use the group name as key: `'Buttons': ['Button', 'IconButton']`
@@ -192,6 +380,25 @@ export function discoverComponents(coreDir) {
192
380
  }
193
381
  }
194
382
 
383
+ // A component folder with no doc in it is still listed when a doc elsewhere
384
+ // documents it, the doc `component <Name>` opens: its own same-stem doc in a
385
+ // family folder (Text/Heading.doc.mjs), or a member entry in the family's doc
386
+ // (HStack and VStack in Stack's doc).
387
+ for (const entry of topEntries) {
388
+ if (!entry.isDirectory() || SKIP_DIRS.has(entry.name)) continue;
389
+ const name = entry.name;
390
+ if (componentGroups.has(name) || name.endsWith('Context')) continue;
391
+ if (listDir(path.join(srcDir, name)).some(file => file.endsWith('.doc.mjs'))) {
392
+ continue;
393
+ }
394
+ if (!hasOwnFolder(srcDir, name)) continue;
395
+ const docPath = findComponentReadme(coreDir, name);
396
+ if (!docPath?.endsWith('.doc.mjs')) continue;
397
+ const meta = readDocMeta(docPath);
398
+ if (meta.hidden || meta.hiddenComponents.has(name)) continue;
399
+ componentGroups.set(name, meta.group);
400
+ }
401
+
195
402
  // Build the result: group name → sorted members, or component name → [self]
196
403
  /** @type {Map<string, string[]>} */
197
404
  const groups = new Map();
@@ -284,6 +491,10 @@ export function findComponentReadme(coreDir, name) {
284
491
  }
285
492
  }
286
493
 
494
+ // A component with its own folder, documented as a member of its family's
495
+ // doc (HStack and VStack in Stack's doc).
496
+ if (hasOwnFolder(srcDir, name)) return findFamilyDoc(srcDir, name);
497
+
287
498
  return null;
288
499
  }
289
500