@planningcenter/tapestry-migration-cli 2.5.0-rc.2 → 2.5.0-rc.4
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/transforms/childrenToLabel.test.ts +18 -2
- package/src/components/button/transforms/childrenToLabel.ts +13 -1
- package/src/components/checkbox/transforms/childrenToLabel.test.ts +18 -2
- package/src/components/checkbox/transforms/childrenToLabel.ts +13 -1
- package/src/components/checkbox/transforms/innerRefToRef.test.ts +20 -2
- package/src/components/checkbox/transforms/innerRefToRef.ts +2 -2
- package/src/components/link/transforms/childrenToLabel.test.ts +18 -2
- package/src/components/link/transforms/childrenToLabel.ts +13 -1
- package/src/components/link/transforms/innerRefToRef.test.ts +19 -2
- package/src/components/link/transforms/innerRefToRef.ts +2 -2
- package/src/components/link/transforms/removeAs.test.ts +18 -2
- package/src/components/link/transforms/removeAs.ts +13 -2
- package/src/components/link/transforms/removeInlineProp.test.ts +20 -2
- package/src/components/link/transforms/removeInlineProp.ts +14 -1
- package/src/components/link/transforms/targetBlankToExternal.test.ts +18 -2
- package/src/components/link/transforms/targetBlankToExternal.ts +13 -4
- package/src/components/link/transforms/toToHref.test.ts +19 -2
- package/src/components/link/transforms/toToHref.ts +2 -2
- package/src/reportGenerator.ts +42 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/tapestry-migration-cli",
|
|
3
|
-
"version": "2.5.0-rc.
|
|
3
|
+
"version": "2.5.0-rc.4",
|
|
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": "914423c21b5fea1b57801efb46cea9c181e8896f"
|
|
55
55
|
}
|
|
@@ -5,12 +5,12 @@ import transform from "./childrenToLabel"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string | null {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string | null {
|
|
9
9
|
const fileInfo = { path: "test.tsx", source }
|
|
10
10
|
return transform(
|
|
11
11
|
fileInfo,
|
|
12
12
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
-
{}
|
|
13
|
+
{ verbose }
|
|
14
14
|
) as string | null
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -360,5 +360,21 @@ function Test() {
|
|
|
360
360
|
"take time to find the right text for the component"
|
|
361
361
|
)
|
|
362
362
|
})
|
|
363
|
+
|
|
364
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
365
|
+
const input = `
|
|
366
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
367
|
+
|
|
368
|
+
function Test() {
|
|
369
|
+
return <Button>Save</Button>
|
|
370
|
+
}
|
|
371
|
+
`.trim()
|
|
372
|
+
|
|
373
|
+
const result = applyTransform(input, true)
|
|
374
|
+
expect(result).toContain('<Button label="Save" />')
|
|
375
|
+
expect(result).toContain(
|
|
376
|
+
"CHANGED: tapestry-migration (children): children converted to label prop"
|
|
377
|
+
)
|
|
378
|
+
})
|
|
363
379
|
})
|
|
364
380
|
})
|
|
@@ -15,7 +15,7 @@ const transform: Transform = attributeTransformFactory({
|
|
|
15
15
|
condition: hasChildren,
|
|
16
16
|
targetComponent: "Button",
|
|
17
17
|
targetPackage: "@planningcenter/tapestry-react",
|
|
18
|
-
transform: (element, { j, source }) => {
|
|
18
|
+
transform: (element, { j, options, source }) => {
|
|
19
19
|
if (hasAttribute("label")(element)) {
|
|
20
20
|
addComment({
|
|
21
21
|
element,
|
|
@@ -32,6 +32,18 @@ const transform: Transform = attributeTransformFactory({
|
|
|
32
32
|
if (isSimpleText && textContent) {
|
|
33
33
|
addAttribute({ element, j, name: "label", value: textContent })
|
|
34
34
|
removeChildren(element)
|
|
35
|
+
|
|
36
|
+
if (options?.verbose) {
|
|
37
|
+
addComment({
|
|
38
|
+
commentKind: "change",
|
|
39
|
+
element,
|
|
40
|
+
j,
|
|
41
|
+
scope: "children",
|
|
42
|
+
source,
|
|
43
|
+
text: buildComment("children converted to label prop", false),
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
return true
|
|
36
48
|
} else if (!isSimpleText) {
|
|
37
49
|
addComment({
|
|
@@ -5,12 +5,12 @@ import transform from "./childrenToLabel"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string {
|
|
9
9
|
const fileInfo = { path: "test.tsx", source }
|
|
10
10
|
const result = transform(
|
|
11
11
|
fileInfo,
|
|
12
12
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
-
{}
|
|
13
|
+
{ verbose }
|
|
14
14
|
) as string | null
|
|
15
15
|
return result || source
|
|
16
16
|
}
|
|
@@ -142,5 +142,21 @@ function Test() {
|
|
|
142
142
|
'<Checkbox checked disabled label="Accept terms" />'
|
|
143
143
|
)
|
|
144
144
|
})
|
|
145
|
+
|
|
146
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
147
|
+
const input = `
|
|
148
|
+
import { Checkbox } from "@planningcenter/tapestry-react"
|
|
149
|
+
|
|
150
|
+
function Test() {
|
|
151
|
+
return <Checkbox>Accept terms</Checkbox>
|
|
152
|
+
}
|
|
153
|
+
`.trim()
|
|
154
|
+
|
|
155
|
+
const result = applyTransform(input, true)
|
|
156
|
+
expect(result).toContain('<Checkbox label="Accept terms" />')
|
|
157
|
+
expect(result).toContain(
|
|
158
|
+
"CHANGED: tapestry-migration (children): children converted to label prop"
|
|
159
|
+
)
|
|
160
|
+
})
|
|
145
161
|
})
|
|
146
162
|
})
|
|
@@ -15,7 +15,7 @@ const transform: Transform = attributeTransformFactory({
|
|
|
15
15
|
condition: hasChildren,
|
|
16
16
|
targetComponent: "Checkbox",
|
|
17
17
|
targetPackage: "@planningcenter/tapestry-react",
|
|
18
|
-
transform: (element, { j, source }) => {
|
|
18
|
+
transform: (element, { j, options, source }) => {
|
|
19
19
|
if (hasAttribute("label")(element)) {
|
|
20
20
|
addComment({
|
|
21
21
|
element,
|
|
@@ -32,6 +32,18 @@ const transform: Transform = attributeTransformFactory({
|
|
|
32
32
|
if (isSimpleText && textContent) {
|
|
33
33
|
addAttribute({ element, j, name: "label", value: textContent })
|
|
34
34
|
removeChildren(element)
|
|
35
|
+
|
|
36
|
+
if (options?.verbose) {
|
|
37
|
+
addComment({
|
|
38
|
+
commentKind: "change",
|
|
39
|
+
element,
|
|
40
|
+
j,
|
|
41
|
+
scope: "children",
|
|
42
|
+
source,
|
|
43
|
+
text: buildComment("children converted to label prop", false),
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
return true
|
|
36
48
|
} else if (!isSimpleText) {
|
|
37
49
|
addComment({
|
|
@@ -5,12 +5,12 @@ import transform from "./innerRefToRef"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string {
|
|
9
9
|
const fileInfo = { path: "test.tsx", source }
|
|
10
10
|
const result = transform(
|
|
11
11
|
fileInfo,
|
|
12
12
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
-
{}
|
|
13
|
+
{ verbose }
|
|
14
14
|
) as string | null
|
|
15
15
|
return result || source
|
|
16
16
|
}
|
|
@@ -157,5 +157,23 @@ function Test() {
|
|
|
157
157
|
expect(result).toContain("disabled")
|
|
158
158
|
expect(result).not.toContain("innerRef=")
|
|
159
159
|
})
|
|
160
|
+
|
|
161
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
162
|
+
const input = `
|
|
163
|
+
import { Checkbox } from "@planningcenter/tapestry-react"
|
|
164
|
+
|
|
165
|
+
function Test() {
|
|
166
|
+
const checkboxRef = React.useRef()
|
|
167
|
+
return <Checkbox innerRef={checkboxRef} label="Test" />
|
|
168
|
+
}
|
|
169
|
+
`.trim()
|
|
170
|
+
|
|
171
|
+
const result = applyTransform(input, true)
|
|
172
|
+
expect(result).toContain("ref={checkboxRef}")
|
|
173
|
+
expect(result).not.toContain("innerRef=")
|
|
174
|
+
expect(result).toContain(
|
|
175
|
+
"CHANGED: tapestry-migration (ref): renamed from innerRef"
|
|
176
|
+
)
|
|
177
|
+
})
|
|
160
178
|
})
|
|
161
179
|
})
|
|
@@ -6,8 +6,8 @@ const transform = attributeTransformFactory({
|
|
|
6
6
|
condition: hasAttribute("innerRef"),
|
|
7
7
|
targetComponent: "Checkbox",
|
|
8
8
|
targetPackage: "@planningcenter/tapestry-react",
|
|
9
|
-
transform: (element) => {
|
|
10
|
-
return transformAttributeName("innerRef", "ref", { element })
|
|
9
|
+
transform: (element, { j, options }) => {
|
|
10
|
+
return transformAttributeName("innerRef", "ref", { element, j, options })
|
|
11
11
|
},
|
|
12
12
|
})
|
|
13
13
|
|
|
@@ -5,12 +5,12 @@ import transform from "./childrenToLabel"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string | null {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string | null {
|
|
9
9
|
const fileInfo = { path: "test.tsx", source }
|
|
10
10
|
return transform(
|
|
11
11
|
fileInfo,
|
|
12
12
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
-
{}
|
|
13
|
+
{ verbose }
|
|
14
14
|
) as string | null
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -327,5 +327,21 @@ function Test() {
|
|
|
327
327
|
"If icons are used in the component, you can use prefix and suffix to correctly display those icons"
|
|
328
328
|
)
|
|
329
329
|
})
|
|
330
|
+
|
|
331
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
332
|
+
const input = `
|
|
333
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
334
|
+
|
|
335
|
+
function Test() {
|
|
336
|
+
return <Link href="/home">Home</Link>
|
|
337
|
+
}
|
|
338
|
+
`.trim()
|
|
339
|
+
|
|
340
|
+
const result = applyTransform(input, true)
|
|
341
|
+
expect(result).toContain('<Link href="/home" label="Home" />')
|
|
342
|
+
expect(result).toContain(
|
|
343
|
+
"CHANGED: tapestry-migration (children): children converted to label prop"
|
|
344
|
+
)
|
|
345
|
+
})
|
|
330
346
|
})
|
|
331
347
|
})
|
|
@@ -15,7 +15,7 @@ const transform: Transform = attributeTransformFactory({
|
|
|
15
15
|
condition: hasChildren,
|
|
16
16
|
targetComponent: "Link",
|
|
17
17
|
targetPackage: "@planningcenter/tapestry-react",
|
|
18
|
-
transform: (element, { j, source }) => {
|
|
18
|
+
transform: (element, { j, options, source }) => {
|
|
19
19
|
if (hasAttribute("label")(element)) {
|
|
20
20
|
addComment({
|
|
21
21
|
element,
|
|
@@ -32,6 +32,18 @@ const transform: Transform = attributeTransformFactory({
|
|
|
32
32
|
if (isSimpleText && textContent) {
|
|
33
33
|
addAttribute({ element, j, name: "label", value: textContent })
|
|
34
34
|
removeChildren(element)
|
|
35
|
+
|
|
36
|
+
if (options?.verbose) {
|
|
37
|
+
addComment({
|
|
38
|
+
commentKind: "change",
|
|
39
|
+
element,
|
|
40
|
+
j,
|
|
41
|
+
scope: "children",
|
|
42
|
+
source,
|
|
43
|
+
text: buildComment("children converted to label prop", false),
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
return true
|
|
36
48
|
} else if (!isSimpleText) {
|
|
37
49
|
addComment({
|
|
@@ -5,12 +5,12 @@ import transform from "./innerRefToRef"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string | null {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string | null {
|
|
9
9
|
const fileInfo = { path: "test.tsx", source }
|
|
10
10
|
return transform(
|
|
11
11
|
fileInfo,
|
|
12
12
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
-
{}
|
|
13
|
+
{ verbose }
|
|
14
14
|
) as string | null
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -166,5 +166,22 @@ export default function Test() {
|
|
|
166
166
|
const result = applyTransform(input)
|
|
167
167
|
expect(result).toBe(expected)
|
|
168
168
|
})
|
|
169
|
+
|
|
170
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
171
|
+
const input = `
|
|
172
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
173
|
+
|
|
174
|
+
export default function Test() {
|
|
175
|
+
return <Link innerRef={linkRef}>Go somewhere</Link>
|
|
176
|
+
}
|
|
177
|
+
`.trim()
|
|
178
|
+
|
|
179
|
+
const result = applyTransform(input, true)
|
|
180
|
+
expect(result).toContain("ref={linkRef}")
|
|
181
|
+
expect(result).not.toContain("innerRef=")
|
|
182
|
+
expect(result).toContain(
|
|
183
|
+
"CHANGED: tapestry-migration (ref): renamed from innerRef"
|
|
184
|
+
)
|
|
185
|
+
})
|
|
169
186
|
})
|
|
170
187
|
})
|
|
@@ -6,8 +6,8 @@ const transform = attributeTransformFactory({
|
|
|
6
6
|
condition: hasAttribute("innerRef"),
|
|
7
7
|
targetComponent: "Link",
|
|
8
8
|
targetPackage: "@planningcenter/tapestry-react",
|
|
9
|
-
transform: (element) => {
|
|
10
|
-
return transformAttributeName("innerRef", "ref", { element })
|
|
9
|
+
transform: (element, { j, options }) => {
|
|
10
|
+
return transformAttributeName("innerRef", "ref", { element, j, options })
|
|
11
11
|
},
|
|
12
12
|
})
|
|
13
13
|
|
|
@@ -5,11 +5,11 @@ import removeAs from "./removeAs"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string | null {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string | null {
|
|
9
9
|
return removeAs(
|
|
10
10
|
{ path: "test.tsx", source },
|
|
11
11
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
12
|
-
{}
|
|
12
|
+
{ verbose }
|
|
13
13
|
) as string | null
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -188,5 +188,21 @@ export default function Test() {
|
|
|
188
188
|
expect(result).toContain('href="/external"')
|
|
189
189
|
expect(result).not.toContain('as="a"')
|
|
190
190
|
})
|
|
191
|
+
|
|
192
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
193
|
+
const input = `
|
|
194
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
195
|
+
|
|
196
|
+
export default function Test() {
|
|
197
|
+
return <Link href="/home" as="a">Home</Link>
|
|
198
|
+
}
|
|
199
|
+
`.trim()
|
|
200
|
+
|
|
201
|
+
const result = applyTransform(input, true)
|
|
202
|
+
expect(result).not.toContain('as="a"')
|
|
203
|
+
expect(result).toContain(
|
|
204
|
+
"CHANGED: tapestry-migration (as): as='a' prop removed"
|
|
205
|
+
)
|
|
206
|
+
})
|
|
191
207
|
})
|
|
192
208
|
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { addComment } from "../../shared/actions/addComment"
|
|
1
2
|
import { removeAttribute } from "../../shared/actions/removeAttribute"
|
|
2
3
|
import { hasAttributeValue } from "../../shared/conditions/hasAttributeValue"
|
|
3
4
|
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
@@ -6,10 +7,20 @@ const transform = attributeTransformFactory({
|
|
|
6
7
|
condition: hasAttributeValue("as", "a"),
|
|
7
8
|
targetComponent: "Link",
|
|
8
9
|
targetPackage: "@planningcenter/tapestry-react",
|
|
9
|
-
transform: (element, { j, source }) => {
|
|
10
|
-
// Remove as attribute
|
|
10
|
+
transform: (element, { j, options, source }) => {
|
|
11
11
|
removeAttribute("as", { element, j, source })
|
|
12
12
|
|
|
13
|
+
if (options?.verbose) {
|
|
14
|
+
addComment({
|
|
15
|
+
commentKind: "change",
|
|
16
|
+
element,
|
|
17
|
+
j,
|
|
18
|
+
scope: "as",
|
|
19
|
+
source,
|
|
20
|
+
text: "as='a' prop removed",
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
return true
|
|
14
25
|
},
|
|
15
26
|
})
|
|
@@ -5,12 +5,12 @@ import transform from "./removeInlineProp"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string | null {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string | null {
|
|
9
9
|
const fileInfo = { path: "test.tsx", source }
|
|
10
10
|
return transform(
|
|
11
11
|
fileInfo,
|
|
12
12
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
-
{}
|
|
13
|
+
{ verbose }
|
|
14
14
|
) as string | null
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -291,5 +291,23 @@ export default function Test() {
|
|
|
291
291
|
const result = applyTransform(input)
|
|
292
292
|
expect(result).toBe(null)
|
|
293
293
|
})
|
|
294
|
+
|
|
295
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
296
|
+
const input = `
|
|
297
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
298
|
+
|
|
299
|
+
export default function Test() {
|
|
300
|
+
return <Link href="/profile" inline>Profile</Link>
|
|
301
|
+
}
|
|
302
|
+
`.trim()
|
|
303
|
+
|
|
304
|
+
const result = applyTransform(input, true)
|
|
305
|
+
expect(result).not.toContain(" inline>")
|
|
306
|
+
expect(result).not.toContain(' inline"')
|
|
307
|
+
expect(result).not.toContain(" inline=")
|
|
308
|
+
expect(result).toContain(
|
|
309
|
+
"CHANGED: tapestry-migration (inline): inline prop removed"
|
|
310
|
+
)
|
|
311
|
+
})
|
|
294
312
|
})
|
|
295
313
|
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { addComment } from "../../shared/actions/addComment"
|
|
1
2
|
import { removeAttribute } from "../../shared/actions/removeAttribute"
|
|
2
3
|
import { hasAttribute } from "../../shared/conditions/hasAttribute"
|
|
3
4
|
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
@@ -6,8 +7,20 @@ const transform = attributeTransformFactory({
|
|
|
6
7
|
condition: hasAttribute("inline"),
|
|
7
8
|
targetComponent: "Link",
|
|
8
9
|
targetPackage: "@planningcenter/tapestry-react",
|
|
9
|
-
transform: (element, { j, source }) => {
|
|
10
|
+
transform: (element, { j, options, source }) => {
|
|
10
11
|
removeAttribute("inline", { element, j, source })
|
|
12
|
+
|
|
13
|
+
if (options?.verbose) {
|
|
14
|
+
addComment({
|
|
15
|
+
commentKind: "change",
|
|
16
|
+
element,
|
|
17
|
+
j,
|
|
18
|
+
scope: "inline",
|
|
19
|
+
source,
|
|
20
|
+
text: "inline prop removed",
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
return true
|
|
12
25
|
},
|
|
13
26
|
})
|
|
@@ -5,11 +5,11 @@ import targetBlankToExternal from "./targetBlankToExternal"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string | null {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string | null {
|
|
9
9
|
return targetBlankToExternal(
|
|
10
10
|
{ path: "test.tsx", source },
|
|
11
11
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
12
|
-
{}
|
|
12
|
+
{ verbose }
|
|
13
13
|
) as string | null
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -201,5 +201,21 @@ export default function Test() {
|
|
|
201
201
|
expect(result).toContain("external")
|
|
202
202
|
expect(result).not.toContain('target="_blank"')
|
|
203
203
|
})
|
|
204
|
+
|
|
205
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
206
|
+
const input = `
|
|
207
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
208
|
+
|
|
209
|
+
export default function Test() {
|
|
210
|
+
return <Link href="/external" target="_blank">External Link</Link>
|
|
211
|
+
}
|
|
212
|
+
`.trim()
|
|
213
|
+
|
|
214
|
+
const result = applyTransform(input, true)
|
|
215
|
+
expect(result).toContain("external")
|
|
216
|
+
expect(result).toContain(
|
|
217
|
+
"CHANGED: tapestry-migration (external): target='_blank' converted to external prop"
|
|
218
|
+
)
|
|
219
|
+
})
|
|
204
220
|
})
|
|
205
221
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { addAttribute } from "../../shared/actions/addAttribute"
|
|
2
|
+
import { addComment } from "../../shared/actions/addComment"
|
|
2
3
|
import { removeAttribute } from "../../shared/actions/removeAttribute"
|
|
3
4
|
import { hasAttributeValue } from "../../shared/conditions/hasAttributeValue"
|
|
4
5
|
import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
|
|
@@ -7,14 +8,11 @@ const transform = attributeTransformFactory({
|
|
|
7
8
|
condition: hasAttributeValue("target", "_blank"),
|
|
8
9
|
targetComponent: "Link",
|
|
9
10
|
targetPackage: "@planningcenter/tapestry-react",
|
|
10
|
-
transform: (element, { j, source }) => {
|
|
11
|
-
// Remove target attribute
|
|
11
|
+
transform: (element, { j, options, source }) => {
|
|
12
12
|
removeAttribute("target", { element, j, source })
|
|
13
13
|
|
|
14
|
-
// Remove rel attribute if it exists
|
|
15
14
|
removeAttribute("rel", { element, j, source })
|
|
16
15
|
|
|
17
|
-
// Add external attribute as shorthand boolean
|
|
18
16
|
addAttribute({
|
|
19
17
|
booleanAsShorthand: true,
|
|
20
18
|
element,
|
|
@@ -23,6 +21,17 @@ const transform = attributeTransformFactory({
|
|
|
23
21
|
value: true, // This will create just "external" not "external={true}"
|
|
24
22
|
})
|
|
25
23
|
|
|
24
|
+
if (options?.verbose) {
|
|
25
|
+
addComment({
|
|
26
|
+
commentKind: "change",
|
|
27
|
+
element,
|
|
28
|
+
j,
|
|
29
|
+
scope: "external",
|
|
30
|
+
source,
|
|
31
|
+
text: "target='_blank' converted to external prop",
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
return true
|
|
27
36
|
},
|
|
28
37
|
})
|
|
@@ -5,12 +5,12 @@ import transform from "./toToHref"
|
|
|
5
5
|
|
|
6
6
|
const j = jscodeshift.withParser("tsx")
|
|
7
7
|
|
|
8
|
-
function applyTransform(source: string): string | null {
|
|
8
|
+
function applyTransform(source: string, verbose = false): string | null {
|
|
9
9
|
const fileInfo = { path: "test.tsx", source }
|
|
10
10
|
return transform(
|
|
11
11
|
fileInfo,
|
|
12
12
|
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
-
{}
|
|
13
|
+
{ verbose }
|
|
14
14
|
) as string | null
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -208,6 +208,23 @@ export default function Test({ items }) {
|
|
|
208
208
|
expect(result).not.toContain("to={item.url}")
|
|
209
209
|
expect(result).not.toContain('to="/conditional"')
|
|
210
210
|
})
|
|
211
|
+
|
|
212
|
+
it("should add CHANGED comment when verbose is enabled", () => {
|
|
213
|
+
const input = `
|
|
214
|
+
import { Link } from "@planningcenter/tapestry-react"
|
|
215
|
+
|
|
216
|
+
export default function Test() {
|
|
217
|
+
return <Link to="/dashboard">Dashboard</Link>
|
|
218
|
+
}
|
|
219
|
+
`.trim()
|
|
220
|
+
|
|
221
|
+
const result = applyTransform(input, true)
|
|
222
|
+
expect(result).toContain('href="/dashboard"')
|
|
223
|
+
expect(result).not.toContain('to="/dashboard"')
|
|
224
|
+
expect(result).toContain(
|
|
225
|
+
"CHANGED: tapestry-migration (href): renamed from to"
|
|
226
|
+
)
|
|
227
|
+
})
|
|
211
228
|
})
|
|
212
229
|
|
|
213
230
|
describe("no changes scenarios", () => {
|
|
@@ -6,8 +6,8 @@ const transform = attributeTransformFactory({
|
|
|
6
6
|
condition: hasAttribute("to"),
|
|
7
7
|
targetComponent: "Link",
|
|
8
8
|
targetPackage: "@planningcenter/tapestry-react",
|
|
9
|
-
transform: (element) => {
|
|
10
|
-
return transformAttributeName("to", "href", { element })
|
|
9
|
+
transform: (element, { j, options }) => {
|
|
10
|
+
return transformAttributeName("to", "href", { element, j, options })
|
|
11
11
|
},
|
|
12
12
|
})
|
|
13
13
|
|
package/src/reportGenerator.ts
CHANGED
|
@@ -363,6 +363,48 @@ function generateMarkdownReport(
|
|
|
363
363
|
lines.push(`- **${difficulty}:** ${data.count} occurrences`)
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
lines.push("")
|
|
367
|
+
lines.push("## Automatic Changes")
|
|
368
|
+
lines.push("")
|
|
369
|
+
lines.push(
|
|
370
|
+
"The following changes were applied automatically during migration:"
|
|
371
|
+
)
|
|
372
|
+
lines.push("")
|
|
373
|
+
|
|
374
|
+
const changedStats = stats.filter((s) => s.type === "changed")
|
|
375
|
+
|
|
376
|
+
if (changedStats.length > 0) {
|
|
377
|
+
const changedByScope = new Map<string, CommentStats[]>()
|
|
378
|
+
for (const stat of changedStats) {
|
|
379
|
+
if (!changedByScope.has(stat.scope)) {
|
|
380
|
+
changedByScope.set(stat.scope, [])
|
|
381
|
+
}
|
|
382
|
+
changedByScope.get(stat.scope)!.push(stat)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
for (const [scope, scopeStats] of Array.from(changedByScope.entries()).sort(
|
|
386
|
+
(a, b) => {
|
|
387
|
+
const totalA = a[1].reduce((sum, s) => sum + s.count, 0)
|
|
388
|
+
const totalB = b[1].reduce((sum, s) => sum + s.count, 0)
|
|
389
|
+
return totalB - totalA
|
|
390
|
+
}
|
|
391
|
+
)) {
|
|
392
|
+
lines.push(`### ${scope}`)
|
|
393
|
+
lines.push("")
|
|
394
|
+
|
|
395
|
+
for (const stat of scopeStats) {
|
|
396
|
+
lines.push(
|
|
397
|
+
`- **${stat.normalizedText}** (${stat.count} occurrence${stat.count > 1 ? "s" : ""})`
|
|
398
|
+
)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
lines.push("")
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
lines.push("_No automatic changes were applied._")
|
|
405
|
+
lines.push("")
|
|
406
|
+
}
|
|
407
|
+
|
|
366
408
|
lines.push("")
|
|
367
409
|
lines.push("## Comments by Effort (sorted by total effort)")
|
|
368
410
|
lines.push("")
|