@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.
- package/CHANGELOG.md +1 -1
- package/README.md +5 -87
- package/lib/__node_tests__/codemodHelpers.test.tsx +455 -0
- package/lib/__node_tests__/{updateV10Breaking.test.ts → codemods.test.ts} +3 -3
- package/lib/__node_tests__/{testHelpers.ts → runTest.ts} +1 -3
- package/lib/index.ts +1 -16
- package/lib/{utils → instui-codemods}/updateToV10Colors.ts +6 -7
- package/lib/updateV10Breaking.ts +12 -26
- package/lib/{helpers → utils}/codemodHelpers.ts +153 -164
- package/lib/utils/codemodTypeCheckers.ts +221 -0
- package/lib/utils/instUICodemodExecutor.ts +89 -0
- package/package.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/helpers/replaceDeprecatedImports.ts +0 -546
- package/lib/helpers/replaceDeprecatedProps.ts +0 -230
- package/lib/updateImports.ts +0 -86
- package/lib/updatePropNames.ts +0 -66
- package/lib/updateV7Props.ts +0 -101
- package/lib/updateV8Breaking.ts +0 -49
- package/lib/updateV8ReactDOM.ts +0 -61
- package/lib/updateV9Breaking.ts +0 -54
- package/lib/utils/UpdateV7ButtonsLink.ts +0 -139
- package/lib/utils/requireUncached.ts +0 -28
- package/lib/utils/updateToV8Theming.ts +0 -84
- package/lib/utils/updateToV9Theming.ts +0 -70
- package/lib/utils/updateV7ButtonsClose.ts +0 -104
- package/lib/utils/updateV7ButtonsIconCircle.ts +0 -240
- package/lib/utils/updateV7ButtonsMisc.ts +0 -137
- package/lib/utils/updateV7ButtonsWithText.ts +0 -111
- package/lib/utils/updateV7FocusableView.ts +0 -105
- package/lib/utils/updateV7Heading.ts +0 -145
- package/lib/utils/updateV7Lists.ts +0 -113
- package/lib/utils/updateV7Pill.ts +0 -83
- package/lib/utils/updateV7Popover.ts +0 -133
- package/lib/utils/updateV7Tabs.ts +0 -129
- package/lib/utils/updateV8RenderProp.ts +0 -142
- package/lib/utils/updateV8ThemeProp.ts +0 -51
- package/lib/utils/warnV7ComponentDeprecations.ts +0 -96
|
@@ -0,0 +1,221 @@
|
|
|
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
|
+
CallExpression,
|
|
27
|
+
Identifier,
|
|
28
|
+
ImportDefaultSpecifier,
|
|
29
|
+
ImportSpecifier,
|
|
30
|
+
JSXAttribute,
|
|
31
|
+
JSXElement,
|
|
32
|
+
JSXExpressionContainer,
|
|
33
|
+
JSXFragment,
|
|
34
|
+
JSXIdentifier,
|
|
35
|
+
JSXMemberExpression,
|
|
36
|
+
JSXText,
|
|
37
|
+
Literal,
|
|
38
|
+
MemberExpression,
|
|
39
|
+
SpreadElement,
|
|
40
|
+
TSTypeParameter
|
|
41
|
+
} from 'jscodeshift'
|
|
42
|
+
|
|
43
|
+
type astElem = { type: string }
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* a function call — basically any invocation like `foo()`, `obj.method()`, or
|
|
47
|
+
* even more complex calls.
|
|
48
|
+
*/
|
|
49
|
+
function isCallExpression(elem?: astElem | null): elem is CallExpression {
|
|
50
|
+
return elem !== null && elem !== undefined && elem.type == 'CallExpression'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* a node that represents the name of something—typically a variable, function,
|
|
55
|
+
* class, or any named entity in source code.
|
|
56
|
+
*
|
|
57
|
+
* For example, in the JavaScript snippet `score` is the indentifier:
|
|
58
|
+
* `let score = 42;`
|
|
59
|
+
*/
|
|
60
|
+
function isIdentifier(elem?: astElem | null): elem is Identifier {
|
|
61
|
+
return elem !== null && elem !== undefined && elem.type === 'Identifier'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function isImportSpecifier(elem?: astElem | null): elem is ImportSpecifier {
|
|
65
|
+
return elem !== null && elem !== undefined && elem.type === 'ImportSpecifier'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isImportDefaultSpecifier(
|
|
69
|
+
elem?: astElem | null
|
|
70
|
+
): elem is ImportDefaultSpecifier {
|
|
71
|
+
return (
|
|
72
|
+
elem !== null &&
|
|
73
|
+
elem !== undefined &&
|
|
74
|
+
elem.type === 'ImportDefaultSpecifier'
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isJSXAttribute(elem?: astElem | null): elem is JSXAttribute {
|
|
79
|
+
return elem !== null && elem !== undefined && elem.type === 'JSXAttribute'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A standard JSX tag like `<div>`, `<MyComponent>`, or any non-fragment JSX
|
|
84
|
+
* structure.
|
|
85
|
+
*/
|
|
86
|
+
function isJSXElement(elem?: astElem | astElem[] | null): elem is JSXElement {
|
|
87
|
+
return (
|
|
88
|
+
elem !== null &&
|
|
89
|
+
elem !== undefined &&
|
|
90
|
+
!Array.isArray(elem) &&
|
|
91
|
+
elem.type == 'JSXElement'
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* raw text between JSX tags.
|
|
97
|
+
*
|
|
98
|
+
* For example in `<div>Hello, world!</div>` the string `"Hello, world!"` is
|
|
99
|
+
* represented as a `JSXText` node in the AST.
|
|
100
|
+
*/
|
|
101
|
+
function isJSXText(elem?: astElem | astElem[] | null): elem is JSXText {
|
|
102
|
+
return (
|
|
103
|
+
elem !== null &&
|
|
104
|
+
elem !== undefined &&
|
|
105
|
+
!Array.isArray(elem) &&
|
|
106
|
+
elem.type == 'JSXText'
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* node that represents the name of a JSX element, attribute, or expression —
|
|
112
|
+
* basically any plain identifier used in JSX
|
|
113
|
+
* @example
|
|
114
|
+
* <div></div>
|
|
115
|
+
* {
|
|
116
|
+
* type: "JSXElement",
|
|
117
|
+
* openingElement: {
|
|
118
|
+
* name: {
|
|
119
|
+
* type: "JSXIdentifier",
|
|
120
|
+
* name: "div"
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
* <MyComponent title="hello" />
|
|
124
|
+
* {
|
|
125
|
+
* type: "JSXAttribute",
|
|
126
|
+
* name: {
|
|
127
|
+
* type: "JSXIdentifier",
|
|
128
|
+
* name: "title"
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
*/
|
|
132
|
+
function isJSXIdentifier(elem?: astElem | null): elem is JSXIdentifier {
|
|
133
|
+
return elem !== null && elem !== undefined && elem.type == 'JSXIdentifier'
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* A JSX fragment (`<>...</>`)
|
|
138
|
+
* @example
|
|
139
|
+
* <>
|
|
140
|
+
* <h1>Hello</h1>
|
|
141
|
+
* </>
|
|
142
|
+
*/
|
|
143
|
+
function isJSXFragment(elem?: astElem | null): elem is JSXFragment {
|
|
144
|
+
return elem !== null && elem !== undefined && elem.type == 'JSXFragment'
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* chained JSX identifier like `<List.Item />
|
|
149
|
+
*/
|
|
150
|
+
function isJSXMemberExpression(
|
|
151
|
+
elem?: astElem | null
|
|
152
|
+
): elem is JSXMemberExpression {
|
|
153
|
+
return (
|
|
154
|
+
elem !== null && elem !== undefined && elem.type == 'JSXMemberExpression'
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* an AST is a node that wraps any JavaScript expression inside curly braces
|
|
160
|
+
* ({}) in JSX.
|
|
161
|
+
* @example
|
|
162
|
+
* <div>{user.name}</div>
|
|
163
|
+
*/
|
|
164
|
+
function isJSXExpressionContainer(
|
|
165
|
+
elem?: astElem | null
|
|
166
|
+
): elem is JSXExpressionContainer {
|
|
167
|
+
return (
|
|
168
|
+
elem !== null && elem !== undefined && elem.type == 'JSXExpressionContainer'
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A concrete primitive value in the code like `'asd'` or `42`
|
|
174
|
+
*/
|
|
175
|
+
function isLiteral(elem?: astElem | null): elem is Literal {
|
|
176
|
+
return elem !== null && elem !== undefined && elem.type === 'Literal'
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Represents property access like `asd.dfg` or `asd["dfg"]`
|
|
181
|
+
*/
|
|
182
|
+
function isMemberExpression(elem?: astElem | null): elem is MemberExpression {
|
|
183
|
+
return elem !== null && elem !== undefined && elem.type == 'MemberExpression'
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The `...` element in the source code
|
|
188
|
+
*/
|
|
189
|
+
function isSpreadElement(elem?: astElem | null): elem is SpreadElement {
|
|
190
|
+
return elem !== null && elem !== undefined && elem.type === 'SpreadElement'
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* This represents a generic type declaration, the part between "<" and ">"
|
|
195
|
+
* For example in
|
|
196
|
+
* ```
|
|
197
|
+
* function foo<T extends number = 42>(x: T) {}
|
|
198
|
+
* ```
|
|
199
|
+
* the `TSTypeParameter` is `T extends number = 42`
|
|
200
|
+
*/
|
|
201
|
+
function isTSTypeParameter(elem?: astElem | null): elem is TSTypeParameter {
|
|
202
|
+
return elem !== null && elem !== undefined && elem.type === 'TSTypeParameter'
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export {
|
|
206
|
+
isCallExpression,
|
|
207
|
+
isIdentifier,
|
|
208
|
+
isImportSpecifier,
|
|
209
|
+
isImportDefaultSpecifier,
|
|
210
|
+
isJSXAttribute,
|
|
211
|
+
isJSXElement,
|
|
212
|
+
isJSXText,
|
|
213
|
+
isJSXIdentifier,
|
|
214
|
+
isJSXFragment,
|
|
215
|
+
isJSXMemberExpression,
|
|
216
|
+
isJSXExpressionContainer,
|
|
217
|
+
isLiteral,
|
|
218
|
+
isMemberExpression,
|
|
219
|
+
isSpreadElement,
|
|
220
|
+
isTSTypeParameter
|
|
221
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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 { writeWarningsToFile } from './codemodHelpers'
|
|
26
|
+
import formatSource from './formatSource'
|
|
27
|
+
import type { API, Collection, FileInfo, JSCodeshift } from 'jscodeshift'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param j JSCodeshift instance
|
|
31
|
+
* @param root the collection to work on. The function should modify this directly
|
|
32
|
+
* @param filePath The path to the file that is being modified
|
|
33
|
+
* @returns `true` if the code was modified
|
|
34
|
+
*/
|
|
35
|
+
export type InstUICodemod = (
|
|
36
|
+
j: JSCodeshift,
|
|
37
|
+
root: Collection,
|
|
38
|
+
filePath: string
|
|
39
|
+
) => boolean
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Runs the given codemod/codemods.
|
|
43
|
+
* @param instUICodemods A function or an array of functions that do code
|
|
44
|
+
* modification. If it returns `true` it modified the input collection.
|
|
45
|
+
* @param file The file to process
|
|
46
|
+
* @param api jscodeshift instance
|
|
47
|
+
* @param options
|
|
48
|
+
* @param options.filename if `filename` is specified then emitted warnings are
|
|
49
|
+
* written to this file.
|
|
50
|
+
* @param options.usePrettier if `true` the transformed code will be run through
|
|
51
|
+
* [Prettier](https://prettier.io/). You can customize this through a [Prettier
|
|
52
|
+
* config file](https://prettier.io/docs/configuration.html)
|
|
53
|
+
* @returns the modified file as `string` or `null`
|
|
54
|
+
*/
|
|
55
|
+
const instUICodemodExecutor = (
|
|
56
|
+
instUICodemods: InstUICodemod[] | InstUICodemod,
|
|
57
|
+
file: FileInfo,
|
|
58
|
+
api: API,
|
|
59
|
+
options?: { fileName?: string; usePrettier?: boolean }
|
|
60
|
+
) => {
|
|
61
|
+
const j = api.jscodeshift.withParser('tsx')
|
|
62
|
+
const root = j(file.source)
|
|
63
|
+
let hasModifications = false
|
|
64
|
+
if (Array.isArray(instUICodemods)) {
|
|
65
|
+
for (const inst of instUICodemods) {
|
|
66
|
+
const modified = inst(j, root, file.path)
|
|
67
|
+
if (modified) {
|
|
68
|
+
hasModifications = true
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
hasModifications = instUICodemods(j, root, file.path)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (options && options.fileName) {
|
|
76
|
+
writeWarningsToFile(options.fileName)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (hasModifications) {
|
|
80
|
+
const shouldUsePrettier = options?.usePrettier !== false
|
|
81
|
+
return shouldUsePrettier
|
|
82
|
+
? formatSource(root.toSource(), file.path)
|
|
83
|
+
: root.toSource()
|
|
84
|
+
} else {
|
|
85
|
+
return null
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default instUICodemodExecutor
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-codemods",
|
|
3
|
-
"version": "10.20.2-snapshot-
|
|
3
|
+
"version": "10.20.2-snapshot-13",
|
|
4
4
|
"description": "Codemod scripts to help upgrade Instructure UI libraries.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"main": "./lib/index.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@instructure/ui-babel-preset": "10.20.2-snapshot-
|
|
21
|
+
"@instructure/ui-babel-preset": "10.20.2-snapshot-13",
|
|
22
22
|
"@types/jscodeshift": "^17.3.0",
|
|
23
23
|
"@types/prettier": "^2.7.3",
|
|
24
24
|
"esbuild": "^0.25.5",
|