@strapi/upgrade 0.0.0-experimental.f6c00790e260ea5a9b6b86abac5fea02b05d569c → 0.0.0-experimental.f74ae50eea1ce95176f088dba837e95b60fa2a4d
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 +10 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -2
- package/dist/index.mjs.map +1 -1
- package/dist/modules/file-scanner/scanner.d.ts.map +1 -1
- package/dist/modules/project/project.d.ts.map +1 -1
- package/package.json +6 -6
- package/resources/codemods/5.0.0/deprecate-helper-plugin.code.ts +186 -0
- package/resources/utils/change-import.ts +23 -10
- package/resources/codemods/5.0.0/change-useAPIErrorHandler-import.code.ts +0 -21
- package/resources/codemods/5.0.0/nocontent-migrate-to-emptystatelayout.code.ts +0 -30
- package/resources/codemods/5.0.0/useRBAC-hook-import-change.code.ts +0 -21
|
@@ -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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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,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
|
-
methodName: 'useAPIErrorHandler',
|
|
14
|
-
oldDependency: '@strapi/helper-plugin',
|
|
15
|
-
newDependency: '@strapi/strapi/admin',
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return root.toSource();
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
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 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;
|