@carbon/upgrade 10.17.0-rc.0 → 10.17.1
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/README.md +9 -0
- package/cli.js +2288 -466
- package/package.json +12 -7
- package/telemetry.yml +7 -0
- package/transforms/ARCHITECTURE.md +47 -0
- package/transforms/__testfixtures__/icons-react-size-prop-object-key.input.js +16 -0
- package/transforms/__testfixtures__/icons-react-size-prop-object-key.output.js +16 -0
- package/transforms/__testfixtures__/icons-react-size-prop-rename.input.js +44 -0
- package/transforms/__testfixtures__/icons-react-size-prop-rename.output.js +44 -0
- package/transforms/__testfixtures__/icons-react-size-prop-with-prop.input.js +19 -0
- package/transforms/__testfixtures__/icons-react-size-prop-with-prop.output.js +22 -0
- package/transforms/__testfixtures__/size-prop-update.input.js +143 -0
- package/transforms/__testfixtures__/size-prop-update.output.js +143 -0
- package/transforms/__testfixtures__/small-to-size-prop.input.js +11 -0
- package/transforms/__testfixtures__/small-to-size-prop.output.js +11 -0
- package/transforms/__testfixtures__/sort-prop-types.input.js +7 -0
- package/transforms/__testfixtures__/sort-prop-types.output.js +7 -0
- package/transforms/__testfixtures__/sort-prop-types2.input.js +7 -0
- package/transforms/__testfixtures__/sort-prop-types2.output.js +7 -0
- package/transforms/__testfixtures__/update-carbon-components-react-import-to-scoped.input.js +8 -0
- package/transforms/__testfixtures__/update-carbon-components-react-import-to-scoped.output.js +8 -0
- package/transforms/__tests__/icons-react-size-prop.js +64 -0
- package/transforms/__tests__/size-prop-update-test.js +12 -0
- package/transforms/__tests__/small-to-size-test.js +12 -0
- package/transforms/__tests__/sort-prop-types-test.js +13 -0
- package/transforms/__tests__/update-carbon-components-react-import-to-scoped.js +12 -0
- package/transforms/icons-react-size-prop.js +324 -0
- package/transforms/size-prop-update.js +140 -0
- package/transforms/small-to-size-prop.js +56 -0
- package/transforms/sort-prop-types.js +88 -0
- package/transforms/update-carbon-components-react-import-to-scoped.js +33 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2020
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
quote: 'single',
|
|
12
|
+
trailingComma: true,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function transform(fileInfo, api, options) {
|
|
16
|
+
const printOptions = options.printOptions || defaultOptions;
|
|
17
|
+
const j = api.jscodeshift;
|
|
18
|
+
const root = j(fileInfo.source);
|
|
19
|
+
|
|
20
|
+
root
|
|
21
|
+
.find(j.AssignmentExpression, {
|
|
22
|
+
left: {
|
|
23
|
+
type: 'MemberExpression',
|
|
24
|
+
property: {
|
|
25
|
+
name: 'propTypes',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
.forEach((path) => {
|
|
30
|
+
path.node.right.properties.sort((a, b) => {
|
|
31
|
+
if (a.type === 'Property' && b.type === 'Property') {
|
|
32
|
+
if (getPropName(a) > getPropName(b)) {
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (a.type === 'SpreadElement' && b.type === 'SpreadElement') {
|
|
39
|
+
if (getPropName(a) > getPropName(b)) {
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
return -1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (a.type === 'SpreadElement') {
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return 1;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
root
|
|
54
|
+
.find(j.ClassProperty, {
|
|
55
|
+
key: {
|
|
56
|
+
name: 'propTypes',
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
.forEach((path) => {
|
|
60
|
+
path.node.value.properties.sort((a, b) => {
|
|
61
|
+
if (getPropName(a) > getPropName(b)) {
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
return -1;
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function getPropName(node) {
|
|
69
|
+
if (node.type === 'SpreadElement') {
|
|
70
|
+
return node.argument.name;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (node.type === 'Property') {
|
|
74
|
+
if (node.key.type === 'Identifier') {
|
|
75
|
+
return node.key.name;
|
|
76
|
+
}
|
|
77
|
+
if (node.key.type === 'Literal') {
|
|
78
|
+
return node.key.value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
throw new Error(`Unknown node of type: ${node.type}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return root.toSource(printOptions);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = transform;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2020
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* Rewrites imports from 'carbon-components-react' to '@carbon/react'
|
|
8
|
+
*
|
|
9
|
+
* Transforms:
|
|
10
|
+
*
|
|
11
|
+
* import { Button } from 'carbon-components-react';
|
|
12
|
+
*
|
|
13
|
+
* Into:
|
|
14
|
+
*
|
|
15
|
+
* import { Button } from "@carbon/react";
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const parser = 'babel';
|
|
19
|
+
|
|
20
|
+
export default function transformer(file, api) {
|
|
21
|
+
const j = api.jscodeshift;
|
|
22
|
+
|
|
23
|
+
return j(file.source)
|
|
24
|
+
.find(j.ImportDeclaration, {
|
|
25
|
+
source: {
|
|
26
|
+
value: 'carbon-components-react',
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
.forEach((path) => {
|
|
30
|
+
path.get('source').replace(j.stringLiteral('@carbon/react'));
|
|
31
|
+
})
|
|
32
|
+
.toSource();
|
|
33
|
+
}
|