@strapi/upgrade 5.0.0-rc.11 → 5.0.0-rc.13
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 +59 -33
- package/dist/cli.js.map +1 -1
- package/dist/index.js +65 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -37
- package/dist/index.mjs.map +1 -1
- package/dist/modules/format/formats.d.ts +2 -1
- package/dist/modules/format/formats.d.ts.map +1 -1
- package/dist/modules/project/constants.d.ts +6 -5
- package/dist/modules/project/constants.d.ts.map +1 -1
- package/dist/modules/project/project.d.ts +16 -2
- package/dist/modules/project/project.d.ts.map +1 -1
- package/dist/modules/project/types.d.ts +3 -0
- package/dist/modules/project/types.d.ts.map +1 -1
- package/dist/tasks/upgrade/upgrade.d.ts.map +1 -1
- package/package.json +5 -5
- package/resources/codemods/5.0.0/nocontent-migrate-to-emptystatelayout.code.ts +30 -0
- package/resources/codemods/5.0.0/useRBAC-hook-import-change.code.ts +1 -1
- package/resources/utils/change-import.ts +17 -8
- package/resources/utils/replace-jsx.ts +49 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/upgrade",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.13",
|
|
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.
|
|
62
|
+
"@strapi/utils": "5.0.0-rc.13",
|
|
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.
|
|
79
|
+
"@strapi/types": "5.0.0-rc.13",
|
|
80
80
|
"@types/fs-extra": "11.0.4",
|
|
81
81
|
"@types/jscodeshift": "0.11.10",
|
|
82
|
-
"eslint-config-custom": "5.0.0-rc.
|
|
82
|
+
"eslint-config-custom": "5.0.0-rc.13",
|
|
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": "
|
|
89
|
+
"gitHead": "cbc694f62f14f82d2931f7a407ea458a831045c9"
|
|
90
90
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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;
|
|
@@ -10,7 +10,7 @@ const transform: Transform = (file, api) => {
|
|
|
10
10
|
const root = j.withParser('tsx')(file.source);
|
|
11
11
|
|
|
12
12
|
changeImportSpecifier(root, j, {
|
|
13
|
-
|
|
13
|
+
oldMethodName: 'useRBAC',
|
|
14
14
|
oldDependency: '@strapi/helper-plugin',
|
|
15
15
|
newDependency: '@strapi/strapi/admin',
|
|
16
16
|
});
|
|
@@ -3,9 +3,15 @@ import type { ImportDeclaration, JSCodeshift, Collection } from 'jscodeshift';
|
|
|
3
3
|
export const changeImportSpecifier = (
|
|
4
4
|
root: Collection,
|
|
5
5
|
j: JSCodeshift,
|
|
6
|
-
options: {
|
|
6
|
+
options: {
|
|
7
|
+
oldDependency: string;
|
|
8
|
+
newDependency: string;
|
|
9
|
+
oldMethodName: string;
|
|
10
|
+
newMethodName?: string;
|
|
11
|
+
}
|
|
7
12
|
): void => {
|
|
8
|
-
const {
|
|
13
|
+
const { oldMethodName, newMethodName, oldDependency, newDependency } = options;
|
|
14
|
+
const methodNameToReplace = newMethodName ?? oldMethodName;
|
|
9
15
|
|
|
10
16
|
// Flag to check if the method was imported from the old dependency
|
|
11
17
|
let methodImportedFromOldDependency = false;
|
|
@@ -21,7 +27,7 @@ export const changeImportSpecifier = (
|
|
|
21
27
|
// Check if the method is imported from the old dependency
|
|
22
28
|
const methodSpecifiers = importDeclaration.specifiers?.filter(
|
|
23
29
|
(specifier) =>
|
|
24
|
-
specifier.type === 'ImportSpecifier' && specifier.imported.name ===
|
|
30
|
+
specifier.type === 'ImportSpecifier' && specifier.imported.name === oldMethodName
|
|
25
31
|
);
|
|
26
32
|
|
|
27
33
|
if (methodSpecifiers && methodSpecifiers.length > 0) {
|
|
@@ -29,17 +35,17 @@ export const changeImportSpecifier = (
|
|
|
29
35
|
|
|
30
36
|
// Collect all aliases for the method
|
|
31
37
|
methodSpecifiers.forEach((specifier) => {
|
|
32
|
-
if (specifier.local && specifier.local.name !==
|
|
38
|
+
if (specifier.local && specifier.local.name !== oldMethodName) {
|
|
33
39
|
methodAliases.push(specifier.local.name);
|
|
34
40
|
} else {
|
|
35
|
-
methodAliases.push(
|
|
41
|
+
methodAliases.push(methodNameToReplace);
|
|
36
42
|
}
|
|
37
43
|
});
|
|
38
44
|
|
|
39
45
|
// Remove the method specifiers from the old import
|
|
40
46
|
const updatedSpecifiers = importDeclaration.specifiers?.filter(
|
|
41
47
|
(specifier) =>
|
|
42
|
-
specifier.type !== 'ImportSpecifier' || specifier.imported.name !==
|
|
48
|
+
specifier.type !== 'ImportSpecifier' || specifier.imported.name !== oldMethodName
|
|
43
49
|
);
|
|
44
50
|
|
|
45
51
|
if (updatedSpecifiers && updatedSpecifiers.length > 0) {
|
|
@@ -63,7 +69,10 @@ export const changeImportSpecifier = (
|
|
|
63
69
|
const importDeclaration: ImportDeclaration = path.node;
|
|
64
70
|
|
|
65
71
|
methodAliases.forEach((alias) => {
|
|
66
|
-
const newSpecifier = j.importSpecifier(
|
|
72
|
+
const newSpecifier = j.importSpecifier(
|
|
73
|
+
j.identifier(methodNameToReplace),
|
|
74
|
+
j.identifier(alias)
|
|
75
|
+
);
|
|
67
76
|
const specifiersArray = importDeclaration.specifiers || [];
|
|
68
77
|
j(path).replaceWith(
|
|
69
78
|
j.importDeclaration([...specifiersArray, newSpecifier], j.literal(newDependency))
|
|
@@ -72,7 +81,7 @@ export const changeImportSpecifier = (
|
|
|
72
81
|
});
|
|
73
82
|
} else {
|
|
74
83
|
const newSpecifiers = methodAliases.map((alias) =>
|
|
75
|
-
j.importSpecifier(j.identifier(
|
|
84
|
+
j.importSpecifier(j.identifier(methodNameToReplace), j.identifier(alias))
|
|
76
85
|
);
|
|
77
86
|
|
|
78
87
|
const newImportDeclaration = j.importDeclaration(newSpecifiers, j.literal(newDependency));
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { JSCodeshift, Collection } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export const replaceJSXElement = (
|
|
4
|
+
root: Collection,
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
{
|
|
7
|
+
oldElementName,
|
|
8
|
+
newElementName,
|
|
9
|
+
oldDependency,
|
|
10
|
+
}: {
|
|
11
|
+
oldElementName: string;
|
|
12
|
+
newElementName: string;
|
|
13
|
+
oldDependency: string;
|
|
14
|
+
}
|
|
15
|
+
) => {
|
|
16
|
+
// Find the import declaration for the old dependency
|
|
17
|
+
const importDeclaration = root.find(j.ImportDeclaration, {
|
|
18
|
+
source: { value: oldDependency },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (importDeclaration.size() === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Get the local name of the imported element
|
|
26
|
+
const localName = importDeclaration
|
|
27
|
+
.find(j.ImportSpecifier, {
|
|
28
|
+
imported: { name: oldElementName },
|
|
29
|
+
})
|
|
30
|
+
.nodes()[0]?.local?.name;
|
|
31
|
+
|
|
32
|
+
if (!localName) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Replace JSX elements
|
|
37
|
+
root.findJSXElements(localName).forEach((path) => {
|
|
38
|
+
const openingElement = path.node.openingElement;
|
|
39
|
+
const closingElement = path.node.closingElement;
|
|
40
|
+
|
|
41
|
+
if (j.JSXIdentifier.check(openingElement.name)) {
|
|
42
|
+
openingElement.name.name = newElementName;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (closingElement && j.JSXIdentifier.check(closingElement.name)) {
|
|
46
|
+
closingElement.name.name = newElementName;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|