Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): keep component and hook text output ASCII (#6553)

Joey91153fadbce4
diff --git a/.changeset/cli-spec-ascii-doc-text.md b/.changeset/cli-spec-ascii-doc-text.md
new file mode 100644
index 0000000000..4b48f0ffad
--- /dev/null
+++ b/.changeset/cli-spec-ascii-doc-text.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] The text output of `astryx component` and `astryx hook` no longer adds non-ASCII characters of its own. Empty table cells show `-` instead of an em dash, the brief view's import hint reads `<- from`, derived properties and deprecated targets use `->`, and brief prop and parameter lists are separated by commas instead of middle dots. Text that comes from the docs themselves is unchanged.
+
+@josephfarina
diff --git a/packages/cli/clients/cli/commands/detail-levels.test.mjs b/packages/cli/clients/cli/commands/detail-levels.test.mjs
index ec6c969755..92bc740eaa 100644
--- a/packages/cli/clients/cli/commands/detail-levels.test.mjs
+++ b/packages/cli/clients/cli/commands/detail-levels.test.mjs
@@ -52,7 +52,7 @@ describe('--detail level ordering: component --list', () => {
it('brief is names-only (no targets, import hints, or prose descriptions)', () => {
expect(brief).not.toMatch(/Targets:/);
- expect(brief).not.toMatch(/\u2190 from/);
+ expect(brief).not.toMatch(/<- from/);
// Names only — should contain XDS component names but no " — " desc separator.
expect(brief).toMatch(/Button/);
expect(brief).not.toMatch(/ \u2014 /);
@@ -66,7 +66,7 @@ describe('--detail level ordering: component --list', () => {
it('full has dense per-entry docs (props, targets, and import hints)', () => {
expect(full).toMatch(/Targets:/);
- expect(full).toMatch(/\u2190 from/);
+ expect(full).toMatch(/<- from/);
// Prop name lists appear in the dense brief-all rendering.
expect(full).toMatch(/children/);
});
diff --git a/packages/cli/clients/cli/lib/component-format.mjs b/packages/cli/clients/cli/lib/component-format.mjs
index 0fa16e2f66..dc0855237f 100644
--- a/packages/cli/clients/cli/lib/component-format.mjs
+++ b/packages/cli/clients/cli/lib/component-format.mjs
@@ -71,7 +71,7 @@ function formatPropsTable(props) {
lines.push('| Prop | Type | Default | Description |');
lines.push('|------|------|---------|-------------|');
for (const p of props) {
- const def = p.default ? `\`${mdCell(p.default)}\`` : '—';
+ const def = p.default ? `\`${mdCell(p.default)}\`` : '-';
const req = p.required ? ' **(required)**' : '';
lines.push(
`| \`${mdCell(p.name)}\` | \`${mdCell(p.type)}\` | ${def} | ${mdCell(p.description)}${req} |`,
@@ -190,11 +190,11 @@ function formatTargetsTable(docs, themeData) {
...themeVariants.map((/** @type {string} */ v) => `${v}*`),
];
- const variantsStr = variantParts.length > 0 ? variantParts.join(', ') : '—';
- const statesStr = states.length > 0 ? states.join(', ') : '—';
+ const variantsStr = variantParts.length > 0 ? variantParts.join(', ') : '-';
+ const statesStr = states.length > 0 ? states.join(', ') : '-';
const dataAttrs = getTargetDataAttributes(target);
const dataAttrsStr =
- dataAttrs.length > 0 ? dataAttrs.map(attr => `\`${attr}\``).join(', ') : '—';
+ dataAttrs.length > 0 ? dataAttrs.map(attr => `\`${attr}\``).join(', ') : '-';
const className = target.deprecatedFor
? `\`${target.className}\` _(deprecated; use \`${target.deprecatedFor}\`)_`
@@ -342,7 +342,7 @@ export function formatFull(docs, options = {}) {
const publicVars = docs.theming.vars.filter((/** @type {any} */ v) => !v.private && !v.derived);
if (publicVars.length > 0) {
- sections.push('**Themeable CSS variables** — additional properties that can be overridden in `defineTheme` component overrides.\n');
+ sections.push('**Themeable CSS variables** - additional properties that can be overridden in `defineTheme` component overrides.\n');
const varLines = [];
varLines.push('| CSS Variable | Default | Description |');
varLines.push('|-------------|---------|-------------|');
@@ -544,7 +544,7 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
signatureProps.length > 0
? `${displayName}(${signatureProps.join(', ')})`
: displayName;
- output.push(importHint ? `${sigStr} ← from '${importHint}'` : sigStr);
+ output.push(importHint ? `${sigStr} <- from '${importHint}'` : sigStr);
// Description (shortened)
if (description) {
@@ -569,7 +569,7 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
// Derived properties (if any)
if (docs.theming?.derived?.length) {
const derivedNames = docs.theming.derived
- .map((/** @type {any} */ d) => d.expand === 'container' ? `${d.property} → container tokens` : `${d.property} → ${(d.vars || []).join(', ')}`)
+ .map((/** @type {any} */ d) => d.expand === 'container' ? `${d.property} -> container tokens` : `${d.property} -> ${(d.vars || []).join(', ')}`)
.join('; ');
output.push(` Derived: ${derivedNames}`);
}
@@ -579,7 +579,7 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
const { themeData = null } = options;
const targetParts = docs.theming.targets.map((/** @type {any} */ t) => {
const parts = [t.className];
- if (t.deprecatedFor) parts.push(`deprecated→${t.deprecatedFor}`);
+ if (t.deprecatedFor) parts.push(`deprecated->${t.deprecatedFor}`);
const dataAttrs = getTargetDataAttributes(t);
if (dataAttrs.length) parts.push(`preferred attrs: ${dataAttrs.join(', ')}`);
if (t.visualProps?.length) parts.push(`variants: ${t.visualProps.join(', ')}`);
@@ -595,7 +595,7 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
// Other props
if (otherProps.length > 0) {
- output.push(` ${otherProps.join(' · ')}`);
+ output.push(` ${otherProps.join(', ')}`);
}
// First code example
diff --git a/packages/cli/clients/cli/lib/component-format.test.mjs b/packages/cli/clients/cli/lib/component-format.test.mjs
index 510284627c..3756a2eb97 100644
--- a/packages/cli/clients/cli/lib/component-format.test.mjs
+++ b/packages/cli/clients/cli/lib/component-format.test.mjs
@@ -157,7 +157,7 @@ describe('deprecated theming target guidance', () => {
it('keeps the replacement in brief agent guidance', () => {
expect(formatBrief(docs, 'Example')).toContain(
- 'astryx-old-target deprecated→new-target',
+ 'astryx-old-target deprecated->new-target',
);
});
});
diff --git a/packages/cli/clients/cli/lib/doc-text-ascii.test.mjs b/packages/cli/clients/cli/lib/doc-text-ascii.test.mjs
new file mode 100644
index 0000000000..21a01dce2e
--- /dev/null
+++ b/packages/cli/clients/cli/lib/doc-text-ascii.test.mjs
@@ -0,0 +1,82 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file The component and hook text renderers add no non-ASCII characters of
+ * their own: given ASCII-only docs, every view they produce is plain ASCII.
+ */
+
+import {describe, it, expect} from 'vitest';
+import {
+ formatBrief,
+ formatCompact,
+ formatFull,
+ formatProps,
+} from './component-format.mjs';
+import {
+ formatHookBrief,
+ formatHookCompact,
+ formatHookFull,
+ formatHookParams,
+} from './hook-format.mjs';
+
+const NON_ASCII = /[\u0080-\uffff]/g;
+
+/** @param {string} out @returns {string[]} */
+const nonAscii = out => out.match(NON_ASCII) ?? [];
+
+// Every optional field left empty and every optional path taken, so each
+// placeholder, separator, and arrow the renderers emit shows up at least once.
+const componentDoc = {
+ name: 'Widget',
+ description: 'A widget for tests.',
+ props: [
+ {name: 'variant', type: "'solid' | 'ghost'", description: 'Look.'},
+ {name: 'label', type: 'string', description: 'Label.', required: true},
+ {name: 'disabled', type: 'boolean', description: 'Disables it.'},
+ {name: 'tone', type: 'string', description: 'Tone.'},
+ ],
+ theming: {
+ vars: [{name: '--widget-gap', default: '8px', description: 'Gap.'}],
+ derived: [
+ {property: 'padding', expand: 'container'},
+ {property: 'radius', vars: ['--widget-radius']},
+ ],
+ targets: [
+ {className: 'astryx-widget', deprecatedFor: 'astryx-widget-v2'},
+ {className: 'astryx-widget-v2', visualProps: ['variant']},
+ ],
+ },
+};
+
+const hookDoc = {
+ name: 'useWidget',
+ importPath: '@astryxdesign/core/useWidget',
+ usage: {description: 'Widget behavior.'},
+ params: [
+ {name: 'options', type: 'object', description: 'Options.', required: true},
+ {name: 'delay', type: 'number', description: 'Delay.'},
+ ],
+ returns: [{name: 'open', type: 'boolean', description: 'Open state.'}],
+};
+
+describe('component text output is ASCII', () => {
+ it.each([
+ ['formatFull', () => formatFull(componentDoc)],
+ ['formatCompact', () => formatCompact(componentDoc, 'Widget')],
+ ['formatBrief', () => formatBrief(componentDoc, 'Widget', '@astryxdesign/core/Widget')],
+ ['formatProps', () => formatProps(componentDoc, 'Widget')],
+ ])('%s', (_name, render) => {
+ expect(nonAscii(render())).toEqual([]);
+ });
+});
+
+describe('hook text output is ASCII', () => {
+ it.each([
+ ['formatHookFull', () => formatHookFull(hookDoc)],
+ ['formatHookCompact', () => formatHookCompact(hookDoc, hookDoc.importPath)],
+ ['formatHookBrief', () => formatHookBrief(hookDoc)],
+ ['formatHookParams', () => formatHookParams(hookDoc)],
+ ])('%s', (_name, render) => {
+ expect(nonAscii(render())).toEqual([]);
+ });
+});
diff --git a/packages/cli/clients/cli/lib/hook-format.mjs b/packages/cli/clients/cli/lib/hook-format.mjs
index 08b511a8eb..540f24a20c 100644
--- a/packages/cli/clients/cli/lib/hook-format.mjs
+++ b/packages/cli/clients/cli/lib/hook-format.mjs
@@ -57,7 +57,7 @@ function formatParamsTable(params) {
lines.push('| Param | Type | Default | Description |');
lines.push('|-------|------|---------|-------------|');
for (const p of params) {
- const def = p.default ? `\`${mdCell(p.default)}\`` : '\u2014';
+ const def = p.default ? `\`${mdCell(p.default)}\`` : '-';
const req = p.required ? ' **(required)**' : '';
lines.push(
`| \`${mdCell(p.name)}\` | \`${mdCell(p.type)}\` | ${def} | ${mdCell(p.description)}${req} |`,
@@ -198,7 +198,7 @@ export function formatHookCompact(docs, importPath) {
/**
* Format a brief, LLM-optimized hook summary.
* Matches component formatBrief conventions:
- * signature ← from 'import/path'
+ * signature <- from 'import/path'
* description
* key params
* @param {any} docs
@@ -211,7 +211,7 @@ export function formatHookBrief(docs) {
// Signature line with import hint (matches component brief)
const sig = buildSignature(docs);
const imp = docs.importPath;
- output.push(imp ? `${sig} \u2190 from '${imp}'` : sig);
+ output.push(imp ? `${sig} <- from '${imp}'` : sig);
// Description (shortened, matches component brief)
const desc = docs.usage?.description || '';
@@ -225,12 +225,12 @@ export function formatHookBrief(docs) {
output.push(` Related: ${docs.relatedComponents.join(', ')}`);
}
- // Key params (matches component brief 'prop · prop' line)
+ // Key params (matches component brief 'prop, prop' line)
const paramNames = (docs.params || [])
.filter((/** @type {any} */ p) => !p.name.includes('.'))
.map((/** @type {any} */ p) => p.required ? `${p.name}: ${p.type.split('|')[0].trim()}` : p.name);
if (paramNames.length > 0) {
- output.push(` ${paramNames.join(' \u00b7 ')}`);
+ output.push(` ${paramNames.join(', ')}`);
}
return output.join('\n') + '\n';