@astryxdesign/cli 0.1.6-canary.63e1347 → 0.1.6-canary.6ec65fb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.1.6-canary.63e1347",
3
+ "version": "0.1.6-canary.6ec65fb",
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",
@@ -79,10 +79,10 @@
79
79
  "zod": "^4.4.3"
80
80
  },
81
81
  "peerDependencies": {
82
- "@astryxdesign/charts": "0.1.6-canary.63e1347",
83
- "@astryxdesign/core": "0.1.6-canary.63e1347",
84
- "@astryxdesign/lab": "0.1.6-canary.63e1347",
85
- "@astryxdesign/theme-neutral": "0.1.6-canary.63e1347",
82
+ "@astryxdesign/charts": "0.1.6-canary.6ec65fb",
83
+ "@astryxdesign/core": "0.1.6-canary.6ec65fb",
84
+ "@astryxdesign/lab": "0.1.6-canary.6ec65fb",
85
+ "@astryxdesign/theme-neutral": "0.1.6-canary.6ec65fb",
86
86
  "gpt-tokenizer": "^3.4.0"
87
87
  },
88
88
  "peerDependenciesMeta": {
@@ -100,10 +100,10 @@
100
100
  }
101
101
  },
102
102
  "devDependencies": {
103
- "@astryxdesign/charts": "0.1.6-canary.63e1347",
104
- "@astryxdesign/core": "0.1.6-canary.63e1347",
105
- "@astryxdesign/lab": "0.1.6-canary.63e1347",
106
- "@astryxdesign/theme-neutral": "0.1.6-canary.63e1347",
103
+ "@astryxdesign/charts": "0.1.6-canary.6ec65fb",
104
+ "@astryxdesign/core": "0.1.6-canary.6ec65fb",
105
+ "@astryxdesign/lab": "0.1.6-canary.6ec65fb",
106
+ "@astryxdesign/theme-neutral": "0.1.6-canary.6ec65fb",
107
107
  "gpt-tokenizer": "^3.4.0"
108
108
  },
109
109
  "scripts": {
@@ -144,64 +144,15 @@ export async function loadDocs(readmePath, {zh = false, dense = false, lang} = {
144
144
 
145
145
  const translation = mod[translationKey];
146
146
 
147
- // A full ComponentDoc-shaped translation (legacy docsZh shape) used to be
148
- // returned wholesale. That made it a REPLACEMENT, not an overlay: any prop
149
- // the translation had not caught up with simply ceased to exist —
150
- // `component Button --zh` silently omitted `isInterruptible` and
151
- // `isIconOnly`. A reader of the translated docs cannot discover a prop that
152
- // is not there. Overlay it instead, so an untranslated prop falls back to
153
- // its English entry. (Same principle as the reference-doc overlays, #2182.)
147
+ // If the translation is a full ComponentDoc (legacy docsZh shape), return it directly
154
148
  if (translation.props || translation.components?.some(c => c.props)) {
155
- return overlayComponentDoc(docs, translation);
149
+ return translation;
156
150
  }
157
151
 
158
152
  // Otherwise it's a TranslationDoc — merge it onto docs
159
153
  return mergeTranslation(docs, translation);
160
154
  }
161
155
 
162
- /**
163
- * Overlay a full-ComponentDoc-shaped translation onto the English doc.
164
- *
165
- * Base order and completeness win; the translation supplies text for the
166
- * entries it covers. Props are matched by name, never by position, so a
167
- * translation that is missing entries (or lists them in another order) can no
168
- * longer drop or misattribute one.
169
- *
170
- * @param {any} docs Base (English) component doc.
171
- * @param {any} translation Translated doc, possibly covering only some props.
172
- * @returns {any} Merged doc with every base prop present.
173
- */
174
- function overlayComponentDoc(docs, translation) {
175
- /** Merge one prop list: keep base entries and order, translate what's covered. */
176
- const overlayProps = (baseProps, tProps) => {
177
- if (!baseProps) return baseProps;
178
- const byName = new Map((tProps ?? []).map(p => [p.name, p]));
179
- return baseProps.map(prop => {
180
- const t = byName.get(prop.name);
181
- // Take the translated text, but never let it drop the prop's contract
182
- // (type/default/required stay authoritative from the English doc).
183
- return t ? {...prop, ...t, name: prop.name, type: prop.type} : prop;
184
- });
185
- };
186
-
187
- const merged = {...docs, ...translation};
188
-
189
- merged.props = overlayProps(docs.props, translation.props);
190
-
191
- if (docs.components) {
192
- const tByName = new Map(
193
- (translation.components ?? []).map(c => [c.name, c]),
194
- );
195
- merged.components = docs.components.map(base => {
196
- const t = tByName.get(base.name);
197
- if (!t) return base;
198
- return {...base, ...t, props: overlayProps(base.props, t.props)};
199
- });
200
- }
201
-
202
- return merged;
203
- }
204
-
205
156
  /**
206
157
  * Find the doc file for a component, checking both top-level
207
158
  * and nested directories. Prefers {Name}.doc.mjs, then README.md
@@ -1,111 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Guards translated/compressed component docs against dropping props.
5
- * @input packages/core/src/{Name}/{Name}.doc.mjs — its `docs`, `docsZh`, `docsDense`.
6
- * @output Vitest failures naming every prop that exists in `docs` but vanishes
7
- * from a translated view.
8
- * @position Regression gate for component-loader.mjs.
9
- *
10
- * A `docsZh` that carries its own `props` array used to REPLACE the base doc
11
- * wholesale, so any prop the translation had not caught up with simply ceased
12
- * to exist: `astryx component Button --zh` silently omitted `isInterruptible`
13
- * and `isIconOnly`. A reader of the translated docs cannot discover a prop that
14
- * is not there, and CLAUDE.md tells every AI agent to read these docs.
15
- *
16
- * Translations are now an overlay: a prop the translation does not cover falls
17
- * back to its English entry rather than disappearing. Same principle as the
18
- * reference-doc overlays in #2182 — an overlay covering a subset must not
19
- * destroy what it does not cover.
20
- */
21
-
22
- import {describe, it, expect} from 'vitest';
23
- import * as fs from 'node:fs';
24
- import * as path from 'node:path';
25
- import {pathToFileURL} from 'node:url';
26
- import {loadDocs} from './component-loader.mjs';
27
-
28
- const CORE_SRC = path.join(
29
- import.meta.dirname,
30
- '..',
31
- '..',
32
- '..',
33
- 'core',
34
- 'src',
35
- );
36
-
37
- /** Component dirs that ship a doc file. */
38
- function componentDocs() {
39
- const out = [];
40
- for (const dir of fs.readdirSync(CORE_SRC)) {
41
- const docPath = path.join(CORE_SRC, dir, `${dir}.doc.mjs`);
42
- if (!fs.existsSync(docPath)) continue;
43
- if (!fs.readdirSync(path.join(CORE_SRC, dir)).includes(`${dir}.doc.mjs`)) {
44
- continue; // case-exact match only
45
- }
46
- out.push({name: dir, docPath});
47
- }
48
- return out;
49
- }
50
-
51
- /** Prop names on a doc, across single- and multi-component shapes. */
52
- function propNames(doc) {
53
- const names = new Set();
54
- for (const p of doc?.props ?? []) names.add(p.name);
55
- for (const c of doc?.components ?? []) {
56
- for (const p of c.props ?? []) names.add(`${c.name ?? '?'}.${p.name}`);
57
- }
58
- return names;
59
- }
60
-
61
- describe('translated component docs never drop a prop', () => {
62
- const comps = componentDocs();
63
-
64
- it('finds component docs to check', () => {
65
- expect(comps.length).toBeGreaterThan(0);
66
- });
67
-
68
- for (const {name, docPath} of comps) {
69
- for (const locale of ['zh', 'dense']) {
70
- it(`${name} --${locale}: documents every prop the English doc documents`, async () => {
71
- const mod = await import(pathToFileURL(docPath).href);
72
- const key = locale === 'zh' ? 'docsZh' : 'docsDense';
73
- if (!mod[key]) return; // no overlay, nothing to drift
74
-
75
- const english = propNames(mod.docs);
76
- const translated = propNames(
77
- await loadDocs(docPath, {[locale]: true}),
78
- );
79
-
80
- const dropped = [...english].filter(p => !translated.has(p));
81
- expect(
82
- dropped,
83
- `${name}.doc.mjs ${key} drops ${dropped.length} prop(s) from the ` +
84
- `--${locale} view: ${dropped.join(', ')}. A reader of the ` +
85
- `translated docs cannot discover a prop that is not there. An ` +
86
- `untranslated prop must fall back to its English entry, not vanish.`,
87
- ).toEqual([]);
88
- });
89
- }
90
- }
91
- });
92
-
93
- describe('the reported symptom', () => {
94
- it('astryx component Button --zh still lists isInterruptible and isIconOnly', async () => {
95
- const docPath = path.join(CORE_SRC, 'Button', 'Button.doc.mjs');
96
- const zh = await loadDocs(docPath, {zh: true});
97
- const names = propNames(zh);
98
- expect(names.has('isInterruptible')).toBe(true);
99
- expect(names.has('isIconOnly')).toBe(true);
100
- });
101
-
102
- it('keeps the translated descriptions it does have', async () => {
103
- const docPath = path.join(CORE_SRC, 'Button', 'Button.doc.mjs');
104
- const mod = await import(pathToFileURL(docPath).href);
105
- const zh = await loadDocs(docPath, {zh: true});
106
-
107
- const translated = mod.docsZh.props.find(p => p.name === 'variant');
108
- const merged = zh.props.find(p => p.name === 'variant');
109
- expect(merged.description).toBe(translated.description);
110
- });
111
- });