@strapi/upgrade 5.0.0-rc.22 → 5.0.0-rc.23

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/dist/cli.js CHANGED
@@ -1477,7 +1477,7 @@ When executed on a Strapi plugin project, it shows every codemods.
1477
1477
  return listCodemods(options);
1478
1478
  });
1479
1479
  };
1480
- const version = "5.0.0-rc.22";
1480
+ const version = "5.0.0-rc.23";
1481
1481
  register$1(commander.program);
1482
1482
  register(commander.program);
1483
1483
  commander.program.usage("<command> [options]").on("command:*", ([invalidCmd]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/upgrade",
3
- "version": "5.0.0-rc.22",
3
+ "version": "5.0.0-rc.23",
4
4
  "description": "CLI to upgrade Strapi applications effortless",
5
5
  "keywords": [
6
6
  "strapi",
@@ -59,7 +59,7 @@
59
59
  "watch": "pack-up watch"
60
60
  },
61
61
  "dependencies": {
62
- "@strapi/utils": "5.0.0-rc.22",
62
+ "@strapi/utils": "5.0.0-rc.23",
63
63
  "chalk": "4.1.2",
64
64
  "cli-table3": "0.6.2",
65
65
  "commander": "8.3.0",
@@ -76,15 +76,15 @@
76
76
  },
77
77
  "devDependencies": {
78
78
  "@strapi/pack-up": "5.0.0",
79
- "@strapi/types": "5.0.0-rc.22",
79
+ "@strapi/types": "5.0.0-rc.23",
80
80
  "@types/fs-extra": "11.0.4",
81
81
  "@types/jscodeshift": "0.11.10",
82
- "eslint-config-custom": "5.0.0-rc.22",
82
+ "eslint-config-custom": "5.0.0-rc.23",
83
83
  "rimraf": "5.0.5"
84
84
  },
85
85
  "engines": {
86
86
  "node": ">=18.0.0 <=20.x.x",
87
87
  "npm": ">=6.0.0"
88
88
  },
89
- "gitHead": "0f2bce1bebfdd4c40c8c559d145d78f3b6ed4cfc"
89
+ "gitHead": "4eadad69ba4010caa82dd8f30eec0b5aa1cabde9"
90
90
  }
@@ -0,0 +1,186 @@
1
+ import type { Transform } from 'jscodeshift';
2
+ import { changeImportSpecifier } from '../../utils/change-import';
3
+ import { replaceJSXElement } from '../../utils/replace-jsx';
4
+
5
+ /**
6
+ * This codemods automates all the imports and naming changes
7
+ * for methods or components that used to be imported from '@strapi/helper-plugin'
8
+ */
9
+ const transform: Transform = (file, api) => {
10
+ const { j } = api;
11
+
12
+ const root = j.withParser('tsx')(file.source);
13
+
14
+ type Replacement = {
15
+ oldName: string;
16
+ oldDependency: string;
17
+ toReplace: boolean;
18
+ toChangeImportSpecifier: boolean;
19
+ newDependency?: string;
20
+ newName?: string;
21
+ };
22
+
23
+ const replacements: Replacement[] = [
24
+ {
25
+ oldName: 'AnErrorOccurred',
26
+ newName: 'Page.Error',
27
+ oldDependency: '@strapi/helper-plugin',
28
+ newDependency: '@strapi/strapi/admin',
29
+ toReplace: true,
30
+ toChangeImportSpecifier: true,
31
+ },
32
+ {
33
+ oldName: 'CheckPagePermissions',
34
+ newName: 'Page.Protect',
35
+ oldDependency: '@strapi/helper-plugin',
36
+ newDependency: '@strapi/strapi/admin',
37
+ toReplace: true,
38
+ toChangeImportSpecifier: true,
39
+ },
40
+ {
41
+ oldName: 'ConfirmDialog',
42
+ oldDependency: '@strapi/helper-plugin',
43
+ newDependency: '@strapi/strapi/admin',
44
+ toChangeImportSpecifier: true,
45
+ toReplace: false,
46
+ },
47
+ {
48
+ oldName: 'DateTimePicker',
49
+ oldDependency: '@strapi/helper-plugin',
50
+ newDependency: '@strapi/design-system',
51
+ toChangeImportSpecifier: true,
52
+ toReplace: false,
53
+ },
54
+ {
55
+ oldName: 'getFetchClient',
56
+ oldDependency: '@strapi/helper-plugin',
57
+ newDependency: '@strapi/strapi/admin',
58
+ toChangeImportSpecifier: true,
59
+ toReplace: false,
60
+ },
61
+ {
62
+ oldName: 'LoadingIndicatorPage',
63
+ newName: 'Page.Loading',
64
+ oldDependency: '@strapi/helper-plugin',
65
+ newDependency: '@strapi/strapi/admin',
66
+ toReplace: true,
67
+ toChangeImportSpecifier: true,
68
+ },
69
+ {
70
+ oldName: 'NoContent',
71
+ newName: 'EmptyStateLayout',
72
+ oldDependency: '@strapi/helper-plugin',
73
+ newDependency: '@strapi/design-system',
74
+ toReplace: true,
75
+ toChangeImportSpecifier: true,
76
+ },
77
+ {
78
+ oldName: 'NoPermissions',
79
+ newName: 'Page.NoPermissions',
80
+ oldDependency: '@strapi/helper-plugin',
81
+ newDependency: '@strapi/strapi/admin',
82
+ toReplace: true,
83
+ toChangeImportSpecifier: true,
84
+ },
85
+ {
86
+ oldName: 'Status',
87
+ oldDependency: '@strapi/helper-plugin',
88
+ newDependency: '@strapi/design-system',
89
+ toChangeImportSpecifier: true,
90
+ toReplace: false,
91
+ },
92
+ {
93
+ oldName: 'translatedErrors',
94
+ oldDependency: '@strapi/helper-plugin',
95
+ newDependency: '@strapi/strapi/admin',
96
+ toChangeImportSpecifier: true,
97
+ toReplace: false,
98
+ },
99
+ {
100
+ oldName: 'useAPIErrorHandler',
101
+ oldDependency: '@strapi/helper-plugin',
102
+ newDependency: '@strapi/strapi/admin',
103
+ toChangeImportSpecifier: true,
104
+ toReplace: false,
105
+ },
106
+ {
107
+ oldName: 'useCallbackRef',
108
+ oldDependency: '@strapi/helper-plugin',
109
+ newDependency: '@strapi/design-system',
110
+ toChangeImportSpecifier: true,
111
+ toReplace: false,
112
+ },
113
+ {
114
+ oldName: 'useCollator',
115
+ oldDependency: '@strapi/helper-plugin',
116
+ newDependency: '@strapi/design-system',
117
+ toChangeImportSpecifier: true,
118
+ toReplace: false,
119
+ },
120
+ {
121
+ oldName: 'useFetchClient',
122
+ oldDependency: '@strapi/helper-plugin',
123
+ newDependency: '@strapi/strapi/admin',
124
+ toChangeImportSpecifier: true,
125
+ toReplace: false,
126
+ },
127
+ {
128
+ oldName: 'useFilter',
129
+ oldDependency: '@strapi/helper-plugin',
130
+ newDependency: '@strapi/design-system',
131
+ toChangeImportSpecifier: true,
132
+ toReplace: false,
133
+ },
134
+ {
135
+ oldName: 'useQueryParams',
136
+ oldDependency: '@strapi/helper-plugin',
137
+ newDependency: '@strapi/strapi/admin',
138
+ toChangeImportSpecifier: true,
139
+ toReplace: false,
140
+ },
141
+ {
142
+ oldName: 'useRBAC',
143
+ oldDependency: '@strapi/helper-plugin',
144
+ newDependency: '@strapi/strapi/admin',
145
+ toChangeImportSpecifier: true,
146
+ toReplace: false,
147
+ },
148
+ {
149
+ oldName: 'SearchURLQuery',
150
+ oldDependency: '@strapi/helper-plugin',
151
+ newDependency: '@strapi/strapi/admin',
152
+ toChangeImportSpecifier: true,
153
+ toReplace: false,
154
+ },
155
+ {
156
+ oldName: 'useSettingsForm',
157
+ oldDependency: '@strapi/helper-plugin',
158
+ newDependency: '@strapi/strapi/admin',
159
+ toChangeImportSpecifier: true,
160
+ toReplace: false,
161
+ },
162
+ ];
163
+
164
+ replacements.forEach((replacement) => {
165
+ if (replacement.toReplace && replacement.newName) {
166
+ replaceJSXElement(root, j, {
167
+ oldElementName: replacement.oldName,
168
+ newElementName: replacement.newName,
169
+ oldDependency: replacement.oldDependency,
170
+ });
171
+ }
172
+
173
+ if (replacement.toChangeImportSpecifier && replacement.newDependency) {
174
+ changeImportSpecifier(root, j, {
175
+ oldMethodName: replacement.oldName,
176
+ newMethodName: replacement.newName,
177
+ oldDependency: replacement.oldDependency,
178
+ newDependency: replacement.newDependency,
179
+ });
180
+ }
181
+ });
182
+
183
+ return root.toSource();
184
+ };
185
+
186
+ export default transform;
@@ -65,19 +65,32 @@ export const changeImportSpecifier = (
65
65
  .filter((path) => path.node.source.value === newDependency);
66
66
 
67
67
  if (dependencies.length > 0) {
68
+ // we have to use a flag to prevent adding the method to multiple imports
69
+ let methodAdded = false;
68
70
  dependencies.forEach((path) => {
69
71
  const importDeclaration: ImportDeclaration = path.node;
72
+ if (!methodAdded) {
73
+ methodAliases.forEach((alias) => {
74
+ // Check if the methodNameToReplace or its alias is already imported
75
+ const specifiersArray = importDeclaration.specifiers || [];
76
+ const methodAlreadyExists = specifiersArray.some(
77
+ (specifier) =>
78
+ specifier.type === 'ImportSpecifier' &&
79
+ specifier.imported.name === methodNameToReplace && // Check if imported method matches
80
+ specifier.local?.name === alias // Check if local alias matches
81
+ );
70
82
 
71
- methodAliases.forEach((alias) => {
72
- const newSpecifier = j.importSpecifier(
73
- j.identifier(methodNameToReplace),
74
- j.identifier(alias)
75
- );
76
- const specifiersArray = importDeclaration.specifiers || [];
77
- j(path).replaceWith(
78
- j.importDeclaration([...specifiersArray, newSpecifier], j.literal(newDependency))
79
- );
80
- });
83
+ if (!methodAlreadyExists) {
84
+ // If method does not exist, add it
85
+ const newSpecifier = j.importSpecifier(
86
+ j.identifier(methodNameToReplace),
87
+ j.identifier(alias)
88
+ );
89
+ path.get('specifiers').replace([...specifiersArray, newSpecifier]);
90
+ methodAdded = true;
91
+ }
92
+ });
93
+ }
81
94
  });
82
95
  } else {
83
96
  const newSpecifiers = methodAliases.map((alias) =>
@@ -1,30 +0,0 @@
1
- import type { Transform } from 'jscodeshift';
2
- import { changeImportSpecifier } from '../../utils/change-import';
3
- import { replaceJSXElement } from '../../utils/replace-jsx';
4
-
5
- /**
6
- * change CheckPagePermissions import from '@strapi/helper-plugin' to Page from '@strapi/strapi/admin'
7
- * And replace all uses of CheckPagePermissions with Page
8
- */
9
- const transform: Transform = (file, api) => {
10
- const { j } = api;
11
-
12
- const root = j.withParser('tsx')(file.source);
13
-
14
- replaceJSXElement(root, j, {
15
- oldElementName: 'CheckPagePermissions',
16
- newElementName: 'Page',
17
- oldDependency: '@strapi/helper-plugin',
18
- });
19
-
20
- changeImportSpecifier(root, j, {
21
- oldMethodName: 'CheckPagePermissions',
22
- newMethodName: 'Page',
23
- oldDependency: '@strapi/helper-plugin',
24
- newDependency: '@strapi/strapi/admin',
25
- });
26
-
27
- return root.toSource();
28
- };
29
-
30
- export default transform;
@@ -1,30 +0,0 @@
1
- import type { Transform } from 'jscodeshift';
2
- import { changeImportSpecifier } from '../../utils/change-import';
3
- import { replaceJSXElement } from '../../utils/replace-jsx';
4
-
5
- /**
6
- * change NoContent import from '@strapi/helper-plugin' to EmptyStateLayout from '@strapi/design-system'
7
- * And replace all uses of NoContent with EmptyStateLayout
8
- */
9
- const transform: Transform = (file, api) => {
10
- const { j } = api;
11
-
12
- const root = j.withParser('tsx')(file.source);
13
-
14
- replaceJSXElement(root, j, {
15
- oldElementName: 'NoContent',
16
- newElementName: 'EmptyStateLayout',
17
- oldDependency: '@strapi/helper-plugin',
18
- });
19
-
20
- changeImportSpecifier(root, j, {
21
- oldMethodName: 'NoContent',
22
- newMethodName: 'EmptyStateLayout',
23
- oldDependency: '@strapi/helper-plugin',
24
- newDependency: '@strapi/design-system',
25
- });
26
-
27
- return root.toSource();
28
- };
29
-
30
- export default transform;
@@ -1,21 +0,0 @@
1
- import type { Transform } from 'jscodeshift';
2
- import { changeImportSpecifier } from '../../utils/change-import';
3
-
4
- /**
5
- * change useAPIErrorHandler import from '@strapi/helper-plugin' to '@strapi/strapi/admin'
6
- */
7
- const transform: Transform = (file, api) => {
8
- const { j } = api;
9
-
10
- const root = j.withParser('tsx')(file.source);
11
-
12
- changeImportSpecifier(root, j, {
13
- oldMethodName: 'useAPIErrorHandler',
14
- oldDependency: '@strapi/helper-plugin',
15
- newDependency: '@strapi/strapi/admin',
16
- });
17
-
18
- return root.toSource();
19
- };
20
-
21
- export default transform;
@@ -1,21 +0,0 @@
1
- import type { Transform } from 'jscodeshift';
2
- import { changeImportSpecifier } from '../../utils/change-import';
3
-
4
- /**
5
- * change useRBAC import from '@strapi/helper-plugin' to '@strapi/strapi/admin'
6
- */
7
- const transform: Transform = (file, api) => {
8
- const { j } = api;
9
-
10
- const root = j.withParser('tsx')(file.source);
11
-
12
- changeImportSpecifier(root, j, {
13
- oldMethodName: 'useRBAC',
14
- oldDependency: '@strapi/helper-plugin',
15
- newDependency: '@strapi/strapi/admin',
16
- });
17
-
18
- return root.toSource();
19
- };
20
-
21
- export default transform;