@astryxdesign/cli 0.1.6-canary.dd1d655 → 0.1.6-canary.e65bbd4

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 (39) hide show
  1. package/docs/internationalization.doc.mjs +243 -0
  2. package/package.json +13 -9
  3. package/src/api/template.mjs +1 -1
  4. package/src/api/validate-integration.mjs +0 -8
  5. package/src/codemods/__tests__/registry.test.mjs +1 -0
  6. package/src/codemods/registry.mjs +1 -0
  7. package/src/codemods/transforms/v0.1.7/__tests__/migrate-table-tableprops-to-direct-props.test.mjs +120 -0
  8. package/src/codemods/transforms/v0.1.7/index.mjs +19 -0
  9. package/src/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +188 -0
  10. package/src/config.mjs +5 -14
  11. package/src/doc.mjs +27 -0
  12. package/src/doc.test.mjs +383 -0
  13. package/src/integration.mjs +4 -15
  14. package/src/lib/component-discovery.importpath.test.mjs +59 -0
  15. package/src/lib/component-discovery.mjs +15 -5
  16. package/src/lib/component-format.mjs +45 -13
  17. package/src/lib/component-format.test.mjs +95 -1
  18. package/src/lib/component-loader.mjs +104 -2
  19. package/src/lib/componentDocOverlay.test.mjs +111 -0
  20. package/src/lib/config-schema.mjs +0 -30
  21. package/src/lib/hook-format.mjs +8 -3
  22. package/src/lib/xle/registry.mjs +0 -5
  23. package/src/schemas/doc-schema.mjs +226 -0
  24. package/src/schemas/template-schema.mjs +47 -0
  25. package/src/template.mjs +9 -67
  26. package/src/types/config.d.ts +11 -66
  27. package/src/types/doc.d.ts +23 -0
  28. package/src/types/integration.d.ts +7 -18
  29. package/src/types/template-api.d.ts +14 -50
  30. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.doc.mjs +14 -0
  31. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.tsx +41 -0
  32. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +13 -0
  33. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +78 -0
  34. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.doc.mjs +14 -0
  35. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.tsx +38 -0
  36. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +14 -0
  37. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +47 -0
  38. package/templates/pages/ide/page.tsx +35 -41
  39. package/templates/themes/neutral/neutralTheme.ts +63 -32
@@ -0,0 +1,243 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('../../core/src/docs-types').ReferenceDoc} */
4
+
5
+ export const docs = {
6
+ name: 'internationalization',
7
+ title: 'Internationalization',
8
+ category: 'guide',
9
+ description:
10
+ 'Localize astryx component strings, provide translation catalogs, override default text, coexist with your own i18n library, swap languages at runtime, and test translations with the pseudo locale.',
11
+
12
+ sections: [
13
+ {
14
+ title: 'Quick Start',
15
+ category: 'guide',
16
+ content: [
17
+ {
18
+ type: 'prose',
19
+ text: 'Internationalization ships with `@astryxdesign/core`. There is nothing to install. Wrap your app in `<InternationalizationProvider>` and set a `locale` — astryx components pick up localized strings automatically.',
20
+ },
21
+ {
22
+ type: 'code',
23
+ lang: 'tsx',
24
+ label: 'Wrap your app',
25
+ code: `import {InternationalizationProvider} from '@astryxdesign/core';
26
+
27
+ function App() {
28
+ return (
29
+ <InternationalizationProvider locale="en">
30
+ <YourApp />
31
+ </InternationalizationProvider>
32
+ );
33
+ }`,
34
+ },
35
+ {
36
+ type: 'code',
37
+ lang: 'tsx',
38
+ label: 'Read strings inside a component',
39
+ code: `import {useTranslator} from '@astryxdesign/core';
40
+
41
+ function SaveButton() {
42
+ const t = useTranslator();
43
+ return <button>{t('@myapp.actions.save')}</button>;
44
+ }`,
45
+ },
46
+ {
47
+ type: 'prose',
48
+ text: 'The hook is available to consumer components too, but using it is entirely optional — many teams keep their app strings on their existing i18n library (react-intl, i18next, next-intl, LinguiJS) and only use `useTranslator` when reading astryx keys. If you do route your own strings through it, we recommend namespacing them (`@myapp.*` or your npm scope) to keep them separated from `@astryx.*`, but this is a convention, not a requirement — the resolver treats every key as an opaque string.',
49
+ },
50
+ {
51
+ type: 'prose',
52
+ text: "Astryx ships translations only for English today. First-party translations for other locales are on the roadmap and coming soon — track https://github.com/facebook/astryx/issues/3641. In the meantime, if you want astryx UI translated into another locale, you can ship your own catalog through the `messages` prop (covered in the next section). If you're using `useTranslator` for your own strings, you'll want to ship your own catalog either way — astryx only carries the fallback for `@astryx.*` keys, not the ones you author.",
53
+ },
54
+ ],
55
+ },
56
+ {
57
+ title: 'Providing locale catalogs',
58
+ category: 'guide',
59
+ content: [
60
+ {
61
+ type: 'prose',
62
+ text: 'Astryx bundles only the English catalog today. To render in any other locale, provide a translation catalog through the `messages` prop and set `locale` accordingly. This matches how MUI, Ant Design, and AG Grid work — the consumer app supplies the catalogs it actually needs so unused translations stay out of the bundle.',
63
+ },
64
+ {
65
+ type: 'code',
66
+ lang: 'tsx',
67
+ label: 'Add French',
68
+ code: `import {InternationalizationProvider} from '@astryxdesign/core';
69
+ import fr from './locales/astryx/fr.json';
70
+
71
+ <InternationalizationProvider locale="fr" messages={{fr}}>
72
+ <App />
73
+ </InternationalizationProvider>;`,
74
+ },
75
+ {
76
+ type: 'prose',
77
+ text: "See `@astryxdesign/core/locales/en.json` for the full inventory of keys to translate. Copy it as the starting point — every key you translate replaces the English default; anything you omit falls back through the locale chain to English (e.g. `pt-BR` walks to `pt` then to shipped `en`), so a partial translation renders as a mix rather than empty text or raw key names.",
78
+ },
79
+ {
80
+ type: 'prose',
81
+ text: 'A community-maintained set of astryx translations is on the roadmap but not shipped yet. For now, consumer apps that ship in multiple languages own their astryx catalogs alongside their app catalogs. Contributions to a first-party set are welcome — track discussion at https://github.com/facebook/astryx/issues/3641.',
82
+ },
83
+ ],
84
+ },
85
+ {
86
+ title: "Overriding astryx's default text",
87
+ category: 'guide',
88
+ content: [
89
+ {
90
+ type: 'prose',
91
+ text: 'Use `overrides` to change individual strings without shipping a full catalog. Overrides are keyed by locale and merged on top of the built-in and user-supplied catalogs.',
92
+ },
93
+ {
94
+ type: 'code',
95
+ lang: 'tsx',
96
+ label: 'Change one string in English',
97
+ code: `<InternationalizationProvider
98
+ locale="en"
99
+ overrides={{en: {'@astryx.pagination.next': 'Next →'}}}
100
+ >
101
+ <App />
102
+ </InternationalizationProvider>`,
103
+ },
104
+ {
105
+ type: 'prose',
106
+ text: 'Overrides win over both bundled English and any `messages` catalog for the same key. Use them for brand voice tweaks or one-off wording changes.',
107
+ },
108
+ ],
109
+ },
110
+ {
111
+ title: 'Using astryx with your own i18n library',
112
+ category: 'guide',
113
+ content: [
114
+ {
115
+ type: 'prose',
116
+ text: "Astryx components render astryx strings through astryx's provider. Consumer components render consumer strings through whatever i18n library you already use — react-intl, i18next, next-intl, LinguiJS, and so on. The two systems coexist and read from the same source of truth for the active locale.",
117
+ },
118
+ {
119
+ type: 'code',
120
+ lang: 'tsx',
121
+ label: 'Astryx + react-intl side by side',
122
+ code: `import {InternationalizationProvider} from '@astryxdesign/core';
123
+ import {Selector} from '@astryxdesign/core/Selector';
124
+ import {Button} from '@astryxdesign/core/Button';
125
+ import {FormattedMessage, IntlProvider, useIntl} from 'react-intl';
126
+ import astryxFr from './locales/astryx/fr.json'; // astryx's UI, in French
127
+ import appFr from './locales/app/fr.json'; // your app strings, in French
128
+
129
+ function Pricing() {
130
+ // Consumer strings — resolved by react-intl.
131
+ const intl = useIntl();
132
+
133
+ return (
134
+ <section>
135
+ <h1><FormattedMessage id="pricing.heading" /></h1>
136
+
137
+ {/* Astryx Selector — trigger placeholder, search-box placeholder,
138
+ clear-button aria-label all resolved by
139
+ <InternationalizationProvider>. Options come from react-intl. */}
140
+ <Selector
141
+ label={intl.formatMessage({id: 'pricing.region.label'})}
142
+ options={[
143
+ {value: 'na', label: intl.formatMessage({id: 'pricing.region.na'})},
144
+ {value: 'eu', label: intl.formatMessage({id: 'pricing.region.eu'})},
145
+ ]}
146
+ hasSearch
147
+ hasClear
148
+ />
149
+
150
+ <Button label={intl.formatMessage({id: 'pricing.cta.subscribe'})} />
151
+ </section>
152
+ );
153
+ }
154
+
155
+ export default function App() {
156
+ return (
157
+ // Same locale, two providers reading their own catalogs.
158
+ <IntlProvider locale="fr" messages={appFr}>
159
+ <InternationalizationProvider locale="fr" messages={{fr: astryxFr}}>
160
+ <Pricing />
161
+ </InternationalizationProvider>
162
+ </IntlProvider>
163
+ );
164
+ }`,
165
+ },
166
+ {
167
+ type: 'prose',
168
+ text: 'Keep the two providers in sync on locale, and each library owns its own catalog. Astryx never sees your app strings, and your i18n library never sees astryx internals. Runtime locale swap works the same way — re-render both providers with a new `locale` prop and the whole tree updates live.',
169
+ },
170
+ {
171
+ type: 'prose',
172
+ text: "Single-catalog usage — where an external i18n runtime like react-intl or i18next resolves both your app strings AND astryx's strings through one provider — is on the roadmap via a `Translator` adapter. Track https://github.com/facebook/astryx/issues/4029. For now, run the two providers side by side as shown above.",
173
+ },
174
+ ],
175
+ },
176
+ {
177
+ title: 'Runtime language swap',
178
+ category: 'guide',
179
+ content: [
180
+ {
181
+ type: 'prose',
182
+ text: 'Re-render `<InternationalizationProvider>` with a new `locale` prop and every astryx string updates live. No reload, no separate API call.',
183
+ },
184
+ {
185
+ type: 'code',
186
+ lang: 'tsx',
187
+ label: 'Toggle between locales',
188
+ code: `const [locale, setLocale] = useState<'en' | 'fr'>('en');
189
+
190
+ <InternationalizationProvider locale={locale} messages={{fr}}>
191
+ <Button
192
+ label={locale === 'en' ? 'Français' : 'English'}
193
+ onClick={() => setLocale(l => (l === 'en' ? 'fr' : 'en'))}
194
+ />
195
+ <App />
196
+ </InternationalizationProvider>;`,
197
+ },
198
+ {
199
+ type: 'prose',
200
+ text: "Persisting the user's choice (localStorage, cookie, URL segment, account setting) is up to the consumer. Astryx reads whatever `locale` you pass in.",
201
+ },
202
+ ],
203
+ },
204
+ {
205
+ title: 'Testing your translations',
206
+ category: 'guide',
207
+ content: [
208
+ {
209
+ type: 'prose',
210
+ text: 'Astryx generates a `pseudo` locale that wraps every string in `⟦…⟧` and replaces letters with accented look-alikes. Switching to it in development instantly reveals any astryx string that isn\'t going through the translator, plus any layout that breaks under longer text.',
211
+ },
212
+ {
213
+ type: 'code',
214
+ lang: 'tsx',
215
+ label: 'Turn on pseudo-localization',
216
+ code: `import pseudo from '@astryxdesign/core/locales/pseudo.json';
217
+
218
+ <InternationalizationProvider locale="pseudo" messages={{pseudo}}>
219
+ <App />
220
+ </InternationalizationProvider>;`,
221
+ },
222
+ {
223
+ type: 'prose',
224
+ text: 'Any bare English text you still see on screen is a hardcoded string that needs to be routed through `useTranslator`.',
225
+ },
226
+ {
227
+ type: 'prose',
228
+ text: "Pseudoloc also has a subtle caveat worth knowing: the pseudo catalog is complete (astryx generates it from every shipped key), so a component using an astryx-shipped key will always render its pseudo version. Your handwritten translation catalogs, on the other hand, only cover the keys you translated — anything missing falls back to English. That means \"looks perfect in pseudo\" is not the same guarantee as \"looks perfect in French.\" Check each real locale by hand for coverage gaps.",
229
+ },
230
+ ],
231
+ },
232
+ {
233
+ title: 'For contributors',
234
+ category: 'guide',
235
+ content: [
236
+ {
237
+ type: 'prose',
238
+ text: "Astryx's own strings live in `packages/core/locales/en.json`. New user-facing strings must go through `useTranslator` — this is enforced by the `@astryx/no-hardcoded-i18n-string` ESLint rule. See the AI contribution guide for the alias-and-resolve pattern used when adding new keys.",
239
+ },
240
+ ],
241
+ },
242
+ ],
243
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.1.6-canary.dd1d655",
3
+ "version": "0.1.6-canary.e65bbd4",
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,6 +47,10 @@
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
+ },
50
54
  "./template": {
51
55
  "types": "./src/types/template-api.d.ts",
52
56
  "import": "./src/template.mjs"
@@ -75,10 +79,10 @@
75
79
  "zod": "^4.4.3"
76
80
  },
77
81
  "peerDependencies": {
78
- "@astryxdesign/charts": "0.1.6-canary.dd1d655",
79
- "@astryxdesign/core": "0.1.6-canary.dd1d655",
80
- "@astryxdesign/lab": "0.1.6-canary.dd1d655",
81
- "@astryxdesign/theme-neutral": "0.1.6-canary.dd1d655",
82
+ "@astryxdesign/charts": "0.1.6-canary.e65bbd4",
83
+ "@astryxdesign/core": "0.1.6-canary.e65bbd4",
84
+ "@astryxdesign/lab": "0.1.6-canary.e65bbd4",
85
+ "@astryxdesign/theme-neutral": "0.1.6-canary.e65bbd4",
82
86
  "gpt-tokenizer": "^3.4.0"
83
87
  },
84
88
  "peerDependenciesMeta": {
@@ -96,10 +100,10 @@
96
100
  }
97
101
  },
98
102
  "devDependencies": {
99
- "@astryxdesign/charts": "0.1.6-canary.dd1d655",
100
- "@astryxdesign/core": "0.1.6-canary.dd1d655",
101
- "@astryxdesign/lab": "0.1.6-canary.dd1d655",
102
- "@astryxdesign/theme-neutral": "0.1.6-canary.dd1d655",
103
+ "@astryxdesign/charts": "0.1.6-canary.e65bbd4",
104
+ "@astryxdesign/core": "0.1.6-canary.e65bbd4",
105
+ "@astryxdesign/lab": "0.1.6-canary.e65bbd4",
106
+ "@astryxdesign/theme-neutral": "0.1.6-canary.e65bbd4",
103
107
  "gpt-tokenizer": "^3.4.0"
104
108
  },
105
109
  "scripts": {
@@ -8,7 +8,7 @@ import * as fs from 'node:fs';
8
8
  import * as path from 'node:path';
9
9
  import {createJiti} from 'jiti';
10
10
  import {loadModuleWithSchema} from '../lib/module-loader.mjs';
11
- import {TemplateEnvelopeSchema} from '../template.mjs';
11
+ import {TemplateEnvelopeSchema} from '../schemas/template-schema.mjs';
12
12
  import {CLI_ROOT, discoverExternalPackages} from '../utils/paths.mjs';
13
13
  import {
14
14
  assertWithin,
@@ -67,11 +67,6 @@ 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
-
75
70
  /**
76
71
  * Verify each declared contribution root exists on disk. A declared-but-missing
77
72
  * root is a `missing_root` error.
@@ -365,6 +360,3 @@ export function summarizeIssues(issues) {
365
360
  }
366
361
  return {errors, warnings};
367
362
  }
368
-
369
- // Re-export issue constructors for callers/tests that want them.
370
- export {error as integrationError, warning as integrationWarning};
@@ -20,6 +20,7 @@ describe('registry', () => {
20
20
  '0.1.2',
21
21
  '0.1.3',
22
22
  '0.1.5',
23
+ '0.1.7',
23
24
  ]);
24
25
  });
25
26
  });
@@ -21,6 +21,7 @@ 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')],
24
25
  ]);
25
26
 
26
27
  // Re-export from the shared utility so registry callers and other consumers
@@ -0,0 +1,120 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, it, expect} from 'vitest';
4
+
5
+ async function applyTransform(source) {
6
+ const {default: transform} = await import(
7
+ '../migrate-table-tableprops-to-direct-props.mjs'
8
+ );
9
+ const jscodeshift = (await import('jscodeshift')).default;
10
+ const j = jscodeshift.withParser('tsx');
11
+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};
12
+ const file = {source, path: 'test.tsx'};
13
+ const result = transform(file, api);
14
+ return result ?? source;
15
+ }
16
+
17
+ const TODO = 'TODO(astryx): tableProps is deprecated';
18
+
19
+ describe('migrate-table-tableprops-to-direct-props', () => {
20
+ it('lifts className and style to sibling props', async () => {
21
+ const input = `import {Table} from '@astryxdesign/core';
22
+ const x = <Table tableProps={{className: 'striped', style: {width: 400}}} columns={cols} />;`;
23
+ const output = await applyTransform(input);
24
+ expect(output).toContain(`className='striped'`);
25
+ expect(output).toContain('style={{width: 400}}');
26
+ expect(output).not.toContain('tableProps');
27
+ });
28
+
29
+ it(`lifts 'aria-label' and 'data-testid' string keys to hyphenated props`, async () => {
30
+ const input = `import {Table} from '@astryxdesign/core/Table';
31
+ const x = <Table tableProps={{'aria-label': 'Users', 'data-testid': 'users-table'}} />;`;
32
+ const output = await applyTransform(input);
33
+ expect(output).toContain(`aria-label='Users'`);
34
+ expect(output).toContain(`data-testid='users-table'`);
35
+ expect(output).not.toContain('tableProps');
36
+ });
37
+
38
+ it('lifts id and an onClick handler', async () => {
39
+ const input = `import {Table} from '@xds/core';
40
+ const x = <Table tableProps={{id: 'users', onClick: (e) => handle(e)}} />;`;
41
+ const output = await applyTransform(input);
42
+ expect(output).toContain(`id='users'`);
43
+ expect(output).toContain('onClick={(e) => handle(e)}');
44
+ expect(output).not.toContain('tableProps');
45
+ });
46
+
47
+ it('keeps colliding keys in a shrunken tableProps with a TODO comment', async () => {
48
+ const input = `import {Table} from '@astryxdesign/core';
49
+ const x = <Table className='mine' tableProps={{className: 'theirs', id: 'users'}} />;`;
50
+ const output = await applyTransform(input);
51
+ // Non-colliding key lifted
52
+ expect(output).toContain(`id='users'`);
53
+ // Existing sibling wins; colliding key stays inside tableProps
54
+ expect(output).toContain(`className='mine'`);
55
+ expect(output).toContain('tableProps={{');
56
+ expect(output).toContain(`className: 'theirs'`);
57
+ expect(output).not.toContain('id: ');
58
+ expect(output).toContain(TODO);
59
+ });
60
+
61
+ it('leaves a dynamic tableProps={identifier} untouched with a TODO comment', async () => {
62
+ const input = `import {Table} from '@astryxdesign/core';
63
+ const x = <Table tableProps={props} />;`;
64
+ const output = await applyTransform(input);
65
+ expect(output).toContain('tableProps={props}');
66
+ expect(output).toContain(TODO);
67
+ });
68
+
69
+ it('leaves an object containing a spread untouched with a TODO comment (no partial lift)', async () => {
70
+ const input = `import {Table} from '@astryxdesign/core';
71
+ const x = <Table tableProps={{className: 'x', ...rest}} />;`;
72
+ const output = await applyTransform(input);
73
+ expect(output).toContain(`tableProps={{className: 'x', ...rest}}`);
74
+ expect(output).not.toContain(`<Table className=`);
75
+ expect(output).toContain(TODO);
76
+ });
77
+
78
+ it('transforms aliased Table imports', async () => {
79
+ const input = `import {Table as DataTable} from '@astryxdesign/core';
80
+ const x = <DataTable tableProps={{className: 'x'}} />;`;
81
+ const output = await applyTransform(input);
82
+ expect(output).toContain(`<DataTable className='x' />`);
83
+ expect(output).not.toContain('tableProps');
84
+ });
85
+
86
+ it('does not touch other components with a tableProps attribute', async () => {
87
+ const input = `import {Table} from '@astryxdesign/core';
88
+ const a = <Table tableProps={{id: 'users'}} />;
89
+ const b = <OtherComponent tableProps={{className: 'x'}} />;`;
90
+ const output = await applyTransform(input);
91
+ expect(output).toContain(`<Table id='users' />`);
92
+ expect(output).toContain(`<OtherComponent tableProps={{className: 'x'}} />`);
93
+ });
94
+
95
+ it('returns undefined for files without a Table import', async () => {
96
+ const {default: transform} = await import(
97
+ '../migrate-table-tableprops-to-direct-props.mjs'
98
+ );
99
+ const jscodeshift = (await import('jscodeshift')).default;
100
+ const j = jscodeshift.withParser('tsx');
101
+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};
102
+ const source = `import {Grid} from '@astryxdesign/core';
103
+ const x = <Table tableProps={{className: 'x'}} />;`;
104
+ const result = transform({source, path: 'test.tsx'}, api);
105
+ expect(result).toBeUndefined();
106
+ });
107
+
108
+ it('returns undefined for already-migrated files (no tableProps)', async () => {
109
+ const {default: transform} = await import(
110
+ '../migrate-table-tableprops-to-direct-props.mjs'
111
+ );
112
+ const jscodeshift = (await import('jscodeshift')).default;
113
+ const j = jscodeshift.withParser('tsx');
114
+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};
115
+ const source = `import {Table} from '@astryxdesign/core';
116
+ const x = <Table className='x' />;`;
117
+ const result = transform({source, path: 'test.tsx'}, api);
118
+ expect(result).toBeUndefined();
119
+ });
120
+ });
@@ -0,0 +1,19 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file v0.1.7 transform manifest
5
+ *
6
+ * Lists all codemods for the v0.1.7 release in the order they should run.
7
+ */
8
+
9
+ import migrateTableTablePropsToDirectProps, {
10
+ meta as migrateTableTablePropsToDirectPropsMeta,
11
+ } from './migrate-table-tableprops-to-direct-props.mjs';
12
+
13
+ export default [
14
+ {
15
+ name: 'migrate-table-tableprops-to-direct-props',
16
+ transform: migrateTableTablePropsToDirectProps,
17
+ meta: migrateTableTablePropsToDirectPropsMeta,
18
+ },
19
+ ];
@@ -0,0 +1,188 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Codemod: Migrate Table tableProps to direct root props
5
+ * @see https://github.com/facebook/astryx/issues/3679
6
+ *
7
+ * `tableProps` (typed HTMLAttributes<HTMLTableElement>, nesting HTML
8
+ * attributes one level deep) is deprecated. As of v0.1.7, <Table> honors
9
+ * className/style/xstyle directly and spreads all other BaseProps
10
+ * (id, aria-*, data-*, event handlers, ...) onto the root <table>, with
11
+ * direct props taking precedence over tableProps.
12
+ *
13
+ * This codemod lifts object-literal `tableProps` keys into sibling JSX
14
+ * props:
15
+ *
16
+ * - tableProps={{className: 'x', style: s}} → className="x" style={s}
17
+ * - String-literal keys ('aria-label', 'data-testid') become hyphenated
18
+ * JSX attributes.
19
+ * - Keys that collide with an existing sibling attribute (or fail the
20
+ * attribute-name guard) are kept inside a shrunken tableProps with a
21
+ * trailing TODO comment for manual migration.
22
+ * - Dynamic values (tableProps={props}, tableProps={fn()}, objects with
23
+ * spreads/computed keys/methods) are left untouched with a TODO comment.
24
+ *
25
+ * Only elements whose name resolves to a `Table` import (alias-aware)
26
+ * from an Astryx core source are rewritten. No import changes are needed.
27
+ */
28
+
29
+ export const meta = {
30
+ title: 'Migrate Table tableProps to direct root props',
31
+ description:
32
+ 'Lifts object-literal `tableProps` keys on <Table> into sibling JSX props ' +
33
+ '(className, style, id, aria-*, data-*, event handlers). Dynamic or ' +
34
+ 'colliding entries are kept and annotated with a TODO comment.',
35
+ pr: '#3679',
36
+ };
37
+
38
+ /** Import sources that provide the Astryx Table component. */
39
+ const TABLE_IMPORT_SOURCES = new Set([
40
+ '@astryxdesign/core',
41
+ '@astryxdesign/core/Table',
42
+ '@xds/core',
43
+ '@xds/core/Table',
44
+ ]);
45
+
46
+ /** Keys must be valid JSX attribute names to be lifted. */
47
+ const LIFTABLE_KEY_RE = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
48
+
49
+ const TODO_COMMENT =
50
+ ' TODO(astryx): tableProps is deprecated — merge these into direct props manually ';
51
+
52
+ /**
53
+ * Extract the static key name from an object property, or null when the
54
+ * property is not a simple liftable entry (spread, computed key, method,
55
+ * getter/setter, non-string literal key).
56
+ */
57
+ function getPropertyKeyName(prop) {
58
+ if (prop.type !== 'ObjectProperty' && prop.type !== 'Property') return null;
59
+ // espree-style Property nodes: skip methods and accessors
60
+ if (prop.method || (prop.kind != null && prop.kind !== 'init')) return null;
61
+ if (prop.computed) return null;
62
+ const key = prop.key;
63
+ if (key.type === 'Identifier') return key.name;
64
+ if (
65
+ (key.type === 'StringLiteral' || key.type === 'Literal') &&
66
+ typeof key.value === 'string'
67
+ ) {
68
+ return key.value;
69
+ }
70
+ return null;
71
+ }
72
+
73
+ export default function transformer(file, api) {
74
+ const j = api.jscodeshift;
75
+ const root = j(file.source);
76
+ let hasChanges = false;
77
+
78
+ // --- 1. Track local names for the Table import (alias-aware) ---
79
+ const tableLocals = new Set();
80
+ root.find(j.ImportDeclaration).forEach((path) => {
81
+ if (!TABLE_IMPORT_SOURCES.has(path.node.source.value)) return;
82
+ for (const spec of path.node.specifiers ?? []) {
83
+ if (spec.type === 'ImportSpecifier' && spec.imported.name === 'Table') {
84
+ tableLocals.add(spec.local.name);
85
+ }
86
+ }
87
+ });
88
+
89
+ if (tableLocals.size === 0) return undefined;
90
+
91
+ function attachTodo(attr) {
92
+ if (!attr.comments) attr.comments = [];
93
+ if (attr.comments.some((c) => c.value === TODO_COMMENT)) return;
94
+ attr.comments.push(j.commentBlock(TODO_COMMENT, false, true));
95
+ hasChanges = true;
96
+ }
97
+
98
+ function buildAttributeValue(valueNode) {
99
+ if (
100
+ valueNode.type === 'StringLiteral' ||
101
+ (valueNode.type === 'Literal' && typeof valueNode.value === 'string')
102
+ ) {
103
+ return j.stringLiteral(valueNode.value);
104
+ }
105
+ return j.jsxExpressionContainer(valueNode);
106
+ }
107
+
108
+ // --- 2. Rewrite tableProps on tracked <Table> elements ---
109
+ root.find(j.JSXOpeningElement).forEach((path) => {
110
+ const name = path.node.name;
111
+ const componentName = name.type === 'JSXIdentifier' ? name.name : null;
112
+ if (!componentName || !tableLocals.has(componentName)) return;
113
+
114
+ const attrs = path.node.attributes;
115
+ const tablePropsAttr = attrs.find(
116
+ (a) => a.type === 'JSXAttribute' && a.name?.name === 'tableProps',
117
+ );
118
+ if (!tablePropsAttr) return;
119
+
120
+ const value = tablePropsAttr.value;
121
+ const isObjectLiteral =
122
+ value?.type === 'JSXExpressionContainer' &&
123
+ value.expression.type === 'ObjectExpression';
124
+
125
+ // Dynamic case: tableProps={identifier}, tableProps={fn()}, ... —
126
+ // leave the attribute untouched and warn via a trailing comment
127
+ // (api.report is a stub; comments are the only warning channel).
128
+ if (!isObjectLiteral) {
129
+ attachTodo(tablePropsAttr);
130
+ return;
131
+ }
132
+
133
+ const obj = value.expression;
134
+
135
+ // Objects containing spreads, computed keys, or methods are treated
136
+ // as dynamic: no partial lift, just the TODO comment.
137
+ const allSimple = obj.properties.every(
138
+ (prop) => getPropertyKeyName(prop) !== null,
139
+ );
140
+ if (!allSimple) {
141
+ attachTodo(tablePropsAttr);
142
+ return;
143
+ }
144
+
145
+ const lifted = [];
146
+ const kept = [];
147
+ for (const prop of obj.properties) {
148
+ const keyName = getPropertyKeyName(prop);
149
+ const collidesWithSibling = attrs.some(
150
+ (a) => a.type === 'JSXAttribute' && a.name?.name === keyName,
151
+ );
152
+ const collidesWithLifted = lifted.some(
153
+ (a) => a.name.name === keyName,
154
+ );
155
+ if (
156
+ !LIFTABLE_KEY_RE.test(keyName) ||
157
+ collidesWithSibling ||
158
+ collidesWithLifted
159
+ ) {
160
+ kept.push(prop);
161
+ continue;
162
+ }
163
+ lifted.push(
164
+ j.jsxAttribute(
165
+ j.jsxIdentifier(keyName),
166
+ buildAttributeValue(prop.value),
167
+ ),
168
+ );
169
+ }
170
+
171
+ const tablePropsIdx = attrs.indexOf(tablePropsAttr);
172
+ if (kept.length === 0) {
173
+ // All keys lifted — replace tableProps with the sibling attributes.
174
+ attrs.splice(tablePropsIdx, 1, ...lifted);
175
+ hasChanges = true;
176
+ } else {
177
+ // Some keys collide or fail the name guard — keep only those in a
178
+ // shrunken tableProps and flag it for manual migration.
179
+ attrs.splice(tablePropsIdx, 0, ...lifted);
180
+ obj.properties = kept;
181
+ attachTodo(tablePropsAttr);
182
+ if (lifted.length > 0) hasChanges = true;
183
+ }
184
+ });
185
+
186
+ if (!hasChanges) return undefined;
187
+ return root.toSource({quote: 'single'});
188
+ }