@sanity/ui-codemod 1.0.0-alpha.5 → 1.0.0-alpha.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 (44) hide show
  1. package/dist/_chunks-es/addAttribute.js +1 -1
  2. package/dist/_chunks-es/box.mods.js +1 -1
  3. package/dist/_chunks-es/flex.mods.js +1 -150
  4. package/dist/_chunks-es/flex.mods.js.map +1 -1
  5. package/dist/_chunks-es/layout-mods.js +4 -0
  6. package/dist/_chunks-es/layout-mods.js.map +1 -1
  7. package/dist/_chunks-es/{transformComponent.js → transformStyledComponents.js} +150 -2
  8. package/dist/_chunks-es/transformStyledComponents.js.map +1 -0
  9. package/dist/transforms/latest/box/box.js +2 -2
  10. package/dist/transforms/latest/card/card.js +24 -9
  11. package/dist/transforms/latest/card/card.js.map +1 -1
  12. package/dist/transforms/latest/code/code.js +18 -7
  13. package/dist/transforms/latest/code/code.js.map +1 -1
  14. package/dist/transforms/latest/container/container.js +15 -7
  15. package/dist/transforms/latest/container/container.js.map +1 -1
  16. package/dist/transforms/latest/flex/flex.js +2 -2
  17. package/dist/transforms/latest/grid/grid.js +15 -7
  18. package/dist/transforms/latest/grid/grid.js.map +1 -1
  19. package/dist/transforms/latest/heading/heading.js +18 -7
  20. package/dist/transforms/latest/heading/heading.js.map +1 -1
  21. package/dist/transforms/latest/text/text.js +18 -7
  22. package/dist/transforms/latest/text/text.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/constants/latest/layout-mods.ts +4 -0
  25. package/src/transforms/latest/box/box.test.ts +3 -8
  26. package/src/transforms/latest/card/card.test.ts +100 -1
  27. package/src/transforms/latest/card/card.ts +42 -19
  28. package/src/transforms/latest/code/code.test.ts +84 -1
  29. package/src/transforms/latest/code/code.ts +47 -16
  30. package/src/transforms/latest/container/container.test.ts +78 -1
  31. package/src/transforms/latest/container/container.ts +29 -9
  32. package/src/transforms/latest/grid/grid.test.ts +78 -1
  33. package/src/transforms/latest/grid/grid.ts +29 -9
  34. package/src/transforms/latest/heading/heading.test.ts +84 -1
  35. package/src/transforms/latest/heading/heading.ts +47 -16
  36. package/src/transforms/latest/inline/inline.test.ts +78 -1
  37. package/src/transforms/latest/inline/inline.ts +29 -9
  38. package/src/transforms/latest/label/label.test.ts +84 -1
  39. package/src/transforms/latest/label/label.ts +36 -1
  40. package/src/transforms/latest/stack/stack.test.ts +100 -1
  41. package/src/transforms/latest/stack/stack.ts +29 -7
  42. package/src/transforms/latest/text/text.test.ts +84 -1
  43. package/src/transforms/latest/text/text.ts +58 -19
  44. package/dist/_chunks-es/transformComponent.js.map +0 -1
@@ -255,8 +255,7 @@ defineCrossFileTest(
255
255
  }
256
256
  `,
257
257
  (output) => {
258
- expect(output).toContain('alignItems: "center"')
259
- expect(output).not.toContain('<RootBox alignItems="center" />')
258
+ expect(output.replace(/\s+/g, ' ')).toContain('<RootBox style={{ alignItems: "center" }} />')
260
259
  },
261
260
  'transforms attributes on imported styled Box wrappers',
262
261
  )
@@ -279,7 +278,6 @@ defineCrossFileTest(
279
278
  (output) => {
280
279
  expect(output).toContain('UI-CODEMOD TODO: Please double check styled(Box) migration below')
281
280
  expect(output).toContain('<RootBox display="flex" alignItems="center" />')
282
- expect(output).not.toContain('const RootBox = styled(Box)')
283
281
  },
284
282
  'adds todo warning when imported styled Box wrapper should be replaced',
285
283
  )
@@ -306,10 +304,8 @@ defineCrossFileTest(
306
304
  }
307
305
  `,
308
306
  (output) => {
309
- expect(output).toContain('alignItems: "center"')
310
- expect(output).not.toContain('<RootBox alignItems="center" />')
307
+ expect(output.replace(/\s+/g, ' ')).toContain('<RootBox style={{ alignItems: "center" }} />')
311
308
  expect(output).toContain('<Box display="flex" />')
312
- expect(output).not.toContain('<Flex')
313
309
  },
314
310
  'does not rewrite unrelated Box from another package',
315
311
  )
@@ -330,8 +326,7 @@ defineCrossFileTest(
330
326
  }
331
327
  `,
332
328
  (output) => {
333
- expect(output).toContain('alignItems: "center"')
334
- expect(output).not.toContain('<RootBox alignItems="center" />')
329
+ expect(output.replace(/\s+/g, ' ')).toContain('<RootBox style={{ alignItems: "center" }} />')
335
330
  },
336
331
  'transforms styled Box wrappers imported through barrel re-exports',
337
332
  {
@@ -1,4 +1,6 @@
1
- import {defineInlineTest} from '../../../utils/testUtils'
1
+ import {expect} from 'vitest'
2
+
3
+ import {defineCrossFileTest, defineInlineTest} from '../../../utils/testUtils'
2
4
  import transform from './card'
3
5
 
4
6
  defineInlineTest(
@@ -205,3 +207,100 @@ defineInlineTest(
205
207
  `,
206
208
  'warns if Card includes muted prop',
207
209
  )
210
+
211
+ defineCrossFileTest(
212
+ transform,
213
+ {},
214
+ `
215
+ import {Card} from '@sanity/ui'
216
+
217
+ export const RootCard = styled(Card)(({theme}) => ({}))
218
+ `,
219
+ `
220
+ import {RootCard} from './Component.styled'
221
+
222
+ export function Component() {
223
+ return <RootCard padding={4} radius={3} border />
224
+ }
225
+ `,
226
+ (output) => {
227
+ expect(output).toContain('<RootCard density="regular" />')
228
+ },
229
+ 'transforms attributes on imported styled Card wrappers',
230
+ )
231
+
232
+ defineCrossFileTest(
233
+ transform,
234
+ {},
235
+ `
236
+ import {Card} from '@sanity/ui'
237
+
238
+ export const RootCard = styled(Card)(({theme}) => ({}))
239
+ `,
240
+ `
241
+ import {RootCard} from './Component.styled'
242
+
243
+ export function Component() {
244
+ return <RootCard padding={1} />
245
+ }
246
+ `,
247
+ (output) => {
248
+ expect(output).toContain('UI-CODEMOD TODO: Please double check styled(Card) migration below')
249
+ expect(output).toContain('<RootCard padding={1} />')
250
+ },
251
+ 'adds todo warning when imported styled Card wrapper should be replaced',
252
+ )
253
+
254
+ defineCrossFileTest(
255
+ transform,
256
+ {},
257
+ `
258
+ import {Card} from '@sanity/ui'
259
+
260
+ export const RootCard = styled(Card)(({theme}) => ({}))
261
+ `,
262
+ `
263
+ import {Card} from 'another-package'
264
+ import {RootCard} from './Component.styled'
265
+
266
+ export function Component() {
267
+ return (
268
+ <>
269
+ <RootCard padding={4} radius={3} border />
270
+ <Card padding={4} radius={3} border />
271
+ </>
272
+ )
273
+ }
274
+ `,
275
+ (output) => {
276
+ expect(output).toContain('<RootCard density="regular" />')
277
+ expect(output).toContain('<Card padding={4} radius={3} border />')
278
+ },
279
+ 'does not rewrite unrelated Card from another package',
280
+ )
281
+
282
+ defineCrossFileTest(
283
+ transform,
284
+ {},
285
+ `
286
+ import {Card} from '@sanity/ui'
287
+
288
+ export const RootCard = styled(Card)(({theme}) => ({}))
289
+ `,
290
+ `
291
+ import {RootCard} from './index'
292
+
293
+ export function Component() {
294
+ return <RootCard padding={4} radius={3} border />
295
+ }
296
+ `,
297
+ (output) => {
298
+ expect(output).toContain('<RootCard density="regular" />')
299
+ },
300
+ 'transforms styled Card wrappers imported through barrel re-exports',
301
+ {
302
+ extraFiles: {
303
+ 'index.ts': `export {RootCard} from './Component.styled'`,
304
+ },
305
+ },
306
+ )
@@ -1,19 +1,22 @@
1
- import {type API, type FileInfo} from 'jscodeshift'
1
+ import {type API, type FileInfo, type JSXAttribute, type JSXSpreadAttribute} from 'jscodeshift'
2
2
 
3
3
  import type {BaseOptions} from '../../../types/BaseOptions'
4
4
  import {getAttribute} from '../../../utils/getAttribute'
5
5
  import {getComponentLocalNames} from '../../../utils/getComponentLocalNames'
6
6
  import {getStaticAttributeExpression} from '../../../utils/getStaticAttributeExpression'
7
+ import {getStyledComponentAliases} from '../../../utils/getStyledComponentAliases'
7
8
  import {replaceElement} from '../../../utils/replaceElement'
8
9
  import {shouldTransformComponent} from '../../../utils/shouldTransformComponent'
9
10
  import {transformAttributes} from '../../../utils/transformAttributes'
10
11
  import {transformComponent} from '../../../utils/transformComponent'
11
12
  import {transformImport} from '../../../utils/transformImport'
13
+ import {transformStyledComponents} from '../../../utils/transformStyledComponents'
12
14
  import {BOX_MODS} from '../box/box.mods'
13
15
  import {CARD_MODS} from './card.mods'
14
16
 
15
17
  const CARD_TODO_WARNING = 'Please double check the Card migration below'
16
18
  const BOX_TODO_WARNING = 'Please double check the Box migration below'
19
+ const STYLED_TODO_WARNING = 'Please double check styled(Card) migration below'
17
20
 
18
21
  /** @internal */
19
22
  export default function transform(
@@ -25,8 +28,16 @@ export default function transform(
25
28
 
26
29
  return transformComponent(fileInfo, api, ({j, root, markChanged}) => {
27
30
  const localNames = getComponentLocalNames(j, root, 'Card', options)
31
+ const styledAliases = getStyledComponentAliases(
32
+ j,
33
+ root,
34
+ 'Card',
35
+ fileInfo.path,
36
+ localNames,
37
+ options,
38
+ )
28
39
 
29
- if (!shouldTransformComponent(j, root, 'Card', localNames, options)) {
40
+ if (!shouldTransformComponent(j, root, 'Card', localNames, options, styledAliases)) {
30
41
  return
31
42
  }
32
43
 
@@ -34,29 +45,32 @@ export default function transform(
34
45
  markChanged()
35
46
  }
36
47
 
48
+ const replaceWithBox = (attrs: (JSXAttribute | JSXSpreadAttribute)[]) => {
49
+ const density = getAttribute(attrs, 'density')
50
+ const muted = getAttribute(attrs, 'muted')
51
+ const scheme = getAttribute(attrs, 'scheme')
52
+ const border = getAttribute(attrs, 'border')
53
+ const padding = getStaticAttributeExpression(j, attrs, 'padding')
54
+ const radius = getStaticAttributeExpression(j, attrs, 'radius')
55
+
56
+ return !(
57
+ density ||
58
+ muted ||
59
+ scheme ||
60
+ (border && padding === 3 && radius == 2) ||
61
+ (border && padding === 4 && radius == 3) ||
62
+ (border && padding === 5 && radius == 4)
63
+ )
64
+ }
65
+
37
66
  if (
38
67
  replaceElement(
39
68
  j,
40
69
  root,
41
- (attrs) => {
42
- const density = getAttribute(attrs, 'density')
43
- const muted = getAttribute(attrs, 'muted')
44
- const scheme = getAttribute(attrs, 'scheme')
45
- const border = getAttribute(attrs, 'border')
46
- const padding = getStaticAttributeExpression(j, attrs, 'padding')
47
- const radius = getStaticAttributeExpression(j, attrs, 'radius')
48
-
49
- return !(
50
- density ||
51
- muted ||
52
- scheme ||
53
- (border && padding === 3 && radius == 2) ||
54
- (border && padding === 4 && radius == 3) ||
55
- (border && padding === 5 && radius == 4)
56
- )
57
- },
70
+ (attrs) => replaceWithBox(attrs),
58
71
  {
59
72
  element: 'Card',
73
+ localNames,
60
74
  callback: (path) => transformAttributes(j, path, CARD_MODS, CARD_TODO_WARNING),
61
75
  },
62
76
  {
@@ -67,5 +81,14 @@ export default function transform(
67
81
  ) {
68
82
  markChanged()
69
83
  }
84
+
85
+ if (
86
+ transformStyledComponents(j, root, styledAliases, (attrs) => !replaceWithBox(attrs), {
87
+ warning: STYLED_TODO_WARNING,
88
+ callback: (path) => transformAttributes(j, path, CARD_MODS, CARD_TODO_WARNING),
89
+ })
90
+ ) {
91
+ markChanged()
92
+ }
70
93
  })
71
94
  }
@@ -1,4 +1,6 @@
1
- import {defineInlineTest} from '../../../utils/testUtils'
1
+ import {expect} from 'vitest'
2
+
3
+ import {defineCrossFileTest, defineInlineTest} from '../../../utils/testUtils'
2
4
  import transform from './code'
3
5
 
4
6
  defineInlineTest(
@@ -59,3 +61,84 @@ defineInlineTest(
59
61
  `,
60
62
  'moves width props to style and uppdates mapped values',
61
63
  )
64
+
65
+ defineCrossFileTest(
66
+ transform,
67
+ {},
68
+ `
69
+ import {Code} from '@sanity/ui'
70
+
71
+ export const RootCode = styled(Code)(({theme}) => ({}))
72
+ `,
73
+ `
74
+ import {RootCode} from './Component.styled'
75
+
76
+ export function RootCode() {
77
+ return <RootCode flex="auto" />
78
+ }
79
+ `,
80
+ (output) => {
81
+ expect(output.replace(/\s+/g, ' ')).toContain(
82
+ '<RootCode style={{ flex: "1 1 auto" }} trim={true} />',
83
+ )
84
+ },
85
+ 'transforms attributes on imported styled Code wrappers',
86
+ )
87
+
88
+ defineCrossFileTest(
89
+ transform,
90
+ {},
91
+ `
92
+ import {Code} from '@sanity/ui'
93
+
94
+ export const RootCode = styled(Code)(({theme}) => ({}))
95
+ `,
96
+ `
97
+ import {Code} from 'another-package'
98
+ import {RootCode} from './Component.styled'
99
+
100
+ export function Component() {
101
+ return (
102
+ <>
103
+ <RootCode flex="auto" />
104
+ <Code flex="auto" />
105
+ </>
106
+ )
107
+ }
108
+ `,
109
+ (output) => {
110
+ expect(output.replace(/\s+/g, ' ')).toContain(
111
+ '<RootCode style={{ flex: "1 1 auto" }} trim={true} />',
112
+ )
113
+ expect(output).toContain('<Code flex="auto" />')
114
+ },
115
+ 'does not transform attributes on unrelated Code from another package',
116
+ )
117
+
118
+ defineCrossFileTest(
119
+ transform,
120
+ {},
121
+ `
122
+ import {Code} from '@sanity/ui'
123
+
124
+ export const RootCode = styled(Code)(({theme}) => ({}))
125
+ `,
126
+ `
127
+ import {RootCode} from './index'
128
+
129
+ export function Component() {
130
+ return <RootCode flex="auto" />
131
+ }
132
+ `,
133
+ (output) => {
134
+ expect(output.replace(/\s+/g, ' ')).toContain(
135
+ '<RootCode style={{ flex: "1 1 auto" }} trim={true} />',
136
+ )
137
+ },
138
+ 'transforms styled Code wrappers imported through barrel re-exports',
139
+ {
140
+ extraFiles: {
141
+ 'index.ts': `export {RootCode} from './Component.styled'`,
142
+ },
143
+ },
144
+ )
@@ -3,10 +3,12 @@ import {type API, type FileInfo} from 'jscodeshift'
3
3
  import type {BaseOptions} from '../../../types/BaseOptions'
4
4
  import {addAttribute} from '../../../utils/addAttribute'
5
5
  import {getComponentLocalNames} from '../../../utils/getComponentLocalNames'
6
+ import {getStyledComponentAliases} from '../../../utils/getStyledComponentAliases'
6
7
  import {shouldTransformComponent} from '../../../utils/shouldTransformComponent'
7
8
  import {transformAttributes} from '../../../utils/transformAttributes'
8
9
  import {transformComponent} from '../../../utils/transformComponent'
9
10
  import {transformImport} from '../../../utils/transformImport'
11
+ import {transformStyledComponents} from '../../../utils/transformStyledComponents'
10
12
  import {CODE_MODS} from './code.mods'
11
13
 
12
14
  const TODO_WARNING = 'Please double check the Code migration below'
@@ -21,8 +23,16 @@ export default function transform(
21
23
 
22
24
  return transformComponent(fileInfo, api, ({j, root, markChanged}) => {
23
25
  const localNames = getComponentLocalNames(j, root, 'Code', options)
26
+ const styledAliases = getStyledComponentAliases(
27
+ j,
28
+ root,
29
+ 'Code',
30
+ fileInfo.path,
31
+ localNames,
32
+ options,
33
+ )
24
34
 
25
- if (!shouldTransformComponent(j, root, 'Code', localNames, options)) {
35
+ if (!shouldTransformComponent(j, root, 'Code', localNames, options, styledAliases)) {
26
36
  return
27
37
  }
28
38
 
@@ -30,24 +40,45 @@ export default function transform(
30
40
  markChanged()
31
41
  }
32
42
 
33
- root
34
- .find(j.JSXOpeningElement, {
35
- name: {type: 'JSXIdentifier', name: 'Code'},
36
- })
37
- .forEach((path) => {
38
- let changed = false
43
+ root.find(j.JSXOpeningElement).forEach((path) => {
44
+ let changed = false
45
+ const name = path.node.name
46
+
47
+ if (name.type !== 'JSXIdentifier' || !localNames.has(name.name)) {
48
+ return
49
+ }
50
+
51
+ if (transformAttributes(j, path, CODE_MODS, TODO_WARNING)) {
52
+ changed = true
53
+ }
54
+
55
+ if (addAttribute(j, path.node, 'trim', true)) {
56
+ changed = true
57
+ }
39
58
 
40
- if (transformAttributes(j, path, CODE_MODS, TODO_WARNING)) {
41
- changed = true
42
- }
59
+ if (changed) {
60
+ markChanged()
61
+ }
62
+ })
43
63
 
44
- if (addAttribute(j, path.node, 'trim', true)) {
45
- changed = true
46
- }
64
+ if (
65
+ transformStyledComponents(j, root, styledAliases, () => true, {
66
+ callback: (path) => {
67
+ let changed = false
47
68
 
48
- if (changed) {
49
- markChanged()
50
- }
69
+ if (transformAttributes(j, path, CODE_MODS, TODO_WARNING)) {
70
+ changed = true
71
+ }
72
+
73
+ if (addAttribute(j, path.node, 'trim', true)) {
74
+ changed = true
75
+ }
76
+
77
+ return changed
78
+ },
51
79
  })
80
+ ) {
81
+ markChanged()
82
+ }
52
83
  })
53
84
  }
@@ -1,4 +1,6 @@
1
- import {defineInlineTest} from '../../../utils/testUtils'
1
+ import {expect} from 'vitest'
2
+
3
+ import {defineCrossFileTest, defineInlineTest} from '../../../utils/testUtils'
2
4
  import transform from './container'
3
5
 
4
6
  defineInlineTest(
@@ -103,3 +105,78 @@ defineInlineTest(
103
105
  `,
104
106
  'moves grid props to style and updates mapped values',
105
107
  )
108
+
109
+ defineCrossFileTest(
110
+ transform,
111
+ {},
112
+ `
113
+ import {Container} from '@sanity/ui'
114
+
115
+ export const RootContainer = styled(Container)(({theme}) => ({}))
116
+ `,
117
+ `
118
+ import {RootContainer} from './Component.styled'
119
+
120
+ export function Component() {
121
+ return <RootContainer width={2} />
122
+ }
123
+ `,
124
+ (output) => {
125
+ expect(output).toContain('<RootContainer size={2} />')
126
+ },
127
+ 'transforms attributes on imported styled Container wrappers',
128
+ )
129
+
130
+ defineCrossFileTest(
131
+ transform,
132
+ {},
133
+ `
134
+ import {Container} from '@sanity/ui'
135
+
136
+ export const RootContainer = styled(Container)(({theme}) => ({}))
137
+ `,
138
+ `
139
+ import {Container} from 'another-package'
140
+ import {RootContainer} from './Component.styled'
141
+
142
+ export function Component() {
143
+ return (
144
+ <>
145
+ <RootContainer width={2} />
146
+ <Container width={2} />
147
+ </>
148
+ )
149
+ }
150
+ `,
151
+ (output) => {
152
+ expect(output).toContain('<RootContainer size={2} />')
153
+ expect(output).toContain('<Container width={2} />')
154
+ },
155
+ 'does not transform attributes on unrelated Container from another package',
156
+ )
157
+
158
+ defineCrossFileTest(
159
+ transform,
160
+ {},
161
+ `
162
+ import {Container} from '@sanity/ui'
163
+
164
+ export const RootContainer = styled(Container)(({theme}) => ({}))
165
+ `,
166
+ `
167
+ import {RootContainer} from './index'
168
+
169
+ export function Component() {
170
+ return <RootContainer width={2} />
171
+ }
172
+ `,
173
+ (output) => {
174
+ expect(output).toContain('<RootContainer size={2} />')
175
+ },
176
+ 'transforms styled Container wrappers imported through barrel re-exports',
177
+ {
178
+ extraFiles: {
179
+ 'index.ts': `export {RootContainer} from './Component.styled'`,
180
+ },
181
+ },
182
+ )
@@ -2,10 +2,12 @@ import {type API, type FileInfo} from 'jscodeshift'
2
2
 
3
3
  import type {BaseOptions} from '../../../types/BaseOptions'
4
4
  import {getComponentLocalNames} from '../../../utils/getComponentLocalNames'
5
+ import {getStyledComponentAliases} from '../../../utils/getStyledComponentAliases'
5
6
  import {shouldTransformComponent} from '../../../utils/shouldTransformComponent'
6
7
  import {transformAttributes} from '../../../utils/transformAttributes'
7
8
  import {transformComponent} from '../../../utils/transformComponent'
8
9
  import {transformImport} from '../../../utils/transformImport'
10
+ import {transformStyledComponents} from '../../../utils/transformStyledComponents'
9
11
  import {CONTAINER_MODS} from './container.mods'
10
12
 
11
13
  const TODO_WARNING = 'Please double check the Container migration below'
@@ -20,8 +22,16 @@ export default function transform(
20
22
 
21
23
  return transformComponent(fileInfo, api, ({j, root, markChanged}) => {
22
24
  const localNames = getComponentLocalNames(j, root, 'Container', options)
25
+ const styledAliases = getStyledComponentAliases(
26
+ j,
27
+ root,
28
+ 'Container',
29
+ fileInfo.path,
30
+ localNames,
31
+ options,
32
+ )
23
33
 
24
- if (!shouldTransformComponent(j, root, 'Container', localNames, options)) {
34
+ if (!shouldTransformComponent(j, root, 'Container', localNames, options, styledAliases)) {
25
35
  return
26
36
  }
27
37
 
@@ -29,14 +39,24 @@ export default function transform(
29
39
  markChanged()
30
40
  }
31
41
 
32
- root
33
- .find(j.JSXOpeningElement, {
34
- name: {type: 'JSXIdentifier', name: 'Container'},
35
- })
36
- .forEach((path) => {
37
- if (transformAttributes(j, path, CONTAINER_MODS, TODO_WARNING)) {
38
- markChanged()
39
- }
42
+ root.find(j.JSXOpeningElement).forEach((path) => {
43
+ const name = path.node.name
44
+
45
+ if (name.type !== 'JSXIdentifier' || !localNames.has(name.name)) {
46
+ return
47
+ }
48
+
49
+ if (transformAttributes(j, path, CONTAINER_MODS, TODO_WARNING)) {
50
+ markChanged()
51
+ }
52
+ })
53
+
54
+ if (
55
+ transformStyledComponents(j, root, styledAliases, () => true, {
56
+ callback: (path) => transformAttributes(j, path, CONTAINER_MODS, TODO_WARNING),
40
57
  })
58
+ ) {
59
+ markChanged()
60
+ }
41
61
  })
42
62
  }
@@ -1,4 +1,6 @@
1
- import {defineInlineTest} from '../../../utils/testUtils'
1
+ import {expect} from 'vitest'
2
+
3
+ import {defineCrossFileTest, defineInlineTest} from '../../../utils/testUtils'
2
4
  import transform from './grid'
3
5
 
4
6
  defineInlineTest(
@@ -95,3 +97,78 @@ defineInlineTest(
95
97
  `,
96
98
  'updates v3 grid props mapped values',
97
99
  )
100
+
101
+ defineCrossFileTest(
102
+ transform,
103
+ {},
104
+ `
105
+ import {Grid} from '@sanity/ui'
106
+
107
+ export const RootGrid = styled(Grid)(({theme}) => ({}))
108
+ `,
109
+ `
110
+ import {RootGrid} from './Component.styled'
111
+
112
+ export function Component() {
113
+ return <RootGrid autoCols="auto" />
114
+ }
115
+ `,
116
+ (output) => {
117
+ expect(output).toContain('<RootGrid gridAutoColumns="auto" />')
118
+ },
119
+ 'transforms attributes on imported styled Grid wrappers',
120
+ )
121
+
122
+ defineCrossFileTest(
123
+ transform,
124
+ {},
125
+ `
126
+ import {Grid} from '@sanity/ui'
127
+
128
+ export const RootGrid = styled(Grid)(({theme}) => ({}))
129
+ `,
130
+ `
131
+ import {Grid} from 'another-package'
132
+ import {RootGrid} from './Component.styled'
133
+
134
+ export function Component() {
135
+ return (
136
+ <>
137
+ <RootGrid autoCols="auto" />
138
+ <Grid autoCols="auto" />
139
+ </>
140
+ )
141
+ }
142
+ `,
143
+ (output) => {
144
+ expect(output).toContain('<RootGrid gridAutoColumns="auto" />')
145
+ expect(output).toContain('<Grid autoCols="auto" />')
146
+ },
147
+ 'does not transform attributes on unrelated Grid from another package',
148
+ )
149
+
150
+ defineCrossFileTest(
151
+ transform,
152
+ {},
153
+ `
154
+ import {Grid} from '@sanity/ui'
155
+
156
+ export const RootGrid = styled(Grid)(({theme}) => ({}))
157
+ `,
158
+ `
159
+ import {RootGrid} from './index'
160
+
161
+ export function Component() {
162
+ return <RootGrid autoCols="auto" />
163
+ }
164
+ `,
165
+ (output) => {
166
+ expect(output).toContain('<RootGrid gridAutoColumns="auto" />')
167
+ },
168
+ 'transforms styled Grid wrappers imported through barrel re-exports',
169
+ {
170
+ extraFiles: {
171
+ 'index.ts': `export {RootGrid} from './Component.styled'`,
172
+ },
173
+ },
174
+ )