@planningcenter/tapestry-migration-cli 3.1.0-rc.2 → 3.1.0-rc.21

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 (115) hide show
  1. package/dist/tapestry-react-shim.cjs +7 -1
  2. package/package.json +3 -3
  3. package/src/components/button/transforms/convertStyleProps.test.ts +97 -0
  4. package/src/components/button/transforms/removeTypeButton.test.ts +0 -1
  5. package/src/components/checkbox/transforms/moveCheckboxImport.test.ts +3 -0
  6. package/src/components/input/index.ts +66 -0
  7. package/src/components/input/transformableInput.ts +49 -0
  8. package/src/components/input/transforms/auditSpreadProps.test.ts +192 -0
  9. package/src/components/input/transforms/auditSpreadProps.ts +26 -0
  10. package/src/components/input/transforms/autoWidthTransform.test.ts +172 -0
  11. package/src/components/input/transforms/autoWidthTransform.ts +41 -0
  12. package/src/components/input/transforms/convertStyleProps.test.ts +128 -0
  13. package/src/components/input/transforms/convertStyleProps.ts +12 -0
  14. package/src/components/input/transforms/highlightOnInteractionToSelectTextOnFocus.test.ts +186 -0
  15. package/src/components/input/transforms/highlightOnInteractionToSelectTextOnFocus.ts +27 -0
  16. package/src/components/input/transforms/inputLabelToLabelProp.test.ts +319 -0
  17. package/src/components/input/transforms/inputLabelToLabelProp.ts +203 -0
  18. package/src/components/input/transforms/mergeFieldIntoInput.test.ts +469 -0
  19. package/src/components/input/transforms/mergeFieldIntoInput.ts +7 -0
  20. package/src/components/input/transforms/mergeInputLabel.test.ts +458 -0
  21. package/src/components/input/transforms/mergeInputLabel.ts +204 -0
  22. package/src/components/input/transforms/moveInputImport.test.ts +166 -0
  23. package/src/components/input/transforms/moveInputImport.ts +14 -0
  24. package/src/components/input/transforms/numberFieldAddTypeNumber.test.ts +92 -0
  25. package/src/components/input/transforms/numberFieldAddTypeNumber.ts +14 -0
  26. package/src/components/input/transforms/numberFieldRenameToInput.test.ts +126 -0
  27. package/src/components/input/transforms/numberFieldRenameToInput.ts +9 -0
  28. package/src/components/input/transforms/removeAsInput.test.ts +139 -0
  29. package/src/components/input/transforms/removeAsInput.ts +20 -0
  30. package/src/components/input/transforms/removeDuplicateKeys.test.ts +302 -0
  31. package/src/components/input/transforms/removeDuplicateKeys.ts +10 -0
  32. package/src/components/input/transforms/removeInputBox.test.ts +352 -0
  33. package/src/components/input/transforms/removeInputBox.ts +109 -0
  34. package/src/components/input/transforms/removeRedundantAriaLabel.test.ts +128 -0
  35. package/src/components/input/transforms/removeRedundantAriaLabel.ts +21 -0
  36. package/src/components/input/transforms/removeTypeInput.test.ts +212 -0
  37. package/src/components/input/transforms/removeTypeInput.ts +22 -0
  38. package/src/components/input/transforms/removeTypeText.test.ts +160 -0
  39. package/src/components/input/transforms/removeTypeText.ts +17 -0
  40. package/src/components/input/transforms/sizeMapping.test.ts +198 -0
  41. package/src/components/input/transforms/sizeMapping.ts +17 -0
  42. package/src/components/input/transforms/skipRenderSideProps.test.ts +236 -0
  43. package/src/components/input/transforms/skipRenderSideProps.ts +27 -0
  44. package/src/components/input/transforms/stateToInvalid.test.ts +208 -0
  45. package/src/components/input/transforms/stateToInvalid.ts +59 -0
  46. package/src/components/input/transforms/stateToInvalidTernary.test.ts +159 -0
  47. package/src/components/input/transforms/stateToInvalidTernary.ts +13 -0
  48. package/src/components/input/transforms/unsupportedProps.test.ts +566 -0
  49. package/src/components/input/transforms/unsupportedProps.ts +84 -0
  50. package/src/components/link/transforms/reviewStyles.test.ts +0 -1
  51. package/src/components/select/index.ts +58 -0
  52. package/src/components/select/transformableSelect.ts +7 -0
  53. package/src/components/select/transforms/auditSpreadProps.test.ts +103 -0
  54. package/src/components/select/transforms/auditSpreadProps.ts +26 -0
  55. package/src/components/select/transforms/childrenToOptions.test.ts +367 -0
  56. package/src/components/select/transforms/childrenToOptions.ts +295 -0
  57. package/src/components/select/transforms/convertLegacyOptions.test.ts +150 -0
  58. package/src/components/select/transforms/convertLegacyOptions.ts +105 -0
  59. package/src/components/select/transforms/convertStyleProps.test.ts +73 -0
  60. package/src/components/select/transforms/convertStyleProps.ts +12 -0
  61. package/src/components/select/transforms/emptyValueToPlaceholder.test.ts +122 -0
  62. package/src/components/select/transforms/emptyValueToPlaceholder.ts +22 -0
  63. package/src/components/select/transforms/innerRefToRef.test.ts +89 -0
  64. package/src/components/select/transforms/innerRefToRef.ts +18 -0
  65. package/src/components/select/transforms/mapChildrenToOptions.test.ts +521 -0
  66. package/src/components/select/transforms/mapChildrenToOptions.ts +312 -0
  67. package/src/components/select/transforms/mergeFieldIntoSelect.test.ts +506 -0
  68. package/src/components/select/transforms/mergeFieldIntoSelect.ts +7 -0
  69. package/src/components/select/transforms/mergeSelectLabel.test.ts +458 -0
  70. package/src/components/select/transforms/mergeSelectLabel.ts +225 -0
  71. package/src/components/select/transforms/moveSelectImport.test.ts +148 -0
  72. package/src/components/select/transforms/moveSelectImport.ts +14 -0
  73. package/src/components/select/transforms/removeDefaultProps.test.ts +249 -0
  74. package/src/components/select/transforms/removeDefaultProps.ts +112 -0
  75. package/src/components/select/transforms/sizeMapping.test.ts +188 -0
  76. package/src/components/select/transforms/sizeMapping.ts +17 -0
  77. package/src/components/select/transforms/skipMultipleSelect.test.ts +148 -0
  78. package/src/components/select/transforms/skipMultipleSelect.ts +23 -0
  79. package/src/components/select/transforms/stateToInvalid.test.ts +217 -0
  80. package/src/components/select/transforms/stateToInvalid.ts +59 -0
  81. package/src/components/select/transforms/stateToInvalidTernary.test.ts +146 -0
  82. package/src/components/select/transforms/stateToInvalidTernary.ts +13 -0
  83. package/src/components/select/transforms/unsupportedProps.test.ts +252 -0
  84. package/src/components/select/transforms/unsupportedProps.ts +44 -0
  85. package/src/components/shared/helpers/getAttributeExpression.ts +26 -0
  86. package/src/components/shared/helpers/unsupportedPropsHelpers.ts +102 -0
  87. package/src/components/shared/transformFactories/helpers/manageImports.ts +14 -12
  88. package/src/components/shared/transformFactories/mergeFieldFactory.ts +244 -0
  89. package/src/components/shared/transformFactories/sizeMappingFactory.ts +9 -2
  90. package/src/components/shared/transformFactories/stylePropTransformFactory.ts +56 -17
  91. package/src/components/shared/transformFactories/ternaryConditionalToPropFactory.ts +65 -0
  92. package/src/components/text-area/index.ts +48 -0
  93. package/src/components/text-area/transforms/auditSpreadProps.test.ts +139 -0
  94. package/src/components/text-area/transforms/auditSpreadProps.ts +10 -0
  95. package/src/components/text-area/transforms/convertStyleProps.test.ts +158 -0
  96. package/src/components/text-area/transforms/convertStyleProps.ts +10 -0
  97. package/src/components/text-area/transforms/innerRefToRef.test.ts +206 -0
  98. package/src/components/text-area/transforms/innerRefToRef.ts +14 -0
  99. package/src/components/text-area/transforms/mergeFieldIntoTextArea.test.ts +477 -0
  100. package/src/components/text-area/transforms/mergeFieldIntoTextArea.ts +5 -0
  101. package/src/components/text-area/transforms/moveTextAreaImport.test.ts +168 -0
  102. package/src/components/text-area/transforms/moveTextAreaImport.ts +13 -0
  103. package/src/components/text-area/transforms/removeDuplicateKeys.test.ts +129 -0
  104. package/src/components/text-area/transforms/removeDuplicateKeys.ts +8 -0
  105. package/src/components/text-area/transforms/removeRedundantAriaLabel.test.ts +183 -0
  106. package/src/components/text-area/transforms/removeRedundantAriaLabel.ts +59 -0
  107. package/src/components/text-area/transforms/sizeMapping.test.ts +199 -0
  108. package/src/components/text-area/transforms/sizeMapping.ts +15 -0
  109. package/src/components/text-area/transforms/stateToInvalid.test.ts +204 -0
  110. package/src/components/text-area/transforms/stateToInvalid.ts +57 -0
  111. package/src/components/text-area/transforms/stateToInvalidTernary.test.ts +133 -0
  112. package/src/components/text-area/transforms/stateToInvalidTernary.ts +11 -0
  113. package/src/components/text-area/transforms/unsupportedProps.test.ts +275 -0
  114. package/src/components/text-area/transforms/unsupportedProps.ts +35 -0
  115. package/src/index.ts +2 -1
@@ -0,0 +1,59 @@
1
+ import { Transform } from "jscodeshift"
2
+
3
+ import { addAttribute } from "../../shared/actions/addAttribute"
4
+ import { addComment } from "../../shared/actions/addComment"
5
+ import { getAttribute } from "../../shared/actions/getAttribute"
6
+ import { getAttributeValue } from "../../shared/actions/getAttributeValue"
7
+ import { removeAttribute } from "../../shared/actions/removeAttribute"
8
+ import { andConditions } from "../../shared/conditions/andConditions"
9
+ import { hasAttribute } from "../../shared/conditions/hasAttribute"
10
+ import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
11
+ import { transformableInput } from "../transformableInput"
12
+
13
+ const transform: Transform = attributeTransformFactory({
14
+ condition: andConditions(hasAttribute("state"), transformableInput),
15
+ targetComponent: "Input",
16
+ targetPackage: "@planningcenter/tapestry-react",
17
+ transform: (element, { j, source }) => {
18
+ const attr = getAttribute({ element, name: "state" })
19
+ if (!attr) return false
20
+
21
+ const value = getAttributeValue({ attribute: attr, j })
22
+
23
+ if (value === "error") {
24
+ removeAttribute("state", { element, j, source })
25
+ addAttribute({
26
+ booleanAsShorthand: true,
27
+ element,
28
+ j,
29
+ name: "invalid",
30
+ value: true,
31
+ })
32
+ return true
33
+ }
34
+
35
+ if (value === "success") {
36
+ removeAttribute("state", { element, j, source })
37
+ addComment({
38
+ element,
39
+ j,
40
+ scope: "state",
41
+ source,
42
+ text: "'state=\"success\"' has no equivalent in the new Input API. Remove this prop and implement success feedback separately.",
43
+ })
44
+ return true
45
+ }
46
+
47
+ // Dynamic value — can't determine at compile time
48
+ addComment({
49
+ element,
50
+ j,
51
+ scope: "state",
52
+ source,
53
+ text: "'state' has been replaced by 'invalid' (boolean). For error state, use invalid={true}. 'success' has no equivalent. Migrate this prop manually.",
54
+ })
55
+ return true
56
+ },
57
+ })
58
+
59
+ export default transform
@@ -0,0 +1,159 @@
1
+ import jscodeshift from "jscodeshift"
2
+ import { describe, expect, it } from "vitest"
3
+
4
+ import transform from "./stateToInvalidTernary"
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("stateToInvalidTernary transform", () => {
18
+ describe("successful conversions", () => {
19
+ it("converts state={hasError ? 'error' : null} → invalid={hasError}", () => {
20
+ const input = `
21
+ import { Input } from "@planningcenter/tapestry-react"
22
+
23
+ function Test() {
24
+ return <Input state={hasError ? "error" : null} label="Name" />
25
+ }
26
+ `.trim()
27
+
28
+ const result = applyTransform(input)
29
+ expect(result).not.toBeNull()
30
+ expect(result).toContain("invalid={hasError}")
31
+ expect(result).not.toContain("state=")
32
+ })
33
+
34
+ it("converts member expression: state={form.hasError ? 'error' : null} → invalid={form.hasError}", () => {
35
+ const input = `
36
+ import { Input } from "@planningcenter/tapestry-react"
37
+
38
+ function Test() {
39
+ return <Input state={form.hasError ? "error" : null} label="Name" />
40
+ }
41
+ `.trim()
42
+
43
+ const result = applyTransform(input)
44
+ expect(result).not.toBeNull()
45
+ expect(result).toContain("invalid={form.hasError}")
46
+ expect(result).not.toContain("state=")
47
+ })
48
+
49
+ it("converts binary expression: state={errors.length > 0 ? 'error' : null} → invalid={errors.length > 0}", () => {
50
+ const input = `
51
+ import { Input } from "@planningcenter/tapestry-react"
52
+
53
+ function Test() {
54
+ return <Input state={errors.length > 0 ? "error" : null} label="Name" />
55
+ }
56
+ `.trim()
57
+
58
+ const result = applyTransform(input)
59
+ expect(result).not.toBeNull()
60
+ expect(result).toContain("invalid={errors.length > 0}")
61
+ expect(result).not.toContain("state=")
62
+ })
63
+
64
+ it("converts state={hasError ? 'error' : undefined} → invalid={hasError}", () => {
65
+ const input = `
66
+ import { Input } from "@planningcenter/tapestry-react"
67
+
68
+ function Test() {
69
+ return <Input state={hasError ? "error" : undefined} label="Name" />
70
+ }
71
+ `.trim()
72
+
73
+ const result = applyTransform(input)
74
+ expect(result).not.toBeNull()
75
+ expect(result).toContain("invalid={hasError}")
76
+ expect(result).not.toContain("state=")
77
+ })
78
+ })
79
+
80
+ describe("no-op cases", () => {
81
+ it("returns null when consequent is not 'error'", () => {
82
+ const input = `
83
+ import { Input } from "@planningcenter/tapestry-react"
84
+
85
+ function Test() {
86
+ return <Input state={hasWarning ? "warning" : null} label="Name" />
87
+ }
88
+ `.trim()
89
+
90
+ const result = applyTransform(input)
91
+ expect(result).toBeNull()
92
+ })
93
+
94
+ it("returns null when alternate is not null/undefined", () => {
95
+ const input = `
96
+ import { Input } from "@planningcenter/tapestry-react"
97
+
98
+ function Test() {
99
+ return <Input state={hasError ? "error" : "success"} label="Name" />
100
+ }
101
+ `.trim()
102
+
103
+ const result = applyTransform(input)
104
+ expect(result).toBeNull()
105
+ })
106
+
107
+ it("returns null when Input is from a different package", () => {
108
+ const input = `
109
+ import { Input } from "other-library"
110
+
111
+ function Test() {
112
+ return <Input state={hasError ? "error" : null} label="Name" />
113
+ }
114
+ `.trim()
115
+
116
+ const result = applyTransform(input)
117
+ expect(result).toBeNull()
118
+ })
119
+
120
+ it("returns null when Input has renderLeft prop", () => {
121
+ const input = `
122
+ import { Input } from "@planningcenter/tapestry-react"
123
+
124
+ function Test() {
125
+ return <Input state={hasError ? "error" : null} renderLeft={() => <span />} label="Name" />
126
+ }
127
+ `.trim()
128
+
129
+ const result = applyTransform(input)
130
+ expect(result).toBeNull()
131
+ })
132
+
133
+ it("returns null when Input has renderRight prop", () => {
134
+ const input = `
135
+ import { Input } from "@planningcenter/tapestry-react"
136
+
137
+ function Test() {
138
+ return <Input state={hasError ? "error" : null} renderRight={() => <span />} label="Name" />
139
+ }
140
+ `.trim()
141
+
142
+ const result = applyTransform(input)
143
+ expect(result).toBeNull()
144
+ })
145
+
146
+ it("returns null when Input has no state prop", () => {
147
+ const input = `
148
+ import { Input } from "@planningcenter/tapestry-react"
149
+
150
+ function Test() {
151
+ return <Input label="Name" />
152
+ }
153
+ `.trim()
154
+
155
+ const result = applyTransform(input)
156
+ expect(result).toBeNull()
157
+ })
158
+ })
159
+ })
@@ -0,0 +1,13 @@
1
+ import { andConditions } from "../../shared/conditions/andConditions"
2
+ import { hasAttribute } from "../../shared/conditions/hasAttribute"
3
+ import { ternaryConditionalToPropFactory } from "../../shared/transformFactories/ternaryConditionalToPropFactory"
4
+ import { transformableInput } from "../transformableInput"
5
+
6
+ export default ternaryConditionalToPropFactory({
7
+ condition: andConditions(hasAttribute("state"), transformableInput),
8
+ fromProp: "state",
9
+ matchValue: "error",
10
+ targetComponent: "Input",
11
+ targetPackage: "@planningcenter/tapestry-react",
12
+ toProp: "invalid",
13
+ })