@planningcenter/tapestry-migration-cli 3.1.0-rc.11 → 3.1.0-rc.13

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": "3.1.0-rc.11",
3
+ "version": "3.1.0-rc.13",
4
4
  "description": "CLI tool for Tapestry migrations",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@emotion/react": "^11.14.0",
35
- "@planningcenter/tapestry": "^3.1.0-rc.11",
35
+ "@planningcenter/tapestry": "^3.1.0-rc.13",
36
36
  "@planningcenter/tapestry-react": "^4.11.5",
37
37
  "@types/jscodeshift": "^17.3.0",
38
38
  "@types/node": "^20.0.0",
@@ -52,5 +52,5 @@
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  },
55
- "gitHead": "ee2eb63013ea632d013ebfe125311e91a230532d"
55
+ "gitHead": "422f12c83f2d17c0dc024d9513589934d7b1c6c8"
56
56
  }
@@ -1,8 +1,49 @@
1
- import { hasAttribute } from "../shared/conditions/hasAttribute"
2
- import { notCondition } from "../shared/conditions/notCondition"
3
- import { orConditions } from "../shared/conditions/orConditions"
1
+ import { JSXElement } from "jscodeshift"
2
+
3
+ import { ACCEPTED_INPUT_TYPES } from "../shared/helpers/unsupportedPropsHelpers"
4
4
  import { TransformCondition } from "../shared/types"
5
5
 
6
- export const transformableInput: TransformCondition = notCondition(
7
- orConditions(hasAttribute("renderLeft"), hasAttribute("renderRight"))
8
- )
6
+ // Include legacy "input" value so removeTypeInput can strip it
7
+ const acceptedTypes: readonly string[] = [...ACCEPTED_INPUT_TYPES, "input"]
8
+
9
+ function hasUnsupportedType(element: JSXElement): boolean {
10
+ const attributes = element.openingElement.attributes || []
11
+ const typeAttr = attributes.find(
12
+ (attr) =>
13
+ attr.type === "JSXAttribute" &&
14
+ attr.name?.type === "JSXIdentifier" &&
15
+ attr.name.name === "type"
16
+ )
17
+
18
+ if (!typeAttr || typeAttr.type !== "JSXAttribute") {
19
+ return false
20
+ }
21
+
22
+ if (typeAttr.value?.type === "StringLiteral") {
23
+ return !acceptedTypes.includes(typeAttr.value.value)
24
+ }
25
+
26
+ if (typeAttr.value?.type === "JSXExpressionContainer") {
27
+ const { expression } = typeAttr.value
28
+ if (expression.type === "StringLiteral") {
29
+ return !acceptedTypes.includes(expression.value)
30
+ }
31
+ }
32
+
33
+ return true
34
+ }
35
+
36
+ function hasAttribute(element: JSXElement, attributeName: string): boolean {
37
+ const attributes = element.openingElement.attributes || []
38
+ return attributes.some(
39
+ (attr) =>
40
+ attr.type === "JSXAttribute" &&
41
+ attr.name?.type === "JSXIdentifier" &&
42
+ attr.name.name === attributeName
43
+ )
44
+ }
45
+
46
+ export const transformableInput: TransformCondition = (element) =>
47
+ !hasAttribute(element, "renderLeft") &&
48
+ !hasAttribute(element, "renderRight") &&
49
+ !hasUnsupportedType(element)
@@ -195,7 +195,7 @@ describe("removeDuplicateKeys transform", () => {
195
195
  export function TestComponent() {
196
196
  return (
197
197
  <form>
198
- <Input type="submit" kind="primary" type="button">Submit</Input>
198
+ <Input type="email" kind="primary" type="text">Submit</Input>
199
199
  <Input disabled loading disabled>Loading</Input>
200
200
  <Input size="small">Small</Input>
201
201
  </form>
@@ -208,8 +208,8 @@ describe("removeDuplicateKeys transform", () => {
208
208
  expect(result).not.toBeNull()
209
209
 
210
210
  // First input: should keep first 'type'
211
- expect(result).toContain('type="submit"')
212
- expect(result).not.toContain('type="button"')
211
+ expect(result).toContain('type="email"')
212
+ expect(result).not.toContain('type="text"')
213
213
 
214
214
  expect(result).toContain("<Input disabled loading>")
215
215
 
@@ -7,12 +7,12 @@ import { attributeTransformFactory } from "../../shared/transformFactories/attri
7
7
  import { transformableInput } from "../transformableInput"
8
8
 
9
9
  const transform: Transform = attributeTransformFactory({
10
- condition: (element, context) =>
11
- transformableInput(element, context) &&
10
+ condition: (element) =>
11
+ transformableInput(element) &&
12
12
  orConditions(
13
13
  hasAttributeValue("type", "input"),
14
14
  hasAttributeValue("type", "text")
15
- )(element, context),
15
+ )(element),
16
16
  targetComponent: "Input",
17
17
  targetPackage: "@planningcenter/tapestry-react",
18
18
  transform: (element, { j, source }) =>
@@ -6,9 +6,8 @@ import { attributeTransformFactory } from "../../shared/transformFactories/attri
6
6
  import { transformableInput } from "../transformableInput"
7
7
 
8
8
  const transform: Transform = attributeTransformFactory({
9
- condition: (element, context) =>
10
- transformableInput(element, context) &&
11
- hasAttributeValue("type", "text")(element, context),
9
+ condition: (element) =>
10
+ transformableInput(element) && hasAttributeValue("type", "text")(element),
12
11
  targetComponent: "Input",
13
12
  targetPackage: "@planningcenter/tapestry-react",
14
13
  transform: (element, { j, source }) =>
@@ -276,7 +276,7 @@ function Test() {
276
276
  expect(result).not.toContain("TODO: tapestry-migration")
277
277
  })
278
278
 
279
- it("should flag step on type='range' (not an accepted Input type)", () => {
279
+ it("should not transform Input with type='range' (unsupported type bails)", () => {
280
280
  const input = `
281
281
  import { Input } from "@planningcenter/tapestry-react"
282
282
 
@@ -286,10 +286,10 @@ function Test() {
286
286
  `.trim()
287
287
 
288
288
  const result = applyTransform(input)
289
- expect(result).toContain("TODO: tapestry-migration (step)")
289
+ expect(result).toBe(input)
290
290
  })
291
291
 
292
- it("should flag step on type={'range'} expression container (not an accepted Input type)", () => {
292
+ it("should not transform Input with type={'range'} expression container (unsupported type bails)", () => {
293
293
  const input = `
294
294
  import { Input } from "@planningcenter/tapestry-react"
295
295
 
@@ -299,11 +299,10 @@ function Test() {
299
299
  `.trim()
300
300
 
301
301
  const result = applyTransform(input)
302
- expect(result).toContain("TODO: tapestry-migration (step)")
303
- expect(result).toContain("TODO: tapestry-migration (type)")
302
+ expect(result).toBe(input)
304
303
  })
305
304
 
306
- it("should be permissive with type-specific props when type is dynamic", () => {
305
+ it("should not transform Input with dynamic type in unsupported-types section (bails)", () => {
307
306
  const input = `
308
307
  import { Input } from "@planningcenter/tapestry-react"
309
308
 
@@ -313,11 +312,10 @@ function Test() {
313
312
  `.trim()
314
313
 
315
314
  const result = applyTransform(input)
316
- expect(result).not.toContain("TODO: tapestry-migration (step)")
317
- expect(result).not.toContain("TODO: tapestry-migration (type)")
315
+ expect(result).toBe(input)
318
316
  })
319
317
 
320
- it("should flag accept on type='file' (not an accepted Input type)", () => {
318
+ it("should not transform Input with type='file' (unsupported type bails)", () => {
321
319
  const input = `
322
320
  import { Input } from "@planningcenter/tapestry-react"
323
321
 
@@ -327,7 +325,7 @@ function Test() {
327
325
  `.trim()
328
326
 
329
327
  const result = applyTransform(input)
330
- expect(result).toContain("TODO: tapestry-migration (accept)")
328
+ expect(result).toBe(input)
331
329
  })
332
330
 
333
331
  it("should not flag pattern on type='text'", () => {
@@ -356,7 +354,7 @@ function Test() {
356
354
  expect(result).not.toContain("TODO: tapestry-migration")
357
355
  })
358
356
 
359
- it("should not flag step when type is dynamic", () => {
357
+ it("should not transform Input when type prop is dynamic (bails)", () => {
360
358
  const input = `
361
359
  import { Input } from "@planningcenter/tapestry-react"
362
360
 
@@ -366,7 +364,7 @@ function Test() {
366
364
  `.trim()
367
365
 
368
366
  const result = applyTransform(input)
369
- expect(result).not.toContain("TODO: tapestry-migration")
367
+ expect(result).toBe(input)
370
368
  })
371
369
 
372
370
  it("should flag step without a type attr", () => {
@@ -465,8 +463,10 @@ function Test() {
465
463
  "submit",
466
464
  "reset",
467
465
  "button",
468
- ])("should flag type='%s' as unsupported", (type) => {
469
- const input = `
466
+ ])(
467
+ "should not transform Input with type='%s' (unsupported type bails)",
468
+ (type) => {
469
+ const input = `
470
470
  import { Input } from "@planningcenter/tapestry-react"
471
471
 
472
472
  function Test() {
@@ -474,10 +474,10 @@ function Test() {
474
474
  }
475
475
  `.trim()
476
476
 
477
- const result = applyTransform(input)
478
- expect(result).toContain("TODO: tapestry-migration (type)")
479
- expect(result).toContain("is not a supported Input type")
480
- })
477
+ const result = applyTransform(input)
478
+ expect(result).toBe(input)
479
+ }
480
+ )
481
481
 
482
482
  it("should not flag accepted type values", () => {
483
483
  const types = [
@@ -503,7 +503,7 @@ function Test() {
503
503
  }
504
504
  })
505
505
 
506
- it("should not flag dynamic type values", () => {
506
+ it("should not transform Input when type prop is dynamic (bails)", () => {
507
507
  const input = `
508
508
  import { Input } from "@planningcenter/tapestry-react"
509
509
 
@@ -513,7 +513,7 @@ function Test() {
513
513
  `.trim()
514
514
 
515
515
  const result = applyTransform(input)
516
- expect(result).not.toContain("TODO: tapestry-migration")
516
+ expect(result).toBe(input)
517
517
  })
518
518
  })
519
519