@planningcenter/tapestry-migration-cli 2.4.0-rc.12 → 2.4.0-rc.13
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 +2 -2
- package/src/components/button/index.ts +2 -0
- package/src/components/button/transforms/innerRefToRef.test.ts +170 -0
- package/src/components/button/transforms/innerRefToRef.ts +14 -0
- package/src/components/link/index.ts +2 -0
- package/src/components/link/transforms/innerRefToRef.test.ts +170 -0
- package/src/components/link/transforms/innerRefToRef.ts +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/tapestry-migration-cli",
|
|
3
|
-
"version": "2.4.0-rc.
|
|
3
|
+
"version": "2.4.0-rc.13",
|
|
4
4
|
"description": "CLI tool for Tapestry migrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "275d9583901bea8ef0d121ef25eff0a1fdf309b4"
|
|
55
55
|
}
|
|
@@ -8,6 +8,7 @@ import convertStyleProps from "./transforms/convertStyleProps"
|
|
|
8
8
|
import iconLeftToPrefix from "./transforms/iconLeftToPrefix"
|
|
9
9
|
import iconRightToSuffix from "./transforms/iconRightToSuffix"
|
|
10
10
|
import iconToIconButton from "./transforms/iconToIconButton"
|
|
11
|
+
import innerRefToRef from "./transforms/innerRefToRef"
|
|
11
12
|
import linkToButton from "./transforms/linkToButton"
|
|
12
13
|
import moveButtonImport from "./transforms/moveButtonImport"
|
|
13
14
|
import removeAsButton from "./transforms/removeAsButton"
|
|
@@ -55,6 +56,7 @@ const transform: Transform = async (fileInfo, api, options) => {
|
|
|
55
56
|
themeVariantToKind,
|
|
56
57
|
titleToLabel,
|
|
57
58
|
childrenToLabel,
|
|
59
|
+
innerRefToRef,
|
|
58
60
|
removeToTransform,
|
|
59
61
|
removeDuplicateKeys,
|
|
60
62
|
removeAsButton,
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./innerRefToRef"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
function applyTransform(source: string): string | null {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
return transform(
|
|
11
|
+
fileInfo,
|
|
12
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
+
{}
|
|
14
|
+
) as string | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("innerRefToRef transform", () => {
|
|
18
|
+
describe("basic transformations", () => {
|
|
19
|
+
it("should transform Button 'innerRef' prop to 'ref' prop", () => {
|
|
20
|
+
const input = `
|
|
21
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
22
|
+
|
|
23
|
+
export default function Test() {
|
|
24
|
+
return <Button innerRef={buttonRef}>Click me</Button>
|
|
25
|
+
}
|
|
26
|
+
`.trim()
|
|
27
|
+
|
|
28
|
+
const expected = `
|
|
29
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
30
|
+
|
|
31
|
+
export default function Test() {
|
|
32
|
+
return <Button ref={buttonRef}>Click me</Button>;
|
|
33
|
+
}
|
|
34
|
+
`.trim()
|
|
35
|
+
|
|
36
|
+
const result = applyTransform(input)
|
|
37
|
+
expect(result).toBe(expected)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it("should transform Button 'innerRef' prop to 'ref' prop with function", () => {
|
|
41
|
+
const input = `
|
|
42
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
43
|
+
|
|
44
|
+
export default function Test() {
|
|
45
|
+
return <Button innerRef={(el) => setButtonRef(el)}>Click me</Button>
|
|
46
|
+
}
|
|
47
|
+
`.trim()
|
|
48
|
+
|
|
49
|
+
const expected = `
|
|
50
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
51
|
+
|
|
52
|
+
export default function Test() {
|
|
53
|
+
return <Button ref={(el) => setButtonRef(el)}>Click me</Button>;
|
|
54
|
+
}
|
|
55
|
+
`.trim()
|
|
56
|
+
|
|
57
|
+
const result = applyTransform(input)
|
|
58
|
+
expect(result).toBe(expected)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it("should transform Button 'innerRef' prop to 'ref' prop with useRef", () => {
|
|
62
|
+
const input = `
|
|
63
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
64
|
+
import { useRef } from "react"
|
|
65
|
+
|
|
66
|
+
export default function Test() {
|
|
67
|
+
const buttonRef = useRef(null)
|
|
68
|
+
return <Button innerRef={buttonRef}>Click me</Button>
|
|
69
|
+
}
|
|
70
|
+
`.trim()
|
|
71
|
+
|
|
72
|
+
const expected = `
|
|
73
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
74
|
+
import { useRef } from "react"
|
|
75
|
+
|
|
76
|
+
export default function Test() {
|
|
77
|
+
const buttonRef = useRef(null)
|
|
78
|
+
return <Button ref={buttonRef}>Click me</Button>;
|
|
79
|
+
}
|
|
80
|
+
`.trim()
|
|
81
|
+
|
|
82
|
+
const result = applyTransform(input)
|
|
83
|
+
expect(result).toBe(expected)
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe("multiple components", () => {
|
|
88
|
+
it("should transform multiple Button components with innerRef", () => {
|
|
89
|
+
const input = `
|
|
90
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
91
|
+
|
|
92
|
+
export default function Test() {
|
|
93
|
+
return (
|
|
94
|
+
<div>
|
|
95
|
+
<Button innerRef={buttonRef1}>First</Button>
|
|
96
|
+
<Button innerRef={buttonRef2}>Second</Button>
|
|
97
|
+
</div>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
`.trim()
|
|
101
|
+
|
|
102
|
+
const expected = `
|
|
103
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
104
|
+
|
|
105
|
+
export default function Test() {
|
|
106
|
+
return (
|
|
107
|
+
<div>
|
|
108
|
+
<Button ref={buttonRef1}>First</Button>
|
|
109
|
+
<Button ref={buttonRef2}>Second</Button>
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
`.trim()
|
|
114
|
+
|
|
115
|
+
const result = applyTransform(input)
|
|
116
|
+
expect(result).toBe(expected)
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
describe("edge cases", () => {
|
|
121
|
+
it("should not transform Button without innerRef", () => {
|
|
122
|
+
const input = `
|
|
123
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
124
|
+
|
|
125
|
+
export default function Test() {
|
|
126
|
+
return <Button onClick={handleClick}>Click me</Button>
|
|
127
|
+
}
|
|
128
|
+
`.trim()
|
|
129
|
+
|
|
130
|
+
const result = applyTransform(input)
|
|
131
|
+
expect(result).toBe(null)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it("should not transform other components with innerRef", () => {
|
|
135
|
+
const input = `
|
|
136
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
137
|
+
|
|
138
|
+
export default function Test() {
|
|
139
|
+
return <Link innerRef={linkRef}>Go somewhere</Link>
|
|
140
|
+
}
|
|
141
|
+
`.trim()
|
|
142
|
+
|
|
143
|
+
const result = applyTransform(input)
|
|
144
|
+
expect(result).toBe(null)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it("should preserve other props when transforming innerRef", () => {
|
|
148
|
+
const input = `
|
|
149
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
150
|
+
|
|
151
|
+
export default function Test() {
|
|
152
|
+
const buttonRef = null
|
|
153
|
+
return <Button innerRef={buttonRef} onClick={() => {}} disabled>Click me</Button>
|
|
154
|
+
}
|
|
155
|
+
`.trim()
|
|
156
|
+
|
|
157
|
+
const expected = `
|
|
158
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
159
|
+
|
|
160
|
+
export default function Test() {
|
|
161
|
+
const buttonRef = null
|
|
162
|
+
return <Button ref={buttonRef} onClick={() => {}} disabled>Click me</Button>;
|
|
163
|
+
}
|
|
164
|
+
`.trim()
|
|
165
|
+
|
|
166
|
+
const result = applyTransform(input)
|
|
167
|
+
expect(result).toBe(expected)
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { transformAttributeName } from "../../shared/actions/transformAttributeName"
|
|
2
|
+
import { hasAttribute } from "../../shared/conditions/hasAttribute"
|
|
3
|
+
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
4
|
+
|
|
5
|
+
const transform = attributeTransformFactory({
|
|
6
|
+
condition: hasAttribute("innerRef"),
|
|
7
|
+
targetComponent: "Button",
|
|
8
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
9
|
+
transform: (element) => {
|
|
10
|
+
return transformAttributeName("innerRef", "ref", { element })
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export default transform
|
|
@@ -4,6 +4,7 @@ import childrenToLabel from "./transforms/childrenToLabel"
|
|
|
4
4
|
import convertStyleProps from "./transforms/convertStyleProps"
|
|
5
5
|
import inlineMemberToKind from "./transforms/inlineMemberToKind"
|
|
6
6
|
import inlinePropToKind from "./transforms/inlinePropToKind"
|
|
7
|
+
import innerRefToRef from "./transforms/innerRefToRef"
|
|
7
8
|
import moveLinkImport from "./transforms/moveLinkImport"
|
|
8
9
|
import removeAs from "./transforms/removeAs"
|
|
9
10
|
import reviewStyles from "./transforms/reviewStyles"
|
|
@@ -22,6 +23,7 @@ const transform: Transform = (fileInfo, api, options) => {
|
|
|
22
23
|
tooltipToWrapper,
|
|
23
24
|
toToHref,
|
|
24
25
|
targetBlankToExternal,
|
|
26
|
+
innerRefToRef,
|
|
25
27
|
removeAs,
|
|
26
28
|
childrenToLabel,
|
|
27
29
|
reviewStyles,
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./innerRefToRef"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
function applyTransform(source: string): string | null {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
return transform(
|
|
11
|
+
fileInfo,
|
|
12
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
+
{}
|
|
14
|
+
) as string | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("innerRefToRef transform", () => {
|
|
18
|
+
describe("basic transformations", () => {
|
|
19
|
+
it("should transform Link 'innerRef' prop to 'ref' prop", () => {
|
|
20
|
+
const input = `
|
|
21
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
22
|
+
|
|
23
|
+
export default function Test() {
|
|
24
|
+
return <Link innerRef={linkRef}>Go somewhere</Link>
|
|
25
|
+
}
|
|
26
|
+
`.trim()
|
|
27
|
+
|
|
28
|
+
const expected = `
|
|
29
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
30
|
+
|
|
31
|
+
export default function Test() {
|
|
32
|
+
return <Link ref={linkRef}>Go somewhere</Link>;
|
|
33
|
+
}
|
|
34
|
+
`.trim()
|
|
35
|
+
|
|
36
|
+
const result = applyTransform(input)
|
|
37
|
+
expect(result).toBe(expected)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it("should transform Link 'innerRef' prop to 'ref' prop with function", () => {
|
|
41
|
+
const input = `
|
|
42
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
43
|
+
|
|
44
|
+
export default function Test() {
|
|
45
|
+
return <Link innerRef={(el) => setLinkRef(el)}>Go somewhere</Link>
|
|
46
|
+
}
|
|
47
|
+
`.trim()
|
|
48
|
+
|
|
49
|
+
const expected = `
|
|
50
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
51
|
+
|
|
52
|
+
export default function Test() {
|
|
53
|
+
return <Link ref={(el) => setLinkRef(el)}>Go somewhere</Link>;
|
|
54
|
+
}
|
|
55
|
+
`.trim()
|
|
56
|
+
|
|
57
|
+
const result = applyTransform(input)
|
|
58
|
+
expect(result).toBe(expected)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it("should transform Link 'innerRef' prop to 'ref' prop with useRef", () => {
|
|
62
|
+
const input = `
|
|
63
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
64
|
+
import { useRef } from "react"
|
|
65
|
+
|
|
66
|
+
export default function Test() {
|
|
67
|
+
const linkRef = useRef(null)
|
|
68
|
+
return <Link innerRef={linkRef}>Go somewhere</Link>
|
|
69
|
+
}
|
|
70
|
+
`.trim()
|
|
71
|
+
|
|
72
|
+
const expected = `
|
|
73
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
74
|
+
import { useRef } from "react"
|
|
75
|
+
|
|
76
|
+
export default function Test() {
|
|
77
|
+
const linkRef = useRef(null)
|
|
78
|
+
return <Link ref={linkRef}>Go somewhere</Link>;
|
|
79
|
+
}
|
|
80
|
+
`.trim()
|
|
81
|
+
|
|
82
|
+
const result = applyTransform(input)
|
|
83
|
+
expect(result).toBe(expected)
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe("multiple components", () => {
|
|
88
|
+
it("should transform multiple Link components with innerRef", () => {
|
|
89
|
+
const input = `
|
|
90
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
91
|
+
|
|
92
|
+
export default function Test() {
|
|
93
|
+
return (
|
|
94
|
+
<div>
|
|
95
|
+
<Link innerRef={linkRef1}>First</Link>
|
|
96
|
+
<Link innerRef={linkRef2}>Second</Link>
|
|
97
|
+
</div>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
`.trim()
|
|
101
|
+
|
|
102
|
+
const expected = `
|
|
103
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
104
|
+
|
|
105
|
+
export default function Test() {
|
|
106
|
+
return (
|
|
107
|
+
<div>
|
|
108
|
+
<Link ref={linkRef1}>First</Link>
|
|
109
|
+
<Link ref={linkRef2}>Second</Link>
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
`.trim()
|
|
114
|
+
|
|
115
|
+
const result = applyTransform(input)
|
|
116
|
+
expect(result).toBe(expected)
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
describe("edge cases", () => {
|
|
121
|
+
it("should not transform Link without innerRef", () => {
|
|
122
|
+
const input = `
|
|
123
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
124
|
+
|
|
125
|
+
export default function Test() {
|
|
126
|
+
return <Link href="/dashboard">Go to dashboard</Link>
|
|
127
|
+
}
|
|
128
|
+
`.trim()
|
|
129
|
+
|
|
130
|
+
const result = applyTransform(input)
|
|
131
|
+
expect(result).toBe(null)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it("should not transform other components with innerRef", () => {
|
|
135
|
+
const input = `
|
|
136
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
137
|
+
|
|
138
|
+
export default function Test() {
|
|
139
|
+
return <Button innerRef={buttonRef}>Click me</Button>
|
|
140
|
+
}
|
|
141
|
+
`.trim()
|
|
142
|
+
|
|
143
|
+
const result = applyTransform(input)
|
|
144
|
+
expect(result).toBe(null)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it("should preserve other props when transforming innerRef", () => {
|
|
148
|
+
const input = `
|
|
149
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
150
|
+
|
|
151
|
+
export default function Test() {
|
|
152
|
+
const linkRef = null
|
|
153
|
+
return <Link innerRef={linkRef} href="/dashboard" onClick={() => {}}>Go to dashboard</Link>
|
|
154
|
+
}
|
|
155
|
+
`.trim()
|
|
156
|
+
|
|
157
|
+
const expected = `
|
|
158
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
159
|
+
|
|
160
|
+
export default function Test() {
|
|
161
|
+
const linkRef = null
|
|
162
|
+
return <Link ref={linkRef} href="/dashboard" onClick={() => {}}>Go to dashboard</Link>;
|
|
163
|
+
}
|
|
164
|
+
`.trim()
|
|
165
|
+
|
|
166
|
+
const result = applyTransform(input)
|
|
167
|
+
expect(result).toBe(expected)
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { transformAttributeName } from "../../shared/actions/transformAttributeName"
|
|
2
|
+
import { hasAttribute } from "../../shared/conditions/hasAttribute"
|
|
3
|
+
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
4
|
+
|
|
5
|
+
const transform = attributeTransformFactory({
|
|
6
|
+
condition: hasAttribute("innerRef"),
|
|
7
|
+
targetComponent: "Link",
|
|
8
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
9
|
+
transform: (element) => {
|
|
10
|
+
return transformAttributeName("innerRef", "ref", { element })
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export default transform
|