@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
@@ -1,240 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Proves the minimal `exports` recipe an integration package needs so a
5
- * bundler-resolution consumer can `import()` its block templates AND type-check
6
- * them under `moduleResolution: bundler`.
7
- *
8
- * Integration packages in this ecosystem ship TypeScript SOURCE — their block
9
- * templates are `.tsx` files with no compiled `.d.ts`. A later feature renders
10
- * showcase previews by a REAL dynamic `import()` of a block's `.tsx` source
11
- * (e.g. `import('@acme/widgets/templates/Gauge/GaugeShowcase.tsx')`) instead of
12
- * eval'ing source text. For that import to resolve, the integration's
13
- * `package.json#exports` map must GATE the deep path.
14
- *
15
- * These tests stand up a throwaway `@acme/widgets` fixture and drive the two
16
- * gates that matter with the repo's own toolchain:
17
- * 1. `tsc --noEmit` under `moduleResolution: bundler` (the consumer profile
18
- * used by the Next.js example apps — NO `allowImportingTsExtensions`).
19
- * 2. `esbuild --bundle` (a real bundler resolving + loading the deep import).
20
- *
21
- * CANONICAL RECIPE (see integration-authoring.md):
22
- * exports: { "./templates/*.tsx": "./templates/*.tsx" }
23
- * import: import('@acme/widgets/templates/<Name>/<Name>Showcase.tsx') // WITH .tsx
24
- *
25
- * The negative controls lock in WHY the extension is required: a bare
26
- * `./templates/*` export with an extensionless import fails to type-check under
27
- * bundler resolution (TS cannot infer the `.tsx` extension for a deep
28
- * specifier), and an extensionless import fails to bundle.
29
- */
30
-
31
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
32
- import * as fs from 'node:fs';
33
- import * as os from 'node:os';
34
- import * as path from 'node:path';
35
- import {createRequire} from 'node:module';
36
- import {execFileSync} from 'node:child_process';
37
-
38
- const require = createRequire(import.meta.url);
39
-
40
- /** Resolve the workspace tsc/esbuild binaries; null if unavailable. */
41
- function resolveBin(spec) {
42
- try {
43
- return require.resolve(spec);
44
- } catch {
45
- return null;
46
- }
47
- }
48
- const TSC_BIN = resolveBin('typescript/bin/tsc');
49
- const ESBUILD_BIN = resolveBin('esbuild/bin/esbuild');
50
-
51
- let tmpDir;
52
-
53
- /**
54
- * Build an @acme/widgets fixture: a block template (`.template.ts` doc +
55
- * same-stem `.tsx` source) under `templates/`, plus an astryx.integration
56
- * manifest, plus a caller-supplied `exports` map.
57
- * @param {Record<string, string> | undefined} exportsMap
58
- */
59
- function makeWidgets(exportsMap) {
60
- const pkgDir = path.join(tmpDir, 'node_modules', '@acme', 'widgets');
61
- const blockDir = path.join(pkgDir, 'templates', 'Gauge');
62
- fs.mkdirSync(blockDir, {recursive: true});
63
-
64
- const pkg = {name: '@acme/widgets', version: '2.0.0', type: 'module'};
65
- if (exportsMap) pkg.exports = exportsMap;
66
- fs.writeFileSync(
67
- path.join(pkgDir, 'package.json'),
68
- JSON.stringify(pkg, null, 2),
69
- );
70
- fs.writeFileSync(
71
- path.join(pkgDir, 'astryx.integration.mjs'),
72
- `export default { templates: './templates' };\n`,
73
- );
74
- // The template-spec doc (canonical `.template.*` family).
75
- fs.writeFileSync(
76
- path.join(blockDir, 'GaugeShowcase.template.ts'),
77
- `export default { name: 'Gauge showcase', description: 'A gauge.' };\n`,
78
- );
79
- // The same-stem `.tsx` SOURCE that a preview will dynamically import().
80
- // Returns a plain value so the fixture type-checks without React types.
81
- fs.writeFileSync(
82
- path.join(blockDir, 'GaugeShowcase.tsx'),
83
- `const GaugeShowcase = (): string => 'gauge-showcase';\n` +
84
- `export default GaugeShowcase;\n`,
85
- );
86
- return pkgDir;
87
- }
88
-
89
- /** Write a consumer that dynamically imports the given specifier. */
90
- function writeConsumer(specifier) {
91
- fs.writeFileSync(
92
- path.join(tmpDir, 'consumer.ts'),
93
- `const load = () => import('${specifier}');\nexport default load;\n`,
94
- );
95
- }
96
-
97
- /**
98
- * The realistic consumer tsconfig: matches the repo's Next.js example apps
99
- * (`moduleResolution: bundler`, `noEmit`, and deliberately NO
100
- * `allowImportingTsExtensions`).
101
- */
102
- function writeTsconfig() {
103
- fs.writeFileSync(
104
- path.join(tmpDir, 'tsconfig.json'),
105
- JSON.stringify(
106
- {
107
- compilerOptions: {
108
- target: 'ES2022',
109
- lib: ['ES2022', 'DOM', 'DOM.Iterable'],
110
- module: 'ESNext',
111
- moduleResolution: 'bundler',
112
- jsx: 'react-jsx',
113
- strict: true,
114
- skipLibCheck: true,
115
- esModuleInterop: true,
116
- noEmit: true,
117
- isolatedModules: true,
118
- },
119
- include: ['consumer.ts'],
120
- },
121
- null,
122
- 2,
123
- ),
124
- );
125
- }
126
-
127
- /** @returns {{ok: boolean, out: string}} */
128
- function runTsc() {
129
- try {
130
- execFileSync(process.execPath, [TSC_BIN, '--noEmit', '-p', 'tsconfig.json'], {
131
- cwd: tmpDir,
132
- stdio: 'pipe',
133
- });
134
- return {ok: true, out: ''};
135
- } catch (e) {
136
- return {ok: false, out: `${e.stdout ?? ''}${e.stderr ?? ''}`};
137
- }
138
- }
139
-
140
- /** @returns {{ok: boolean, out: string}} */
141
- function runEsbuild() {
142
- try {
143
- // esbuild's bin is a native executable (not a node script), so invoke it
144
- // directly rather than through process.execPath.
145
- execFileSync(
146
- ESBUILD_BIN,
147
- [
148
- 'consumer.ts',
149
- '--bundle',
150
- '--format=esm',
151
- '--loader:.tsx=tsx',
152
- '--outfile=/dev/null',
153
- '--log-level=error',
154
- ],
155
- {cwd: tmpDir, stdio: 'pipe'},
156
- );
157
- return {ok: true, out: ''};
158
- } catch (e) {
159
- return {ok: false, out: `${e.stdout ?? ''}${e.stderr ?? ''}`};
160
- }
161
- }
162
-
163
- beforeEach(() => {
164
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-block-exports-'));
165
- fs.writeFileSync(
166
- path.join(tmpDir, 'package.json'),
167
- JSON.stringify({name: 'consumer', private: true, type: 'module'}),
168
- );
169
- writeTsconfig();
170
- });
171
-
172
- afterEach(() => {
173
- fs.rmSync(tmpDir, {recursive: true, force: true});
174
- });
175
-
176
- const CANONICAL = 'import(@acme/widgets/templates/Gauge/GaugeShowcase.tsx)';
177
- const SPEC = '@acme/widgets/templates/Gauge/GaugeShowcase.tsx';
178
-
179
- describe('integration block-template exports recipe', () => {
180
- it.runIf(TSC_BIN != null)(
181
- `CANONICAL: exports {"./templates/*.tsx"} + ${CANONICAL} type-checks under bundler resolution`,
182
- () => {
183
- makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
184
- writeConsumer(SPEC);
185
- const {ok, out} = runTsc();
186
- expect(out).toBe('');
187
- expect(ok).toBe(true);
188
- },
189
- 30_000,
190
- );
191
-
192
- it.runIf(ESBUILD_BIN != null)(
193
- `CANONICAL: the same import resolves + bundles with a real bundler`,
194
- () => {
195
- makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
196
- writeConsumer(SPEC);
197
- const {ok, out} = runEsbuild();
198
- expect(out).toBe('');
199
- expect(ok).toBe(true);
200
- },
201
- 30_000,
202
- );
203
-
204
- it.runIf(TSC_BIN != null)(
205
- 'NEGATIVE: an extensionless import does NOT type-check (TS cannot infer .tsx)',
206
- () => {
207
- makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
208
- writeConsumer('@acme/widgets/templates/Gauge/GaugeShowcase');
209
- const {ok, out} = runTsc();
210
- expect(ok).toBe(false);
211
- expect(out).toContain('TS2307');
212
- },
213
- 30_000,
214
- );
215
-
216
- it.runIf(TSC_BIN != null)(
217
- 'NEGATIVE: a bare "./templates/*" export (no .tsx entry) does NOT type-check the .tsx import',
218
- () => {
219
- // Only a bare mapping — the extensionful subpath is not exported.
220
- makeWidgets({'./templates/*': './templates/*'});
221
- writeConsumer(SPEC);
222
- const {ok, out} = runTsc();
223
- expect(ok).toBe(false);
224
- // Bare export forces the TS5097 opt-in requirement (allowImportingTsExtensions).
225
- expect(out).toContain('TS5097');
226
- },
227
- 30_000,
228
- );
229
-
230
- it.runIf(ESBUILD_BIN != null)(
231
- 'NEGATIVE: an extensionless import does NOT bundle against the .tsx-only export',
232
- () => {
233
- makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
234
- writeConsumer('@acme/widgets/templates/Gauge/GaugeShowcase');
235
- const {ok} = runEsbuild();
236
- expect(ok).toBe(false);
237
- },
238
- 30_000,
239
- );
240
- });
@@ -1,246 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file The canonical `.template.{ts,mjs,js}` suffix is discovered identically
5
- * to the legacy `.doc.{ts,mjs,js}` suffix.
6
- *
7
- * Template-spec files are named for what they are: a scaffoldable TEMPLATE that
8
- * exports `createBlockTemplate`/`createPageTemplate`. The `.doc.*` suffix was
9
- * inherited from the component-doc convention and is still accepted during the
10
- * transition. These tests stand up integration templates and external blocks in
11
- * both families and assert byte-for-byte-equivalent discovery + scaffolding.
12
- */
13
-
14
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
15
- import * as fs from 'node:fs';
16
- import * as path from 'node:path';
17
- import * as os from 'node:os';
18
- import {
19
- template,
20
- findShowcase,
21
- findRelatedBlocks,
22
- } from './template.mjs';
23
-
24
- /** Absolute path to the CLI package so fixtures can import /src/template.mjs. */
25
- const CLI_PKG = path.resolve(import.meta.dirname, '..', '..');
26
-
27
- let tmpDir;
28
- let originalCwd;
29
-
30
- function makeConsumer() {
31
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-template-suffix-'));
32
- fs.writeFileSync(
33
- path.join(dir, 'package.json'),
34
- JSON.stringify({name: 'consumer'}),
35
- );
36
- fs.writeFileSync(
37
- path.join(dir, 'astryx.config.mjs'),
38
- `export default { integrations: ['@acme/widgets'] };\n`,
39
- );
40
- return dir;
41
- }
42
-
43
- function installWidgets(consumerDir) {
44
- const pkgDir = path.join(consumerDir, 'node_modules', '@acme', 'widgets');
45
- fs.mkdirSync(path.join(pkgDir, 'templates'), {recursive: true});
46
- fs.writeFileSync(
47
- path.join(pkgDir, 'package.json'),
48
- JSON.stringify({name: '@acme/widgets', version: '2.0.0'}),
49
- );
50
- fs.writeFileSync(
51
- path.join(pkgDir, 'astryx.integration.mjs'),
52
- `export default { templates: './templates' };\n`,
53
- );
54
- return pkgDir;
55
- }
56
-
57
- /**
58
- * Write a template-spec file (default-export createPageTemplate/BlockTemplate)
59
- * plus its same-stem `.tsx` source under the templates root.
60
- * @param {string} pkgDir
61
- * @param {string} id
62
- * @param {{kind: 'page'|'block', suffix: string}} opts
63
- */
64
- function writeTemplate(pkgDir, id, {kind, suffix}) {
65
- const docPath = path.join(pkgDir, 'templates', `${id}${suffix}`);
66
- fs.mkdirSync(path.dirname(docPath), {recursive: true});
67
- const create =
68
- kind === 'page' ? 'createPageTemplate' : 'createBlockTemplate';
69
- fs.writeFileSync(
70
- docPath,
71
- `import {${create}} from '${CLI_PKG}/src/template.mjs';\n` +
72
- `export default ${create}({name: '${id} name', description: '${id} desc'});\n`,
73
- );
74
- fs.writeFileSync(
75
- path.join(pkgDir, 'templates', `${id}.tsx`),
76
- `export default function ${id.replace(/[^a-zA-Z0-9]/g, '')}() { return null; }\n`,
77
- );
78
- }
79
-
80
- beforeEach(() => {
81
- originalCwd = process.cwd();
82
- tmpDir = makeConsumer();
83
- process.chdir(tmpDir);
84
- });
85
-
86
- afterEach(() => {
87
- process.chdir(originalCwd);
88
- fs.rmSync(tmpDir, {recursive: true, force: true});
89
- });
90
-
91
- describe('integration templates: .template.* discovered like legacy .doc.*', () => {
92
- for (const suffix of ['.template.ts', '.template.mjs', '.doc.mjs']) {
93
- it(`discovers + lists a page template authored as ${suffix}`, async () => {
94
- const pkgDir = installWidgets(tmpDir);
95
- writeTemplate(pkgDir, 'pricing', {kind: 'page', suffix});
96
-
97
- const result = await template(undefined, {list: true, cwd: tmpDir});
98
- const entry = result.data.find(t => t.id === 'pricing');
99
- expect(entry).toBeTruthy();
100
- expect(entry.type).toBe('page');
101
- expect(entry.package).toBe('@acme/widgets');
102
- expect(entry.name).toBe('pricing name');
103
- expect(entry.description).toBe('pricing desc');
104
- });
105
-
106
- it(`scaffolds a page template authored as ${suffix}`, async () => {
107
- const pkgDir = installWidgets(tmpDir);
108
- writeTemplate(pkgDir, 'pricing', {kind: 'page', suffix});
109
-
110
- const result = await template('pricing', {
111
- targetPath: './dest',
112
- cwd: tmpDir,
113
- });
114
- expect(result.type).toBe('template.copy');
115
- expect(result.data.fileName).toBe('page.tsx');
116
- expect(fs.existsSync(path.join(tmpDir, 'dest', 'page.tsx'))).toBe(true);
117
- });
118
-
119
- it(`scaffolds a nested block template authored as ${suffix}`, async () => {
120
- const pkgDir = installWidgets(tmpDir);
121
- writeTemplate(pkgDir, 'marketing/hero', {kind: 'block', suffix});
122
-
123
- const result = await template('marketing/hero', {
124
- targetPath: './dest',
125
- cwd: tmpDir,
126
- });
127
- expect(result.type).toBe('template.copy');
128
- expect(result.data.fileName).toBe('hero.tsx');
129
- expect(fs.existsSync(path.join(tmpDir, 'dest', 'hero.tsx'))).toBe(true);
130
- });
131
- }
132
-
133
- it('treats a .template.ts and a legacy .doc.mjs identically (same shape)', async () => {
134
- const pkgDir = installWidgets(tmpDir);
135
- writeTemplate(pkgDir, 'gauge', {kind: 'block', suffix: '.template.ts'});
136
- writeTemplate(pkgDir, 'chip', {kind: 'block', suffix: '.doc.mjs'});
137
-
138
- const result = await template(undefined, {list: true, cwd: tmpDir});
139
- const gauge = result.data.find(t => t.id === 'gauge');
140
- const chip = result.data.find(t => t.id === 'chip');
141
-
142
- // Both discovered, both blocks, both from the same package, both ready.
143
- for (const entry of [gauge, chip]) {
144
- expect(entry).toBeTruthy();
145
- expect(entry.type).toBe('block');
146
- expect(entry.package).toBe('@acme/widgets');
147
- }
148
- // Field-by-field parity apart from the (intentionally different) id/name.
149
- expect(gauge.type).toBe(chip.type);
150
- expect(gauge.package).toBe(chip.package);
151
- });
152
- });
153
-
154
- describe('external showcase blocks: .template.* discovered like legacy .doc.*', () => {
155
- /**
156
- * Create a consumer whose @test/ext package contributes two showcase blocks,
157
- * one authored as `Foo.template.ts` and one as legacy `Bar.doc.mjs`.
158
- */
159
- function makeShowcaseFixture() {
160
- // Symlink the real core package (needed by findCoreDir during discovery).
161
- const realCoreDir = path.resolve(
162
- import.meta.dirname,
163
- '..',
164
- '..',
165
- '..',
166
- 'core',
167
- );
168
- const coreDir = path.join(tmpDir, 'packages', 'core');
169
- fs.mkdirSync(path.dirname(coreDir), {recursive: true});
170
- fs.symlinkSync(realCoreDir, coreDir);
171
-
172
- const extDir = path.join(tmpDir, 'node_modules', '@test', 'ext');
173
- const blocksDir = path.join(extDir, 'blocks', 'components');
174
-
175
- // Foo showcase — canonical .template.ts (default-export createBlockTemplate).
176
- const fooDir = path.join(blocksDir, 'Foo');
177
- fs.mkdirSync(fooDir, {recursive: true});
178
- fs.writeFileSync(
179
- path.join(fooDir, 'FooShowcase.template.ts'),
180
- `import {createBlockTemplate} from '${CLI_PKG}/src/template.mjs';\n` +
181
- `export default createBlockTemplate({\n` +
182
- ` name: 'Foo — Showcase',\n` +
183
- ` description: 'Foo showcase.',\n` +
184
- ` isShowcase: true,\n` +
185
- ` aspectRatio: 16 / 9,\n` +
186
- ` componentsUsed: ['Foo'],\n` +
187
- `});\n`,
188
- );
189
- fs.writeFileSync(
190
- path.join(fooDir, 'FooShowcase.tsx'),
191
- "'use client';\nexport default function FooShowcase() { return <div>Foo</div>; }",
192
- );
193
-
194
- // Bar showcase — legacy .doc.mjs (export const doc).
195
- const barDir = path.join(blocksDir, 'Bar');
196
- fs.mkdirSync(barDir, {recursive: true});
197
- fs.writeFileSync(
198
- path.join(barDir, 'BarShowcase.doc.mjs'),
199
- `export const doc = {\n` +
200
- ` type: 'block',\n` +
201
- ` name: 'Bar — Showcase',\n` +
202
- ` description: 'Bar showcase.',\n` +
203
- ` isReady: true,\n` +
204
- ` isShowcase: true,\n` +
205
- ` aspectRatio: 4 / 3,\n` +
206
- ` componentsUsed: ['Bar', 'Chip'],\n` +
207
- `};\n`,
208
- );
209
- fs.writeFileSync(
210
- path.join(barDir, 'BarShowcase.tsx'),
211
- "'use client';\nexport default function BarShowcase() { return <div>Bar</div>; }",
212
- );
213
-
214
- fs.writeFileSync(
215
- path.join(extDir, 'package.json'),
216
- JSON.stringify({
217
- name: '@test/ext',
218
- astryx: {docs: './src', category: 'Common', blocks: './blocks/components'},
219
- }),
220
- );
221
- fs.mkdirSync(path.join(extDir, 'src'), {recursive: true});
222
- }
223
-
224
- it('findShowcase resolves a .template.ts external block by directory name', async () => {
225
- makeShowcaseFixture();
226
- const result = await findShowcase('Foo', tmpDir);
227
- expect(result).not.toBeNull();
228
- expect(result.name).toBe('Foo — Showcase');
229
- expect(result.filePath).toContain('FooShowcase.tsx');
230
- });
231
-
232
- it('findShowcase resolves a legacy .doc.mjs external block by componentsUsed', async () => {
233
- makeShowcaseFixture();
234
- const result = await findShowcase('Bar', tmpDir);
235
- expect(result).not.toBeNull();
236
- expect(result.name).toBe('Bar — Showcase');
237
- });
238
-
239
- it('findRelatedBlocks finds both suffix families', async () => {
240
- makeShowcaseFixture();
241
- const foo = await findRelatedBlocks('Foo', tmpDir);
242
- expect(foo.map(b => b.dirName)).toContain('FooShowcase');
243
- const chip = await findRelatedBlocks('Chip', tmpDir);
244
- expect(chip.map(b => b.dirName)).toContain('BarShowcase');
245
- });
246
- });
@@ -1,120 +0,0 @@
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
- });
@@ -1,19 +0,0 @@
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
- ];