@planningcenter/tapestry-migration-cli 3.6.0 → 3.7.0-rc.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 +195 -11
- package/package.json +3 -3
- package/src/components/flex/index.test.ts +181 -0
- package/src/components/flex/index.ts +16 -0
- package/src/components/flex/transforms/alignmentToAlign.test.ts +101 -0
- package/src/components/flex/transforms/alignmentToAlign.ts +74 -20
- package/src/components/flex/transforms/auditSpreadProps.test.ts +93 -0
- package/src/components/flex/transforms/auditSpreadProps.ts +6 -0
- package/src/components/flex/transforms/axisToDirection.test.ts +15 -0
- package/src/components/flex/transforms/axisToDirection.ts +26 -0
- package/src/components/flex/transforms/constants.ts +4 -0
- package/src/components/flex/transforms/convertStyleProps.test.ts +147 -0
- package/src/components/flex/transforms/convertStyleProps.ts +23 -0
- package/src/components/flex/transforms/cssFlexAliasesToProps.test.ts +202 -0
- package/src/components/flex/transforms/cssFlexAliasesToProps.ts +106 -0
- package/src/components/flex/transforms/dedupeAttributes.test.ts +120 -0
- package/src/components/flex/transforms/dedupeAttributes.ts +49 -0
- package/src/components/flex/transforms/distributionToJustify.test.ts +59 -0
- package/src/components/flex/transforms/distributionToJustify.ts +69 -20
- package/src/components/flex/transforms/flexPropToExpand.test.ts +172 -0
- package/src/components/flex/transforms/flexPropToExpand.ts +100 -0
- package/src/components/flex/transforms/mediaQueriesToResponsive.test.ts +795 -0
- package/src/components/flex/transforms/mediaQueriesToResponsive.ts +562 -0
- package/src/components/flex/transforms/paddingPropsToFlex.test.ts +252 -0
- package/src/components/flex/transforms/paddingPropsToFlex.ts +150 -0
- package/src/components/flex/transforms/setDefaultAxis.test.ts +12 -0
- package/src/components/flex/transforms/setDefaultAxis.ts +1 -0
- package/src/components/flex/transforms/spacingToGap.test.ts +87 -0
- package/src/components/flex/transforms/spacingToGap.ts +28 -10
- package/src/components/flex/transforms/unsupportedProps.test.ts +141 -0
- package/src/components/flex/transforms/unsupportedProps.ts +17 -0
- package/src/components/shared/helpers/unsupportedPropsHelpers.ts +41 -0
- package/src/components/shared/transformFactories/stylePropTransformFactory.test.ts +47 -0
- package/src/components/shared/transformFactories/stylePropTransformFactory.ts +16 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./unsupportedProps"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
function applyTransform(source: string): string {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
return (
|
|
11
|
+
(transform(
|
|
12
|
+
fileInfo,
|
|
13
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
14
|
+
{}
|
|
15
|
+
) as string | null) || source
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe("unsupportedProps transform", () => {
|
|
20
|
+
describe("flags removed props", () => {
|
|
21
|
+
it("flags visible", () => {
|
|
22
|
+
const input = `
|
|
23
|
+
import { StackView } from "@planningcenter/tapestry-react"
|
|
24
|
+
|
|
25
|
+
export default function Test() {
|
|
26
|
+
return <StackView visible={isOpen}>Test</StackView>
|
|
27
|
+
}
|
|
28
|
+
`.trim()
|
|
29
|
+
|
|
30
|
+
const result = applyTransform(input)
|
|
31
|
+
expect(result).toContain("TODO: tapestry-migration (visible)")
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("flags variants", () => {
|
|
35
|
+
const input = `
|
|
36
|
+
import { StackView } from "@planningcenter/tapestry-react"
|
|
37
|
+
|
|
38
|
+
export default function Test() {
|
|
39
|
+
return <StackView variants={["elevated"]}>Test</StackView>
|
|
40
|
+
}
|
|
41
|
+
`.trim()
|
|
42
|
+
|
|
43
|
+
const result = applyTransform(input)
|
|
44
|
+
expect(result).toContain("TODO: tapestry-migration (variants)")
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it("flags multiple unsupported props", () => {
|
|
48
|
+
const input = `
|
|
49
|
+
import { StackView } from "@planningcenter/tapestry-react"
|
|
50
|
+
|
|
51
|
+
export default function Test() {
|
|
52
|
+
return <StackView visible={isOpen} variants={["elevated"]}>Test</StackView>
|
|
53
|
+
}
|
|
54
|
+
`.trim()
|
|
55
|
+
|
|
56
|
+
const result = applyTransform(input)
|
|
57
|
+
expect(result).toContain("TODO: tapestry-migration (visible)")
|
|
58
|
+
expect(result).toContain("TODO: tapestry-migration (variants)")
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe("does not flag supported props", () => {
|
|
63
|
+
it("does not flag valid Flex layout props", () => {
|
|
64
|
+
const input = `
|
|
65
|
+
import { StackView } from "@planningcenter/tapestry-react"
|
|
66
|
+
|
|
67
|
+
export default function Test() {
|
|
68
|
+
return <StackView direction="row" gap={2} align="center" justify="space-between" wrap="wrap">Test</StackView>
|
|
69
|
+
}
|
|
70
|
+
`.trim()
|
|
71
|
+
|
|
72
|
+
expect(applyTransform(input)).toBe(input)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it("does not flag Flex sizing and responsive props", () => {
|
|
76
|
+
const input = `
|
|
77
|
+
import { StackView } from "@planningcenter/tapestry-react"
|
|
78
|
+
|
|
79
|
+
export default function Test() {
|
|
80
|
+
return <StackView expand responsive={{ md: { direction: "row" } }} paddingBlock={2} alignSelf="center" columnGap={1}>Test</StackView>
|
|
81
|
+
}
|
|
82
|
+
`.trim()
|
|
83
|
+
|
|
84
|
+
expect(applyTransform(input)).toBe(input)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it("does not flag props with dedicated transforms that may remain when values cannot be resolved", () => {
|
|
88
|
+
const input = `
|
|
89
|
+
import { StackView } from "@planningcenter/tapestry-react"
|
|
90
|
+
|
|
91
|
+
export default function Test() {
|
|
92
|
+
return <StackView axis={someVar} alignment={a} distribution={d} spacing={s} mediaQueries={mq}>Test</StackView>
|
|
93
|
+
}
|
|
94
|
+
`.trim()
|
|
95
|
+
|
|
96
|
+
expect(applyTransform(input)).toBe(input)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it("does not flag className, style, ref", () => {
|
|
100
|
+
const input = `
|
|
101
|
+
import { StackView } from "@planningcenter/tapestry-react"
|
|
102
|
+
|
|
103
|
+
export default function Test() {
|
|
104
|
+
return <StackView className="my-stack" style={{ color: "red" }} ref={ref}>Test</StackView>
|
|
105
|
+
}
|
|
106
|
+
`.trim()
|
|
107
|
+
|
|
108
|
+
expect(applyTransform(input)).toBe(input)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it("does not flag aria-* and data-* attributes", () => {
|
|
112
|
+
const input = `
|
|
113
|
+
import { StackView } from "@planningcenter/tapestry-react"
|
|
114
|
+
|
|
115
|
+
export default function Test() {
|
|
116
|
+
return <StackView aria-label="Content" data-pendo="stack">Test</StackView>
|
|
117
|
+
}
|
|
118
|
+
`.trim()
|
|
119
|
+
|
|
120
|
+
expect(applyTransform(input)).toBe(input)
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
describe("no changes scenarios", () => {
|
|
125
|
+
it("returns source unchanged when not from tapestry-react", () => {
|
|
126
|
+
const input = `
|
|
127
|
+
import { StackView } from "some-other-library"
|
|
128
|
+
|
|
129
|
+
export default function Test() {
|
|
130
|
+
return <StackView visible={true}>Test</StackView>
|
|
131
|
+
}
|
|
132
|
+
`.trim()
|
|
133
|
+
|
|
134
|
+
expect(applyTransform(input)).toBe(input)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it("returns source unchanged for empty file", () => {
|
|
138
|
+
expect(applyTransform("")).toBe("")
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FLEX_SUPPORTED_PROPS } from "../../shared/helpers/unsupportedPropsHelpers"
|
|
2
|
+
import { unsupportedPropsFactory } from "../../shared/transformFactories/unsupportedPropsFactory"
|
|
3
|
+
|
|
4
|
+
export default unsupportedPropsFactory({
|
|
5
|
+
commentNotes: (prop) => {
|
|
6
|
+
if (prop === "visible") {
|
|
7
|
+
return "\n * `visible` is not supported in Flex. Conditionally render the element instead.\n"
|
|
8
|
+
}
|
|
9
|
+
if (prop === "variants") {
|
|
10
|
+
return "\n * `variants` is not supported in Flex.\n"
|
|
11
|
+
}
|
|
12
|
+
return ""
|
|
13
|
+
},
|
|
14
|
+
supportedProps: FLEX_SUPPORTED_PROPS,
|
|
15
|
+
targetComponent: "StackView",
|
|
16
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
17
|
+
})
|
|
@@ -233,3 +233,44 @@ export const DROPDOWN_LINK_SUPPORTED_PROPS = [
|
|
|
233
233
|
"href",
|
|
234
234
|
"to",
|
|
235
235
|
]
|
|
236
|
+
|
|
237
|
+
// StackView props that have dedicated transforms. When a transform cannot resolve
|
|
238
|
+
// a value at codemod time, it leaves the prop name unchanged and adds a TODO.
|
|
239
|
+
// Listing them here prevents unsupportedPropsFactory from adding a second TODO.
|
|
240
|
+
export const FLEX_IGNORE_PROPS = [
|
|
241
|
+
"alignItems",
|
|
242
|
+
"alignment",
|
|
243
|
+
"axis",
|
|
244
|
+
"distribution",
|
|
245
|
+
"flex",
|
|
246
|
+
"justifyContent",
|
|
247
|
+
"mediaQueries",
|
|
248
|
+
"spacing",
|
|
249
|
+
]
|
|
250
|
+
|
|
251
|
+
export const FLEX_SPECIFIC_PROPS = [
|
|
252
|
+
"align",
|
|
253
|
+
"alignSelf",
|
|
254
|
+
"as",
|
|
255
|
+
"basis",
|
|
256
|
+
"columnGap",
|
|
257
|
+
"direction",
|
|
258
|
+
"expand",
|
|
259
|
+
"gap",
|
|
260
|
+
"grow",
|
|
261
|
+
"inline",
|
|
262
|
+
"justify",
|
|
263
|
+
"padding",
|
|
264
|
+
"paddingBlock",
|
|
265
|
+
"paddingInline",
|
|
266
|
+
"responsive",
|
|
267
|
+
"rowGap",
|
|
268
|
+
"shrink",
|
|
269
|
+
"wrap",
|
|
270
|
+
]
|
|
271
|
+
|
|
272
|
+
export const FLEX_SUPPORTED_PROPS = [
|
|
273
|
+
...COMMON_PROPS,
|
|
274
|
+
...FLEX_IGNORE_PROPS,
|
|
275
|
+
...FLEX_SPECIFIC_PROPS,
|
|
276
|
+
]
|
|
@@ -120,6 +120,53 @@ describe("stylePropTransformFactory", () => {
|
|
|
120
120
|
}} />"
|
|
121
121
|
`)
|
|
122
122
|
})
|
|
123
|
+
|
|
124
|
+
it("converts negative numeric margin props through the spacing scale", () => {
|
|
125
|
+
const input = `import { Box } from "@planningcenter/tapestry-react";<Box margin={-1} marginTop={-2} marginLeft={-0.5} />`
|
|
126
|
+
const result = applyTransform(transform, input)
|
|
127
|
+
expect(result).toMatchInlineSnapshot(`
|
|
128
|
+
"import { Box } from "@planningcenter/tapestry-react";<Box
|
|
129
|
+
style={{
|
|
130
|
+
marginTop: "-16px",
|
|
131
|
+
marginRight: "-8px",
|
|
132
|
+
marginBottom: "-8px",
|
|
133
|
+
marginLeft: "-4px"
|
|
134
|
+
}} />"
|
|
135
|
+
`)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it("converts negative numeric margin longhand props through the spacing scale", () => {
|
|
139
|
+
const input = `import { Box } from "@planningcenter/tapestry-react";<Box marginTop={-1} marginBottom={-2} marginLeft={-3} marginRight={-4} />`
|
|
140
|
+
const result = applyTransform(transform, input)
|
|
141
|
+
expect(result).toMatchInlineSnapshot(`
|
|
142
|
+
"import { Box } from "@planningcenter/tapestry-react";<Box
|
|
143
|
+
style={{
|
|
144
|
+
marginTop: "-8px",
|
|
145
|
+
marginRight: "-32px",
|
|
146
|
+
marginBottom: "-16px",
|
|
147
|
+
marginLeft: "-24px"
|
|
148
|
+
}} />"
|
|
149
|
+
`)
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
describe("stylesToExclude", () => {
|
|
154
|
+
const transform = stylePropTransformFactory({
|
|
155
|
+
stylesToExclude: ["gap"],
|
|
156
|
+
stylesToRemove: [],
|
|
157
|
+
targetComponent: "Box",
|
|
158
|
+
targetPackage: "@planningcenter/tapestry-react",
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it("leaves excluded props untouched while migrating others", () => {
|
|
162
|
+
const input = `import { Box } from "@planningcenter/tapestry-react";<Box gap={2} marginTop={2} />`
|
|
163
|
+
const result = applyTransform(transform, input)
|
|
164
|
+
expect(result).toMatchInlineSnapshot(`
|
|
165
|
+
"import { Box } from "@planningcenter/tapestry-react";<Box gap={2} style={{
|
|
166
|
+
marginTop: "16px"
|
|
167
|
+
}} />"
|
|
168
|
+
`)
|
|
169
|
+
})
|
|
123
170
|
})
|
|
124
171
|
|
|
125
172
|
describe("value-transforming aliases", () => {
|
|
@@ -81,6 +81,19 @@ function extractPropValue(attr: JSXAttribute, j: JSCodeshift) {
|
|
|
81
81
|
return expression.value
|
|
82
82
|
} else if (expression.type === "NumericLiteral") {
|
|
83
83
|
return expression.value
|
|
84
|
+
} else if (expression.type === "UnaryExpression") {
|
|
85
|
+
const unary = expression as unknown as {
|
|
86
|
+
argument?: { type?: string; value?: unknown }
|
|
87
|
+
operator: string
|
|
88
|
+
}
|
|
89
|
+
if (
|
|
90
|
+
unary.operator === "-" &&
|
|
91
|
+
unary.argument?.type === "NumericLiteral" &&
|
|
92
|
+
typeof unary.argument.value === "number"
|
|
93
|
+
) {
|
|
94
|
+
return -unary.argument.value
|
|
95
|
+
}
|
|
96
|
+
return `{${j(expression).toSource()}}`
|
|
84
97
|
} else if (expression.type === "BooleanLiteral") {
|
|
85
98
|
return expression.value
|
|
86
99
|
} else if (expression.type === "Identifier") {
|
|
@@ -363,6 +376,7 @@ export function stylePropTransformFactory(config: {
|
|
|
363
376
|
styleProps: string[]
|
|
364
377
|
}
|
|
365
378
|
stylePropMapping?: StylePropMapping
|
|
379
|
+
stylesToExclude?: string[]
|
|
366
380
|
stylesToKeep?: string[]
|
|
367
381
|
stylesToRemove: string[]
|
|
368
382
|
targetComponent: string
|
|
@@ -370,6 +384,7 @@ export function stylePropTransformFactory(config: {
|
|
|
370
384
|
}): Transform {
|
|
371
385
|
const {
|
|
372
386
|
stylePropMapping = {} as StylePropMapping,
|
|
387
|
+
stylesToExclude = [],
|
|
373
388
|
stylesToKeep = [],
|
|
374
389
|
stylesToRemove,
|
|
375
390
|
} = config
|
|
@@ -387,6 +402,7 @@ export function stylePropTransformFactory(config: {
|
|
|
387
402
|
return (
|
|
388
403
|
name &&
|
|
389
404
|
name !== "css" &&
|
|
405
|
+
!stylesToExclude.includes(name) &&
|
|
390
406
|
(stylePropNames.includes(name) ||
|
|
391
407
|
name in stylePropMapping ||
|
|
392
408
|
stylesToKeep.includes(name) ||
|