@strapi/upgrade 0.0.0-experimental.f31889311d753b5f7d95198ae84d8fce1d156cd6 → 0.0.0-experimental.f49f46a1c17445a39e8af3f63124bcccf73842e6
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/README.md +1 -1
- package/dist/cli.js +439 -317
- package/dist/cli.js.map +1 -1
- package/dist/index.js +462 -343
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +458 -340
- package/dist/index.mjs.map +1 -1
- package/dist/modules/error/utils.d.ts +8 -0
- package/dist/modules/error/utils.d.ts.map +1 -1
- package/dist/modules/file-scanner/scanner.d.ts.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/modules/upgrader/types.d.ts +6 -0
- package/dist/modules/upgrader/types.d.ts.map +1 -1
- package/dist/modules/upgrader/upgrader.d.ts +4 -0
- package/dist/modules/upgrader/upgrader.d.ts.map +1 -1
- package/dist/modules/version/range.d.ts.map +1 -1
- package/dist/modules/version/types.d.ts +2 -1
- package/dist/modules/version/types.d.ts.map +1 -1
- package/dist/tasks/codemods/utils.d.ts.map +1 -1
- package/dist/tasks/upgrade/prompts/index.d.ts +2 -0
- package/dist/tasks/upgrade/prompts/index.d.ts.map +1 -0
- package/dist/tasks/upgrade/prompts/latest.d.ts +9 -0
- package/dist/tasks/upgrade/prompts/latest.d.ts.map +1 -0
- package/dist/tasks/upgrade/requirements/major.d.ts.map +1 -1
- package/dist/tasks/upgrade/upgrade.d.ts.map +1 -1
- package/package.json +7 -7
- 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/deprecate-helper-plugin.code.ts +192 -0
- package/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts +0 -1
- package/resources/codemods/5.1.0/dependency-better-sqlite3.json.ts +48 -0
- package/resources/utils/change-import.ts +118 -0
- package/resources/utils/replace-jsx.ts +49 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { ImportDeclaration, JSCodeshift, Collection } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export const changeImportSpecifier = (
|
|
4
|
+
root: Collection,
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
options: {
|
|
7
|
+
oldDependency: string;
|
|
8
|
+
newDependency: string;
|
|
9
|
+
oldMethodName: string;
|
|
10
|
+
newMethodName?: string;
|
|
11
|
+
}
|
|
12
|
+
): void => {
|
|
13
|
+
const { oldMethodName, newMethodName, oldDependency, newDependency } = options;
|
|
14
|
+
const methodNameToReplace = newMethodName ?? oldMethodName;
|
|
15
|
+
|
|
16
|
+
// Flag to check if the method was imported from the old dependency
|
|
17
|
+
let methodImportedFromOldDependency = false;
|
|
18
|
+
const methodAliases: string[] = [];
|
|
19
|
+
|
|
20
|
+
// Remove the method from the old dependency and check if it was imported
|
|
21
|
+
root
|
|
22
|
+
.find(j.ImportDeclaration)
|
|
23
|
+
.filter((path) => path.node.source.value === oldDependency)
|
|
24
|
+
.forEach((path) => {
|
|
25
|
+
const importDeclaration: ImportDeclaration = path.node;
|
|
26
|
+
|
|
27
|
+
// Check if the method is imported from the old dependency
|
|
28
|
+
const methodSpecifiers = importDeclaration.specifiers?.filter(
|
|
29
|
+
(specifier) =>
|
|
30
|
+
specifier.type === 'ImportSpecifier' && specifier.imported.name === oldMethodName
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (methodSpecifiers && methodSpecifiers.length > 0) {
|
|
34
|
+
methodImportedFromOldDependency = true;
|
|
35
|
+
|
|
36
|
+
// Collect all aliases for the method
|
|
37
|
+
methodSpecifiers.forEach((specifier) => {
|
|
38
|
+
if (specifier.local && specifier.local.name !== oldMethodName) {
|
|
39
|
+
methodAliases.push(specifier.local.name);
|
|
40
|
+
} else {
|
|
41
|
+
methodAliases.push(methodNameToReplace);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Remove the method specifiers from the old import
|
|
46
|
+
const updatedSpecifiers = importDeclaration.specifiers?.filter(
|
|
47
|
+
(specifier) =>
|
|
48
|
+
specifier.type !== 'ImportSpecifier' || specifier.imported.name !== oldMethodName
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
if (updatedSpecifiers && updatedSpecifiers.length > 0) {
|
|
52
|
+
// Replace the import with the updated specifiers if there are other imports left
|
|
53
|
+
j(path).replaceWith(j.importDeclaration(updatedSpecifiers, j.literal(oldDependency)));
|
|
54
|
+
} else {
|
|
55
|
+
// Remove the entire import statement if the specified method was the only import
|
|
56
|
+
j(path).remove();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Add new import dependency if the method was imported from the old dependency
|
|
62
|
+
if (methodImportedFromOldDependency) {
|
|
63
|
+
const dependencies = root
|
|
64
|
+
.find(j.ImportDeclaration)
|
|
65
|
+
.filter((path) => path.node.source.value === newDependency);
|
|
66
|
+
|
|
67
|
+
if (dependencies.length > 0) {
|
|
68
|
+
// we have to use a flag to prevent adding the method to multiple imports
|
|
69
|
+
let methodAdded = false;
|
|
70
|
+
dependencies.forEach((path) => {
|
|
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
|
+
);
|
|
82
|
+
|
|
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
|
+
}
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
const newSpecifiers = methodAliases.map((alias) =>
|
|
97
|
+
j.importSpecifier(j.identifier(methodNameToReplace), j.identifier(alias))
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const newImportDeclaration = j.importDeclaration(newSpecifiers, j.literal(newDependency));
|
|
101
|
+
|
|
102
|
+
// Find the index of the first non-import declaration
|
|
103
|
+
const body = root.get().node.program.body;
|
|
104
|
+
const lastImportIndex = body.findIndex((node) => node.type !== 'ImportDeclaration');
|
|
105
|
+
|
|
106
|
+
if (lastImportIndex > -1) {
|
|
107
|
+
// Insert the new import declaration just before the first non-import node
|
|
108
|
+
body.splice(lastImportIndex, 0, newImportDeclaration);
|
|
109
|
+
} else {
|
|
110
|
+
// Check if 'use strict' exists at the beginning
|
|
111
|
+
const hasUseStrict =
|
|
112
|
+
body[0]?.type === 'ExpressionStatement' && body[0]?.expression?.value === 'use strict';
|
|
113
|
+
// Add the new import after 'use strict' if it exists, otherwise at the beginning
|
|
114
|
+
body.splice(hasUseStrict ? 1 : 0, 0, newImportDeclaration);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
@@ -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
|
+
};
|