@carbon/upgrade 11.18.0-rc.0 → 11.18.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/cli.js CHANGED
@@ -52629,6 +52629,29 @@ var upgrades = [
52629
52629
  verbose: options.verbose
52630
52630
  });
52631
52631
  }
52632
+ },
52633
+ {
52634
+ name: "refactor-to-callout",
52635
+ description: "Rewrites imports and usages of StaticNotification to Callout",
52636
+ migrate: async (options) => {
52637
+ const transform = import_path2.default.join(TRANSFORM_DIR, "refactor-to-callout.js");
52638
+ const paths = Array.isArray(options.paths) && options.paths.length > 0 ? options.paths : await (0, import_fast_glob2.default)(["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"], {
52639
+ cwd: options.workspaceDir,
52640
+ ignore: [
52641
+ "**/es/**",
52642
+ "**/lib/**",
52643
+ "**/umd/**",
52644
+ "**/node_modules/**",
52645
+ "**/storybook-static/**"
52646
+ ]
52647
+ });
52648
+ await run2({
52649
+ dry: !options.write,
52650
+ transform,
52651
+ paths,
52652
+ verbose: options.verbose
52653
+ });
52654
+ }
52632
52655
  }
52633
52656
  ]
52634
52657
  },
@@ -52657,7 +52680,7 @@ var upgrades = [
52657
52680
  var package_default = {
52658
52681
  name: "@carbon/upgrade",
52659
52682
  description: "A tool for upgrading Carbon versions",
52660
- version: "11.18.0-rc.0",
52683
+ version: "11.18.1",
52661
52684
  license: "Apache-2.0",
52662
52685
  bin: {
52663
52686
  "carbon-upgrade": "./bin/carbon-upgrade.js"
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": "11.18.0-rc.0",
4
+ "version": "11.18.1",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
7
7
  "carbon-upgrade": "./bin/carbon-upgrade.js"
@@ -61,5 +61,5 @@
61
61
  "@ibm/telemetry-js": "^1.5.0",
62
62
  "jscodeshift": "^17.0.0"
63
63
  },
64
- "gitHead": "124d86cfad8f2efd4d60372f735fea534fc6f374"
64
+ "gitHead": "2df4c295d300f96fae292a00b88f07a99e9a80c7"
65
65
  }
@@ -0,0 +1,25 @@
1
+ // Typical imports
2
+ import { unstable__StaticNotification as StaticNotification } from '@carbon/react';
3
+ import { unstable__StaticNotification } from '@carbon/react';
4
+
5
+ // If they used a custom name
6
+ import { unstable__StaticNotification as SomeOtherName } from '@carbon/react';
7
+
8
+ // If they already renamed it Callout
9
+ import { unstable__StaticNotification as Callout } from '@carbon/react';
10
+
11
+ // Local renames like this are unlikely but technically possible
12
+ const LocallyRenamedStaticNotification = unstable__StaticNotification;
13
+
14
+ // Component usages
15
+ // prettier-ignore
16
+ const App = () => {
17
+ return (
18
+ <>
19
+ <StaticNotification title="Test" />
20
+ <SomeOtherName title="Test" />
21
+ <Callout title="Test" />
22
+ <LocallyRenamedStaticNotification title="Test" />
23
+ </>
24
+ );
25
+ };
@@ -0,0 +1,23 @@
1
+ // Typical imports
2
+ import { unstable__Callout as Callout } from '@carbon/react';
3
+ import { unstable__Callout } from '@carbon/react';
4
+
5
+ // If they used a custom name
6
+ import { unstable__Callout as SomeOtherName } from '@carbon/react';
7
+
8
+ // If they already renamed it Callout
9
+ import { unstable__Callout as Callout } from '@carbon/react';
10
+
11
+ // Local renames like this are unlikely but technically possible
12
+ const LocallyRenamedStaticNotification = unstable__Callout;
13
+
14
+ // Component usages
15
+ // prettier-ignore
16
+ const App = () => {
17
+ return (<>
18
+ <Callout title="Test" />
19
+ <SomeOtherName title="Test" />
20
+ <Callout title="Test" />
21
+ <LocallyRenamedStaticNotification title="Test" />
22
+ </>);
23
+ };
@@ -0,0 +1,4 @@
1
+ // Existing usages should not be transformed
2
+ import { unstable__Callout } from '@carbon/react';
3
+ import { unstable__Callout as Callout } from '@carbon/react';
4
+ import { unstable__Callout as SomeOtherOtherName } from '@carbon/react';
@@ -0,0 +1,4 @@
1
+ // Existing usages should not be transformed
2
+ import { unstable__Callout } from '@carbon/react';
3
+ import { unstable__Callout as Callout } from '@carbon/react';
4
+ import { unstable__Callout as SomeOtherOtherName } from '@carbon/react';
@@ -0,0 +1,5 @@
1
+ // Do not transform potential naming collisions from local paths
2
+ import { unstable__Callout } from './my/local/project';
3
+ import { unstable__Callout as Callout } from './my/local/project';
4
+ import { unstable_StaticNotification } from './my/local/project';
5
+ import { unstable_StaticNotification as StaticNotification } from './my/local/project';
@@ -0,0 +1,5 @@
1
+ // Do not transform potential naming collisions from local paths
2
+ import { unstable__Callout } from './my/local/project';
3
+ import { unstable__Callout as Callout } from './my/local/project';
4
+ import { unstable_StaticNotification } from './my/local/project';
5
+ import { unstable_StaticNotification as StaticNotification } from './my/local/project';
@@ -0,0 +1,3 @@
1
+ // Do not transform potential naming collisions from local paths
2
+ import { Callout } from '../my/local/project';
3
+ import { StaticNotification } from './my/local/project';
@@ -0,0 +1,3 @@
1
+ // Do not transform potential naming collisions from local paths
2
+ import { Callout } from '../my/local/project';
3
+ import { StaticNotification } from './my/local/project';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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 { defineTest } = require('jscodeshift/dist/testUtils');
11
+
12
+ defineTest(__dirname, 'refactor-to-callout');
13
+ defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout2');
14
+ defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout3');
15
+ defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout4');
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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: 'auto',
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
+ // Helper function to check if the import source is from '@carbon/react' or its subpaths
21
+ function isCarbonReactImport(sourceValue) {
22
+ return (
23
+ sourceValue === '@carbon/react' ||
24
+ sourceValue.startsWith('@carbon/react/es') ||
25
+ sourceValue.startsWith('@carbon/react/lib')
26
+ );
27
+ }
28
+
29
+ // Collect names of identifiers imported from '@carbon/react' or its subpaths
30
+ const importedIdentifiers = new Map(); // Map of local name to transformed name
31
+
32
+ // Transform import declarations
33
+ root.find(j.ImportDeclaration).forEach((path) => {
34
+ const sourceValue = path.node.source.value;
35
+
36
+ // Only transform imports from '@carbon/react' and its subpaths
37
+ if (!isCarbonReactImport(sourceValue)) {
38
+ return;
39
+ }
40
+
41
+ path.node.specifiers.forEach((specifier) => {
42
+ if (specifier.type === 'ImportSpecifier') {
43
+ let importedName = specifier.imported.name;
44
+ let localName = specifier.local ? specifier.local.name : importedName;
45
+ let transformedImportedName = importedName;
46
+ let transformedLocalName = localName;
47
+
48
+ // Transform imported names and local names as necessary
49
+ if (importedName === 'unstable__StaticNotification') {
50
+ transformedImportedName = 'unstable__Callout';
51
+ specifier.imported.name = transformedImportedName;
52
+
53
+ if (localName === 'StaticNotification') {
54
+ transformedLocalName = 'Callout';
55
+ specifier.local.name = transformedLocalName;
56
+ } else if (localName === 'unstable__StaticNotification') {
57
+ transformedLocalName = 'unstable__Callout';
58
+ specifier.local.name = transformedLocalName;
59
+ }
60
+ // If local name is something else (e.g., SomeOtherName), leave it unchanged
61
+ } else if (importedName === 'StaticNotification') {
62
+ transformedImportedName = 'Callout';
63
+ specifier.imported.name = transformedImportedName;
64
+
65
+ if (localName === 'StaticNotification') {
66
+ transformedLocalName = 'Callout';
67
+ specifier.local.name = transformedLocalName;
68
+ }
69
+ // If local name is different, leave it unchanged
70
+ } else if (importedName === 'StaticNotificationProps') {
71
+ transformedImportedName = 'CalloutProps';
72
+ specifier.imported.name = transformedImportedName;
73
+
74
+ if (localName === 'StaticNotificationProps') {
75
+ transformedLocalName = 'CalloutProps';
76
+ specifier.local.name = transformedLocalName;
77
+ }
78
+ // If local name is different, leave it unchanged
79
+ }
80
+
81
+ // If imported name and local name are the same after transformation, remove the alias
82
+ if (
83
+ specifier.local &&
84
+ specifier.local.name === specifier.imported.name
85
+ ) {
86
+ delete specifier.local;
87
+ }
88
+
89
+ // Update the mapping of imported identifiers
90
+ // Only add to the map if the local name or the transformed name is different
91
+ if (localName !== transformedLocalName) {
92
+ importedIdentifiers.set(localName, transformedLocalName);
93
+ }
94
+ }
95
+ });
96
+ });
97
+
98
+ // Deduplicate imports
99
+ const importDeclarations = root.find(j.ImportDeclaration);
100
+
101
+ importDeclarations.forEach((path) => {
102
+ const sourceValue = path.node.source.value;
103
+
104
+ // Only deduplicate imports from '@carbon/react' and its subpaths
105
+ if (!isCarbonReactImport(sourceValue)) {
106
+ return;
107
+ }
108
+
109
+ const specifiers = path.node.specifiers;
110
+ const uniqueSpecifiers = [];
111
+ const seen = new Set();
112
+
113
+ specifiers.forEach((specifier) => {
114
+ const importedName = specifier.imported.name;
115
+ const localName = specifier.local ? specifier.local.name : importedName;
116
+ const key = `${importedName}:${localName}`;
117
+
118
+ if (!seen.has(key)) {
119
+ seen.add(key);
120
+ uniqueSpecifiers.push(specifier);
121
+ }
122
+ });
123
+
124
+ path.node.specifiers = uniqueSpecifiers;
125
+ });
126
+
127
+ // Remove empty import declarations
128
+ importDeclarations.forEach((path) => {
129
+ if (path.node.specifiers.length === 0) {
130
+ j(path).remove();
131
+ }
132
+ });
133
+
134
+ // Update usages in the code
135
+ root.find(j.Identifier).forEach((path) => {
136
+ const name = path.node.name;
137
+
138
+ // Skip if the identifier is part of an import specifier
139
+ if (
140
+ path.parent.node.type === 'ImportSpecifier' ||
141
+ path.parent.node.type === 'ImportDefaultSpecifier' ||
142
+ path.parent.node.type === 'ImportNamespaceSpecifier'
143
+ ) {
144
+ return;
145
+ }
146
+
147
+ // Only transform identifiers that match the imported identifiers
148
+ if (importedIdentifiers.has(name)) {
149
+ const transformedName = importedIdentifiers.get(name);
150
+ path.node.name = transformedName;
151
+ }
152
+ });
153
+
154
+ return root.toSource(printOptions);
155
+ }
156
+
157
+ module.exports = transform;