@carbon/upgrade 10.17.0-rc.0 → 10.17.0

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 (29) hide show
  1. package/cli.js +2159 -394
  2. package/package.json +8 -6
  3. package/transforms/ARCHITECTURE.md +47 -0
  4. package/transforms/__testfixtures__/icons-react-size-prop-object-key.input.js +16 -0
  5. package/transforms/__testfixtures__/icons-react-size-prop-object-key.output.js +16 -0
  6. package/transforms/__testfixtures__/icons-react-size-prop-rename.input.js +44 -0
  7. package/transforms/__testfixtures__/icons-react-size-prop-rename.output.js +44 -0
  8. package/transforms/__testfixtures__/icons-react-size-prop-with-prop.input.js +19 -0
  9. package/transforms/__testfixtures__/icons-react-size-prop-with-prop.output.js +22 -0
  10. package/transforms/__testfixtures__/size-prop-update.input.js +143 -0
  11. package/transforms/__testfixtures__/size-prop-update.output.js +143 -0
  12. package/transforms/__testfixtures__/small-to-size-prop.input.js +11 -0
  13. package/transforms/__testfixtures__/small-to-size-prop.output.js +11 -0
  14. package/transforms/__testfixtures__/sort-prop-types.input.js +7 -0
  15. package/transforms/__testfixtures__/sort-prop-types.output.js +7 -0
  16. package/transforms/__testfixtures__/sort-prop-types2.input.js +7 -0
  17. package/transforms/__testfixtures__/sort-prop-types2.output.js +7 -0
  18. package/transforms/__testfixtures__/update-carbon-components-react-import-to-scoped.input.js +8 -0
  19. package/transforms/__testfixtures__/update-carbon-components-react-import-to-scoped.output.js +8 -0
  20. package/transforms/__tests__/icons-react-size-prop.js +64 -0
  21. package/transforms/__tests__/size-prop-update-test.js +12 -0
  22. package/transforms/__tests__/small-to-size-test.js +12 -0
  23. package/transforms/__tests__/sort-prop-types-test.js +13 -0
  24. package/transforms/__tests__/update-carbon-components-react-import-to-scoped.js +12 -0
  25. package/transforms/icons-react-size-prop.js +324 -0
  26. package/transforms/size-prop-update.js +140 -0
  27. package/transforms/small-to-size-prop.js +56 -0
  28. package/transforms/sort-prop-types.js +88 -0
  29. package/transforms/update-carbon-components-react-import-to-scoped.js +33 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/upgrade",
3
3
  "description": "A tool for upgrading Carbon versions",
4
- "version": "10.17.0-rc.0",
4
+ "version": "10.17.0",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
7
7
  "carbon-upgrade": "./bin/carbon-upgrade.js"
@@ -14,7 +14,8 @@
14
14
  "bugs": "https://github.com/carbon-design-system/carbon/issues",
15
15
  "files": [
16
16
  "bin",
17
- "cli.js"
17
+ "cli.js",
18
+ "transforms"
18
19
  ],
19
20
  "keywords": [
20
21
  "carbon",
@@ -30,14 +31,13 @@
30
31
  "access": "public"
31
32
  },
32
33
  "scripts": {
33
- "build": "esbuild src/cli.js --bundle --platform=node --outfile=cli.js --target=node14",
34
+ "build": "esbuild src/cli.js --bundle --platform=node --outfile=cli.js --target=node14 --external:jscodeshift",
34
35
  "clean": "rimraf cli.js",
35
36
  "watch": "yarn build --watch"
36
37
  },
37
38
  "devDependencies": {
38
39
  "chalk": "^4.1.1",
39
40
  "change-case": "^4.1.2",
40
- "cross-spawn": "^7.0.3",
41
41
  "esbuild": "^0.14.10",
42
42
  "execa": "^5.1.1",
43
43
  "fast-glob": "^3.2.7",
@@ -45,7 +45,6 @@
45
45
  "inquirer": "^8.1.0",
46
46
  "is-git-clean": "^1.1.0",
47
47
  "jest-diff": "^27.4.6",
48
- "jscodeshift": "^0.13.0",
49
48
  "lodash.clonedeep": "^4.5.0",
50
49
  "lodash.merge": "^4.6.2",
51
50
  "memfs": "^3.4.0",
@@ -55,5 +54,8 @@
55
54
  "semver": "^7.3.5",
56
55
  "yargs": "^17.0.1"
57
56
  },
58
- "gitHead": "885c987334058efa5ba30582d615c04de2e631a4"
57
+ "dependencies": {
58
+ "jscodeshift": "^0.13.1"
59
+ },
60
+ "gitHead": "e76c42ab78cbee043db643597b7b5d79bd387c9b"
59
61
  }
@@ -0,0 +1,47 @@
1
+ # transforms
2
+
3
+ > A folder of codemod transforms to be ran independently or via the
4
+ > @carbon/upgrade cli
5
+
6
+ ## Usage
7
+
8
+ The transforms contained within this folder are primarily intended to be used
9
+ within @carbon/upgrade cli commands.
10
+
11
+ You can run a specific transform for a path in the project by running:
12
+
13
+ ```bash
14
+ yarn jscodeshift -t transforms/<name>.js 'path/to/file'
15
+ ```
16
+
17
+ If you want to preview changes that are being made, you should enable the `dry`
18
+ and `print` options:
19
+
20
+ ```bash
21
+ yarn jscodeshift -d -p -t transforms/<name>.js 'path/to/file'
22
+ ```
23
+
24
+ ## Writing transforms
25
+
26
+ Transforms are written in the `transforms` directory with their tests and
27
+ fixtures written in the `__tests__` and `__testfixtures__` directories,
28
+ accordingly.
29
+
30
+ As an example, to add a transform called `sort-prop-types` oone would create the
31
+ following files:
32
+
33
+ ```
34
+ - codemods
35
+ - transforms
36
+ - __testfixtures__
37
+ - sort-prop-types.input.js
38
+ - sort-prop-types.output.js
39
+ - __tests__
40
+ - sort-prop-types-test.js
41
+ - sort-prop-types.js
42
+ ```
43
+
44
+ In this structure, the test file will determine which test fixtures get run.
45
+ Test fixtures are written with a `*.input.js` and `*.output.js` convention.
46
+ Files that end with `*.input.js` are given to your transform and the test runner
47
+ will assert that the output matches what is available in `*.output.js`.
@@ -0,0 +1,16 @@
1
+ import { Add16, Add32 } from '@carbon/icons-react';
2
+
3
+ const icons = {
4
+ Add16,
5
+ // prettier-ignore
6
+ Add32,
7
+ };
8
+
9
+ const options = {
10
+ Add16: 'Add16',
11
+ Add32: 'Add32',
12
+ };
13
+
14
+ function TestComponent() {
15
+ return <div>{icons[options['Add16']]}</div>;
16
+ }
@@ -0,0 +1,16 @@
1
+ import { Add } from '@carbon/icons-react/next';
2
+
3
+ const icons = {
4
+ Add16: Add,
5
+ // prettier-ignore
6
+ Add32: props => <Add size={32} {...props} />,
7
+ };
8
+
9
+ const options = {
10
+ Add16: 'Add16',
11
+ Add32: 'Add32',
12
+ };
13
+
14
+ function TestComponent() {
15
+ return <div>{icons[options['Add16']]}</div>;
16
+ }
@@ -0,0 +1,44 @@
1
+ import {
2
+ Add32,
3
+ Bee24,
4
+ Caret20,
5
+ DownArrow16,
6
+ Search24,
7
+ Zone24 as CustomZone,
8
+ } from '@carbon/icons-react';
9
+ import { Search } from 'test';
10
+
11
+ function RendersIconDirectly() {
12
+ return (
13
+ <div>
14
+ <Add32 />
15
+ <Bee24 />
16
+ <Caret20 />
17
+ <DownArrow16 />
18
+ </div>
19
+ );
20
+ }
21
+
22
+ function RendersIconWithProps(props) {
23
+ return (
24
+ <div>
25
+ <Add32 aria-label="test" {...props} />
26
+ <Bee24 aria-label="test" {...props} />
27
+ <Caret20 aria-label="test" {...props} />
28
+ <DownArrow16 aria-label="test" {...props} />
29
+ </div>
30
+ );
31
+ }
32
+
33
+ function AliasedIcon() {
34
+ return <CustomZone />;
35
+ }
36
+
37
+ function ExistingScope() {
38
+ return (
39
+ <div>
40
+ <Search />
41
+ <Search24 />
42
+ </div>
43
+ );
44
+ }
@@ -0,0 +1,44 @@
1
+ import {
2
+ Add,
3
+ Bee,
4
+ Caret,
5
+ DownArrow,
6
+ Search as SearchIcon,
7
+ Zone as CustomZone,
8
+ } from '@carbon/icons-react/next';
9
+ import { Search } from 'test';
10
+
11
+ function RendersIconDirectly() {
12
+ return (
13
+ <div>
14
+ <Add size={32} />
15
+ <Bee size={24} />
16
+ <Caret size={20} />
17
+ <DownArrow />
18
+ </div>
19
+ );
20
+ }
21
+
22
+ function RendersIconWithProps(props) {
23
+ return (
24
+ <div>
25
+ <Add size={32} aria-label="test" {...props} />
26
+ <Bee size={24} aria-label="test" {...props} />
27
+ <Caret size={20} aria-label="test" {...props} />
28
+ <DownArrow aria-label="test" {...props} />
29
+ </div>
30
+ );
31
+ }
32
+
33
+ function AliasedIcon() {
34
+ return <CustomZone size={24} />;
35
+ }
36
+
37
+ function ExistingScope() {
38
+ return (
39
+ <div>
40
+ <Search />
41
+ <SearchIcon size={24} />
42
+ </div>
43
+ );
44
+ }
@@ -0,0 +1,19 @@
1
+ import { Add16, Bee24, Chevron24 as chevron } from '@carbon/icons-react';
2
+
3
+ const mapped = {
4
+ default: Add16,
5
+ // prettier-ignore
6
+ size: Bee24,
7
+ // prettier-ignore
8
+ lowercase: chevron,
9
+ };
10
+
11
+ function RenderIconProp() {
12
+ // prettier-ignore
13
+ return (
14
+ <div>
15
+ <DefaultSize renderIcon={Add16} />
16
+ <Size renderIcon={Bee24} />
17
+ </div>
18
+ );
19
+ }
@@ -0,0 +1,22 @@
1
+ import { Add, Bee, Chevron as chevron } from '@carbon/icons-react/next';
2
+
3
+ const mapped = {
4
+ default: Add,
5
+ // prettier-ignore
6
+ size: props => <Bee size={24} {...props} />,
7
+ // prettier-ignore
8
+ lowercase: props => React.createElement(chevron, {
9
+ size: 24,
10
+ ...props
11
+ }),
12
+ };
13
+
14
+ function RenderIconProp() {
15
+ // prettier-ignore
16
+ return (
17
+ <div>
18
+ <DefaultSize renderIcon={Add} />
19
+ <Size renderIcon={props => <Bee size={24} {...props} />} />
20
+ </div>
21
+ );
22
+ }
@@ -0,0 +1,143 @@
1
+ function Accordion() {
2
+ return (
3
+ <div>
4
+ <Accordion className="test" size="xl" />
5
+ <Accordion className="test" size="xl">
6
+ <AccordionItem>Test</AccordionItem>
7
+ </Accordion>
8
+ </div>
9
+ );
10
+ }
11
+
12
+ function Button() {
13
+ return (
14
+ <div>
15
+ <Button className="test" size="small" />
16
+ <Button className="test" size="field"></Button>
17
+ <Button className="test" size="default"></Button>
18
+ <Button className="test" size="lg"></Button>
19
+ <Button className="test" size="xl"></Button>
20
+ </div>
21
+ );
22
+ }
23
+
24
+ function ComboBox() {
25
+ return <ComboBox className="test" size="xl" />;
26
+ }
27
+
28
+ function ContentSwitcher() {
29
+ return (
30
+ <ContentSwitcher className="test" size="xl">
31
+ <Switch name="one" text="First section" />
32
+ <Switch name="two" text="Second section" />
33
+ <Switch name="three" text="Third section" />
34
+ </ContentSwitcher>
35
+ );
36
+ }
37
+
38
+ function Dropdown() {
39
+ return <Dropdown className="test" size="xl" />;
40
+ }
41
+
42
+ function DataTable() {
43
+ return (
44
+ <div>
45
+ <Table className="test" size="compact"></Table>
46
+ <Table className="test" size="short"></Table>
47
+ <Table className="test" size="tall"></Table>
48
+ <DataTable className="test" size="compact"></DataTable>
49
+ <DataTable className="test" size="short"></DataTable>
50
+ <DataTable className="test" size="tall"></DataTable>
51
+ </div>
52
+ );
53
+ }
54
+
55
+ function DatePicker() {
56
+ return (
57
+ <DatePicker datePickerType="single">
58
+ <DatePickerInput
59
+ size="xl"
60
+ id="datepicker"
61
+ labelText="Datepicker Test"></DatePickerInput>
62
+ </DatePicker>
63
+ );
64
+ }
65
+
66
+ function FileUploader() {
67
+ return (
68
+ <div>
69
+ <FileUploader size="small"></FileUploader>
70
+ <FileUploader size="field"></FileUploader>
71
+ <FileUploader size="default"></FileUploader>
72
+ <FileUploaderItem size="small"></FileUploaderItem>
73
+ <FileUploaderItem size="field"></FileUploaderItem>
74
+ <FileUploaderItem size="default"></FileUploaderItem>
75
+ <FileUploaderButton size="small"></FileUploaderButton>
76
+ <FileUploaderButton size="field"></FileUploaderButton>
77
+ <FileUploaderButton size="default"></FileUploaderButton>
78
+ <FileUploaderDropContainer size="small"></FileUploaderDropContainer>
79
+ <FileUploaderDropContainer size="field"></FileUploaderDropContainer>
80
+ <FileUploaderDropContainer size="default"></FileUploaderDropContainer>
81
+ </div>
82
+ );
83
+ }
84
+
85
+ function Link() {
86
+ return <Link size="lg" />;
87
+ }
88
+
89
+ function MultiSelect() {
90
+ return (
91
+ <div>
92
+ <MultiSelect
93
+ size="xl"
94
+ items={items}
95
+ itemToString={(item) => (item ? item.text : '')}
96
+ />
97
+ <MultiSelect.Filterable
98
+ size="xl"
99
+ items={items}
100
+ itemToString={(item) => (item ? item.text : '')}
101
+ />
102
+ </div>
103
+ );
104
+ }
105
+
106
+ function NumberInput() {
107
+ return <NumberInput size="xl" id="numberinput"></NumberInput>;
108
+ }
109
+
110
+ function OverflowMenu() {
111
+ return <OverflowMenu size="xl" className="test"></OverflowMenu>;
112
+ }
113
+
114
+ function Search() {
115
+ return (
116
+ <div>
117
+ <Search className="test" size="lg" />
118
+ <Search className="test" size="xl" />
119
+ </div>
120
+ );
121
+ }
122
+
123
+ function Select() {
124
+ return (
125
+ <div>
126
+ <Select className="test" size="lg" />
127
+ <Select className="test" size="xl" />
128
+ </div>
129
+ );
130
+ }
131
+
132
+ function TextInput() {
133
+ return (
134
+ <div>
135
+ <TextInput size="lg" id="textinput1" labelText="lg -> md"></TextInput>
136
+ <TextInput size="xl" id="textinput1" labelText="xl -> lg"></TextInput>
137
+ </div>
138
+ );
139
+ }
140
+
141
+ function TimePicker() {
142
+ return <TimePicker size="xl" id="timeinput" />;
143
+ }
@@ -0,0 +1,143 @@
1
+ function Accordion() {
2
+ return (
3
+ <div>
4
+ <Accordion className="test" size="lg" />
5
+ <Accordion className="test" size="lg">
6
+ <AccordionItem>Test</AccordionItem>
7
+ </Accordion>
8
+ </div>
9
+ );
10
+ }
11
+
12
+ function Button() {
13
+ return (
14
+ <div>
15
+ <Button className="test" size="sm" />
16
+ <Button className="test" size="md"></Button>
17
+ <Button className="test" size="lg"></Button>
18
+ <Button className="test" size="xl"></Button>
19
+ <Button className="test" size="2xl"></Button>
20
+ </div>
21
+ );
22
+ }
23
+
24
+ function ComboBox() {
25
+ return <ComboBox className="test" size="lg" />;
26
+ }
27
+
28
+ function ContentSwitcher() {
29
+ return (
30
+ <ContentSwitcher className="test" size="lg">
31
+ <Switch name="one" text="First section" />
32
+ <Switch name="two" text="Second section" />
33
+ <Switch name="three" text="Third section" />
34
+ </ContentSwitcher>
35
+ );
36
+ }
37
+
38
+ function Dropdown() {
39
+ return <Dropdown className="test" size="lg" />;
40
+ }
41
+
42
+ function DataTable() {
43
+ return (
44
+ <div>
45
+ <Table className="test" size="xs"></Table>
46
+ <Table className="test" size="sm"></Table>
47
+ <Table className="test" size="xl"></Table>
48
+ <DataTable className="test" size="xs"></DataTable>
49
+ <DataTable className="test" size="sm"></DataTable>
50
+ <DataTable className="test" size="xl"></DataTable>
51
+ </div>
52
+ );
53
+ }
54
+
55
+ function DatePicker() {
56
+ return (
57
+ <DatePicker datePickerType="single">
58
+ <DatePickerInput
59
+ size="lg"
60
+ id="datepicker"
61
+ labelText="Datepicker Test"></DatePickerInput>
62
+ </DatePicker>
63
+ );
64
+ }
65
+
66
+ function FileUploader() {
67
+ return (
68
+ <div>
69
+ <FileUploader size="sm"></FileUploader>
70
+ <FileUploader size="md"></FileUploader>
71
+ <FileUploader size="lg"></FileUploader>
72
+ <FileUploaderItem size="sm"></FileUploaderItem>
73
+ <FileUploaderItem size="md"></FileUploaderItem>
74
+ <FileUploaderItem size="lg"></FileUploaderItem>
75
+ <FileUploaderButton size="sm"></FileUploaderButton>
76
+ <FileUploaderButton size="md"></FileUploaderButton>
77
+ <FileUploaderButton size="lg"></FileUploaderButton>
78
+ <FileUploaderDropContainer size="sm"></FileUploaderDropContainer>
79
+ <FileUploaderDropContainer size="md"></FileUploaderDropContainer>
80
+ <FileUploaderDropContainer size="lg"></FileUploaderDropContainer>
81
+ </div>
82
+ );
83
+ }
84
+
85
+ function Link() {
86
+ return <Link size="lg" />;
87
+ }
88
+
89
+ function MultiSelect() {
90
+ return (
91
+ <div>
92
+ <MultiSelect
93
+ size="lg"
94
+ items={items}
95
+ itemToString={(item) => (item ? item.text : '')}
96
+ />
97
+ <MultiSelect.Filterable
98
+ size="lg"
99
+ items={items}
100
+ itemToString={(item) => (item ? item.text : '')}
101
+ />
102
+ </div>
103
+ );
104
+ }
105
+
106
+ function NumberInput() {
107
+ return <NumberInput size="lg" id="numberinput"></NumberInput>;
108
+ }
109
+
110
+ function OverflowMenu() {
111
+ return <OverflowMenu size="lg" className="test"></OverflowMenu>;
112
+ }
113
+
114
+ function Search() {
115
+ return (
116
+ <div>
117
+ <Search className="test" size="md" />
118
+ <Search className="test" size="lg" />
119
+ </div>
120
+ );
121
+ }
122
+
123
+ function Select() {
124
+ return (
125
+ <div>
126
+ <Select className="test" size="md" />
127
+ <Select className="test" size="lg" />
128
+ </div>
129
+ );
130
+ }
131
+
132
+ function TextInput() {
133
+ return (
134
+ <div>
135
+ <TextInput size="md" id="textinput1" labelText="lg -> md"></TextInput>
136
+ <TextInput size="lg" id="textinput1" labelText="xl -> lg"></TextInput>
137
+ </div>
138
+ );
139
+ }
140
+
141
+ function TimePicker() {
142
+ return <TimePicker size="lg" id="timeinput" />;
143
+ }
@@ -0,0 +1,11 @@
1
+ function Test1() {
2
+ return <Button className="test" small />;
3
+ }
4
+
5
+ function Test2() {
6
+ return (
7
+ <Button className="test" small>
8
+ Test
9
+ </Button>
10
+ );
11
+ }
@@ -0,0 +1,11 @@
1
+ function Test1() {
2
+ return <Button className="test" size="sm" />;
3
+ }
4
+
5
+ function Test2() {
6
+ return (
7
+ <Button className="test" size="sm">
8
+ Test
9
+ </Button>
10
+ );
11
+ }
@@ -0,0 +1,7 @@
1
+ function MyComponent() {}
2
+
3
+ MyComponent.propTypes = {
4
+ a: PropTypes.string,
5
+ c: PropTypes.string,
6
+ b: PropTypes.string,
7
+ };
@@ -0,0 +1,7 @@
1
+ function MyComponent() {}
2
+
3
+ MyComponent.propTypes = {
4
+ a: PropTypes.string,
5
+ b: PropTypes.string,
6
+ c: PropTypes.string,
7
+ };
@@ -0,0 +1,7 @@
1
+ class A extends React.Component {
2
+ static propTypes = {
3
+ a: PropTypes.string,
4
+ c: PropTypes.string,
5
+ b: PropTypes.string,
6
+ };
7
+ }
@@ -0,0 +1,7 @@
1
+ class A extends React.Component {
2
+ static propTypes = {
3
+ a: PropTypes.string,
4
+ b: PropTypes.string,
5
+ c: PropTypes.string,
6
+ };
7
+ }
@@ -0,0 +1,8 @@
1
+ //prettier-ignore
2
+ import { Button } from 'carbon-components-react';
3
+ //prettier-ignore
4
+ import { Tile, Tooltip } from 'carbon-components-react';
5
+ //prettier-ignore
6
+ import CodeSnippet from 'carbon-components-react';
7
+ import Something from 'somewhere-else';
8
+ import { SomethingElse } from 'somewhere-else';
@@ -0,0 +1,8 @@
1
+ //prettier-ignore
2
+ import { Button } from "@carbon/react";
3
+ //prettier-ignore
4
+ import { Tile, Tooltip } from "@carbon/react";
5
+ //prettier-ignore
6
+ import CodeSnippet from "@carbon/react";
7
+ import Something from 'somewhere-else';
8
+ import { SomethingElse } from 'somewhere-else';