@planningcenter/tapestry-migration-cli 2.3.0 → 2.4.0-rc.1
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/tapestry-migration-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-rc.1",
|
|
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": "3194c750cad894cc6db7c806659074705082e986"
|
|
55
55
|
}
|
|
@@ -13,6 +13,7 @@ import moveButtonImport from "./transforms/moveButtonImport"
|
|
|
13
13
|
import removeAsButton from "./transforms/removeAsButton"
|
|
14
14
|
import removeDuplicateKeys from "./transforms/removeDuplicateKeys"
|
|
15
15
|
import removeToTransform from "./transforms/removeTo"
|
|
16
|
+
import removeTypeButton from "./transforms/removeTypeButton"
|
|
16
17
|
import reviewStyles from "./transforms/reviewStyles"
|
|
17
18
|
import spinnerToLoadingButton from "./transforms/spinnerToLoadingButton"
|
|
18
19
|
import themeVariantToKind from "./transforms/themeVariantToKind"
|
|
@@ -57,6 +58,7 @@ const transform: Transform = async (fileInfo, api, options) => {
|
|
|
57
58
|
removeToTransform,
|
|
58
59
|
removeDuplicateKeys,
|
|
59
60
|
removeAsButton,
|
|
61
|
+
removeTypeButton,
|
|
60
62
|
auditSpreadProps,
|
|
61
63
|
reviewStyles,
|
|
62
64
|
convertStyleProps,
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./removeTypeButton"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
// Helper to run transform and get result
|
|
9
|
+
function applyTransform(source: string): string | null {
|
|
10
|
+
const fileInfo = { path: "test.tsx", source }
|
|
11
|
+
const api = {
|
|
12
|
+
j,
|
|
13
|
+
jscodeshift: j,
|
|
14
|
+
report: () => {},
|
|
15
|
+
stats: () => {},
|
|
16
|
+
}
|
|
17
|
+
const result = transform(fileInfo, api, {})
|
|
18
|
+
return result as string | null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("removeTypeButton transform", () => {
|
|
22
|
+
describe("basic transformation", () => {
|
|
23
|
+
it("should remove type='button' from Button", () => {
|
|
24
|
+
const input = `
|
|
25
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
26
|
+
|
|
27
|
+
function Component() {
|
|
28
|
+
return <Button type="button">Click me</Button>
|
|
29
|
+
}
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
const result = applyTransform(input)
|
|
33
|
+
|
|
34
|
+
expect(result).toContain("<Button>Click me</Button>")
|
|
35
|
+
expect(result).not.toContain('type="button"')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should remove type="button" from Button', () => {
|
|
39
|
+
const input = `
|
|
40
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
41
|
+
|
|
42
|
+
function Component() {
|
|
43
|
+
return <Button type="button" onClick={handleClick}>Submit</Button>
|
|
44
|
+
}
|
|
45
|
+
`
|
|
46
|
+
|
|
47
|
+
const result = applyTransform(input)
|
|
48
|
+
|
|
49
|
+
expect(result).toContain("<Button onClick={handleClick}>Submit</Button>")
|
|
50
|
+
expect(result).not.toContain('type="button"')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it("should preserve Button without type='button'", () => {
|
|
54
|
+
const input = `
|
|
55
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
56
|
+
|
|
57
|
+
function Component() {
|
|
58
|
+
return <Button onClick={handleClick}>Click me</Button>
|
|
59
|
+
}
|
|
60
|
+
`
|
|
61
|
+
|
|
62
|
+
const result = applyTransform(input)
|
|
63
|
+
|
|
64
|
+
expect(result).toBeNull()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it("should preserve Button with type='submit'", () => {
|
|
68
|
+
const input = `
|
|
69
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
70
|
+
|
|
71
|
+
function Component() {
|
|
72
|
+
return <Button type="submit">Submit</Button>
|
|
73
|
+
}
|
|
74
|
+
`
|
|
75
|
+
|
|
76
|
+
const result = applyTransform(input)
|
|
77
|
+
|
|
78
|
+
expect(result).toBeNull()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it("should preserve Button with type='reset'", () => {
|
|
82
|
+
const input = `
|
|
83
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
84
|
+
|
|
85
|
+
function Component() {
|
|
86
|
+
return <Button type="reset">Reset</Button>
|
|
87
|
+
}
|
|
88
|
+
`
|
|
89
|
+
|
|
90
|
+
const result = applyTransform(input)
|
|
91
|
+
|
|
92
|
+
expect(result).toBeNull()
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
describe("multiple buttons", () => {
|
|
97
|
+
it("should handle mixed Button usage", () => {
|
|
98
|
+
const input = `
|
|
99
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
100
|
+
|
|
101
|
+
function Component() {
|
|
102
|
+
return (
|
|
103
|
+
<div>
|
|
104
|
+
<Button type="button">Click me</Button>
|
|
105
|
+
<Button type="submit">Submit</Button>
|
|
106
|
+
<Button type="button" onClick={handleClick}>Action</Button>
|
|
107
|
+
</div>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
`
|
|
111
|
+
|
|
112
|
+
const result = applyTransform(input)
|
|
113
|
+
|
|
114
|
+
expect(result).toContain("<Button>Click me</Button>")
|
|
115
|
+
expect(result).toContain('<Button type="submit">Submit</Button>')
|
|
116
|
+
expect(result).toContain("<Button onClick={handleClick}>Action</Button>")
|
|
117
|
+
expect(result).not.toContain('type="button"')
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe("edge cases", () => {
|
|
122
|
+
it("should handle Button with multiple attributes including type='button'", () => {
|
|
123
|
+
const input = `
|
|
124
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
125
|
+
|
|
126
|
+
function Component() {
|
|
127
|
+
return <Button className="btn" type="button" disabled>Disabled</Button>
|
|
128
|
+
}
|
|
129
|
+
`
|
|
130
|
+
|
|
131
|
+
const result = applyTransform(input)
|
|
132
|
+
|
|
133
|
+
expect(result).toContain(
|
|
134
|
+
'<Button className="btn" disabled>Disabled</Button>'
|
|
135
|
+
)
|
|
136
|
+
expect(result).not.toContain('type="button"')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it("should not affect other components with type='button'", () => {
|
|
140
|
+
const input = `
|
|
141
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
142
|
+
|
|
143
|
+
function Component() {
|
|
144
|
+
return (
|
|
145
|
+
<div>
|
|
146
|
+
<Button type="button">Tapestry Button</Button>
|
|
147
|
+
<button type="button">HTML Button</button>
|
|
148
|
+
</div>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
`
|
|
152
|
+
|
|
153
|
+
const result = applyTransform(input)
|
|
154
|
+
|
|
155
|
+
expect(result).toContain("<Button>Tapestry Button</Button>")
|
|
156
|
+
expect(result).toContain('<button type="button">HTML Button</button>')
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it("should handle Button with expression type", () => {
|
|
160
|
+
const input = `
|
|
161
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
162
|
+
|
|
163
|
+
function Component() {
|
|
164
|
+
return <Button type={"button"}>Click me</Button>
|
|
165
|
+
}
|
|
166
|
+
`
|
|
167
|
+
|
|
168
|
+
const result = applyTransform(input)
|
|
169
|
+
|
|
170
|
+
if (result) {
|
|
171
|
+
expect(result).toContain("<Button>Click me</Button>")
|
|
172
|
+
expect(result).not.toContain('type={"button"}')
|
|
173
|
+
} else {
|
|
174
|
+
// If no transformation occurred, the original should still have the expression
|
|
175
|
+
expect(input).toContain('type={"button"}')
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
describe("import handling", () => {
|
|
181
|
+
it("should not affect imports", () => {
|
|
182
|
+
const input = `
|
|
183
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
184
|
+
|
|
185
|
+
function Component() {
|
|
186
|
+
return <Button type="button">Click me</Button>
|
|
187
|
+
}
|
|
188
|
+
`
|
|
189
|
+
|
|
190
|
+
const result = applyTransform(input)
|
|
191
|
+
|
|
192
|
+
expect(result).toContain(
|
|
193
|
+
'import { Button } from "@planningcenter/tapestry-react"'
|
|
194
|
+
)
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Transform } from "jscodeshift"
|
|
2
|
+
|
|
3
|
+
import { removeAttribute } from "../../shared/actions/removeAttribute"
|
|
4
|
+
import { hasAttributeValue } from "../../shared/conditions/hasAttributeValue"
|
|
5
|
+
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
6
|
+
|
|
7
|
+
const transform: Transform = attributeTransformFactory({
|
|
8
|
+
condition: hasAttributeValue("type", "button"),
|
|
9
|
+
targetComponent: "Button",
|
|
10
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
11
|
+
transform: (element, { j, source }) =>
|
|
12
|
+
removeAttribute("type", { element, j, source }),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export default transform
|