@strapi/upgrade 0.0.0-experimental.d362bf200f5f9359a4bbd4a549603de5ee1f04ca → 0.0.0-experimental.d834c9e658d1fb037e6da1105150593521c667cc
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/LICENSE +19 -4
- package/dist/cli.js +1456 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.js +234 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +235 -95
- package/dist/index.mjs.map +1 -1
- package/dist/modules/codemod/codemod.d.ts +4 -2
- package/dist/modules/codemod/codemod.d.ts.map +1 -1
- package/dist/modules/codemod/types.d.ts +8 -1
- package/dist/modules/codemod/types.d.ts.map +1 -1
- package/dist/modules/codemod-repository/constants.d.ts.map +1 -1
- package/dist/modules/codemod-repository/repository.d.ts +5 -5
- package/dist/modules/codemod-repository/repository.d.ts.map +1 -1
- package/dist/modules/codemod-repository/types.d.ts +7 -3
- package/dist/modules/codemod-repository/types.d.ts.map +1 -1
- package/dist/modules/codemod-runner/codemod-runner.d.ts +6 -3
- package/dist/modules/codemod-runner/codemod-runner.d.ts.map +1 -1
- package/dist/modules/codemod-runner/index.d.ts +1 -0
- package/dist/modules/codemod-runner/index.d.ts.map +1 -1
- package/dist/modules/codemod-runner/types.d.ts +1 -0
- package/dist/modules/codemod-runner/types.d.ts.map +1 -1
- package/dist/modules/format/formats.d.ts +5 -0
- package/dist/modules/format/formats.d.ts.map +1 -1
- package/dist/modules/project/constants.d.ts.map +1 -1
- package/dist/modules/project/project.d.ts +1 -1
- package/dist/modules/project/project.d.ts.map +1 -1
- package/dist/modules/project/types.d.ts +1 -0
- package/dist/modules/project/types.d.ts.map +1 -1
- package/dist/modules/project/utils.d.ts +1 -1
- package/dist/modules/project/utils.d.ts.map +1 -1
- package/dist/modules/report/report.d.ts.map +1 -1
- package/dist/modules/runner/json/transform.d.ts.map +1 -1
- package/dist/modules/upgrader/upgrader.d.ts.map +1 -1
- package/dist/modules/version/range.d.ts +2 -0
- package/dist/modules/version/range.d.ts.map +1 -1
- package/dist/tasks/codemods/index.d.ts +2 -1
- package/dist/tasks/codemods/index.d.ts.map +1 -1
- package/dist/tasks/codemods/list-codemods.d.ts +3 -0
- package/dist/tasks/codemods/list-codemods.d.ts.map +1 -0
- package/dist/tasks/codemods/run-codemods.d.ts +3 -0
- package/dist/tasks/codemods/run-codemods.d.ts.map +1 -0
- package/dist/tasks/codemods/types.d.ts +9 -3
- package/dist/tasks/codemods/types.d.ts.map +1 -1
- package/dist/tasks/codemods/utils.d.ts +6 -0
- package/dist/tasks/codemods/utils.d.ts.map +1 -0
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.d.ts.map +1 -1
- package/package.json +9 -8
- package/resources/codemods/5.0.0/change-useAPIErrorHandler-import.code.ts +21 -0
- package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
- package/resources/codemods/5.0.0/dependency-upgrade-react-and-react-dom.json.ts +67 -0
- package/resources/codemods/5.0.0/dependency-upgrade-styled-components.json.ts +49 -0
- package/resources/codemods/5.0.0/entity-service-document-service.code.ts +437 -0
- package/resources/codemods/5.0.0/strapi-public-interface.code.ts +126 -0
- package/resources/codemods/5.0.0/useRBAC-hook-import-change.code.ts +21 -0
- package/resources/codemods/5.0.0/utils-public-interface.code.ts +320 -0
- package/resources/utils/change-import.ts +96 -0
- package/dist/_chunks/codemod-runner-mXNzVpHm.js +0 -798
- package/dist/_chunks/codemod-runner-mXNzVpHm.js.map +0 -1
- package/dist/_chunks/codemods-S4mNX9Qg.js +0 -105
- package/dist/_chunks/codemods-S4mNX9Qg.js.map +0 -1
- package/dist/_chunks/index-Pt-TU9MN.js +0 -103
- package/dist/_chunks/index-Pt-TU9MN.js.map +0 -1
- package/dist/_chunks/upgrade-aWNYibWB.js +0 -361
- package/dist/_chunks/upgrade-aWNYibWB.js.map +0 -1
- package/dist/tasks/codemods/codemods.d.ts +0 -3
- package/dist/tasks/codemods/codemods.d.ts.map +0 -1
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { Transform, JSCodeshift, Collection } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
This codemod transforms @strapi/utils imports to change method calls to match the new public interface.
|
|
6
|
+
It will also warn about removed functions to avoid breaking user code.
|
|
7
|
+
|
|
8
|
+
ESM
|
|
9
|
+
|
|
10
|
+
Before:
|
|
11
|
+
|
|
12
|
+
import * as utils from '@strapi/utils';
|
|
13
|
+
|
|
14
|
+
utils.nameToSlug();
|
|
15
|
+
|
|
16
|
+
After:
|
|
17
|
+
|
|
18
|
+
import { strings } from '@strapi/utils';
|
|
19
|
+
|
|
20
|
+
strings.nameToSlug();
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
ESM
|
|
24
|
+
|
|
25
|
+
Before:
|
|
26
|
+
|
|
27
|
+
import { nameToSlug } from '@strapi/utils';
|
|
28
|
+
|
|
29
|
+
nameToSlug();
|
|
30
|
+
|
|
31
|
+
After:
|
|
32
|
+
|
|
33
|
+
import { strings } from '@strapi/utils';
|
|
34
|
+
|
|
35
|
+
strings.nameToSlug();
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
Common JS
|
|
40
|
+
|
|
41
|
+
Before:
|
|
42
|
+
|
|
43
|
+
const utils = require('@strapi/utils');
|
|
44
|
+
|
|
45
|
+
utils.nameToSlug();
|
|
46
|
+
|
|
47
|
+
After:
|
|
48
|
+
|
|
49
|
+
const { strings } = require('@strapi/utils');
|
|
50
|
+
|
|
51
|
+
strings.nameToSlug();
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
Common JS
|
|
55
|
+
|
|
56
|
+
Before:
|
|
57
|
+
|
|
58
|
+
const { nameToSlug } = require('@strapi/utils');
|
|
59
|
+
|
|
60
|
+
nameToSlug();
|
|
61
|
+
|
|
62
|
+
After:
|
|
63
|
+
|
|
64
|
+
const { strings } = require('@strapi/utils');
|
|
65
|
+
|
|
66
|
+
strings.nameToSlug();
|
|
67
|
+
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
const changes = {
|
|
71
|
+
strings: {
|
|
72
|
+
nameToSlug: 'nameToSlug',
|
|
73
|
+
nameToCollectionName: 'nameToCollectionName',
|
|
74
|
+
stringEquals: 'isEqual',
|
|
75
|
+
isCamelCase: 'isCamelCase',
|
|
76
|
+
isKebabCase: 'isKebabCase',
|
|
77
|
+
toKebabCase: 'toKebabCase',
|
|
78
|
+
toRegressedEnumValue: 'toRegressedEnumValue',
|
|
79
|
+
startsWithANumber: 'startsWithANumber',
|
|
80
|
+
joinBy: 'joinBy',
|
|
81
|
+
},
|
|
82
|
+
arrays: {
|
|
83
|
+
stringIncludes: 'includesString',
|
|
84
|
+
},
|
|
85
|
+
objects: {
|
|
86
|
+
keysDeep: 'keysDeep',
|
|
87
|
+
},
|
|
88
|
+
dates: {
|
|
89
|
+
generateTimestampCode: 'timestampCode',
|
|
90
|
+
},
|
|
91
|
+
async: {
|
|
92
|
+
pipeAsync: 'pipe',
|
|
93
|
+
mapAsync: 'map',
|
|
94
|
+
reduceAsync: 'reduce',
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const removed = [
|
|
99
|
+
'getCommonBeginning',
|
|
100
|
+
'templateConfiguration',
|
|
101
|
+
'removeUndefined',
|
|
102
|
+
'getConfigUrls',
|
|
103
|
+
'getAbsoluteAdminUrl',
|
|
104
|
+
'getAbsoluteServerUrl',
|
|
105
|
+
'forEachAsync',
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
const transformImports = (root: Collection, j: JSCodeshift) => {
|
|
109
|
+
root
|
|
110
|
+
.find(j.ImportDeclaration, {
|
|
111
|
+
source: { value: '@strapi/utils' },
|
|
112
|
+
})
|
|
113
|
+
.forEach((path) => {
|
|
114
|
+
if (!j.ImportDeclaration.check(path.value)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
path.value.specifiers.forEach((specifier) => {
|
|
119
|
+
if (!j.ImportSpecifier.check(specifier)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (removed.includes(specifier.imported.name)) {
|
|
124
|
+
console.warn(
|
|
125
|
+
`Function "${specifier.imported.name}" was removed. You will have to remove it from your code.`
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
for (const primitive of Object.keys(changes)) {
|
|
133
|
+
const functions = Object.keys(changes[primitive]);
|
|
134
|
+
|
|
135
|
+
const specifiersToRefactor = path.value.specifiers.filter((specifier) => {
|
|
136
|
+
return j.ImportSpecifier.check(specifier) && functions.includes(specifier.imported.name);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
if (specifiersToRefactor.length > 0) {
|
|
140
|
+
path.value.specifiers.unshift(j.importSpecifier(j.identifier(primitive)));
|
|
141
|
+
|
|
142
|
+
specifiersToRefactor.forEach((specifier) => {
|
|
143
|
+
const index = path.value.specifiers.indexOf(specifier);
|
|
144
|
+
path.value.specifiers.splice(index, 1);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (path.value.specifiers?.length === 0) {
|
|
150
|
+
j(path).remove();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
root.find(j.ImportNamespaceSpecifier).forEach((specifierPath) => {
|
|
155
|
+
if (specifierPath.parent.value.source.value === '@strapi/utils') {
|
|
156
|
+
for (const primitive of Object.keys(changes)) {
|
|
157
|
+
const functions = Object.keys(changes[primitive]);
|
|
158
|
+
functions.forEach((funcName) => {
|
|
159
|
+
root
|
|
160
|
+
.find(j.CallExpression, {
|
|
161
|
+
callee: {
|
|
162
|
+
type: 'MemberExpression',
|
|
163
|
+
property: {
|
|
164
|
+
type: 'Identifier',
|
|
165
|
+
name: funcName,
|
|
166
|
+
},
|
|
167
|
+
object: {
|
|
168
|
+
type: 'Identifier',
|
|
169
|
+
name: specifierPath.value.local.name,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
})
|
|
173
|
+
.replaceWith((path) => {
|
|
174
|
+
return j.callExpression(
|
|
175
|
+
j.memberExpression(
|
|
176
|
+
j.memberExpression(
|
|
177
|
+
j.identifier(specifierPath.value.local.name),
|
|
178
|
+
j.identifier(primitive)
|
|
179
|
+
),
|
|
180
|
+
j.identifier(changes[primitive][funcName])
|
|
181
|
+
),
|
|
182
|
+
path.value.arguments
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
root
|
|
191
|
+
.find(j.VariableDeclarator, {
|
|
192
|
+
init: {
|
|
193
|
+
callee: {
|
|
194
|
+
name: 'require',
|
|
195
|
+
},
|
|
196
|
+
arguments: [{ value: '@strapi/utils' }],
|
|
197
|
+
},
|
|
198
|
+
})
|
|
199
|
+
.forEach((path) => {
|
|
200
|
+
// destructured require
|
|
201
|
+
|
|
202
|
+
if (j.ObjectPattern.check(path.value.id)) {
|
|
203
|
+
const properties = path.value.id.properties;
|
|
204
|
+
|
|
205
|
+
properties?.forEach((property) => {
|
|
206
|
+
if (!j.ObjectProperty.check(property) || !j.Identifier.check(property.value)) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (removed.includes(property.value.name)) {
|
|
211
|
+
console.warn(
|
|
212
|
+
`Function "${property.value.name}" was removed. You will have to remove it from your code.`
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
for (const primitive of Object.keys(changes)) {
|
|
220
|
+
const functions = Object.keys(changes[primitive]);
|
|
221
|
+
|
|
222
|
+
const propertiesToRefactor = properties?.filter((property) => {
|
|
223
|
+
return (
|
|
224
|
+
j.ObjectProperty.check(property) &&
|
|
225
|
+
j.Identifier.check(property.value) &&
|
|
226
|
+
functions.includes(property.value.name)
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
if (propertiesToRefactor?.length > 0) {
|
|
231
|
+
const identifier = j.identifier(primitive);
|
|
232
|
+
|
|
233
|
+
properties?.unshift(
|
|
234
|
+
j.objectProperty.from({
|
|
235
|
+
key: identifier,
|
|
236
|
+
value: identifier,
|
|
237
|
+
shorthand: true,
|
|
238
|
+
})
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
propertiesToRefactor.forEach((property) => {
|
|
242
|
+
const index = properties?.indexOf(property);
|
|
243
|
+
properties?.splice(index, 1);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (path.value.id.properties?.length === 0) {
|
|
249
|
+
j(path).remove();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// namespace require
|
|
254
|
+
if (path.value.id.type === 'Identifier') {
|
|
255
|
+
const identifier = path.value.id.name;
|
|
256
|
+
|
|
257
|
+
for (const primitive of Object.keys(changes)) {
|
|
258
|
+
const functions = Object.keys(changes[primitive]);
|
|
259
|
+
functions.forEach((funcName) => {
|
|
260
|
+
root
|
|
261
|
+
.find(j.CallExpression, {
|
|
262
|
+
callee: {
|
|
263
|
+
type: 'MemberExpression',
|
|
264
|
+
property: {
|
|
265
|
+
type: 'Identifier',
|
|
266
|
+
name: funcName,
|
|
267
|
+
},
|
|
268
|
+
object: {
|
|
269
|
+
type: 'Identifier',
|
|
270
|
+
name: identifier,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
})
|
|
274
|
+
.replaceWith((path) => {
|
|
275
|
+
return j.callExpression(
|
|
276
|
+
j.memberExpression(
|
|
277
|
+
j.memberExpression(j.identifier(identifier), j.identifier(primitive)),
|
|
278
|
+
j.identifier(changes[primitive][funcName])
|
|
279
|
+
),
|
|
280
|
+
path.value.arguments
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
for (const primitive of Object.keys(changes)) {
|
|
289
|
+
const functions = Object.keys(changes[primitive]);
|
|
290
|
+
functions.forEach((funcName) => {
|
|
291
|
+
root
|
|
292
|
+
.find(j.CallExpression, {
|
|
293
|
+
callee: {
|
|
294
|
+
type: 'Identifier',
|
|
295
|
+
name: funcName,
|
|
296
|
+
},
|
|
297
|
+
})
|
|
298
|
+
.replaceWith((path) => {
|
|
299
|
+
if (j.Identifier.check(path.value.callee)) {
|
|
300
|
+
path.value.callee.name = changes[primitive][funcName];
|
|
301
|
+
return j.memberExpression(j.identifier(primitive), path.value);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const transform: Transform = (file, api) => {
|
|
309
|
+
const j = api.jscodeshift;
|
|
310
|
+
|
|
311
|
+
const root = j(file.source);
|
|
312
|
+
|
|
313
|
+
transformImports(root, j);
|
|
314
|
+
|
|
315
|
+
return root.toSource();
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export const parser = 'tsx';
|
|
319
|
+
|
|
320
|
+
export default transform;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { ImportDeclaration, JSCodeshift, Collection } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export const changeImportSpecifier = (
|
|
4
|
+
root: Collection,
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
options: { methodName: string; oldDependency: string; newDependency: string }
|
|
7
|
+
): void => {
|
|
8
|
+
const { methodName, oldDependency, newDependency } = options;
|
|
9
|
+
|
|
10
|
+
// Flag to check if the method was imported from the old dependency
|
|
11
|
+
let methodImportedFromOldDependency = false;
|
|
12
|
+
const methodAliases: string[] = [];
|
|
13
|
+
|
|
14
|
+
// Remove the method from the old dependency and check if it was imported
|
|
15
|
+
root
|
|
16
|
+
.find(j.ImportDeclaration)
|
|
17
|
+
.filter((path) => path.node.source.value === oldDependency)
|
|
18
|
+
.forEach((path) => {
|
|
19
|
+
const importDeclaration: ImportDeclaration = path.node;
|
|
20
|
+
|
|
21
|
+
// Check if the method is imported from the old dependency
|
|
22
|
+
const methodSpecifiers = importDeclaration.specifiers?.filter(
|
|
23
|
+
(specifier) =>
|
|
24
|
+
specifier.type === 'ImportSpecifier' && specifier.imported.name === methodName
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (methodSpecifiers && methodSpecifiers.length > 0) {
|
|
28
|
+
methodImportedFromOldDependency = true;
|
|
29
|
+
|
|
30
|
+
// Collect all aliases for the method
|
|
31
|
+
methodSpecifiers.forEach((specifier) => {
|
|
32
|
+
if (specifier.local && specifier.local.name !== methodName) {
|
|
33
|
+
methodAliases.push(specifier.local.name);
|
|
34
|
+
} else {
|
|
35
|
+
methodAliases.push(methodName);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Remove the method specifiers from the old import
|
|
40
|
+
const updatedSpecifiers = importDeclaration.specifiers?.filter(
|
|
41
|
+
(specifier) =>
|
|
42
|
+
specifier.type !== 'ImportSpecifier' || specifier.imported.name !== methodName
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (updatedSpecifiers && updatedSpecifiers.length > 0) {
|
|
46
|
+
// Replace the import with the updated specifiers if there are other imports left
|
|
47
|
+
j(path).replaceWith(j.importDeclaration(updatedSpecifiers, j.literal(oldDependency)));
|
|
48
|
+
} else {
|
|
49
|
+
// Remove the entire import statement if the specified method was the only import
|
|
50
|
+
j(path).remove();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Add new import dependency if the method was imported from the old dependency
|
|
56
|
+
if (methodImportedFromOldDependency) {
|
|
57
|
+
const dependencies = root
|
|
58
|
+
.find(j.ImportDeclaration)
|
|
59
|
+
.filter((path) => path.node.source.value === newDependency);
|
|
60
|
+
|
|
61
|
+
if (dependencies.length > 0) {
|
|
62
|
+
dependencies.forEach((path) => {
|
|
63
|
+
const importDeclaration: ImportDeclaration = path.node;
|
|
64
|
+
|
|
65
|
+
methodAliases.forEach((alias) => {
|
|
66
|
+
const newSpecifier = j.importSpecifier(j.identifier(methodName), j.identifier(alias));
|
|
67
|
+
const specifiersArray = importDeclaration.specifiers || [];
|
|
68
|
+
j(path).replaceWith(
|
|
69
|
+
j.importDeclaration([...specifiersArray, newSpecifier], j.literal(newDependency))
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
const newSpecifiers = methodAliases.map((alias) =>
|
|
75
|
+
j.importSpecifier(j.identifier(methodName), j.identifier(alias))
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const newImportDeclaration = j.importDeclaration(newSpecifiers, j.literal(newDependency));
|
|
79
|
+
|
|
80
|
+
// Find the index of the first non-import declaration
|
|
81
|
+
const body = root.get().node.program.body;
|
|
82
|
+
const lastImportIndex = body.findIndex((node) => node.type !== 'ImportDeclaration');
|
|
83
|
+
|
|
84
|
+
if (lastImportIndex > -1) {
|
|
85
|
+
// Insert the new import declaration just before the first non-import node
|
|
86
|
+
body.splice(lastImportIndex, 0, newImportDeclaration);
|
|
87
|
+
} else {
|
|
88
|
+
// Check if 'use strict' exists at the beginning
|
|
89
|
+
const hasUseStrict =
|
|
90
|
+
body[0]?.type === 'ExpressionStatement' && body[0]?.expression?.value === 'use strict';
|
|
91
|
+
// Add the new import after 'use strict' if it exists, otherwise at the beginning
|
|
92
|
+
body.splice(hasUseStrict ? 1 : 0, 0, newImportDeclaration);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|