@instructure/ui-codemods 8.14.1-snapshot.7 → 8.15.1-snapshot.2
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 +4 -0
- package/README.md +1 -1
- package/lib/helpers/{replaceDeprecatedImports.js → replaceDeprecatedImports.ts} +51 -34
- package/lib/helpers/{replaceDeprecatedProps.js → replaceDeprecatedProps.ts} +31 -23
- package/lib/{index.js → index.ts} +3 -4
- package/lib/{updateImports.js → updateImports.ts} +43 -15
- package/lib/{updatePropNames.js → updatePropNames.ts} +22 -8
- package/lib/utils/{createLiteral.js → createLiteral.ts} +7 -2
- package/lib/utils/{findDeprecatedProp.js → findDeprecatedProp.ts} +7 -2
- package/lib/utils/{findImportDeclaration.js → findImportDeclaration.ts} +15 -4
- package/lib/utils/{findTransform.js → findTransform.ts} +10 -7
- package/lib/utils/{formatSource.js → formatSource.ts} +3 -4
- package/lib/utils/{parseImport.js → parseImport.ts} +11 -4
- package/lib/utils/{requireUncached.js → requireUncached.ts} +2 -1
- package/package.json +7 -4
- package/tsconfig.build.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/deprecatePropNames.js +0 -59
- package/lib/helpers/insertOrUpdateDecorator.js +0 -86
- package/lib/helpers/replacePropertyMembers.js +0 -68
- package/lib/helpers/replacePropsAndDefaults.js +0 -67
- package/lib/helpers/replaceVariableDeclarations.js +0 -100
- package/lib/utils/getClassDeclarations.js +0 -37
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [8.15.0](https://github.com/instructure/instructure-ui/compare/v8.14.0...v8.15.0) (2022-01-26)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-codemods
|
|
9
|
+
|
|
6
10
|
# [8.14.0](https://github.com/instructure/instructure-ui/compare/v8.13.0...v8.14.0) (2021-12-16)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @instructure/ui-codemods
|
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ jscodeshift -t node_modules/@instructure/ui-codemods/lib/updatePropNames.js <pat
|
|
|
42
42
|
This codemod helps you update your project by renaming `imports` that have changed (e.g., `instructure-ui` => `@instructure/<package name>`).
|
|
43
43
|
|
|
44
44
|
```sh
|
|
45
|
-
jscodeshift -t node_modules/@instructure/ui-codemods/lib/updateImports.js <path> --config=node_modules/@instructure/instui-config/codemod-configs/v<version number ex. 5 or 6>/imports.config.
|
|
45
|
+
jscodeshift -t node_modules/@instructure/ui-codemods/lib/updateImports.js <path> --config=node_modules/@instructure/instui-config/codemod-configs/v<version number ex. 5 or 6>/imports.config.js
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
[npm]: https://img.shields.io/npm/v/@instructure/ui-codemods.svg
|
|
@@ -22,15 +22,25 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
import parseImport, { ParsedImport } from '../utils/parseImport'
|
|
26
|
+
import findTransform from '../utils/findTransform'
|
|
27
|
+
import findImportDeclaration from '../utils/findImportDeclaration'
|
|
28
|
+
import {
|
|
29
|
+
API,
|
|
30
|
+
ASTPath,
|
|
31
|
+
Collection,
|
|
32
|
+
ImportDeclaration,
|
|
33
|
+
ImportDefaultSpecifier,
|
|
34
|
+
ImportSpecifier,
|
|
35
|
+
JSCodeshift
|
|
36
|
+
} from 'jscodeshift'
|
|
37
|
+
import type { ConfigObject, TransformObj } from '../updateImports'
|
|
28
38
|
|
|
29
39
|
function transformImportPath(
|
|
30
|
-
importPath,
|
|
31
|
-
parsedImport,
|
|
32
|
-
transform,
|
|
33
|
-
transformDefaults
|
|
40
|
+
importPath: string,
|
|
41
|
+
parsedImport: ParsedImport,
|
|
42
|
+
transform: TransformObj,
|
|
43
|
+
transformDefaults: TransformObj
|
|
34
44
|
) {
|
|
35
45
|
let updatedImportPath = transform.importPath || transformDefaults.importPath
|
|
36
46
|
|
|
@@ -47,34 +57,34 @@ function transformImportPath(
|
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
function updateImports(
|
|
50
|
-
j,
|
|
51
|
-
root,
|
|
52
|
-
config,
|
|
53
|
-
api,
|
|
54
|
-
importDeclaration
|
|
55
|
-
importSpecifier
|
|
56
|
-
importPath
|
|
60
|
+
j: JSCodeshift,
|
|
61
|
+
root: Collection,
|
|
62
|
+
config: ConfigObject,
|
|
63
|
+
api: API,
|
|
64
|
+
importDeclaration: ASTPath<ImportDeclaration>,
|
|
65
|
+
importSpecifier: ASTPath<ImportDefaultSpecifier> | ASTPath<ImportSpecifier>,
|
|
66
|
+
importPath: string
|
|
57
67
|
) {
|
|
58
68
|
let hasModifications = false
|
|
59
|
-
const { transformDefaults = {}, transforms = [] } = config
|
|
60
|
-
|
|
69
|
+
const { transformDefaults = {} as TransformObj, transforms = [] } = config
|
|
61
70
|
// This is the name of the export imported from the module. For example, in the import
|
|
62
71
|
// `import { Foo as Bar } from '@instructure...` this would be Foo
|
|
63
72
|
let moduleName
|
|
64
73
|
if (
|
|
65
74
|
importSpecifier &&
|
|
66
75
|
importSpecifier.value &&
|
|
67
|
-
importSpecifier.value.imported
|
|
76
|
+
(importSpecifier.value as ImportSpecifier).imported
|
|
68
77
|
) {
|
|
69
|
-
moduleName = importSpecifier.value.imported.name
|
|
78
|
+
moduleName = (importSpecifier.value as ImportSpecifier).imported.name
|
|
70
79
|
}
|
|
71
80
|
|
|
72
81
|
// This is the local name created by the consumer. For example, in the import
|
|
73
82
|
// `import { Foo as Bar } from '@instructure...` this would be Bar
|
|
74
|
-
|
|
83
|
+
const localName = (importSpecifier.value as ImportDefaultSpecifier).local!
|
|
84
|
+
.name
|
|
75
85
|
|
|
76
86
|
const parsedImport = parseImport(importPath)
|
|
77
|
-
|
|
87
|
+
const transform = findTransform(
|
|
78
88
|
transforms,
|
|
79
89
|
importPath,
|
|
80
90
|
parsedImport,
|
|
@@ -90,16 +100,17 @@ function updateImports(
|
|
|
90
100
|
importType = moduleName ? 'named' : 'default'
|
|
91
101
|
}
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
const updatedModuleName =
|
|
104
|
+
transform.moduleName || transformDefaults.moduleName
|
|
105
|
+
const currentModuleName = moduleName || parsedImport.moduleName!
|
|
106
|
+
let updatedModuleNameStr: string
|
|
96
107
|
if (updatedModuleName) {
|
|
97
|
-
|
|
108
|
+
updatedModuleNameStr =
|
|
98
109
|
typeof updatedModuleName === 'function'
|
|
99
110
|
? updatedModuleName(currentModuleName)
|
|
100
111
|
: updatedModuleName
|
|
101
112
|
} else {
|
|
102
|
-
|
|
113
|
+
updatedModuleNameStr = currentModuleName
|
|
103
114
|
}
|
|
104
115
|
|
|
105
116
|
const updatedImportPath = transformImportPath(
|
|
@@ -125,7 +136,7 @@ function updateImports(
|
|
|
125
136
|
if (
|
|
126
137
|
importType === 'named' &&
|
|
127
138
|
importPath === updatedImportPath &&
|
|
128
|
-
moduleName ===
|
|
139
|
+
moduleName === updatedModuleNameStr
|
|
129
140
|
) {
|
|
130
141
|
return false
|
|
131
142
|
}
|
|
@@ -140,7 +151,7 @@ function updateImports(
|
|
|
140
151
|
const { comments: existingComments = [] } =
|
|
141
152
|
(updatedDeclaration || {}).value || {}
|
|
142
153
|
|
|
143
|
-
const cleanup = (newDeclaration) => {
|
|
154
|
+
const cleanup = (newDeclaration?: ImportDeclaration) => {
|
|
144
155
|
hasModifications = true
|
|
145
156
|
j(importSpecifier).remove()
|
|
146
157
|
|
|
@@ -168,7 +179,7 @@ function updateImports(
|
|
|
168
179
|
// were already on the updated import declaration
|
|
169
180
|
updatedDeclaration.value.comments = [
|
|
170
181
|
...(existingComments || []),
|
|
171
|
-
...(removedImportDeclaration ? comments : [])
|
|
182
|
+
...(removedImportDeclaration ? comments! : [])
|
|
172
183
|
]
|
|
173
184
|
}
|
|
174
185
|
}
|
|
@@ -198,7 +209,7 @@ function updateImports(
|
|
|
198
209
|
.at(0)
|
|
199
210
|
.insertAfter(
|
|
200
211
|
j.importSpecifier(
|
|
201
|
-
j.identifier(
|
|
212
|
+
j.identifier(updatedModuleNameStr),
|
|
202
213
|
j.identifier(localName)
|
|
203
214
|
)
|
|
204
215
|
)
|
|
@@ -211,7 +222,7 @@ function updateImports(
|
|
|
211
222
|
.at(0)
|
|
212
223
|
.insertAfter(
|
|
213
224
|
j.importSpecifier(
|
|
214
|
-
j.identifier(
|
|
225
|
+
j.identifier(updatedModuleNameStr),
|
|
215
226
|
j.identifier(localName)
|
|
216
227
|
)
|
|
217
228
|
)
|
|
@@ -224,7 +235,7 @@ function updateImports(
|
|
|
224
235
|
j.importDeclaration(
|
|
225
236
|
[
|
|
226
237
|
j.importSpecifier(
|
|
227
|
-
j.identifier(
|
|
238
|
+
j.identifier(updatedModuleNameStr),
|
|
228
239
|
j.identifier(localName)
|
|
229
240
|
)
|
|
230
241
|
],
|
|
@@ -238,7 +249,7 @@ function updateImports(
|
|
|
238
249
|
const newDeclaration = j.importDeclaration(
|
|
239
250
|
[
|
|
240
251
|
j.importSpecifier(
|
|
241
|
-
j.identifier(
|
|
252
|
+
j.identifier(updatedModuleNameStr),
|
|
242
253
|
j.identifier(localName)
|
|
243
254
|
)
|
|
244
255
|
],
|
|
@@ -314,7 +325,12 @@ function updateImports(
|
|
|
314
325
|
* Example:
|
|
315
326
|
* import Modal from 'instructure-ui/lib/Modal'
|
|
316
327
|
*/
|
|
317
|
-
|
|
328
|
+
export default function replaceDeprecatedImports(
|
|
329
|
+
j: JSCodeshift,
|
|
330
|
+
root: Collection,
|
|
331
|
+
config: ConfigObject,
|
|
332
|
+
api: API
|
|
333
|
+
) {
|
|
318
334
|
let hasModifications = false
|
|
319
335
|
|
|
320
336
|
root.find(j.ImportDeclaration).forEach((importDeclaration) => {
|
|
@@ -360,7 +376,8 @@ module.exports = function replaceDeprecatedImports(j, root, config, api) {
|
|
|
360
376
|
})
|
|
361
377
|
} else {
|
|
362
378
|
// If we have a declaration, but no specifiers that means there is just the import path
|
|
363
|
-
const { transformDefaults = {}, transforms = [] } =
|
|
379
|
+
const { transformDefaults = {} as TransformObj, transforms = [] } =
|
|
380
|
+
config
|
|
364
381
|
const parsedImport = parseImport(importPath)
|
|
365
382
|
const transform = findTransform(transforms, importPath, parsedImport)
|
|
366
383
|
|
|
@@ -22,8 +22,20 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
import findDeprecatedProp from '../utils/findDeprecatedProp'
|
|
26
|
+
import createLiteral from '../utils/createLiteral'
|
|
27
|
+
import {
|
|
28
|
+
ASTPath,
|
|
29
|
+
Collection,
|
|
30
|
+
JSCodeshift,
|
|
31
|
+
JSXAttribute,
|
|
32
|
+
JSXExpressionContainer,
|
|
33
|
+
JSXIdentifier
|
|
34
|
+
} from 'jscodeshift'
|
|
35
|
+
import type {
|
|
36
|
+
ComponentUpdateData,
|
|
37
|
+
UpdatePropNamesOptions
|
|
38
|
+
} from '../updatePropNames'
|
|
27
39
|
|
|
28
40
|
/**
|
|
29
41
|
* Find JSX attributes (props)
|
|
@@ -31,14 +43,17 @@ const createLiteral = require('../utils/createLiteral')
|
|
|
31
43
|
* Example:
|
|
32
44
|
* <MyComponent [name] />
|
|
33
45
|
*/
|
|
34
|
-
|
|
46
|
+
export default function replaceDeprecatedProps(
|
|
47
|
+
j: JSCodeshift,
|
|
48
|
+
root: Collection,
|
|
49
|
+
config: UpdatePropNamesOptions
|
|
50
|
+
) {
|
|
35
51
|
let hasModifications = false
|
|
36
|
-
|
|
37
52
|
// Find JSX Elements
|
|
38
53
|
//
|
|
39
54
|
// Rewrite usages of deprecated props for a Component.
|
|
40
55
|
root.find(j.JSXOpeningElement).forEach((el) => {
|
|
41
|
-
const name = el.value.name.name
|
|
56
|
+
const name = (el.value.name as JSXIdentifier).name
|
|
42
57
|
|
|
43
58
|
// Make sure we're working with a Component that we need to modify
|
|
44
59
|
if (config[name]) {
|
|
@@ -51,10 +66,8 @@ module.exports = function replaceDeprecatedProps(j, root, config) {
|
|
|
51
66
|
.forEach((i) => {
|
|
52
67
|
const prop = i.value.name
|
|
53
68
|
const match = findDeprecatedProp(config, name, prop)
|
|
54
|
-
|
|
55
69
|
if (match) {
|
|
56
70
|
hasModifications = true
|
|
57
|
-
|
|
58
71
|
if (!match.new) {
|
|
59
72
|
// If config sets the new name to null, the prop has been
|
|
60
73
|
// removed. Remove the prop and value.
|
|
@@ -81,20 +94,20 @@ module.exports = function replaceDeprecatedProps(j, root, config) {
|
|
|
81
94
|
const { type } = expressionContainer.value.expression
|
|
82
95
|
// Verify that the expression container contains a literal
|
|
83
96
|
if (type === 'Literal') {
|
|
84
|
-
replaceValue(
|
|
97
|
+
replaceValue(
|
|
85
98
|
j,
|
|
86
99
|
literals,
|
|
87
100
|
match,
|
|
88
101
|
attr,
|
|
89
102
|
expressionContainer
|
|
90
|
-
|
|
103
|
+
)
|
|
91
104
|
}
|
|
92
105
|
})
|
|
93
106
|
} else if (literals && literals.length > 0) {
|
|
94
107
|
// If the value isn't in a jsx expression container, but we have a literal, that
|
|
95
108
|
// means that the user is passing a string value. For example, in the following
|
|
96
109
|
// jsx, `<div prop="someValue" />` we are looking at `"someValue"`
|
|
97
|
-
replaceValue(
|
|
110
|
+
replaceValue(j, literals, match, attr)
|
|
98
111
|
} else {
|
|
99
112
|
// If we don't have a jsx expression container or a string literal, that means that
|
|
100
113
|
// we have just the attribute. For example, in the following jsx, `<div prop />`
|
|
@@ -104,12 +117,7 @@ module.exports = function replaceDeprecatedProps(j, root, config) {
|
|
|
104
117
|
j.jsxAttribute(newPropName, j.booleanLiteral(true))
|
|
105
118
|
)
|
|
106
119
|
// Look for literals again after update
|
|
107
|
-
replaceValue(
|
|
108
|
-
j,
|
|
109
|
-
literals: j(attr).find(j.Literal),
|
|
110
|
-
match,
|
|
111
|
-
attr
|
|
112
|
-
})
|
|
120
|
+
replaceValue(j, j(attr).find(j.Literal), match, attr)
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
123
|
}
|
|
@@ -122,13 +130,13 @@ module.exports = function replaceDeprecatedProps(j, root, config) {
|
|
|
122
130
|
return hasModifications
|
|
123
131
|
}
|
|
124
132
|
|
|
125
|
-
const replaceValue = (
|
|
126
|
-
j,
|
|
127
|
-
literals,
|
|
128
|
-
match,
|
|
129
|
-
attr
|
|
130
|
-
expressionContainer
|
|
131
|
-
|
|
133
|
+
const replaceValue = (
|
|
134
|
+
j: JSCodeshift,
|
|
135
|
+
literals: Collection,
|
|
136
|
+
match: ComponentUpdateData,
|
|
137
|
+
attr: ASTPath<JSXAttribute>,
|
|
138
|
+
expressionContainer?: ASTPath<JSXExpressionContainer>
|
|
139
|
+
) => {
|
|
132
140
|
literals.forEach((literalValue) => {
|
|
133
141
|
const currentValue = literalValue.value.value
|
|
134
142
|
|
|
@@ -22,33 +22,38 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
import fs from 'fs'
|
|
26
|
+
import path from 'path'
|
|
27
|
+
import formatSource from './utils/formatSource'
|
|
28
|
+
import requireUncached from './utils/requireUncached'
|
|
29
|
+
import replaceDeprecatedImports from './helpers/replaceDeprecatedImports'
|
|
30
|
+
import type { API, FileInfo } from 'jscodeshift'
|
|
31
|
+
import { ParsedImport } from './utils/parseImport'
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* updates imports to the new per-package or the metapackage syntax.
|
|
35
|
+
* @param file Holds information about the currently processed file.
|
|
36
|
+
* @param api This object exposes the jscodeshift library and helper functions from the runner.
|
|
37
|
+
* @param options Contains all options that have been passed to runner
|
|
38
|
+
* @returns {*|null} null if there was nothing to reformat
|
|
39
|
+
*/
|
|
40
|
+
export default function updateImports(file: FileInfo, api: API, options: any) {
|
|
34
41
|
const j = api.jscodeshift
|
|
35
42
|
const c = path.resolve(process.cwd(), options.config)
|
|
36
|
-
let config
|
|
37
|
-
|
|
43
|
+
let config:
|
|
44
|
+
| ConfigObject
|
|
45
|
+
| ((opts: { isMetaComponentPackageMigration: boolean }) => ConfigObject) =
|
|
46
|
+
fs.existsSync(c) ? requireUncached(c) : null
|
|
38
47
|
if (!config) {
|
|
39
|
-
throw new Error(`Invalid config file "${c}"
|
|
48
|
+
throw new Error(`Invalid config file "${c}", is this the correct path?`)
|
|
40
49
|
}
|
|
41
|
-
|
|
42
50
|
if (typeof config === 'function') {
|
|
43
51
|
const configOptions = {
|
|
44
52
|
isMetaComponentPackageMigration: options.isMetaComponentPackageMigration
|
|
45
53
|
}
|
|
46
|
-
|
|
47
54
|
config = config(configOptions)
|
|
48
55
|
}
|
|
49
|
-
|
|
50
56
|
const root = j(file.source)
|
|
51
|
-
|
|
52
57
|
let hasModifications = false
|
|
53
58
|
|
|
54
59
|
hasModifications =
|
|
@@ -56,3 +61,26 @@ module.exports = function (file, api, options) {
|
|
|
56
61
|
|
|
57
62
|
return hasModifications ? formatSource(root.toSource(), file.path) : null
|
|
58
63
|
}
|
|
64
|
+
|
|
65
|
+
export type ConfigObject = {
|
|
66
|
+
transformDefaults: TransformObj
|
|
67
|
+
transforms: Transform[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type TransformObj = {
|
|
71
|
+
importType?: string
|
|
72
|
+
importPath: string | ((path: string, parsedImport?: ParsedImport) => string)
|
|
73
|
+
moduleName: string | ((path?: string) => string)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type Transform = {
|
|
77
|
+
where: {
|
|
78
|
+
importPath?: string
|
|
79
|
+
importPattern?: string
|
|
80
|
+
packageName?: string
|
|
81
|
+
packageNames?: string[]
|
|
82
|
+
moduleName?: string
|
|
83
|
+
moduleNames?: string[]
|
|
84
|
+
}
|
|
85
|
+
transform: TransformObj
|
|
86
|
+
}
|
|
@@ -22,17 +22,19 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
import fs from 'fs'
|
|
26
|
+
import path from 'path'
|
|
27
|
+
import formatSource from './utils/formatSource'
|
|
28
|
+
import requireUncached from './utils/requireUncached'
|
|
29
|
+
import replaceDeprecatedProps from './helpers/replaceDeprecatedProps'
|
|
30
|
+
import { API, FileInfo } from 'jscodeshift'
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
const requireUncached = require('./utils/requireUncached')
|
|
30
|
-
const replaceDeprecatedProps = require('./helpers/replaceDeprecatedProps')
|
|
31
|
-
|
|
32
|
-
module.exports = function (file, api, options) {
|
|
32
|
+
export default function (file: FileInfo, api: API, options: any) {
|
|
33
33
|
const j = api.jscodeshift
|
|
34
34
|
const c = path.resolve(process.cwd(), options.config)
|
|
35
|
-
const config = fs.existsSync(c)
|
|
35
|
+
const config: UpdatePropNamesOptions = fs.existsSync(c)
|
|
36
|
+
? requireUncached(c)
|
|
37
|
+
: null
|
|
36
38
|
|
|
37
39
|
if (!config) {
|
|
38
40
|
throw new Error(`Invalid config file "${c}"`)
|
|
@@ -45,3 +47,15 @@ module.exports = function (file, api, options) {
|
|
|
45
47
|
|
|
46
48
|
return hasModifications ? formatSource(root.toSource(), file.path) : null
|
|
47
49
|
}
|
|
50
|
+
|
|
51
|
+
export type UpdatePropNamesOptions = {
|
|
52
|
+
[ComponentNames: string]: {
|
|
53
|
+
[versionNumber: string]: ComponentUpdateData[]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type ComponentUpdateData = {
|
|
58
|
+
old: string
|
|
59
|
+
new: string
|
|
60
|
+
values: { old: string | boolean; new: string | null }[]
|
|
61
|
+
}
|
|
@@ -22,7 +22,12 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
import type { JSCodeshift } from 'jscodeshift'
|
|
26
|
+
|
|
27
|
+
export default function createLiteral(
|
|
28
|
+
j: JSCodeshift,
|
|
29
|
+
value: string | boolean | number | null
|
|
30
|
+
) {
|
|
26
31
|
if (typeof value === 'string') {
|
|
27
32
|
return j.stringLiteral(value)
|
|
28
33
|
}
|
|
@@ -36,7 +41,7 @@ module.exports = function createLiteral(j, value) {
|
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
if (value === null) {
|
|
39
|
-
return j.jsxExpressionContainer(j.nullLiteral(
|
|
44
|
+
return j.jsxExpressionContainer(j.nullLiteral())
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
return null
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import type { UpdatePropNamesOptions } from '../updatePropNames'
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* Find the deprecated prop for a component
|
|
27
29
|
*
|
|
@@ -30,7 +32,11 @@
|
|
|
30
32
|
* @param {string} prop Property name
|
|
31
33
|
* @return {object} Object if a match is found, otherwise null
|
|
32
34
|
*/
|
|
33
|
-
|
|
35
|
+
export default function findDeprecatedProp(
|
|
36
|
+
config: UpdatePropNamesOptions,
|
|
37
|
+
comp: string,
|
|
38
|
+
prop: string
|
|
39
|
+
) {
|
|
34
40
|
if (config && comp && prop && config[comp]) {
|
|
35
41
|
const component = config[comp]
|
|
36
42
|
|
|
@@ -49,6 +55,5 @@ module.exports = function findDeprecatedProp(config, comp, prop) {
|
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
|
-
|
|
53
58
|
return null
|
|
54
59
|
}
|
|
@@ -22,19 +22,30 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
let importDeclaration
|
|
25
|
+
import { Collection, JSCodeshift } from 'jscodeshift'
|
|
27
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Finds an import statement with the given path in the given collection, e.g.
|
|
29
|
+
* "findImportDeclaration(j, root, 'myPath')" finds
|
|
30
|
+
* "import otherModule from 'myPath'"
|
|
31
|
+
* @param j JSCodeshift
|
|
32
|
+
* @param root the collection (AST tree) to search
|
|
33
|
+
* @param importPath the import path to look for
|
|
34
|
+
*/
|
|
35
|
+
export default function findImportDeclaration(
|
|
36
|
+
j: JSCodeshift,
|
|
37
|
+
root: Collection,
|
|
38
|
+
importPath: string
|
|
39
|
+
) {
|
|
40
|
+
let importDeclaration
|
|
28
41
|
const declarationQueryResult = root.find(j.ImportDeclaration, {
|
|
29
42
|
source: {
|
|
30
43
|
type: 'StringLiteral',
|
|
31
44
|
value: importPath
|
|
32
45
|
}
|
|
33
46
|
})
|
|
34
|
-
|
|
35
47
|
if (declarationQueryResult.length > 0) {
|
|
36
48
|
importDeclaration = declarationQueryResult.get()
|
|
37
49
|
}
|
|
38
|
-
|
|
39
50
|
return importDeclaration
|
|
40
51
|
}
|
|
@@ -22,11 +22,14 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
import { Transform } from '../updateImports'
|
|
26
|
+
import { ParsedImport } from './parseImport'
|
|
27
|
+
|
|
28
|
+
export default function findTransform(
|
|
29
|
+
transforms: Transform[],
|
|
30
|
+
importPath: string,
|
|
31
|
+
parsedImport: ParsedImport,
|
|
32
|
+
moduleName?: string
|
|
30
33
|
) {
|
|
31
34
|
return (
|
|
32
35
|
transforms.find(({ where = {} }) => {
|
|
@@ -57,7 +60,7 @@ module.exports = function findTransform(
|
|
|
57
60
|
} else {
|
|
58
61
|
foundTransform =
|
|
59
62
|
foundTransform &&
|
|
60
|
-
where.moduleNames.includes(parsedImport.moduleName)
|
|
63
|
+
where.moduleNames.includes(parsedImport.moduleName!)
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
|
|
@@ -72,7 +75,7 @@ module.exports = function findTransform(
|
|
|
72
75
|
performedTest = true
|
|
73
76
|
|
|
74
77
|
foundTransform =
|
|
75
|
-
foundTransform && where.packageNames.includes(parsedImport.fullName)
|
|
78
|
+
foundTransform && where.packageNames.includes(parsedImport.fullName!)
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
if (where.importPath) {
|
|
@@ -22,14 +22,13 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
import prettier from 'prettier'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
export default function formatSource(source: string, sourcePath: string) {
|
|
28
28
|
let options = null
|
|
29
29
|
|
|
30
30
|
try {
|
|
31
31
|
options = prettier.resolveConfig.sync(sourcePath)
|
|
32
|
-
|
|
33
32
|
if (options) {
|
|
34
33
|
// Set the parser argument if the consumer did not set one to avoid a console warning
|
|
35
34
|
options = {
|
|
@@ -38,7 +37,7 @@ module.exports = function formatSource(source, sourcePath) {
|
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
} catch (err) {
|
|
41
|
-
// Will revert to the
|
|
40
|
+
// Will revert to the default prettier options if a config cannot be parsed
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
return prettier.format(
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
import path from 'path'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
export default function parseImport(importPath: string): ParsedImport {
|
|
28
28
|
let parsedImport = {}
|
|
29
29
|
|
|
30
30
|
if (!importPath) return {}
|
|
31
31
|
|
|
32
32
|
const splitPath = importPath.split('/')
|
|
33
33
|
|
|
34
|
-
const parseSourceAndModule = (entries = []) => {
|
|
34
|
+
const parseSourceAndModule = (entries: string[] = []) => {
|
|
35
35
|
if (entries.length === 0) return {}
|
|
36
36
|
|
|
37
37
|
const lastEntry = entries[entries.length - 1]
|
|
@@ -66,6 +66,13 @@ module.exports = function parseImport(importPath) {
|
|
|
66
66
|
...parseSourceAndModule(rest)
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
|
|
70
69
|
return parsedImport
|
|
71
70
|
}
|
|
71
|
+
|
|
72
|
+
export type ParsedImport = {
|
|
73
|
+
scope?: string
|
|
74
|
+
name?: string
|
|
75
|
+
fullName?: string
|
|
76
|
+
moduleName?: string
|
|
77
|
+
sourcePath?: string
|
|
78
|
+
}
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
export default function requireUncached(module: string) {
|
|
25
26
|
delete require.cache[require.resolve(module)]
|
|
26
27
|
return require(module)
|
|
27
28
|
}
|