@instructure/ui-codemods 10.20.2-snapshot-11 → 10.20.2-snapshot-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.
Files changed (38) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +5 -87
  3. package/lib/__node_tests__/codemodHelpers.test.tsx +455 -0
  4. package/lib/__node_tests__/{updateV10Breaking.test.ts → codemods.test.ts} +3 -3
  5. package/lib/__node_tests__/{testHelpers.ts → runTest.ts} +1 -3
  6. package/lib/index.ts +1 -16
  7. package/lib/{utils → instui-codemods}/updateToV10Colors.ts +6 -7
  8. package/lib/updateV10Breaking.ts +12 -26
  9. package/lib/{helpers → utils}/codemodHelpers.ts +153 -164
  10. package/lib/utils/codemodTypeCheckers.ts +221 -0
  11. package/lib/utils/instUICodemodExecutor.ts +89 -0
  12. package/package.json +2 -2
  13. package/tsconfig.build.tsbuildinfo +1 -1
  14. package/lib/helpers/replaceDeprecatedImports.ts +0 -546
  15. package/lib/helpers/replaceDeprecatedProps.ts +0 -230
  16. package/lib/updateImports.ts +0 -86
  17. package/lib/updatePropNames.ts +0 -66
  18. package/lib/updateV7Props.ts +0 -101
  19. package/lib/updateV8Breaking.ts +0 -49
  20. package/lib/updateV8ReactDOM.ts +0 -61
  21. package/lib/updateV9Breaking.ts +0 -54
  22. package/lib/utils/UpdateV7ButtonsLink.ts +0 -139
  23. package/lib/utils/requireUncached.ts +0 -28
  24. package/lib/utils/updateToV8Theming.ts +0 -84
  25. package/lib/utils/updateToV9Theming.ts +0 -70
  26. package/lib/utils/updateV7ButtonsClose.ts +0 -104
  27. package/lib/utils/updateV7ButtonsIconCircle.ts +0 -240
  28. package/lib/utils/updateV7ButtonsMisc.ts +0 -137
  29. package/lib/utils/updateV7ButtonsWithText.ts +0 -111
  30. package/lib/utils/updateV7FocusableView.ts +0 -105
  31. package/lib/utils/updateV7Heading.ts +0 -145
  32. package/lib/utils/updateV7Lists.ts +0 -113
  33. package/lib/utils/updateV7Pill.ts +0 -83
  34. package/lib/utils/updateV7Popover.ts +0 -133
  35. package/lib/utils/updateV7Tabs.ts +0 -129
  36. package/lib/utils/updateV8RenderProp.ts +0 -142
  37. package/lib/utils/updateV8ThemeProp.ts +0 -51
  38. package/lib/utils/warnV7ComponentDeprecations.ts +0 -96
@@ -1,137 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import {
26
- findAttribute,
27
- findElements,
28
- isJSXAttribue,
29
- isJSXExpressionContainer,
30
- isLiteral,
31
- printWarning
32
- } from '../helpers/codemodHelpers'
33
- import { Collection, JSCodeshift } from 'jscodeshift'
34
-
35
- /**
36
- * Does the following updates on a <Button>:
37
- * - `buttonRef` -> `elementRef`
38
- * - `fluidWidth` -> removed and `display="block" textAlign="start"` added
39
- * (overwrites any existing `display` and `textAlign` props)
40
- * - `icon` -> `renderIcon`
41
- */
42
- export default function updateV7ButtonsMisc(
43
- j: JSCodeshift,
44
- root: Collection,
45
- importedName: string,
46
- filePath: string
47
- ) {
48
- ///// <Button fluidWidth .. -> <Button display="block" textAlign="start"
49
- // remove fluidWidth attribute if its value is 'false' (it's the default)
50
- findElements(filePath, j, root, importedName)
51
- .find(j.JSXAttribute, {
52
- name: {
53
- name: 'fluidWidth'
54
- },
55
- value: {
56
- expression: {
57
- value: false
58
- }
59
- }
60
- })
61
- .remove()
62
-
63
- const buttonsWithFluidWidth = findElements(filePath, j, root, importedName, {
64
- name: 'fluidWidth'
65
- }).filter((path) => {
66
- const attributes = path.value.openingElement.attributes!
67
- for (const att of attributes) {
68
- if (isJSXAttribue(att) && att.name.name === 'fluidWidth') {
69
- if (!att.value) {
70
- // <Button fluidWidth />
71
- return true
72
- }
73
- if (
74
- isJSXExpressionContainer(att.value) &&
75
- isLiteral(att.value.expression) &&
76
- typeof att.value.expression.value === 'boolean'
77
- ) {
78
- // <Button fluidWidth={true} />
79
- return att.value.expression.value
80
- } else {
81
- printWarning(
82
- filePath,
83
- att.loc?.start.line,
84
- "Button's `fluidWidth` attribute has non-literal" +
85
- ' value, please update manually.'
86
- )
87
- return false
88
- }
89
- }
90
- }
91
- return false
92
- })
93
- // remove fluidWidth attribute
94
- findAttribute(filePath, j, buttonsWithFluidWidth, 'fluidWidth').remove()
95
- // remove display attribute
96
- findAttribute(filePath, j, buttonsWithFluidWidth, 'display')
97
- .forEach((path) => {
98
- printWarning(
99
- filePath,
100
- path.value.loc!.start.line,
101
- "'display' attribute was changed to 'block'"
102
- )
103
- })
104
- .remove()
105
- // remove textAlign attribute
106
- findAttribute(filePath, j, buttonsWithFluidWidth, 'textAlign')
107
- .forEach((path) => {
108
- printWarning(
109
- filePath,
110
- path.value.loc!.start.line,
111
- "'textAlign' attribute was changed to 'start'"
112
- )
113
- })
114
- .remove()
115
- // add display="block" attribute
116
- buttonsWithFluidWidth.forEach((path) => {
117
- path.value.openingElement.attributes!.push(
118
- j.jsxAttribute(j.jsxIdentifier('display'), j.stringLiteral('block'))
119
- )
120
- })
121
- // add textAlign="start" attribute
122
- buttonsWithFluidWidth.forEach((path) => {
123
- path.value.openingElement!.attributes!.push(
124
- j.jsxAttribute(j.jsxIdentifier('textAlign'), j.stringLiteral('start'))
125
- )
126
- })
127
-
128
- ///// replace <Button icon=.. with <Button renderIcon=..
129
- findElements(filePath, j, root, importedName)
130
- .find(j.JSXIdentifier, { name: 'icon' })
131
- .replaceWith('renderIcon')
132
-
133
- ///// replace <Button buttonRef=.. with <Button elementRef=..
134
- findElements(filePath, j, root, importedName)
135
- .find(j.JSXIdentifier, { name: 'buttonRef' })
136
- .replaceWith('elementRef')
137
- }
@@ -1,111 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { findAttribute, findElements } from '../helpers/codemodHelpers'
26
- import { Collection, JSCodeshift, Literal } from 'jscodeshift'
27
-
28
- /**
29
- * Does the following updates on a <Button>:
30
- * - `variant="default"` -> removed
31
- * - `variant="primary"` -> `color="primary"`
32
- * - `variant="success"` -> `color="success"`
33
- * - `variant="danger"` -> `color="danger"`
34
- * - `variant="light"` -> `color="primary-inverse"`
35
- * - `variant="ghost"` -> `color="ghost" withBackground={false}`
36
- * - `variant="ghost-inverse"` -> `color="primary-inverse" withBackground={false}`
37
- */
38
- export default function updateV7ButtonsWithText(
39
- j: JSCodeshift,
40
- root: Collection,
41
- importedName: string,
42
- filePath: string
43
- ) {
44
- const buttons = findElements(filePath, j, root, importedName)
45
-
46
- // remove variant="default"
47
- findAttribute(filePath, j, buttons, 'variant', 'default').remove()
48
- // replace <Button variant="primary" with <Button color="primary"
49
- findAttribute(filePath, j, buttons, 'variant', 'primary').replaceWith(
50
- (nodePath) => {
51
- const { node } = nodePath
52
- node.name.name = 'color'
53
- return nodePath.node
54
- }
55
- )
56
- // replace <Button variant="success" with <Button color="success"
57
- findAttribute(filePath, j, buttons, 'variant', 'success').replaceWith(
58
- (nodePath) => {
59
- const { node } = nodePath
60
- node.name.name = 'color'
61
- return nodePath.node
62
- }
63
- )
64
- // replace <Button variant="danger" with <Button color="danger"
65
- findAttribute(filePath, j, buttons, 'variant', 'danger').replaceWith(
66
- (nodePath) => {
67
- const { node } = nodePath
68
- node.name.name = 'color'
69
- return nodePath.node
70
- }
71
- )
72
- // replace <Button variant="light" with color="primary-inverse"
73
- findAttribute(filePath, j, buttons, 'variant', 'light').replaceWith(
74
- (nodePath) => {
75
- const { node } = nodePath
76
- node.name.name = 'color'
77
- ;(node.value as Literal).value = 'primary-inverse'
78
- return nodePath.node
79
- }
80
- )
81
- // replace <Button variant="ghost" with <Button color="primary" withBackground={false}
82
- findAttribute(filePath, j, buttons, 'variant', 'ghost')
83
- .replaceWith((nodePath) => {
84
- const { node } = nodePath
85
- node.name.name = 'color'
86
- ;(node.value as Literal).value = 'primary'
87
- return nodePath.node
88
- })
89
- .insertAfter(
90
- j.jsxAttribute(
91
- j.jsxIdentifier('withBackground'),
92
- j.jsxExpressionContainer(j.jsxIdentifier('false'))
93
- )
94
- )
95
-
96
- // replace <Button variant="ghost-inverse" with
97
- // <Button color="primary-inverse" withBackground={false}
98
- findAttribute(filePath, j, buttons, 'variant', 'ghost-inverse')
99
- .replaceWith((nodePath) => {
100
- const { node } = nodePath
101
- node.name.name = 'color'
102
- ;(node.value as Literal).value = 'primary-inverse'
103
- return nodePath.node
104
- })
105
- .insertAfter(
106
- j.jsxAttribute(
107
- j.jsxIdentifier('withBackground'),
108
- j.jsxExpressionContainer(j.jsxIdentifier('false'))
109
- )
110
- )
111
- }
@@ -1,105 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import type { Collection, JSCodeshift } from 'jscodeshift'
26
- import {
27
- addImportIfNeeded,
28
- findAttribute,
29
- findElements,
30
- findImport,
31
- printWarning,
32
- renameElements
33
- } from '../helpers/codemodHelpers'
34
- import { Literal } from 'jscodeshift'
35
-
36
- /**
37
- * Does the following updates on a <FocusableView>:
38
- * - `<FocusableView/>` -> `<View/>`
39
- * - focused -> withFocusOutline
40
- * - shape -> delete and display warning, that focus ring shape cannot be set
41
- * - color="primary" -> delete, its the default
42
- * - color="error" -> focusColor="danger"
43
- * - color="inverse" -> focusColor="inverse"
44
- *
45
- **/
46
- export default function updateV7FocusableView(
47
- j: JSCodeshift,
48
- root: Collection,
49
- filePath: string
50
- ) {
51
- const importName = findImport(j, root, 'FocusableView', [
52
- '@instructure/ui-focusable',
53
- '@instructure/ui'
54
- ])
55
- if (!importName) {
56
- return false
57
- }
58
- const views = findElements(filePath, j, root, importName)
59
-
60
- ///// `<FocusableView/>` -> `<View/>`
61
- renameElements(filePath, views, 'FocusableView', 'View')
62
- addImportIfNeeded(j, root, 'View', '@instructure/ui-view')
63
-
64
- ///// focused -> withFocusOutline
65
- findAttribute(filePath, j, views, 'focused').replaceWith((nodePath) => {
66
- const { node } = nodePath
67
- node.name.name = 'withFocusOutline'
68
- return nodePath.node
69
- })
70
-
71
- ///// shape -> delete and display warning, that focus ring shape cannot be set
72
- findAttribute(filePath, j, views, 'shape')
73
- .forEach((path) => {
74
- printWarning(
75
- filePath,
76
- path.value.loc?.start.line,
77
- `The 'shape' property was removed, focus ring shape
78
- cannot be set in InstUI v8`
79
- )
80
- })
81
- .remove()
82
-
83
- //// color="primary" -> delete, its the default
84
- findAttribute(filePath, j, views, 'color', 'primary').remove()
85
-
86
- //// color="error" -> focusColor="danger"
87
- findAttribute(filePath, j, views, 'color', 'error').replaceWith(
88
- (nodePath) => {
89
- const { node } = nodePath
90
- node.name.name = 'focusColor'
91
- ;(node.value as Literal).value = 'danger'
92
- return nodePath.node
93
- }
94
- )
95
-
96
- ///// color="inverse" -> focusColor="inverse"
97
- findAttribute(filePath, j, views, 'color', 'inverse').replaceWith(
98
- (nodePath) => {
99
- const { node } = nodePath
100
- node.name.name = 'focusColor'
101
- return nodePath.node
102
- }
103
- )
104
- return true
105
- }
@@ -1,145 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import type {
26
- Collection,
27
- JSCodeshift,
28
- JSXAttribute,
29
- JSXElement
30
- } from 'jscodeshift'
31
- import {
32
- addImportIfNeeded,
33
- findElements,
34
- findImport,
35
- isJSXAttribue,
36
- isJSXExpressionContainer,
37
- isLiteral,
38
- printWarning
39
- } from '../helpers/codemodHelpers'
40
-
41
- /**
42
- * Does the following update on a <Heading>:
43
- * `<Heading ellipsis>abc</Heading>` ->
44
- * `<Heading><TruncateText>abc</TruncateText></Heading>
45
- */
46
- export default function updateV7Heading(
47
- j: JSCodeshift,
48
- root: Collection,
49
- filePath: string
50
- ) {
51
- const importName = findImport(j, root, 'Heading', [
52
- '@instructure/ui-heading',
53
- '@instructure/ui'
54
- ])
55
- if (!importName) {
56
- return false
57
- }
58
- const tags = findElements(filePath, j, root, importName, {
59
- name: 'ellipsis'
60
- })
61
-
62
- tags.forEach((path) => {
63
- if (path.value.openingElement.attributes) {
64
- for (const attr of path.value.openingElement.attributes) {
65
- if (isJSXAttribue(attr) && attr.name.name === 'ellipsis') {
66
- if (!attr.value) {
67
- // <Heading ellipsis>abc</Heading>
68
- wrapInTruncateText(j, root, attr, path.value)
69
- } else if (isJSXExpressionContainer(attr.value)) {
70
- // <Heading ellipsis={expr}>abc</Heading>
71
- if (isLiteral(attr.value.expression)) {
72
- if (typeof attr.value.expression.value === 'boolean') {
73
- if (attr.value.expression.value === true) {
74
- // <Heading ellipsis={true}>abc</Heading>
75
- wrapInTruncateText(j, root, attr, path.value)
76
- } else {
77
- // <Heading ellipsis={false}>abc</Heading>
78
- // remove ellipsis attribute
79
- path.value.openingElement.attributes.splice(
80
- path.value.openingElement.attributes.indexOf(attr),
81
- 1
82
- )
83
- return
84
- }
85
- } else {
86
- printWarning(
87
- filePath,
88
- path.value.loc?.start.line,
89
- 'Heading ellipsis ' +
90
- 'parameter has non-boolean value, please refactor manually'
91
- )
92
- return
93
- }
94
- } else {
95
- printWarning(
96
- filePath,
97
- path.value.loc?.start.line,
98
- 'Heading ellipsis ' +
99
- 'parameter has non-boolean value, please refactor manually'
100
- )
101
- return
102
- }
103
- } else {
104
- printWarning(
105
- filePath,
106
- path.value.loc?.start.line,
107
- 'Heading ellipsis ' +
108
- 'parameter has non-boolean value, please refactor manually'
109
- )
110
- return
111
- }
112
- }
113
- }
114
- }
115
- })
116
- if (tags) {
117
- return true
118
- }
119
- return false
120
- }
121
-
122
- function wrapInTruncateText(
123
- j: JSCodeshift,
124
- root: Collection,
125
- attr: JSXAttribute,
126
- elem: JSXElement
127
- ) {
128
- elem.openingElement.attributes!.splice(
129
- elem.openingElement.attributes!.indexOf(attr),
130
- 1
131
- )
132
- addImportIfNeeded(j, root, 'TruncateText', [
133
- '@instructure/ui-truncate-text',
134
- '@instructure/ui'
135
- ])
136
- // move children under a new TruncateText
137
- const children = elem.children
138
- const tt = j.jsxElement(
139
- j.jsxOpeningElement(j.jsxIdentifier('TruncateText')),
140
- j.jsxClosingElement(j.jsxIdentifier('TruncateText')),
141
- children
142
- )
143
- // eslint-disable-next-line no-param-reassign
144
- elem.children = [tt]
145
- }
@@ -1,113 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { Collection, JSCodeshift } from 'jscodeshift'
26
- import {
27
- addImportIfNeeded,
28
- findAttribute,
29
- findElements,
30
- findImport,
31
- printWarning,
32
- renameElements
33
- } from '../helpers/codemodHelpers'
34
-
35
- /**
36
- * Does the following update on a <List>:
37
- * - `<List variant="default"` -> `<List`
38
- * - `<List variant="unstyled"` -> `<List isUnstyled={true}`
39
- * - `<List variant="inline"` -> `<InlineList`
40
- * - `<List delimiter=` -> display warning
41
- * - `<List.Item delimiter=` -> display warning
42
- */
43
- export default function updateV7Lists(
44
- j: JSCodeshift,
45
- root: Collection,
46
- filePath: string
47
- ) {
48
- const importName = findImport(j, root, 'List', [
49
- '@instructure/ui-list',
50
- '@instructure/ui'
51
- ])
52
- if (!importName) {
53
- return false
54
- }
55
- const tags = findElements(filePath, j, root, importName, {
56
- name: 'variant'
57
- })
58
-
59
- ///// `<List variant="default"` -> `<List`
60
- findAttribute(filePath, j, tags, 'variant', 'default').remove()
61
-
62
- ///// `<List variant="unstyled"` -> `<List isUnstyled`
63
- findAttribute(filePath, j, tags, 'variant', 'unstyled')
64
- .remove()
65
- .insertAfter(j.jsxAttribute(j.jsxIdentifier('isUnstyled')))
66
-
67
- ///// `<List variant="inline"` -> `<InlineList`
68
- const inlineLists = findElements(filePath, j, root, 'List', {
69
- name: 'variant',
70
- value: 'inline'
71
- })
72
- if (inlineLists.length > 0) {
73
- findAttribute(filePath, j, inlineLists, 'variant').remove()
74
- renameElements(filePath, inlineLists, 'List', 'InlineList')
75
- inlineLists.forEach((path) => {
76
- if (path.value.children) {
77
- // rename List.Item to InlineList.Item
78
- renameElements(
79
- filePath,
80
- path.value.children,
81
- 'List.Item',
82
- 'InlineList.Item'
83
- )
84
- }
85
- })
86
- addImportIfNeeded(j, root, 'InlineList', [
87
- '@instructure/ui',
88
- '@instructure/ui-lists'
89
- ])
90
- }
91
-
92
- ///// `<List delimiter=` -> display warning
93
- ///// `<List.Item delimiter=` -> display warning
94
- findElements(filePath, j, root, importName, { name: 'delimiter' }).forEach(
95
- (path) => {
96
- printWarning(
97
- filePath,
98
- path.value.loc?.start.line,
99
- `List's delimiter prop is only available for 'InlineList' in InstUI v8, please check.`
100
- )
101
- }
102
- )
103
- findElements(filePath, j, root, 'List.Item', { name: 'delimiter' }).forEach(
104
- (path) => {
105
- printWarning(
106
- filePath,
107
- path.value.loc?.start.line,
108
- `List's delimiter prop is only available for 'InlineList' in InstUI v8, please check.`
109
- )
110
- }
111
- )
112
- return tags.length > 0
113
- }
@@ -1,83 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { Collection, JSCodeshift } from 'jscodeshift'
26
- import {
27
- findElements,
28
- findImport,
29
- isJSXAttribue,
30
- printWarning
31
- } from '../helpers/codemodHelpers'
32
-
33
- /**
34
- * Does the following updates on a <Pill>:
35
- * - `<Pill text="abc"/>` -> `<Pill>abc</Pill>`
36
- **/
37
- export default function updateV7Pill(
38
- j: JSCodeshift,
39
- root: Collection,
40
- filePath: string
41
- ) {
42
- const importName = findImport(j, root, 'Pill', [
43
- '@instructure/ui-pill',
44
- '@instructure/ui'
45
- ])
46
- if (!importName) {
47
- return false
48
- }
49
- ///// `<Pill text="abc"/>` -> `<Pill>abc</Pill>`
50
- let isUpdated = false
51
- findElements(filePath, j, root, importName, { name: 'text' }).forEach(
52
- (path) => {
53
- const tag = path.value
54
- for (const attr of tag.openingElement.attributes!) {
55
- if (isJSXAttribue(attr) && attr.name.name === 'text') {
56
- if (tag.children && tag.children.length !== 0) {
57
- printWarning(
58
- filePath,
59
- tag.loc?.start.line,
60
- "Pill had both `text` attribute and children. I've " +
61
- 'moved the value of `text` under its `children`, please double ' +
62
- 'check.'
63
- )
64
- }
65
- if (tag.openingElement.selfClosing) {
66
- tag.openingElement.selfClosing = false
67
- tag.closingElement = j.jsxClosingElement(j.jsxIdentifier('Pill'))
68
- }
69
- if (!tag.children) {
70
- tag.children = []
71
- }
72
- tag.children!.push(attr.value!)
73
- tag.openingElement.attributes!.splice(
74
- tag.openingElement.attributes!.indexOf(attr),
75
- 1
76
- )
77
- isUpdated = true
78
- }
79
- }
80
- }
81
- )
82
- return isUpdated
83
- }