@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/upgrade",
3
- "version": "5.0.0-rc.11",
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.11",
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.11",
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.11",
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": "8210c57d2001c53e1591a8ce1e46d6605b3b39de"
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
- methodName: 'useRBAC',
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: { methodName: string; oldDependency: string; newDependency: string }
6
+ options: {
7
+ oldDependency: string;
8
+ newDependency: string;
9
+ oldMethodName: string;
10
+ newMethodName?: string;
11
+ }
7
12
  ): void => {
8
- const { methodName, oldDependency, newDependency } = options;
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 === methodName
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 !== methodName) {
38
+ if (specifier.local && specifier.local.name !== oldMethodName) {
33
39
  methodAliases.push(specifier.local.name);
34
40
  } else {
35
- methodAliases.push(methodName);
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 !== methodName
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(j.identifier(methodName), j.identifier(alias));
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(methodName), j.identifier(alias))
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
+ };