@planningcenter/tapestry-migration-cli 3.1.0-rc.8 → 3.1.0
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/dist/tapestry-react-shim.cjs +7 -1
- package/package.json +3 -3
- package/src/components/input/transformableInput.ts +47 -6
- package/src/components/input/transforms/mergeFieldIntoInput.test.ts +78 -0
- package/src/components/input/transforms/mergeFieldIntoInput.ts +6 -212
- package/src/components/input/transforms/removeDuplicateKeys.test.ts +3 -3
- package/src/components/input/transforms/removeTypeInput.test.ts +212 -0
- package/src/components/input/transforms/removeTypeInput.ts +22 -0
- package/src/components/input/transforms/removeTypeText.ts +2 -3
- package/src/components/input/transforms/unsupportedProps.test.ts +20 -20
- package/src/components/select/index.ts +58 -0
- package/src/components/select/transformableSelect.ts +7 -0
- package/src/components/select/transforms/auditSpreadProps.test.ts +103 -0
- package/src/components/select/transforms/auditSpreadProps.ts +26 -0
- package/src/components/select/transforms/childrenToOptions.test.ts +367 -0
- package/src/components/select/transforms/childrenToOptions.ts +295 -0
- package/src/components/select/transforms/convertLegacyOptions.test.ts +150 -0
- package/src/components/select/transforms/convertLegacyOptions.ts +105 -0
- package/src/components/select/transforms/convertStyleProps.test.ts +73 -0
- package/src/components/select/transforms/convertStyleProps.ts +12 -0
- package/src/components/select/transforms/emptyValueToPlaceholder.test.ts +122 -0
- package/src/components/select/transforms/emptyValueToPlaceholder.ts +22 -0
- package/src/components/select/transforms/innerRefToRef.test.ts +89 -0
- package/src/components/select/transforms/innerRefToRef.ts +18 -0
- package/src/components/select/transforms/mapChildrenToOptions.test.ts +521 -0
- package/src/components/select/transforms/mapChildrenToOptions.ts +312 -0
- package/src/components/select/transforms/mergeFieldIntoSelect.test.ts +506 -0
- package/src/components/select/transforms/mergeFieldIntoSelect.ts +7 -0
- package/src/components/select/transforms/mergeSelectLabel.test.ts +458 -0
- package/src/components/select/transforms/mergeSelectLabel.ts +225 -0
- package/src/components/select/transforms/moveSelectImport.test.ts +148 -0
- package/src/components/select/transforms/moveSelectImport.ts +14 -0
- package/src/components/select/transforms/removeDefaultProps.test.ts +249 -0
- package/src/components/select/transforms/removeDefaultProps.ts +112 -0
- package/src/components/select/transforms/sizeMapping.test.ts +188 -0
- package/src/components/select/transforms/sizeMapping.ts +17 -0
- package/src/components/select/transforms/skipMultipleSelect.test.ts +148 -0
- package/src/components/select/transforms/skipMultipleSelect.ts +23 -0
- package/src/components/select/transforms/stateToInvalid.test.ts +217 -0
- package/src/components/select/transforms/stateToInvalid.ts +59 -0
- package/src/components/select/transforms/stateToInvalidTernary.test.ts +146 -0
- package/src/components/select/transforms/stateToInvalidTernary.ts +13 -0
- package/src/components/select/transforms/unsupportedProps.test.ts +252 -0
- package/src/components/select/transforms/unsupportedProps.ts +44 -0
- package/src/components/shared/helpers/getAttributeExpression.ts +26 -0
- package/src/components/shared/helpers/unsupportedPropsHelpers.ts +52 -2
- package/src/components/shared/transformFactories/mergeFieldFactory.ts +244 -0
- package/src/components/shared/transformFactories/stylePropTransformFactory.ts +2 -1
- package/src/components/text-area/index.ts +48 -0
- package/src/components/text-area/transforms/auditSpreadProps.test.ts +139 -0
- package/src/components/text-area/transforms/auditSpreadProps.ts +10 -0
- package/src/components/text-area/transforms/convertStyleProps.test.ts +158 -0
- package/src/components/text-area/transforms/convertStyleProps.ts +10 -0
- package/src/components/text-area/transforms/innerRefToRef.test.ts +206 -0
- package/src/components/text-area/transforms/innerRefToRef.ts +14 -0
- package/src/components/text-area/transforms/mergeFieldIntoTextArea.test.ts +477 -0
- package/src/components/text-area/transforms/mergeFieldIntoTextArea.ts +5 -0
- package/src/components/text-area/transforms/moveTextAreaImport.test.ts +168 -0
- package/src/components/text-area/transforms/moveTextAreaImport.ts +13 -0
- package/src/components/text-area/transforms/removeDuplicateKeys.test.ts +129 -0
- package/src/components/text-area/transforms/removeDuplicateKeys.ts +8 -0
- package/src/components/text-area/transforms/removeRedundantAriaLabel.test.ts +183 -0
- package/src/components/text-area/transforms/removeRedundantAriaLabel.ts +59 -0
- package/src/components/text-area/transforms/sizeMapping.test.ts +199 -0
- package/src/components/text-area/transforms/sizeMapping.ts +15 -0
- package/src/components/text-area/transforms/stateToInvalid.test.ts +204 -0
- package/src/components/text-area/transforms/stateToInvalid.ts +57 -0
- package/src/components/text-area/transforms/stateToInvalidTernary.test.ts +133 -0
- package/src/components/text-area/transforms/stateToInvalidTernary.ts +11 -0
- package/src/components/text-area/transforms/unsupportedProps.test.ts +275 -0
- package/src/components/text-area/transforms/unsupportedProps.ts +35 -0
- package/src/index.ts +4 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./emptyValueToPlaceholder"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
function applyTransform(source: string): string {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
const result = transform(
|
|
11
|
+
fileInfo,
|
|
12
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
+
{}
|
|
14
|
+
) as string | null
|
|
15
|
+
return result || source
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("emptyValueToPlaceholder transform", () => {
|
|
19
|
+
it("should rename emptyValue string literal to placeholder", () => {
|
|
20
|
+
const input = `
|
|
21
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
22
|
+
|
|
23
|
+
function Test() {
|
|
24
|
+
return <Select emptyValue="Pick one" />
|
|
25
|
+
}
|
|
26
|
+
`.trim()
|
|
27
|
+
|
|
28
|
+
const result = applyTransform(input)
|
|
29
|
+
expect(result).toContain('placeholder="Pick one"')
|
|
30
|
+
expect(result).not.toContain("emptyValue")
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should rename emptyValue={"text"} expression to placeholder', () => {
|
|
34
|
+
const input = `
|
|
35
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
36
|
+
|
|
37
|
+
function Test() {
|
|
38
|
+
return <Select emptyValue={"Pick one"} />
|
|
39
|
+
}
|
|
40
|
+
`.trim()
|
|
41
|
+
|
|
42
|
+
const result = applyTransform(input)
|
|
43
|
+
expect(result).toContain("placeholder=")
|
|
44
|
+
expect(result).not.toContain("emptyValue")
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it("should rename emptyValue with JSX expression value", () => {
|
|
48
|
+
const input = `
|
|
49
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
50
|
+
|
|
51
|
+
function Test() {
|
|
52
|
+
const text = "Pick one"
|
|
53
|
+
return <Select emptyValue={text} />
|
|
54
|
+
}
|
|
55
|
+
`.trim()
|
|
56
|
+
|
|
57
|
+
const result = applyTransform(input)
|
|
58
|
+
expect(result).toContain("placeholder={text}")
|
|
59
|
+
expect(result).not.toContain("emptyValue")
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it("should not transform Select without emptyValue", () => {
|
|
63
|
+
const input = `
|
|
64
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
65
|
+
|
|
66
|
+
function Test() {
|
|
67
|
+
return <Select value="test" />
|
|
68
|
+
}
|
|
69
|
+
`.trim()
|
|
70
|
+
|
|
71
|
+
const result = applyTransform(input)
|
|
72
|
+
expect(result).toBe(input)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it("should not transform other components", () => {
|
|
76
|
+
const input = `
|
|
77
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
78
|
+
|
|
79
|
+
function Test() {
|
|
80
|
+
return <Button emptyValue="test">Click</Button>
|
|
81
|
+
}
|
|
82
|
+
`.trim()
|
|
83
|
+
|
|
84
|
+
const result = applyTransform(input)
|
|
85
|
+
expect(result).toBe(input)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it("should handle multiple Select components", () => {
|
|
89
|
+
const input = `
|
|
90
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
91
|
+
|
|
92
|
+
function Test() {
|
|
93
|
+
return (
|
|
94
|
+
<div>
|
|
95
|
+
<Select emptyValue="Pick one" />
|
|
96
|
+
<Select emptyValue="Pick another" />
|
|
97
|
+
</div>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
`.trim()
|
|
101
|
+
|
|
102
|
+
const result = applyTransform(input)
|
|
103
|
+
expect(result).not.toContain("emptyValue")
|
|
104
|
+
expect(result).toMatch(/placeholder="Pick one"/)
|
|
105
|
+
expect(result).toMatch(/placeholder="Pick another"/)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it("should preserve other props", () => {
|
|
109
|
+
const input = `
|
|
110
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
111
|
+
|
|
112
|
+
function Test() {
|
|
113
|
+
return <Select emptyValue="Pick one" disabled onChange={handler} />
|
|
114
|
+
}
|
|
115
|
+
`.trim()
|
|
116
|
+
|
|
117
|
+
const result = applyTransform(input)
|
|
118
|
+
expect(result).toContain('placeholder="Pick one"')
|
|
119
|
+
expect(result).toContain("disabled")
|
|
120
|
+
expect(result).toContain("onChange={handler}")
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Transform } from "jscodeshift"
|
|
2
|
+
|
|
3
|
+
import { transformAttributeName } from "../../shared/actions/transformAttributeName"
|
|
4
|
+
import { andConditions } from "../../shared/conditions/andConditions"
|
|
5
|
+
import { hasAttribute } from "../../shared/conditions/hasAttribute"
|
|
6
|
+
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
7
|
+
import { transformableSelect } from "../transformableSelect"
|
|
8
|
+
|
|
9
|
+
const transform: Transform = attributeTransformFactory({
|
|
10
|
+
condition: andConditions(transformableSelect, hasAttribute("emptyValue")),
|
|
11
|
+
targetComponent: "Select",
|
|
12
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
13
|
+
transform: (element, { j, options }) => {
|
|
14
|
+
return transformAttributeName("emptyValue", "placeholder", {
|
|
15
|
+
element,
|
|
16
|
+
j,
|
|
17
|
+
options,
|
|
18
|
+
})
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export default transform
|
|
@@ -0,0 +1,89 @@
|
|
|
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 {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
const result = transform(
|
|
11
|
+
fileInfo,
|
|
12
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
+
{}
|
|
14
|
+
) as string | null
|
|
15
|
+
return result || source
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("innerRefToRef transform", () => {
|
|
19
|
+
it("should rename innerRef to ref", () => {
|
|
20
|
+
const input = `
|
|
21
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
22
|
+
|
|
23
|
+
function Test() {
|
|
24
|
+
const ref = useRef()
|
|
25
|
+
return <Select innerRef={ref} emptyValue="Pick one" />
|
|
26
|
+
}
|
|
27
|
+
`.trim()
|
|
28
|
+
|
|
29
|
+
const result = applyTransform(input)
|
|
30
|
+
expect(result).toContain("ref={ref}")
|
|
31
|
+
expect(result).not.toContain("innerRef")
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("should handle innerRef with callback ref", () => {
|
|
35
|
+
const input = `
|
|
36
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
37
|
+
|
|
38
|
+
function Test() {
|
|
39
|
+
return <Select innerRef={(node) => { myRef = node }} emptyValue="Pick one" />
|
|
40
|
+
}
|
|
41
|
+
`.trim()
|
|
42
|
+
|
|
43
|
+
const result = applyTransform(input)
|
|
44
|
+
expect(result).toContain("ref={(node)")
|
|
45
|
+
expect(result).not.toContain("innerRef")
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it("should not transform Select without innerRef", () => {
|
|
49
|
+
const input = `
|
|
50
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
51
|
+
|
|
52
|
+
function Test() {
|
|
53
|
+
return <Select emptyValue="Pick one" />
|
|
54
|
+
}
|
|
55
|
+
`.trim()
|
|
56
|
+
|
|
57
|
+
const result = applyTransform(input)
|
|
58
|
+
expect(result).toBe(input)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it("should not transform other components", () => {
|
|
62
|
+
const input = `
|
|
63
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
64
|
+
|
|
65
|
+
function Test() {
|
|
66
|
+
return <Button innerRef={ref}>Click</Button>
|
|
67
|
+
}
|
|
68
|
+
`.trim()
|
|
69
|
+
|
|
70
|
+
const result = applyTransform(input)
|
|
71
|
+
expect(result).toBe(input)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it("should preserve other props", () => {
|
|
75
|
+
const input = `
|
|
76
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
77
|
+
|
|
78
|
+
function Test() {
|
|
79
|
+
return <Select innerRef={ref} emptyValue="Pick" disabled onChange={handler} />
|
|
80
|
+
}
|
|
81
|
+
`.trim()
|
|
82
|
+
|
|
83
|
+
const result = applyTransform(input)
|
|
84
|
+
expect(result).toContain("ref={ref}")
|
|
85
|
+
expect(result).toContain("disabled")
|
|
86
|
+
expect(result).toContain("onChange={handler}")
|
|
87
|
+
expect(result).not.toContain("innerRef")
|
|
88
|
+
})
|
|
89
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Transform } from "jscodeshift"
|
|
2
|
+
|
|
3
|
+
import { transformAttributeName } from "../../shared/actions/transformAttributeName"
|
|
4
|
+
import { andConditions } from "../../shared/conditions/andConditions"
|
|
5
|
+
import { hasAttribute } from "../../shared/conditions/hasAttribute"
|
|
6
|
+
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
7
|
+
import { transformableSelect } from "../transformableSelect"
|
|
8
|
+
|
|
9
|
+
const transform: Transform = attributeTransformFactory({
|
|
10
|
+
condition: andConditions(transformableSelect, hasAttribute("innerRef")),
|
|
11
|
+
targetComponent: "Select",
|
|
12
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
13
|
+
transform: (element, { j, options }) => {
|
|
14
|
+
return transformAttributeName("innerRef", "ref", { element, j, options })
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export default transform
|