@astryxdesign/cli 0.1.7-canary.6b74cb0 → 0.1.7-canary.7ceccc1
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 +9 -9
- package/src/codemods/__tests__/registry.test.mjs +1 -0
- package/src/codemods/registry.mjs +1 -0
- package/src/codemods/transforms/v0.1.8/__tests__/rename-avatar-size-scale.test.mjs +161 -0
- package/src/codemods/transforms/v0.1.8/index.mjs +19 -0
- package/src/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +234 -0
- package/templates/blocks/components/Avatar/AvatarFallbackChain.tsx +4 -4
- package/templates/blocks/components/Avatar/AvatarGroup.tsx +2 -2
- package/templates/blocks/components/Avatar/AvatarInitialsFallback.tsx +1 -1
- package/templates/blocks/components/Avatar/AvatarShowcase.tsx +4 -4
- package/templates/blocks/components/Avatar/AvatarUserCard.tsx +1 -1
- package/templates/blocks/components/Avatar/AvatarWithImage.tsx +4 -4
- package/templates/blocks/components/Avatar/AvatarWithStatus.tsx +3 -3
- package/templates/blocks/components/AvatarGroup/AvatarGroupShowcase.tsx +2 -2
- package/templates/blocks/components/AvatarGroupOverflow/AvatarGroupOverflowCustomText.tsx +1 -1
- package/templates/blocks/components/AvatarGroupOverflow/AvatarGroupOverflowDefault.tsx +1 -1
- package/templates/blocks/components/AvatarGroupOverflow/AvatarGroupOverflowShowcase.tsx +2 -2
- package/templates/blocks/components/AvatarStatusDot/AvatarStatusDotShowcase.tsx +3 -3
- package/templates/blocks/components/AvatarStatusDot/AvatarStatusDotVariants.tsx +3 -3
- package/templates/blocks/components/Carousel/CarouselSnap.tsx +1 -1
- package/templates/blocks/components/ChatMessage/ChatMessageAvatarName.tsx +2 -2
- package/templates/blocks/components/ChatMessage/ChatMessageMultiBubble.tsx +1 -1
- package/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleGrouping.tsx +1 -1
- package/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleMetadata.tsx +1 -1
- package/templates/blocks/components/ChatMessageList/ChatMessageListDensity.tsx +5 -9
- package/templates/blocks/components/ChatMessageList/ChatMessageListFullFeatured.tsx +1 -1
- package/templates/blocks/components/HoverCard/HoverCardShowcase.tsx +1 -1
- package/templates/blocks/components/Item/ItemWithMedia.tsx +2 -2
- package/templates/blocks/components/ListItem/ListItemWithMedia.tsx +2 -2
- package/templates/blocks/components/Pagination/PaginationDotsCarousel.tsx +2 -6
- package/templates/blocks/components/Stack/StackFillItem.tsx +2 -6
- package/templates/blocks/components/TypeaheadItem/TypeaheadItemShowcase.tsx +1 -1
- package/templates/pages/ai-chat/page.tsx +4 -4
- package/templates/pages/dashboard-portfolio/page.tsx +3 -11
- package/templates/pages/detail-page/page.tsx +5 -12
- package/templates/pages/documentation-design/page.tsx +1 -1
- package/templates/pages/messaging-shell/page.tsx +6 -8
- package/templates/pages/table-grouped/page.tsx +9 -14
- package/templates/pages/table-page/page.tsx +7 -9
- package/templates/pages/table-page-heatmap-status/page.tsx +5 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.1.7-canary.
|
|
3
|
+
"version": "0.1.7-canary.7ceccc1",
|
|
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.7-canary.
|
|
83
|
-
"@astryxdesign/core": "0.1.7-canary.
|
|
84
|
-
"@astryxdesign/lab": "0.1.7-canary.
|
|
85
|
-
"@astryxdesign/theme-neutral": "0.1.7-canary.
|
|
82
|
+
"@astryxdesign/charts": "0.1.7-canary.7ceccc1",
|
|
83
|
+
"@astryxdesign/core": "0.1.7-canary.7ceccc1",
|
|
84
|
+
"@astryxdesign/lab": "0.1.7-canary.7ceccc1",
|
|
85
|
+
"@astryxdesign/theme-neutral": "0.1.7-canary.7ceccc1",
|
|
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.7-canary.
|
|
104
|
-
"@astryxdesign/core": "0.1.7-canary.
|
|
105
|
-
"@astryxdesign/lab": "0.1.7-canary.
|
|
106
|
-
"@astryxdesign/theme-neutral": "0.1.7-canary.
|
|
103
|
+
"@astryxdesign/charts": "0.1.7-canary.7ceccc1",
|
|
104
|
+
"@astryxdesign/core": "0.1.7-canary.7ceccc1",
|
|
105
|
+
"@astryxdesign/lab": "0.1.7-canary.7ceccc1",
|
|
106
|
+
"@astryxdesign/theme-neutral": "0.1.7-canary.7ceccc1",
|
|
107
107
|
"gpt-tokenizer": "^3.4.0"
|
|
108
108
|
},
|
|
109
109
|
"scripts": {
|
|
@@ -22,6 +22,7 @@ const registry = new Map([
|
|
|
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
24
|
['0.1.7', () => import('./transforms/v0.1.7/index.mjs')],
|
|
25
|
+
['0.1.8', () => import('./transforms/v0.1.8/index.mjs')],
|
|
25
26
|
]);
|
|
26
27
|
|
|
27
28
|
// Re-export from the shared utility so registry callers and other consumers
|
|
@@ -0,0 +1,161 @@
|
|
|
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('../rename-avatar-size-scale.mjs');
|
|
7
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
8
|
+
const j = jscodeshift.withParser('tsx');
|
|
9
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
10
|
+
const file = {source, path: 'test.tsx'};
|
|
11
|
+
const result = transform(file, api);
|
|
12
|
+
return result ?? source;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('rename-avatar-size-scale', () => {
|
|
16
|
+
it('renames every named size on an Avatar JSX size attribute', async () => {
|
|
17
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
18
|
+
const a = <Avatar name="A" size="tiny" />;
|
|
19
|
+
const b = <Avatar name="B" size="xsmall" />;
|
|
20
|
+
const c = <Avatar name="C" size="small" />;
|
|
21
|
+
const d = <Avatar name="D" size="medium" />;
|
|
22
|
+
const e = <Avatar name="E" size="large" />;`;
|
|
23
|
+
const output = await applyTransform(input);
|
|
24
|
+
expect(output).toContain(`size='xsm'`);
|
|
25
|
+
expect(output).toContain(`size='sm'`);
|
|
26
|
+
expect(output).toContain(`size='md'`);
|
|
27
|
+
expect(output).toContain(`size='lg'`);
|
|
28
|
+
expect(output).toContain(`size='xl'`);
|
|
29
|
+
for (const old of ['tiny', 'xsmall', 'small', 'medium', 'large']) {
|
|
30
|
+
expect(output).not.toContain(`size="${old}"`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('renames size on AvatarGroup', async () => {
|
|
35
|
+
const input = `import {AvatarGroup} from '@astryxdesign/core';
|
|
36
|
+
const x = <AvatarGroup size="medium">{kids}</AvatarGroup>;`;
|
|
37
|
+
const output = await applyTransform(input);
|
|
38
|
+
expect(output).toContain(`size='lg'`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('leaves numeric sizes untouched', async () => {
|
|
42
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
43
|
+
const x = <Avatar name="A" size={48} />;`;
|
|
44
|
+
const output = await applyTransform(input);
|
|
45
|
+
expect(output).toContain('size={48}');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('is alias-aware', async () => {
|
|
49
|
+
const input = `import {Avatar as Face} from '@astryxdesign/core';
|
|
50
|
+
const x = <Face name="A" size="small" />;`;
|
|
51
|
+
const output = await applyTransform(input);
|
|
52
|
+
expect(output).toContain(`size='md'`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('renames the subpath and legacy import sources', async () => {
|
|
56
|
+
const sub = `import {Avatar} from '@astryxdesign/core/Avatar';
|
|
57
|
+
const x = <Avatar name="A" size="large" />;`;
|
|
58
|
+
expect(await applyTransform(sub)).toContain(`size='xl'`);
|
|
59
|
+
const legacy = `import {Avatar} from '@xds/core';
|
|
60
|
+
const x = <Avatar name="A" size="tiny" />;`;
|
|
61
|
+
expect(await applyTransform(legacy)).toContain(`size='xsm'`);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('renames a size inside a ternary on an Avatar element', async () => {
|
|
65
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
66
|
+
const x = <Avatar name="A" size={big ? 'large' : 'small'} />;`;
|
|
67
|
+
const output = await applyTransform(input);
|
|
68
|
+
expect(output).toContain(`big ? 'xl' : 'md'`);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('renames the UNIQUE names tiny/xsmall in Storybook options and size args', async () => {
|
|
72
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
73
|
+
const meta = {
|
|
74
|
+
argTypes: {size: {control: 'select', options: ['tiny', 'xsmall']}},
|
|
75
|
+
args: {size: 'tiny'},
|
|
76
|
+
};`;
|
|
77
|
+
const output = await applyTransform(input);
|
|
78
|
+
expect(output).toContain(`['xsm', 'sm']`);
|
|
79
|
+
expect(output).toContain(`size: 'xsm'`);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('renames a FULL Storybook options array (unique name unlocks ambiguous members)', async () => {
|
|
83
|
+
// The presence of a unique name (tiny/xsmall) proves the whole array is the
|
|
84
|
+
// Avatar size enum, so small/medium/large in it are safe to rename too.
|
|
85
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
86
|
+
const meta = {
|
|
87
|
+
argTypes: {size: {control: 'select', options: ['tiny', 'xsmall', 'small', 'medium', 'large']}},
|
|
88
|
+
};`;
|
|
89
|
+
const output = await applyTransform(input);
|
|
90
|
+
expect(output).toContain(`['xsm', 'sm', 'md', 'lg', 'xl']`);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('renames a standalone Avatar-size array literal used with .map()', async () => {
|
|
94
|
+
const input = `import {AvatarGroup} from '@astryxdesign/core';
|
|
95
|
+
const sizes = (['tiny', 'xsmall', 'small', 'medium', 'large'] as const).map(s => s);`;
|
|
96
|
+
const output = await applyTransform(input);
|
|
97
|
+
expect(output).toContain(`['xsm', 'sm', 'md', 'lg', 'xl']`);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('does NOT rename an array of ambiguous words with no unique Avatar name', async () => {
|
|
101
|
+
// Without tiny/xsmall, the array could be anything (priorities, densities),
|
|
102
|
+
// so ambiguous members are left untouched.
|
|
103
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
104
|
+
const densities = ['small', 'medium', 'large'] as const;`;
|
|
105
|
+
const output = await applyTransform(input);
|
|
106
|
+
expect(output).toContain(`['small', 'medium', 'large']`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('renames a UNIQUE name in a size-typed union literal', async () => {
|
|
110
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
111
|
+
type Props = {size: 'tiny' | 'xsmall'};`;
|
|
112
|
+
const output = await applyTransform(input);
|
|
113
|
+
expect(output).toContain(`'xsm' | 'sm'`);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// --- Precision guards: ambiguous common words must NOT be corrupted in
|
|
117
|
+
// --- context-blind positions, even in files that import Avatar. ---
|
|
118
|
+
|
|
119
|
+
it('does NOT rename ambiguous names in an unrelated union type', async () => {
|
|
120
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
121
|
+
type TaskPriority = 'urgent' | 'high' | 'medium' | 'low' | 'none';`;
|
|
122
|
+
const output = await applyTransform(input);
|
|
123
|
+
expect(output).toContain(`'medium'`);
|
|
124
|
+
expect(output).not.toContain(`'lg'`);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('does NOT rename an ambiguous name in a non-size object property', async () => {
|
|
128
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
129
|
+
const cfg = {priority: 'medium', density: 'large'};`;
|
|
130
|
+
const output = await applyTransform(input);
|
|
131
|
+
expect(output).toContain(`priority: 'medium'`);
|
|
132
|
+
expect(output).toContain(`density: 'large'`);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('does NOT rename an ambiguous name in a size-keyed object property (component unknown)', async () => {
|
|
136
|
+
// A `size: 'small'` object entry could belong to any component; renaming it
|
|
137
|
+
// blind would be unsafe, so it is left for manual migration.
|
|
138
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
139
|
+
const args = {size: 'small'};`;
|
|
140
|
+
const output = await applyTransform(input);
|
|
141
|
+
expect(output).toContain(`size: 'small'`);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('does not touch files that never import Avatar/AvatarGroup', async () => {
|
|
145
|
+
const input = `import {Badge} from '@astryxdesign/core';
|
|
146
|
+
const x = <Badge size="small" />;
|
|
147
|
+
type P = 'tiny' | 'xsmall';`;
|
|
148
|
+
const output = await applyTransform(input);
|
|
149
|
+
expect(output).toContain(`size="small"`);
|
|
150
|
+
expect(output).toContain(`'tiny' | 'xsmall'`);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('does not rename an unrelated non-size string in an Avatar file', async () => {
|
|
154
|
+
const input = `import {Avatar} from '@astryxdesign/core';
|
|
155
|
+
const label = 'small';
|
|
156
|
+
const x = <Avatar name="A" size="small" />;`;
|
|
157
|
+
const output = await applyTransform(input);
|
|
158
|
+
expect(output).toContain(`const label = 'small'`);
|
|
159
|
+
expect(output).toContain(`size='md'`);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file v0.1.8 transform manifest
|
|
5
|
+
*
|
|
6
|
+
* Lists all codemods for the v0.1.8 release in the order they should run.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import renameAvatarSizeScale, {
|
|
10
|
+
meta as renameAvatarSizeScaleMeta,
|
|
11
|
+
} from './rename-avatar-size-scale.mjs';
|
|
12
|
+
|
|
13
|
+
export default [
|
|
14
|
+
{
|
|
15
|
+
name: 'rename-avatar-size-scale',
|
|
16
|
+
transform: renameAvatarSizeScale,
|
|
17
|
+
meta: renameAvatarSizeScaleMeta,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Codemod: Rename Avatar named sizes to Icon's abbreviated scale
|
|
5
|
+
* @see https://github.com/facebook/astryx/issues/2672
|
|
6
|
+
*
|
|
7
|
+
* As of v0.1.8, Avatar and AvatarGroup use the same abbreviated size scale as
|
|
8
|
+
* Icon (`xsm`/`sm`/`md`/`lg`/`xl`) instead of full words. Pixel values are
|
|
9
|
+
* unchanged — only the names move:
|
|
10
|
+
*
|
|
11
|
+
* tiny (20px) → xsm
|
|
12
|
+
* xsmall (24px) → sm
|
|
13
|
+
* small (36px) → md ← also the new default (was `small`)
|
|
14
|
+
* medium (48px) → lg
|
|
15
|
+
* large (128px) → xl
|
|
16
|
+
*
|
|
17
|
+
* The default size shifts from `small` to `md`, but that is the SAME 36px, so
|
|
18
|
+
* call sites that relied on the default need no change.
|
|
19
|
+
*
|
|
20
|
+
* ## Precision
|
|
21
|
+
*
|
|
22
|
+
* `small`, `medium`, and `large` are common English words that appear as
|
|
23
|
+
* unrelated string/type literals (priorities, statuses, breakpoints, …). To
|
|
24
|
+
* avoid corrupting those, the three AMBIGUOUS names are renamed ONLY in a
|
|
25
|
+
* precise context: a `size` JSX attribute on a component that resolves to an
|
|
26
|
+
* Avatar/AvatarGroup import (alias-aware).
|
|
27
|
+
*
|
|
28
|
+
* `tiny` and `xsmall` are unique to Avatar's scale, so they are additionally
|
|
29
|
+
* renamed in context-blind positions (object properties keyed `size`/`*Size`,
|
|
30
|
+
* Storybook `options` arrays, and size-typed union literals) within files that
|
|
31
|
+
* import Avatar/AvatarGroup.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export const meta = {
|
|
35
|
+
title: 'Rename Avatar named sizes tiny/xsmall/small/medium/large → xsm/sm/md/lg/xl',
|
|
36
|
+
description:
|
|
37
|
+
'Avatar and AvatarGroup adopt Icon\'s abbreviated size scale ' +
|
|
38
|
+
'(xsm/sm/md/lg/xl). Pixel values are unchanged; the default moves from ' +
|
|
39
|
+
'`small` to `md` (both 36px). The ambiguous names small/medium/large are ' +
|
|
40
|
+
'only renamed on Avatar/AvatarGroup `size` JSX attributes; the unique ' +
|
|
41
|
+
'names tiny/xsmall are also renamed in size-keyed props, Storybook ' +
|
|
42
|
+
'options, and union types in files importing Avatar/AvatarGroup.',
|
|
43
|
+
pr: '#2672',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Import sources that provide the Astryx Avatar/AvatarGroup components. */
|
|
47
|
+
const IMPORT_SOURCES = new Set([
|
|
48
|
+
'@astryxdesign/core',
|
|
49
|
+
'@astryxdesign/core/Avatar',
|
|
50
|
+
'@astryxdesign/core/AvatarGroup',
|
|
51
|
+
'@xds/core',
|
|
52
|
+
'@xds/core/Avatar',
|
|
53
|
+
'@xds/core/AvatarGroup',
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
/** Component names whose `size` prop is renamed. */
|
|
57
|
+
const TARGET_IMPORTED_NAMES = new Set(['Avatar', 'AvatarGroup']);
|
|
58
|
+
|
|
59
|
+
/** Old → new size-name mapping. */
|
|
60
|
+
const RENAMES = new Map([
|
|
61
|
+
['tiny', 'xsm'],
|
|
62
|
+
['xsmall', 'sm'],
|
|
63
|
+
['small', 'md'],
|
|
64
|
+
['medium', 'lg'],
|
|
65
|
+
['large', 'xl'],
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Ambiguous names — common words that must ONLY be renamed in a precise
|
|
70
|
+
* context. `tiny`/`xsmall` are omitted because they are unique to Avatar's
|
|
71
|
+
* scale; their presence in a collection proves it is an Avatar size enum.
|
|
72
|
+
*/
|
|
73
|
+
const AMBIGUOUS = new Set(['small', 'medium', 'large']);
|
|
74
|
+
|
|
75
|
+
/** Names that appear only in Avatar's scale — safe signals of Avatar sizing. */
|
|
76
|
+
const UNIQUE = new Set(['tiny', 'xsmall']);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Rename a string-literal node if its value is an old size name.
|
|
80
|
+
* Unwraps `'small' as const`. In non-precise contexts, ambiguous names are
|
|
81
|
+
* skipped. Returns true when a rename occurred.
|
|
82
|
+
*/
|
|
83
|
+
function renameValue(node, {precise = false} = {}) {
|
|
84
|
+
if (!node) return false;
|
|
85
|
+
const target = node.type === 'TSAsExpression' ? node.expression : node;
|
|
86
|
+
const isString =
|
|
87
|
+
target.type === 'StringLiteral' || target.type === 'Literal';
|
|
88
|
+
if (!isString || typeof target.value !== 'string') return false;
|
|
89
|
+
const replacement = RENAMES.get(target.value);
|
|
90
|
+
if (!replacement) return false;
|
|
91
|
+
if (!precise && AMBIGUOUS.has(target.value)) return false;
|
|
92
|
+
target.value = replacement;
|
|
93
|
+
if (target.raw) target.raw = undefined;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Extract a plain string value from a literal-ish node, or null. */
|
|
98
|
+
function literalString(node) {
|
|
99
|
+
const target = node?.type === 'TSAsExpression' ? node.expression : node;
|
|
100
|
+
if (
|
|
101
|
+
target &&
|
|
102
|
+
(target.type === 'StringLiteral' || target.type === 'Literal') &&
|
|
103
|
+
typeof target.value === 'string'
|
|
104
|
+
) {
|
|
105
|
+
return target.value;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default function transformer(file, api) {
|
|
111
|
+
const j = api.jscodeshift;
|
|
112
|
+
const root = j(file.source);
|
|
113
|
+
let hasChanges = false;
|
|
114
|
+
|
|
115
|
+
// Track alias-aware local names for the target components.
|
|
116
|
+
const targetLocals = new Set();
|
|
117
|
+
root.find(j.ImportDeclaration).forEach((path) => {
|
|
118
|
+
if (!IMPORT_SOURCES.has(path.node.source.value)) return;
|
|
119
|
+
for (const spec of path.node.specifiers ?? []) {
|
|
120
|
+
if (
|
|
121
|
+
spec.type === 'ImportSpecifier' &&
|
|
122
|
+
TARGET_IMPORTED_NAMES.has(spec.imported.name)
|
|
123
|
+
) {
|
|
124
|
+
targetLocals.add(spec.local.name);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (targetLocals.size === 0) return undefined;
|
|
130
|
+
|
|
131
|
+
function renameArrayElements(node) {
|
|
132
|
+
let arr = node;
|
|
133
|
+
if (arr.type === 'TSAsExpression') arr = arr.expression;
|
|
134
|
+
if (arr.type !== 'ArrayExpression') return;
|
|
135
|
+
// If the array contains a name unique to Avatar's scale (tiny/xsmall), the
|
|
136
|
+
// whole collection is unambiguously the Avatar size enum, so it is safe to
|
|
137
|
+
// rename the ambiguous members too. Otherwise stay conservative.
|
|
138
|
+
const precise = arr.elements.some((el) => UNIQUE.has(literalString(el)));
|
|
139
|
+
for (const el of arr.elements) {
|
|
140
|
+
if (renameValue(el, {precise})) hasChanges = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 1. `size` JSX attributes on target components — PRECISE (component known),
|
|
145
|
+
// so all five names, including the ambiguous ones, are renamed here.
|
|
146
|
+
root.find(j.JSXOpeningElement).forEach((path) => {
|
|
147
|
+
const name = path.node.name;
|
|
148
|
+
const componentName = name.type === 'JSXIdentifier' ? name.name : null;
|
|
149
|
+
if (!componentName || !targetLocals.has(componentName)) return;
|
|
150
|
+
|
|
151
|
+
for (const attr of path.node.attributes) {
|
|
152
|
+
if (attr.type !== 'JSXAttribute' || attr.name?.name !== 'size') continue;
|
|
153
|
+
const value = attr.value;
|
|
154
|
+
|
|
155
|
+
// size="small"
|
|
156
|
+
if (renameValue(value, {precise: true})) {
|
|
157
|
+
hasChanges = true;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (
|
|
161
|
+
value &&
|
|
162
|
+
value.type === 'JSXExpressionContainer' &&
|
|
163
|
+
value.expression
|
|
164
|
+
) {
|
|
165
|
+
// size={'small'}
|
|
166
|
+
if (renameValue(value.expression, {precise: true})) {
|
|
167
|
+
hasChanges = true;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
// size={cond ? 'small' : 'large'}
|
|
171
|
+
if (value.expression.type === 'ConditionalExpression') {
|
|
172
|
+
if (renameValue(value.expression.consequent, {precise: true}))
|
|
173
|
+
hasChanges = true;
|
|
174
|
+
if (renameValue(value.expression.alternate, {precise: true}))
|
|
175
|
+
hasChanges = true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// 2. Object properties keyed `size` (or `*Size`) + Storybook `options`
|
|
182
|
+
// arrays — NON-PRECISE (the component isn't known here), so only the
|
|
183
|
+
// unique names tiny/xsmall are renamed.
|
|
184
|
+
const PropertyType = j.ObjectProperty ?? j.Property;
|
|
185
|
+
root.find(PropertyType).forEach((path) => {
|
|
186
|
+
const key = path.node.key;
|
|
187
|
+
const keyName =
|
|
188
|
+
key.type === 'Identifier'
|
|
189
|
+
? key.name
|
|
190
|
+
: key.type === 'StringLiteral' || key.type === 'Literal'
|
|
191
|
+
? key.value
|
|
192
|
+
: null;
|
|
193
|
+
if (typeof keyName !== 'string') return;
|
|
194
|
+
|
|
195
|
+
const lower = keyName.toLowerCase();
|
|
196
|
+
if (lower !== 'size' && !lower.endsWith('size')) return;
|
|
197
|
+
|
|
198
|
+
const value = path.node.value;
|
|
199
|
+
// size: 'tiny'
|
|
200
|
+
if (renameValue(value)) {
|
|
201
|
+
hasChanges = true;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
// size: { control: 'select', options: ['tiny', ...] }
|
|
205
|
+
if (value.type === 'ObjectExpression') {
|
|
206
|
+
const optionsProp = value.properties.find(
|
|
207
|
+
(p) => p.key && (p.key.name === 'options' || p.key.value === 'options'),
|
|
208
|
+
);
|
|
209
|
+
if (optionsProp) renameArrayElements(optionsProp.value);
|
|
210
|
+
}
|
|
211
|
+
// size: ['tiny', 'xsmall', ...]
|
|
212
|
+
renameArrayElements(value);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// 3. Union-type literals — NON-PRECISE, so only the unique names tiny/xsmall
|
|
216
|
+
// are renamed. This avoids corrupting unrelated unions that happen to use
|
|
217
|
+
// common words like 'medium' (e.g. a priority or breakpoint type) in a
|
|
218
|
+
// file that also imports Avatar.
|
|
219
|
+
root.find(j.TSLiteralType).forEach((path) => {
|
|
220
|
+
if (renameValue(path.node.literal)) hasChanges = true;
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// 4. Standalone array literals whose members are exactly the Avatar size
|
|
224
|
+
// scale (identified by the presence of a unique name like tiny/xsmall) —
|
|
225
|
+
// e.g. `(['tiny', 'xsmall', 'small', 'medium', 'large'] as const).map(...)`
|
|
226
|
+
// used to render every size. The unique name proves the whole array is the
|
|
227
|
+
// Avatar enum, so its ambiguous members can be renamed safely.
|
|
228
|
+
root.find(j.ArrayExpression).forEach((path) => {
|
|
229
|
+
renameArrayElements(path.node);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
if (!hasChanges) return undefined;
|
|
233
|
+
return root.toSource({quote: 'single'});
|
|
234
|
+
}
|
|
@@ -13,7 +13,7 @@ export default function AvatarFallbackChain() {
|
|
|
13
13
|
<Avatar
|
|
14
14
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Daniela-Gimenez.png"
|
|
15
15
|
name="Daniela Gimenez"
|
|
16
|
-
size="
|
|
16
|
+
size="lg"
|
|
17
17
|
/>
|
|
18
18
|
<Text type="supporting">Valid src</Text>
|
|
19
19
|
</HStack>
|
|
@@ -22,7 +22,7 @@ export default function AvatarFallbackChain() {
|
|
|
22
22
|
src="https://lookaside.facebook.com/assets/astryx/does-not-exist-primary.jpg"
|
|
23
23
|
fallbackSrc="https://lookaside.facebook.com/assets/astryx/DATA-Ami-Pena.png"
|
|
24
24
|
name="Invalid User"
|
|
25
|
-
size="
|
|
25
|
+
size="lg"
|
|
26
26
|
/>
|
|
27
27
|
<Text type="supporting">Invalid src, valid fallbackSrc</Text>
|
|
28
28
|
</HStack>
|
|
@@ -31,14 +31,14 @@ export default function AvatarFallbackChain() {
|
|
|
31
31
|
src="https://lookaside.facebook.com/assets/astryx/does-not-exist-primary.jpg"
|
|
32
32
|
fallbackSrc="https://lookaside.facebook.com/assets/astryx/does-not-exist-fallback.jpg"
|
|
33
33
|
name="Test User"
|
|
34
|
-
size="
|
|
34
|
+
size="lg"
|
|
35
35
|
/>
|
|
36
36
|
<Text type="supporting">Both invalid, has name</Text>
|
|
37
37
|
</HStack>
|
|
38
38
|
<HStack gap={3} vAlign="center">
|
|
39
39
|
<Avatar
|
|
40
40
|
src="https://lookaside.facebook.com/assets/astryx/does-not-exist-primary.jpg"
|
|
41
|
-
size="
|
|
41
|
+
size="lg"
|
|
42
42
|
/>
|
|
43
43
|
<Text type="supporting">All invalid, no name</Text>
|
|
44
44
|
</HStack>
|
|
@@ -37,7 +37,7 @@ export default function AvatarGroupBlock() {
|
|
|
37
37
|
<Text type="supporting" color="secondary">
|
|
38
38
|
Team members
|
|
39
39
|
</Text>
|
|
40
|
-
<AvatarGroup size="
|
|
40
|
+
<AvatarGroup size="lg">
|
|
41
41
|
{USERS.map(user => (
|
|
42
42
|
<Avatar key={user.name} src={user.src} name={user.name} />
|
|
43
43
|
))}
|
|
@@ -48,7 +48,7 @@ export default function AvatarGroupBlock() {
|
|
|
48
48
|
<Text type="supporting" color="secondary">
|
|
49
49
|
Larger group
|
|
50
50
|
</Text>
|
|
51
|
-
<AvatarGroup size="
|
|
51
|
+
<AvatarGroup size="lg">
|
|
52
52
|
{USERS.slice(0, 3).map(user => (
|
|
53
53
|
<Avatar key={user.name} src={user.src} name={user.name} />
|
|
54
54
|
))}
|
|
@@ -18,7 +18,7 @@ export default function AvatarInitialsFallback() {
|
|
|
18
18
|
<Stack direction="horizontal" gap={6} vAlign="center">
|
|
19
19
|
{NAMES.map(({name, note}) => (
|
|
20
20
|
<Stack key={name} direction="vertical" gap={2} hAlign="center">
|
|
21
|
-
<Avatar name={name} size="
|
|
21
|
+
<Avatar name={name} size="lg" />
|
|
22
22
|
<Text type="supporting" color="secondary">
|
|
23
23
|
{note}
|
|
24
24
|
</Text>
|
|
@@ -11,23 +11,23 @@ export default function AvatarShowcase() {
|
|
|
11
11
|
<Avatar
|
|
12
12
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Ana-Thomas.png"
|
|
13
13
|
name="Ana Thomas"
|
|
14
|
-
size="
|
|
14
|
+
size="xl"
|
|
15
15
|
status={<AvatarStatusDot variant="success" label="Online" />}
|
|
16
16
|
/>
|
|
17
17
|
<Avatar
|
|
18
18
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Drew-Young.png"
|
|
19
19
|
name="Drew Young"
|
|
20
|
-
size="
|
|
20
|
+
size="xl"
|
|
21
21
|
/>
|
|
22
22
|
<Avatar
|
|
23
23
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Jihoo-Song.png"
|
|
24
24
|
name="Jihoo Song"
|
|
25
|
-
size="
|
|
25
|
+
size="xl"
|
|
26
26
|
/>
|
|
27
27
|
<Avatar
|
|
28
28
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Nam-Tran.png"
|
|
29
29
|
name="Nam Tran"
|
|
30
|
-
size="
|
|
30
|
+
size="xl"
|
|
31
31
|
status={<AvatarStatusDot variant="error" label="Online" />}
|
|
32
32
|
/>
|
|
33
33
|
</Stack>
|
|
@@ -11,22 +11,22 @@ export default function AvatarWithImage() {
|
|
|
11
11
|
<Avatar
|
|
12
12
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Ami-Pena.png"
|
|
13
13
|
name="Ami Pena"
|
|
14
|
-
size="
|
|
14
|
+
size="xsm"
|
|
15
15
|
/>
|
|
16
16
|
<Avatar
|
|
17
17
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Ana-Thomas.png"
|
|
18
18
|
name="Ana Thomas"
|
|
19
|
-
size="
|
|
19
|
+
size="md"
|
|
20
20
|
/>
|
|
21
21
|
<Avatar
|
|
22
22
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Daniela-Gimenez.png"
|
|
23
23
|
name="Daniela Gimenez"
|
|
24
|
-
size="
|
|
24
|
+
size="lg"
|
|
25
25
|
/>
|
|
26
26
|
<Avatar
|
|
27
27
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Gabriela-Fernandez.png"
|
|
28
28
|
name="Gabriela Fernandez"
|
|
29
|
-
size="
|
|
29
|
+
size="xl"
|
|
30
30
|
/>
|
|
31
31
|
</Stack>
|
|
32
32
|
);
|
|
@@ -11,19 +11,19 @@ export default function AvatarWithStatus() {
|
|
|
11
11
|
<Avatar
|
|
12
12
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Itai-Jordaan.png"
|
|
13
13
|
name="Itai Jordaan"
|
|
14
|
-
size="
|
|
14
|
+
size="xl"
|
|
15
15
|
status={<AvatarStatusDot variant="success" label="Online" />}
|
|
16
16
|
/>
|
|
17
17
|
<Avatar
|
|
18
18
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Margot-Schroder.png"
|
|
19
19
|
name="Margot Schroder"
|
|
20
|
-
size="
|
|
20
|
+
size="xl"
|
|
21
21
|
status={<AvatarStatusDot variant="neutral" label="Offline" />}
|
|
22
22
|
/>
|
|
23
23
|
<Avatar
|
|
24
24
|
src="https://lookaside.facebook.com/assets/astryx/DATA-Pablo-Morales.png"
|
|
25
25
|
name="Pablo Morales"
|
|
26
|
-
size="
|
|
26
|
+
size="xl"
|
|
27
27
|
status={<AvatarStatusDot variant="error" label="Busy" />}
|
|
28
28
|
/>
|
|
29
29
|
</Stack>
|
|
@@ -36,7 +36,7 @@ export default function AvatarGroupShowcase() {
|
|
|
36
36
|
<Text type="supporting" color="secondary">
|
|
37
37
|
Team members
|
|
38
38
|
</Text>
|
|
39
|
-
<AvatarGroup size="
|
|
39
|
+
<AvatarGroup size="lg">
|
|
40
40
|
{USERS.map(u => (
|
|
41
41
|
<Avatar key={u.key} name={u.name} />
|
|
42
42
|
))}
|
|
@@ -46,7 +46,7 @@ export default function AvatarGroupShowcase() {
|
|
|
46
46
|
<Text type="supporting" color="secondary">
|
|
47
47
|
With overflow
|
|
48
48
|
</Text>
|
|
49
|
-
<AvatarGroup size="
|
|
49
|
+
<AvatarGroup size="lg">
|
|
50
50
|
{USERS.slice(0, 3).map(u => (
|
|
51
51
|
<Avatar key={u.key} name={u.name} />
|
|
52
52
|
))}
|
|
@@ -24,7 +24,7 @@ export default function AvatarGroupOverflowCustomText() {
|
|
|
24
24
|
<Text type="supporting" color="secondary">
|
|
25
25
|
Team members
|
|
26
26
|
</Text>
|
|
27
|
-
<AvatarGroup size="
|
|
27
|
+
<AvatarGroup size="lg">
|
|
28
28
|
{TEAM.map(member => (
|
|
29
29
|
<Avatar key={member.name} name={member.name} />
|
|
30
30
|
))}
|
|
@@ -24,7 +24,7 @@ export default function AvatarGroupOverflowDefault() {
|
|
|
24
24
|
<Text type="supporting" color="secondary">
|
|
25
25
|
Reviewers
|
|
26
26
|
</Text>
|
|
27
|
-
<AvatarGroup size="
|
|
27
|
+
<AvatarGroup size="lg">
|
|
28
28
|
{REVIEWERS.map(reviewer => (
|
|
29
29
|
<Avatar key={reviewer.name} name={reviewer.name} />
|
|
30
30
|
))}
|