@astryxdesign/cli 0.1.6-canary.fec872b → 0.1.6

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 (54) hide show
  1. package/package.json +9 -13
  2. package/src/api/template.mjs +28 -104
  3. package/src/api/validate-integration.mjs +8 -0
  4. package/src/codemods/__tests__/registry.test.mjs +0 -1
  5. package/src/codemods/registry.mjs +0 -1
  6. package/src/config.mjs +14 -5
  7. package/src/integration.mjs +15 -4
  8. package/src/lib/component-discovery.mjs +5 -15
  9. package/src/lib/component-format.mjs +13 -45
  10. package/src/lib/component-format.test.mjs +1 -95
  11. package/src/lib/component-loader.mjs +2 -104
  12. package/src/lib/config-schema.mjs +30 -0
  13. package/src/lib/hook-format.mjs +3 -8
  14. package/src/lib/xle/registry.mjs +5 -0
  15. package/src/template.mjs +67 -9
  16. package/src/types/config.d.ts +66 -11
  17. package/src/types/integration.d.ts +18 -7
  18. package/src/types/template-api.d.ts +50 -14
  19. package/templates/blocks/components/Avatar/AvatarGroup.tsx +7 -5
  20. package/templates/blocks/components/Avatar/AvatarShowcase.tsx +6 -4
  21. package/templates/blocks/components/Avatar/AvatarUserCard.tsx +5 -3
  22. package/templates/blocks/components/Avatar/AvatarWithImage.tsx +6 -8
  23. package/templates/blocks/components/Avatar/AvatarWithStatus.tsx +5 -3
  24. package/templates/blocks/components/ChatComposerInput/ChatComposerInputControlledInput.tsx +1 -1
  25. package/templates/blocks/components/ChatComposerInput/ChatComposerInputDisabled.tsx +1 -1
  26. package/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +1 -1
  27. package/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +1 -1
  28. package/templates/blocks/components/ChatComposerInput/ChatComposerInputShowcase.tsx +1 -1
  29. package/templates/blocks/components/ChatComposerInput/ChatComposerInputSlashCommands.tsx +1 -1
  30. package/templates/pages/ide/page.tsx +41 -35
  31. package/templates/pages/theme-showcase/page.tsx +7 -7
  32. package/templates/themes/neutral/neutralTheme.ts +32 -63
  33. package/docs/integration-authoring.md +0 -105
  34. package/docs/internationalization.doc.mjs +0 -243
  35. package/src/api/integration-block-exports.test.mjs +0 -240
  36. package/src/api/template-suffix.test.mjs +0 -246
  37. package/src/codemods/transforms/v0.1.7/__tests__/migrate-table-tableprops-to-direct-props.test.mjs +0 -120
  38. package/src/codemods/transforms/v0.1.7/index.mjs +0 -19
  39. package/src/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +0 -188
  40. package/src/doc.mjs +0 -27
  41. package/src/doc.test.mjs +0 -383
  42. package/src/lib/component-discovery.importpath.test.mjs +0 -59
  43. package/src/lib/componentDocOverlay.test.mjs +0 -111
  44. package/src/schemas/doc-schema.mjs +0 -226
  45. package/src/schemas/template-schema.mjs +0 -47
  46. package/src/types/doc.d.ts +0 -23
  47. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.doc.mjs +0 -14
  48. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.tsx +0 -41
  49. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +0 -13
  50. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +0 -78
  51. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.doc.mjs +0 -14
  52. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.tsx +0 -38
  53. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +0 -14
  54. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +0 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.1.6-canary.fec872b",
3
+ "version": "0.1.6",
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",
@@ -47,10 +47,6 @@
47
47
  "types": "./src/types/integration.d.ts",
48
48
  "import": "./src/integration.mjs"
49
49
  },
50
- "./doc": {
51
- "types": "./src/types/doc.d.ts",
52
- "import": "./src/doc.mjs"
53
- },
54
50
  "./template": {
55
51
  "types": "./src/types/template-api.d.ts",
56
52
  "import": "./src/template.mjs"
@@ -79,10 +75,10 @@
79
75
  "zod": "^4.4.3"
80
76
  },
81
77
  "peerDependencies": {
82
- "@astryxdesign/charts": "0.1.6-canary.fec872b",
83
- "@astryxdesign/core": "0.1.6-canary.fec872b",
84
- "@astryxdesign/lab": "0.1.6-canary.fec872b",
85
- "@astryxdesign/theme-neutral": "0.1.6-canary.fec872b",
78
+ "@astryxdesign/charts": "*",
79
+ "@astryxdesign/core": "*",
80
+ "@astryxdesign/lab": "*",
81
+ "@astryxdesign/theme-neutral": "*",
86
82
  "gpt-tokenizer": "^3.4.0"
87
83
  },
88
84
  "peerDependenciesMeta": {
@@ -100,10 +96,10 @@
100
96
  }
101
97
  },
102
98
  "devDependencies": {
103
- "@astryxdesign/charts": "0.1.6-canary.fec872b",
104
- "@astryxdesign/core": "0.1.6-canary.fec872b",
105
- "@astryxdesign/lab": "0.1.6-canary.fec872b",
106
- "@astryxdesign/theme-neutral": "0.1.6-canary.fec872b",
99
+ "@astryxdesign/charts": "*",
100
+ "@astryxdesign/core": "*",
101
+ "@astryxdesign/lab": "*",
102
+ "@astryxdesign/theme-neutral": "*",
107
103
  "gpt-tokenizer": "^3.4.0"
108
104
  },
109
105
  "scripts": {
@@ -6,9 +6,8 @@
6
6
 
7
7
  import * as fs from 'node:fs';
8
8
  import * as path from 'node:path';
9
- import {createJiti} from 'jiti';
10
9
  import {loadModuleWithSchema} from '../lib/module-loader.mjs';
11
- import {TemplateEnvelopeSchema} from '../schemas/template-schema.mjs';
10
+ import {TemplateEnvelopeSchema} from '../template.mjs';
12
11
  import {CLI_ROOT, discoverExternalPackages} from '../utils/paths.mjs';
13
12
  import {
14
13
  assertWithin,
@@ -22,54 +21,9 @@ import {Project} from '../lib/project.mjs';
22
21
  /** Identity used for core (built-in) templates in package-scoped listings. */
23
22
  const CORE_PACKAGE = '@astryxdesign/core';
24
23
 
25
- /**
26
- * Canonical basename suffixes for template-spec files, in precedence order.
27
- * A template spec exports a `createBlockTemplate`/`createPageTemplate` result
28
- * (a scaffoldable TEMPLATE), so `.template.*` is the descriptive family name.
29
- */
30
- const TEMPLATE_SUFFIXES = ['.template.ts', '.template.mjs', '.template.js'];
31
-
32
- /**
33
- * Legacy basename suffixes for template-spec files, in precedence order.
34
- * `.doc.*` was inherited from the component-doc convention before templates
35
- * had their own name; it is still accepted during the transition window.
36
- */
24
+ /** Doc-file basename suffixes for integration templates, in precedence order. */
37
25
  const DOC_SUFFIXES = ['.doc.ts', '.doc.mjs', '.doc.js'];
38
26
 
39
- /**
40
- * The union of canonical + legacy template-spec suffixes, canonical first so
41
- * `.template.*` wins over `.doc.*` when both stems exist. All template
42
- * discovery matches this union so a `Foo.template.ts` file is treated exactly
43
- * like a legacy `Foo.doc.mjs`.
44
- */
45
- const ALL_TEMPLATE_SUFFIXES = [...TEMPLATE_SUFFIXES, ...DOC_SUFFIXES];
46
-
47
- /**
48
- * The template-spec suffix present on `file`, or null if none matches.
49
- * Recognizes both the canonical `.template.*` and legacy `.doc.*` families.
50
- * @param {string} file
51
- * @returns {string | null}
52
- */
53
- function matchedTemplateSuffix(file) {
54
- return ALL_TEMPLATE_SUFFIXES.find(suffix => file.endsWith(suffix)) ?? null;
55
- }
56
-
57
- /**
58
- * RegExp matching either template-spec suffix family at end of a basename.
59
- * Used where a per-file regex is convenient (e.g. block discovery walks).
60
- */
61
- const TEMPLATE_SUFFIX_RE = /\.(template|doc)\.(ts|mjs|js)$/;
62
-
63
- let jitiInstance;
64
- /** Lazily-created jiti for loading `.ts` template specs (JSX-capable). */
65
- function getJiti() {
66
- if (!jitiInstance) {
67
- jitiInstance = createJiti(import.meta.url, {jsx: true});
68
- }
69
- return jitiInstance;
70
- }
71
-
72
-
73
27
  /**
74
28
  * Load an integration template doc module and validate it against the template
75
29
  * envelope at the load boundary. Default export only — `.ts` via jiti,
@@ -133,29 +87,12 @@ export function stripTemplateAssetRefs(source) {
133
87
  source,
134
88
  );
135
89
  }
136
- /**
137
- * Load a template-spec module and return its metadata object. Supports both
138
- * families of suffix:
139
- * - Legacy `.doc.*` core/external specs export `export const doc = {...}`.
140
- * - Specs authored with `createPageTemplate`/`createBlockTemplate` export the
141
- * stamped object as the default export.
142
- * Prefers the default export, falling back to the named `doc` export, so a
143
- * `Foo.template.ts` (default export) is read identically to a legacy
144
- * `Foo.doc.mjs` (`doc` export). `.ts` is loaded via jiti; `.mjs`/`.js` via a
145
- * native dynamic import. Returns null if the file does not exist.
146
- *
147
- * @param {string} docPath absolute path to the spec file
148
- * @returns {Promise<Record<string, unknown> | undefined | null>}
149
- */
150
90
  async function loadDocModule(docPath) {
151
91
  if (!fs.existsSync(docPath)) return null;
152
- const docModule = docPath.endsWith('.ts')
153
- ? await getJiti().import(docPath)
154
- : await import(`file://${docPath}`);
155
- return docModule.default ?? docModule.doc;
92
+ const docModule = await import(`file://${docPath}`);
93
+ return docModule.doc;
156
94
  }
157
95
 
158
-
159
96
  export {discoverAll as discoverTemplates};
160
97
 
161
98
  export function listTemplates() {
@@ -185,20 +122,6 @@ function findDocFiles(dir, pattern) {
185
122
  return results;
186
123
  }
187
124
 
188
- /**
189
- * Resolve the template-spec file for a core page directory: the first existing
190
- * `template.<suffix>` in canonical-then-legacy precedence, or null.
191
- * @param {string} dirPath
192
- * @returns {string | null}
193
- */
194
- function findPageDocFile(dirPath) {
195
- for (const suffix of ALL_TEMPLATE_SUFFIXES) {
196
- const candidate = path.join(dirPath, `template${suffix}`);
197
- if (fs.existsSync(candidate)) return candidate;
198
- }
199
- return null;
200
- }
201
-
202
125
  async function discoverPages() {
203
126
  if (!fs.existsSync(PAGES_DIR)) return [];
204
127
  const dirs = fs
@@ -208,9 +131,7 @@ async function discoverPages() {
208
131
  const templates = [];
209
132
  for (const dir of dirs) {
210
133
  const dirPath = path.join(PAGES_DIR, dir.name);
211
- const docPath =
212
- findPageDocFile(dirPath) ?? path.join(dirPath, 'template.doc.mjs');
213
- const doc = await loadDocModule(docPath);
134
+ const doc = await loadDocModule(path.join(dirPath, 'template.doc.mjs'));
214
135
  templates.push({
215
136
  type: 'page',
216
137
  dirName: dir.name,
@@ -220,18 +141,17 @@ async function discoverPages() {
220
141
  isReady: doc?.isReady ?? true,
221
142
  scaffold: doc?.scaffold ?? false,
222
143
  filePath: path.join(dirPath, 'page.tsx'),
223
- docPath,
144
+ docPath: path.join(dirPath, 'template.doc.mjs'),
224
145
  });
225
146
  }
226
147
  return templates;
227
148
  }
228
149
 
229
150
  async function discoverBlocks() {
230
- const docFiles = findDocFiles(BLOCKS_DIR, TEMPLATE_SUFFIX_RE);
151
+ const docFiles = findDocFiles(BLOCKS_DIR, /\.doc\.mjs$/);
231
152
  const blocks = [];
232
153
  for (const docPath of docFiles) {
233
- const suffix = matchedTemplateSuffix(docPath);
234
- const basename = path.basename(docPath, suffix);
154
+ const basename = path.basename(docPath, '.doc.mjs');
235
155
  const tsxPath = path.join(path.dirname(docPath), basename + '.tsx');
236
156
  if (!fs.existsSync(tsxPath)) continue;
237
157
  const doc = await loadDocModule(docPath);
@@ -253,7 +173,6 @@ async function discoverBlocks() {
253
173
  return blocks;
254
174
  }
255
175
 
256
-
257
176
  /**
258
177
  * Discover blocks from external packages that declare `astryx.blocks` in
259
178
  * their package.json. Same shape as discoverBlocks() output.
@@ -266,10 +185,9 @@ async function discoverExternalBlocks(cwd = process.cwd()) {
266
185
 
267
186
  for (const ext of externals) {
268
187
  if (!ext.blocksDir || !fs.existsSync(ext.blocksDir)) continue;
269
- const docFiles = findDocFiles(ext.blocksDir, TEMPLATE_SUFFIX_RE);
188
+ const docFiles = findDocFiles(ext.blocksDir, /\.doc\.mjs$/);
270
189
  for (const docPath of docFiles) {
271
- const suffix = matchedTemplateSuffix(docPath);
272
- const basename = path.basename(docPath, suffix);
190
+ const basename = path.basename(docPath, '.doc.mjs');
273
191
  const tsxPath = path.join(path.dirname(docPath), basename + '.tsx');
274
192
  if (!fs.existsSync(tsxPath)) continue;
275
193
  const doc = await loadDocModule(docPath);
@@ -340,9 +258,8 @@ async function discoverAllWithErrors(cwd = process.cwd()) {
340
258
  export {discoverAllWithErrors};
341
259
 
342
260
  /**
343
- * Recursively collect integration template-spec files under `root`.
344
- * Returns absolute paths to files ending in one of ALL_TEMPLATE_SUFFIXES
345
- * (canonical `.template.*` or legacy `.doc.*`).
261
+ * Recursively collect integration template doc files under `root`.
262
+ * Returns absolute paths to files ending in one of DOC_SUFFIXES.
346
263
  *
347
264
  * @param {string} root
348
265
  * @returns {string[]}
@@ -355,7 +272,7 @@ function findIntegrationDocFiles(root) {
355
272
  const full = path.join(dir, entry.name);
356
273
  if (entry.isDirectory()) {
357
274
  walk(full);
358
- } else if (ALL_TEMPLATE_SUFFIXES.some(suffix => entry.name.endsWith(suffix))) {
275
+ } else if (DOC_SUFFIXES.some(suffix => entry.name.endsWith(suffix))) {
359
276
  results.push(full);
360
277
  }
361
278
  }
@@ -364,17 +281,24 @@ function findIntegrationDocFiles(root) {
364
281
  return results;
365
282
  }
366
283
 
284
+ /**
285
+ * The doc-file suffix present on `file`, or null if none matches.
286
+ * @param {string} file
287
+ */
288
+ function matchedDocSuffix(file) {
289
+ return DOC_SUFFIXES.find(suffix => file.endsWith(suffix)) ?? null;
290
+ }
291
+
367
292
  /**
368
293
  * Discover templates contributed by configured integrations.
369
294
  *
370
295
  * For each integration with a resolved `templates` root, every
371
- * `<id>.template.{ts,mjs,js}` (or legacy `<id>.doc.{ts,mjs,js}`) file is a
372
- * template whose id is its path relative to the templates root with the
373
- * matched suffix stripped (kebab-case, may be nested). The doc's `type`
374
- * (page|block) decides scaffolding — there is no `/pages` vs `/blocks`
375
- * requirement. A same-stem sibling source file (`<id>.tsx`) is required; a doc
376
- * missing its source, or missing `type`, is an integration error and that
377
- * template is skipped (recorded in `errors`).
296
+ * `<id>.doc.{ts,mjs,js}` file is a template whose id is its path relative to
297
+ * the templates root with the `.doc.*` suffix stripped (kebab-case, may be
298
+ * nested). The doc's `type` (page|block) decides scaffolding — there is no
299
+ * `/pages` vs `/blocks` requirement. A same-stem sibling source file
300
+ * (`<id>.tsx`) is required; a doc missing its source, or missing `type`, is
301
+ * an integration error and that template is skipped (recorded in `errors`).
378
302
  *
379
303
  * @param {string} [cwd]
380
304
  * @returns {Promise<{templates: object[], errors: {package: string, template?: string, message: string}[]}>}
@@ -420,7 +344,7 @@ export async function discoverIntegrationTemplatesForOne(integration) {
420
344
  if (!root || !fs.existsSync(root)) return {templates, errors};
421
345
 
422
346
  for (const docPath of findIntegrationDocFiles(root)) {
423
- const suffix = matchedTemplateSuffix(docPath);
347
+ const suffix = matchedDocSuffix(docPath);
424
348
  const id = path
425
349
  .relative(root, docPath)
426
350
  .slice(0, -suffix.length)
@@ -67,6 +67,11 @@ function error(code, message) {
67
67
  return {code, severity: 'error', message};
68
68
  }
69
69
 
70
+ /** @param {string} code @param {string} message @returns {Issue} */
71
+ function warning(code, message) {
72
+ return {code, severity: 'warning', message};
73
+ }
74
+
70
75
  /**
71
76
  * Verify each declared contribution root exists on disk. A declared-but-missing
72
77
  * root is a `missing_root` error.
@@ -360,3 +365,6 @@ export function summarizeIssues(issues) {
360
365
  }
361
366
  return {errors, warnings};
362
367
  }
368
+
369
+ // Re-export issue constructors for callers/tests that want them.
370
+ export {error as integrationError, warning as integrationWarning};
@@ -20,7 +20,6 @@ describe('registry', () => {
20
20
  '0.1.2',
21
21
  '0.1.3',
22
22
  '0.1.5',
23
- '0.1.7',
24
23
  ]);
25
24
  });
26
25
  });
@@ -21,7 +21,6 @@ const registry = new Map([
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
23
  ['0.1.5', () => import('./transforms/v0.1.5/index.mjs')],
24
- ['0.1.7', () => import('./transforms/v0.1.7/index.mjs')],
25
24
  ]);
26
25
 
27
26
  // Re-export from the shared utility so registry callers and other consumers
package/src/config.mjs CHANGED
@@ -1,9 +1,18 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * Re-export of the config-authoring helper, which now lives in
5
- * `@astryxdesign/core/config` so an app's config file gets type feedback
6
- * without depending on the CLI. Kept here so existing
7
- * `@astryxdesign/cli/config` imports continue to work unchanged.
4
+ * Type-preserving helper for the Astryx config file.
5
+ *
6
+ * This is an intentionally tiny runtime identity function: it returns its
7
+ * argument unchanged. Its value is the exported TypeScript surface from
8
+ * `@astryxdesign/cli/config`, so config files get editor/type feedback without
9
+ * coupling to CLI internals. Validation is NOT performed here — it happens at
10
+ * the load boundary (see `loadModuleWithSchema` + `AstryxConfigSchema`).
11
+ *
12
+ * @template {import('./types/config').AstryxConfig} T
13
+ * @param {T} config
14
+ * @returns {T}
8
15
  */
9
- export {createConfig} from '@astryxdesign/core/config';
16
+ export function createConfig(config) {
17
+ return config;
18
+ }
@@ -1,8 +1,19 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * Re-export of the integration-authoring helper, which now lives in
5
- * `@astryxdesign/core/authoring`. Kept here so existing
6
- * `@astryxdesign/cli/integration` imports continue to work unchanged.
4
+ * Type-preserving helper for an Astryx integration manifest.
5
+ *
6
+ * This is an intentionally tiny runtime identity function: it returns its
7
+ * argument unchanged. Its value is the exported TypeScript surface from
8
+ * `@astryxdesign/cli/integration`, so manifests get editor/type feedback
9
+ * without coupling to CLI internals. Validation is NOT performed here — it
10
+ * happens at the load boundary (see `loadModuleWithSchema` +
11
+ * `AstryxIntegrationSchema`).
12
+ *
13
+ * @template {import('./types/integration').AstryxIntegration} T
14
+ * @param {T} integration
15
+ * @returns {T}
7
16
  */
8
- export {createIntegration} from '@astryxdesign/core/authoring';
17
+ export function createIntegration(integration) {
18
+ return integration;
19
+ }
@@ -273,24 +273,14 @@ export function findComponentReadme(coreDir, name) {
273
273
  * For "Button" finds src/Button/XDSButton.tsx
274
274
  * For "Layout" finds src/Layout/XDSLayout/XDSLayout.tsx
275
275
  * For "Card" finds src/Layout/Container/XDSCard.tsx (deep search fallback)
276
- *
277
- * Hooks and other functions are authored as `.ts` (e.g. `useMediaQuery.ts`,
278
- * `useResizable.ts`), so `.ts` candidates are searched alongside `.tsx`. Without
279
- * this, deriving the import path for a `.ts`-authored function falls back to the
280
- * bare `@astryxdesign/core` root instead of its tree-shakeable subpath.
281
276
  */
282
277
  export function findComponentSource(coreDir, name) {
283
278
  const srcDir = path.join(coreDir, 'src');
284
- // Try the prefixed forms (`XDSButton.tsx`) first since that is the current
285
- // on-disk convention, then the bare forms (`Button.tsx`) that the Astryx-prefix
286
- // migration (P4) renames to. `.tsx` before `.ts` within each so a component's
287
- // `.tsx` wins over a same-named `.ts` helper; `.ts` covers hooks/functions.
288
- const candidateFiles = [
289
- `XDS${name}.tsx`,
290
- `${name}.tsx`,
291
- `XDS${name}.ts`,
292
- `${name}.ts`,
293
- ];
279
+ // Try the prefixed form (`XDSButton.tsx`) first since that is the current
280
+ // on-disk convention, then the bare form (`Button.tsx`) that the Astryx-prefix
281
+ // migration (P4) renames to. Listing the prefixed name first keeps behavior
282
+ // identical until files are actually renamed.
283
+ const candidateFiles = [`XDS${name}.tsx`, `${name}.tsx`];
294
284
 
295
285
  function searchDir(dirPath) {
296
286
  if (!fs.existsSync(dirPath)) return null;
@@ -34,30 +34,15 @@ function getTargetDataAttributes(target) {
34
34
  ];
35
35
  }
36
36
 
37
- /**
38
- * Escape a value for a markdown table cell.
39
- *
40
- * A prop type is a union, and a union is spelled with the same `|` that GFM
41
- * uses to separate cells — backticks do not protect it. A row with more cells
42
- * than the header has columns gets the excess *discarded*, so an unescaped
43
- * `gap: 0 | 0.5 | ...` silently eats its own Default and Description columns.
44
- * <!-- SYNC: packages/core/src/Markdown/parser.ts (splits on unescaped pipes) -->
45
- */
46
- export function mdCell(value) {
47
- return String(value ?? '').replace(/\|/g, '\\|');
48
- }
49
-
50
37
  function formatPropsTable(props) {
51
38
  if (!props || props.length === 0) return '';
52
39
  const lines = [];
53
40
  lines.push('| Prop | Type | Default | Description |');
54
41
  lines.push('|------|------|---------|-------------|');
55
42
  for (const p of props) {
56
- const def = p.default ? `\`${mdCell(p.default)}\`` : '—';
43
+ const def = p.default ? `\`${p.default}\`` : '—';
57
44
  const req = p.required ? ' **(required)**' : '';
58
- lines.push(
59
- `| \`${mdCell(p.name)}\` | \`${mdCell(p.type)}\` | ${def} | ${mdCell(p.description)}${req} |`,
60
- );
45
+ lines.push(`| \`${p.name}\` | \`${p.type}\` | ${def} | ${p.description}${req} |`);
61
46
  }
62
47
  return lines.join('\n');
63
48
  }
@@ -192,7 +177,7 @@ export function formatFull(docs, options = {}) {
192
177
  sections.push('|---------|----------|-------------|');
193
178
  for (const el of docs.usage.anatomy) {
194
179
  const req = el.required ? 'Yes' : 'No';
195
- sections.push(`| ${mdCell(el.name)} | ${req} | ${mdCell(el.description)} |`);
180
+ sections.push(`| ${el.name} | ${req} | ${el.description} |`);
196
181
  }
197
182
  sections.push('');
198
183
  }
@@ -297,9 +282,7 @@ export function formatFull(docs, options = {}) {
297
282
  varLines.push('| CSS Variable | Default | Description |');
298
283
  varLines.push('|-------------|---------|-------------|');
299
284
  for (const v of publicVars) {
300
- varLines.push(
301
- `| \`${mdCell(v.name)}\` | \`${mdCell(v.default)}\` | ${mdCell(v.description)} |`,
302
- );
285
+ varLines.push(`| \`${v.name}\` | \`${v.default}\` | ${v.description} |`);
303
286
  }
304
287
  sections.push(varLines.join('\n') + '\n');
305
288
  }
@@ -395,8 +378,8 @@ export function formatCompact(docs, componentName, importHint) {
395
378
  propLines.push('| CSS Property | Sets |');
396
379
  propLines.push('|-------------|------|');
397
380
  for (const d of docs.theming.derived) {
398
- const target = d.expand === 'container' ? 'container layout tokens' : (d.vars || []).map(v => `\`${mdCell(v)}\``).join(', ');
399
- propLines.push(`| \`${mdCell(d.property)}\` | ${target} |`);
381
+ const target = d.expand === 'container' ? 'container layout tokens' : (d.vars || []).map(v => `\`${v}\``).join(', ');
382
+ propLines.push(`| \`${d.property}\` | ${target} |`);
400
383
  }
401
384
  sections.push(propLines.join('\n') + '\n');
402
385
  }
@@ -412,19 +395,6 @@ export function formatCompact(docs, componentName, importHint) {
412
395
  *
413
396
  * For multi-component docs, extracts the entry matching componentName.
414
397
  */
415
- /**
416
- * Longest union `--detail brief` will spell out inside the one-line signature.
417
- *
418
- * The signature is a glance, not a reference: a six-member enum like
419
- * `start|center|end|between|around|evenly` reads at a glance, an eleven-member
420
- * spacing scale does not — and Stack carries four of them (gap, padding,
421
- * paddingInline, paddingBlock), so it printed the same scale four times. Longer
422
- * unions fall through to the terse prop list, exactly as they did when the type
423
- * was still the bare name `SpacingStep`. The full values are always one
424
- * `astryx component <Name>` away.
425
- */
426
- const SIGNATURE_UNION_MAX_MEMBERS = 8;
427
-
428
398
  export function formatBrief(docs, componentName, importHint, options = {}) {
429
399
  const displayName = componentName.startsWith('XDS')
430
400
  ? componentName.slice(3)
@@ -451,15 +421,13 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
451
421
  const otherProps = [];
452
422
 
453
423
  for (const prop of props) {
454
- const values =
455
- prop.type.includes('|') && !prop.type.includes('ReactNode')
456
- ? prop.type
457
- .replace(/['"]/g, '')
458
- .split('|')
459
- .map(v => v.trim())
460
- : null;
461
- if (values && values.length <= SIGNATURE_UNION_MAX_MEMBERS) {
462
- signatureProps.push(`${prop.name}: ${values.join('|')}`);
424
+ if (prop.type.includes('|') && !prop.type.includes('ReactNode')) {
425
+ const values = prop.type
426
+ .replace(/['"]/g, '')
427
+ .split('|')
428
+ .map(v => v.trim())
429
+ .join('|');
430
+ signatureProps.push(`${prop.name}: ${values}`);
463
431
  } else if (prop.required) {
464
432
  otherProps.unshift(`${prop.name}: ${prop.type.split('|')[0].trim()}`);
465
433
  } else {
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  import {describe, it, expect} from 'vitest';
4
- import {formatBrief, formatFull} from './component-format.mjs';
4
+ import {formatFull} from './component-format.mjs';
5
5
 
6
6
  describe('formatFull sub-component rendering', () => {
7
7
  // Regression guard: sub-components are sometimes declared as a bare
@@ -93,97 +93,3 @@ describe('formatFull theming override keys', () => {
93
93
  expect(out).not.toContain("'astryx-table-cell': {");
94
94
  });
95
95
  });
96
-
97
- /** Pipes that actually separate cells — a `\|` is content, not a separator. */
98
- function cellPipes(row) {
99
- return (row.match(/(?<!\\)\|/g) || []).length;
100
- }
101
-
102
- describe('markdown table cells escape their pipes', () => {
103
- // A prop type is a union, and a union is spelled with `|` — the very
104
- // character GFM uses to separate cells. Backticks do not protect it: a row
105
- // with more cells than the header has columns gets its excess *discarded*,
106
- // so an unescaped `gap: 0 | 0.5 | ...` silently eats its own Default and
107
- // Description columns. See packages/core/src/Markdown/parser.ts, which
108
- // splits on unescaped pipes and preserves `\|` as literal.
109
- it('keeps a union-typed prop row at four cells', () => {
110
- const docs = {
111
- name: 'Grid',
112
- description: 'A grid.',
113
- props: [
114
- {
115
- name: 'gap',
116
- type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10',
117
- default: '2',
118
- description: 'Spacing between all items.',
119
- },
120
- ],
121
- };
122
- const row = formatFull(docs)
123
- .split('\n')
124
- .find(l => l.startsWith('| `gap`'));
125
-
126
- // A 4-column row has exactly 5 separators. Unescaped, this row had 15.
127
- expect(cellPipes(row)).toBe(5);
128
- expect(row).toContain('\\|');
129
- // The columns the unescaped pipes were swallowing.
130
- expect(row).toContain('`2`');
131
- expect(row).toContain('Spacing between all items.');
132
- });
133
-
134
- it('escapes pipes in a description too', () => {
135
- const docs = {
136
- name: 'AppShell',
137
- description: 'A shell.',
138
- props: [
139
- {
140
- name: 'mobileNav',
141
- type: 'ReactNode',
142
- description: "Config. breakpoint is 'sm' | 'md' | 'lg' | 'none'.",
143
- },
144
- ],
145
- };
146
- const row = formatFull(docs)
147
- .split('\n')
148
- .find(l => l.startsWith('| `mobileNav`'));
149
-
150
- expect(cellPipes(row)).toBe(5);
151
- });
152
- });
153
-
154
- describe('formatBrief signature stays terse', () => {
155
- // `--detail brief` exists to be token-cheap. It hoists union-typed props into
156
- // the signature because a short enum reads at a glance — but an 11-member
157
- // spacing scale does not, and Stack carries four of them (gap, padding,
158
- // paddingInline, paddingBlock), so the same scale got printed four times.
159
- // Long unions stay in the terse prop list, exactly as they did when the type
160
- // was still the bare name `SpacingStep`.
161
- it('hoists a short enum but not a long scale', () => {
162
- const docs = {
163
- name: 'HStack',
164
- description: 'A stack.',
165
- props: [
166
- {
167
- name: 'gap',
168
- type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10',
169
- description: 'Gap.',
170
- },
171
- {name: 'wrap', type: "'nowrap' | 'wrap' | 'wrap-reverse'", description: 'Wrap.'},
172
- {
173
- name: 'hAlign',
174
- type: "'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'",
175
- description: 'Align.',
176
- },
177
- ],
178
- };
179
- const signature = formatBrief(docs, 'HStack', '').split('\n')[0];
180
-
181
- // Short enums still earn their place in the signature.
182
- expect(signature).toContain('wrap: nowrap|wrap|wrap-reverse');
183
- expect(signature).toContain('hAlign: start|center|end|between|around|evenly');
184
- // The long scale does not.
185
- expect(signature).not.toContain('0|0.5|1|1.5|2|3|4|5|6|8|10');
186
- // But the prop is still named, so it is not lost.
187
- expect(formatBrief(docs, 'HStack', '')).toContain('gap');
188
- });
189
- });