@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,230 +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
- ASTPath,
27
- Collection,
28
- JSCodeshift,
29
- JSXAttribute,
30
- JSXExpressionContainer,
31
- JSXIdentifier
32
- } from 'jscodeshift'
33
- import type {
34
- ComponentUpdateData,
35
- UpdatePropNamesOptions
36
- } from '../updatePropNames'
37
- import { printWarning } from './codemodHelpers'
38
-
39
- /**
40
- * DEPRECATED, this should be deleted in the future
41
- * Replaces deprecated pros and their values based on the given config
42
- * object
43
- * Example:
44
- * <Flex wrapItems -> <Flex wrap="wrap"
45
- */
46
- export default function replaceDeprecatedProps(
47
- filePath: string,
48
- j: JSCodeshift,
49
- root: Collection,
50
- config: UpdatePropNamesOptions
51
- ) {
52
- let hasModifications = false
53
- // Find JSX Elements
54
- //
55
- // Rewrite usages of deprecated props for a Component.
56
- root.find(j.JSXOpeningElement).forEach((el) => {
57
- const name = (el.value.name as JSXIdentifier).name
58
-
59
- // Make sure we're working with a Component that we need to modify
60
- if (config[name]) {
61
- j(el)
62
- .find(j.JSXAttribute)
63
- .forEach((attr) => {
64
- // Find identifiers
65
- j(attr)
66
- .find(j.JSXIdentifier)
67
- .forEach((i) => {
68
- const prop = i.value.name
69
- const match = findDeprecatedProp(config, name, prop)
70
- if (match) {
71
- hasModifications = true
72
- if (!match.new) {
73
- // If config sets the new name to null, the prop has been
74
- // removed. Remove the prop and value.
75
- j(attr).remove()
76
- } else {
77
- // Update the prop name if the config specifies a new name
78
- const newPropName = j.jsxIdentifier(match.new)
79
- j(i).replaceWith(newPropName)
80
-
81
- // If replacement values are specified, replace the value
82
- if (match.values && match.values.length > 0) {
83
- const expressionContainers = j(attr).find(
84
- j.JSXExpressionContainer
85
- )
86
- const literals = j(attr).find(j.Literal)
87
-
88
- if (
89
- expressionContainers &&
90
- expressionContainers.length > 0
91
- ) {
92
- // This means the value is contained in a jsx expression container. For example,
93
- // in the following jsx, `<div prop={someValue} />` we are looking at `{someValue}`
94
- expressionContainers.forEach((expressionContainer) => {
95
- // Verify that the expression container contains a literal
96
- if (
97
- expressionContainer.value.expression.type ===
98
- 'Literal'
99
- ) {
100
- replaceValue(
101
- j,
102
- literals,
103
- match,
104
- attr,
105
- expressionContainer
106
- )
107
- } else {
108
- printWarning(
109
- filePath,
110
- el.value.loc?.start.line,
111
- "Could not rename the value of '" +
112
- prop +
113
- "' because its value is a function or a variable " +
114
- 'reference. Please update manually.'
115
- )
116
- }
117
- })
118
- } else if (literals && literals.length > 0) {
119
- // If the value isn't in a jsx expression container, but we have a literal, that
120
- // means that the user is passing a string value. For example, in the following
121
- // jsx, `<div prop="someValue" />` we are looking at `"someValue"`
122
- replaceValue(j, literals, match, attr)
123
- } else {
124
- // If we don't have a jsx expression container or a string literal, that means that
125
- // we have just the attribute. For example, in the following jsx, `<div prop />`
126
- // we are looking at `prop`. Modify it so that it is a standard bool expression
127
- // and then execute replace like the others
128
- j(attr).replaceWith(
129
- j.jsxAttribute(newPropName, j.booleanLiteral(true))
130
- )
131
- // Look for literals again after update
132
- replaceValue(j, j(attr).find(j.Literal), match, attr)
133
- }
134
- }
135
- }
136
- }
137
- })
138
- })
139
- }
140
- })
141
-
142
- return hasModifications
143
- }
144
-
145
- const replaceValue = (
146
- j: JSCodeshift,
147
- literals: Collection,
148
- match: ComponentUpdateData,
149
- attr: ASTPath<JSXAttribute>,
150
- expressionContainer?: ASTPath<JSXExpressionContainer>
151
- ) => {
152
- literals.forEach((literalValue) => {
153
- const currentValue = literalValue.value.value
154
-
155
- // Find an old value provided that matches the existing value
156
- const valueUpdate = match.values.find((entry) => entry.old === currentValue)
157
-
158
- if (valueUpdate) {
159
- const newValue = valueUpdate.new
160
-
161
- if (typeof newValue === 'undefined') {
162
- j(attr).remove()
163
- } else {
164
- const replacement = createLiteral(j, newValue)
165
-
166
- if (replacement) {
167
- // Replace the entire expression container if present. If not, just replace the literal
168
- j(expressionContainer || literalValue).replaceWith(replacement)
169
- }
170
- }
171
- }
172
- })
173
- }
174
-
175
- /**
176
- * Find the deprecated prop for a component
177
- *
178
- * @param config Deprecated property configuration
179
- * @param comp Component name
180
- * @param prop Property name
181
- * @return Object if a match is found, otherwise null
182
- */
183
- const findDeprecatedProp = (
184
- config: UpdatePropNamesOptions,
185
- comp: string,
186
- prop: string
187
- ) => {
188
- if (config && comp && prop && config[comp]) {
189
- const component = config[comp]
190
-
191
- // Iterate versions
192
- const versions = Object.keys(component)
193
- for (let i = 0; i < versions.length; i++) {
194
- const props = component[versions[i]]
195
-
196
- // Iterate properties
197
- for (let j = 0; j < props.length; j++) {
198
- const match = props[j]
199
-
200
- if (prop === match.old) {
201
- return match
202
- }
203
- }
204
- }
205
- }
206
- return null
207
- }
208
-
209
- const createLiteral = (
210
- j: JSCodeshift,
211
- value: string | boolean | number | null
212
- ) => {
213
- if (typeof value === 'string') {
214
- return j.stringLiteral(value)
215
- }
216
-
217
- if (typeof value === 'number') {
218
- return j.jsxExpressionContainer(j.numericLiteral(value))
219
- }
220
-
221
- if (typeof value === 'boolean') {
222
- return j.jsxExpressionContainer(j.booleanLiteral(value))
223
- }
224
-
225
- if (value === null) {
226
- return j.jsxExpressionContainer(j.nullLiteral())
227
- }
228
-
229
- return null
230
- }
@@ -1,86 +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 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 type { ParsedImport } from './helpers/replaceDeprecatedImports'
32
-
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) {
41
- const j = api.jscodeshift
42
- const c = path.resolve(process.cwd(), options.config)
43
- let config:
44
- | ConfigObject
45
- | ((opts: { isMetaComponentPackageMigration: boolean }) => ConfigObject) =
46
- fs.existsSync(c) ? requireUncached(c) : null
47
- if (!config) {
48
- throw new Error(`Invalid config file "${c}", is this the correct path?`)
49
- }
50
- if (typeof config === 'function') {
51
- const configOptions = {
52
- isMetaComponentPackageMigration: options.isMetaComponentPackageMigration
53
- }
54
- config = config(configOptions)
55
- }
56
- const root = j(file.source)
57
- let hasModifications = false
58
-
59
- hasModifications =
60
- replaceDeprecatedImports(j, root, config, api) || hasModifications
61
-
62
- return hasModifications ? formatSource(root.toSource(), file.path) : null
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
- }
@@ -1,66 +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 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'
31
-
32
- export default function updatePropNames(
33
- file: FileInfo,
34
- api: API,
35
- options: any
36
- ) {
37
- const j = api.jscodeshift
38
- const c = path.resolve(process.cwd(), options.config)
39
- const config: UpdatePropNamesOptions = fs.existsSync(c)
40
- ? requireUncached(c)
41
- : null
42
-
43
- if (!config) {
44
- throw new Error(`Invalid config file "${c}"`)
45
- }
46
-
47
- const root = j(file.source)
48
- let hasModifications = false
49
-
50
- hasModifications =
51
- replaceDeprecatedProps(file.path, j, root, config) || hasModifications
52
-
53
- return hasModifications ? formatSource(root.toSource(), file.path) : null
54
- }
55
-
56
- export type UpdatePropNamesOptions = {
57
- [ComponentNames: string]: {
58
- [versionNumber: string]: ComponentUpdateData[]
59
- }
60
- }
61
-
62
- export type ComponentUpdateData = {
63
- old: string
64
- new: string
65
- values: { old: string | boolean; new: string | null }[]
66
- }
@@ -1,101 +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 { API, Collection, FileInfo, JSCodeshift } from 'jscodeshift'
26
- import formatSource from './utils/formatSource'
27
- import { findImport, writeWarningsToFile } from './helpers/codemodHelpers'
28
- import updateV7ButtonsMisc from './utils/updateV7ButtonsMisc'
29
- import updateV7ButtonsWithText from './utils/updateV7ButtonsWithText'
30
- import updateV7ButtonsIconCircle from './utils/updateV7ButtonsIconCircle'
31
- import updateV7ButtonsClose from './utils/updateV7ButtonsClose'
32
- import UpdateV7ButtonsLink from './utils/UpdateV7ButtonsLink'
33
- import updateV7Heading from './utils/updateV7Heading'
34
- import updateV7Lists from './utils/updateV7Lists'
35
- import updateV7Pill from './utils/updateV7Pill'
36
- import updateV7Popover from './utils/updateV7Popover'
37
- import updateV7Tabs from './utils/updateV7Tabs'
38
- import updateV7FocusableView from './utils/updateV7FocusableView'
39
- import warnV7ComponentDeprecations from './utils/warnV7ComponentDeprecations'
40
-
41
- /**
42
- * Updates complex code from the InstUI v7 syntax to the v8 syntax.
43
- * This script contains the codemods referenced in
44
- * https://instructure.design/v7/#button-upgrade-guide and in
45
- * https://instructure.design/v7/#v7-deprecated-props-and-components
46
- * It can handle if a component and its attributes are defined in JSX; if its
47
- * imported via an alias (`import {Button as BBB}`) is OK too.
48
- * It cannot handle if props are added via the spread operator or programmatically.
49
- * @param file Holds information about the currently processed file.
50
- * @param api This object exposes the JSCodeshift library and helper functions
51
- * from the runner.
52
- * @param options pass a fileName parameter to write the warnings to a file.
53
- * @returns {*|null} null if there was nothing to reformat
54
- */
55
- export default function updateV7Props(
56
- file: FileInfo,
57
- api: API,
58
- options?: { fileName: string }
59
- ) {
60
- const j = api.jscodeshift
61
- const root = j(file.source)
62
- const hasModifications = updateProps(j, root, file.path)
63
- if (options && options.fileName) {
64
- writeWarningsToFile(options.fileName)
65
- }
66
- return hasModifications ? formatSource(root.toSource(), file.path) : null
67
- }
68
-
69
- function updateProps(j: JSCodeshift, root: Collection, filePath: string) {
70
- const buttonImportName = findImport(j, root, 'Button', [
71
- '@instructure/ui-buttons',
72
- '@instructure/ui'
73
- ])
74
- if (buttonImportName) {
75
- updateV7ButtonsMisc(j, root, buttonImportName, filePath)
76
- updateV7ButtonsWithText(j, root, buttonImportName, filePath)
77
- updateV7ButtonsIconCircle(j, root, buttonImportName, filePath)
78
- UpdateV7ButtonsLink(j, root, buttonImportName, filePath)
79
- }
80
- const closeButtonUpdated = updateV7ButtonsClose(j, root, filePath)
81
- const headingUpdated = updateV7Heading(j, root, filePath)
82
- const listsUpdated = updateV7Lists(j, root, filePath)
83
- const pillUpdated = updateV7Pill(j, root, filePath)
84
- const popoverUpdated = updateV7Popover(j, root, filePath)
85
- const tabsUpdated = updateV7Tabs(j, root, filePath)
86
- const focusableViewUpdated = updateV7FocusableView(j, root, filePath)
87
- warnV7ComponentDeprecations(j, root, filePath)
88
- if (
89
- buttonImportName ||
90
- closeButtonUpdated ||
91
- headingUpdated ||
92
- listsUpdated ||
93
- pillUpdated ||
94
- popoverUpdated ||
95
- tabsUpdated ||
96
- focusableViewUpdated
97
- ) {
98
- return formatSource(root.toSource(), filePath)
99
- }
100
- return null
101
- }
@@ -1,49 +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 { API, Collection, FileInfo, JSCodeshift } from 'jscodeshift'
26
- import { writeWarningsToFile } from './helpers/codemodHelpers'
27
- import formatSource from './utils/formatSource'
28
- import { updateToV8Theming } from './utils/updateToV8Theming'
29
- import updateV8ThemeProp from './utils/updateV8ThemeProp'
30
-
31
- export default function updateV8Breaking(
32
- file: FileInfo,
33
- api: API,
34
- options?: { fileName: string }
35
- ) {
36
- const j = api.jscodeshift
37
- const root = j(file.source)
38
- const hasModifications = doUpdate(j, root, file.path)
39
- if (options && options.fileName) {
40
- writeWarningsToFile(options.fileName)
41
- }
42
- return hasModifications ? formatSource(root.toSource(), file.path) : null
43
- }
44
-
45
- function doUpdate(j: JSCodeshift, root: Collection, filePath: string) {
46
- const themeUpdated = updateToV8Theming(j, root, filePath)
47
- const themePropUpdated = updateV8ThemeProp(j, root)
48
- return themeUpdated || themePropUpdated
49
- }
@@ -1,61 +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 { API, FileInfo } from 'jscodeshift'
26
- import { writeWarningsToFile } from './helpers/codemodHelpers'
27
- import formatSource from './utils/formatSource'
28
- import updateV8RenderProp from './utils/updateV8RenderProp'
29
-
30
- export default function updateV8Breaking(
31
- file: FileInfo,
32
- api: API,
33
- options?: {
34
- fileName: string
35
- wrapperPath: string
36
- wrapperTag: string
37
- isDefaultImport: true
38
- }
39
- ) {
40
- const j = api.jscodeshift
41
- const root = j(file.source)
42
- const finalOptions = {
43
- wrapperPath: '@canvas/react-root',
44
- wrapperTag: 'Root',
45
- isDefaultImport: true
46
- }
47
- if (options && options.wrapperPath) {
48
- finalOptions.wrapperPath = options.wrapperPath
49
- }
50
- if (options && options.wrapperTag) {
51
- finalOptions.wrapperTag = options.wrapperTag
52
- }
53
- if (options && options.isDefaultImport) {
54
- finalOptions.isDefaultImport = options.isDefaultImport
55
- }
56
- const hasModifications = updateV8RenderProp(j, root, file.path, finalOptions)
57
- if (options && options.fileName) {
58
- writeWarningsToFile(options.fileName)
59
- }
60
- return hasModifications ? formatSource(root.toSource(), file.path) : null
61
- }
@@ -1,54 +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 { API, Collection, FileInfo, JSCodeshift } from 'jscodeshift'
26
- import { writeWarningsToFile } from './helpers/codemodHelpers'
27
- import formatSource from './utils/formatSource'
28
- import { updateToV9Theming } from './utils/updateToV9Theming'
29
-
30
- export default function updateV9Breaking(
31
- file: FileInfo,
32
- api: API,
33
- options?: { fileName: string; usePrettier?: boolean }
34
- ) {
35
- const j = api.jscodeshift
36
- const root = j(file.source)
37
- const hasModifications = doUpdate(j, root, file.path)
38
- if (options && options.fileName) {
39
- writeWarningsToFile(options.fileName)
40
- }
41
-
42
- if (hasModifications) {
43
- const shouldUsePrettier = options?.usePrettier !== false
44
- return shouldUsePrettier
45
- ? formatSource(root.toSource(), file.path)
46
- : root.toSource()
47
- } else {
48
- return null
49
- }
50
- }
51
-
52
- function doUpdate(j: JSCodeshift, root: Collection, filePath: string) {
53
- return updateToV9Theming(j, root, filePath)
54
- }