@strapi/upgrade 0.0.0-experimental.e9122b401c96877b6707775c4f893660eab93ae3 → 0.0.0-experimental.f0d3b2d782e972f1dcb8acf0dce31d4090d1e420
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 +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 +7 -7
- 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 +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,192 @@
|
|
|
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
|
+
newImport?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const replacements: Replacement[] = [
|
|
25
|
+
{
|
|
26
|
+
oldName: 'AnErrorOccurred',
|
|
27
|
+
newImport: 'Page',
|
|
28
|
+
newName: 'Page.Error',
|
|
29
|
+
oldDependency: '@strapi/helper-plugin',
|
|
30
|
+
newDependency: '@strapi/strapi/admin',
|
|
31
|
+
toReplace: true,
|
|
32
|
+
toChangeImportSpecifier: true,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
oldName: 'CheckPagePermissions',
|
|
36
|
+
newImport: 'Page',
|
|
37
|
+
newName: 'Page.Protect',
|
|
38
|
+
oldDependency: '@strapi/helper-plugin',
|
|
39
|
+
newDependency: '@strapi/strapi/admin',
|
|
40
|
+
toReplace: true,
|
|
41
|
+
toChangeImportSpecifier: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
oldName: 'ConfirmDialog',
|
|
45
|
+
oldDependency: '@strapi/helper-plugin',
|
|
46
|
+
newDependency: '@strapi/strapi/admin',
|
|
47
|
+
toChangeImportSpecifier: true,
|
|
48
|
+
toReplace: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
oldName: 'DateTimePicker',
|
|
52
|
+
oldDependency: '@strapi/helper-plugin',
|
|
53
|
+
newDependency: '@strapi/design-system',
|
|
54
|
+
toChangeImportSpecifier: true,
|
|
55
|
+
toReplace: false,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
oldName: 'getFetchClient',
|
|
59
|
+
oldDependency: '@strapi/helper-plugin',
|
|
60
|
+
newDependency: '@strapi/strapi/admin',
|
|
61
|
+
toChangeImportSpecifier: true,
|
|
62
|
+
toReplace: false,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
oldName: 'LoadingIndicatorPage',
|
|
66
|
+
newImport: 'Page',
|
|
67
|
+
newName: 'Page.Loading',
|
|
68
|
+
oldDependency: '@strapi/helper-plugin',
|
|
69
|
+
newDependency: '@strapi/strapi/admin',
|
|
70
|
+
toReplace: true,
|
|
71
|
+
toChangeImportSpecifier: true,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
oldName: 'NoContent',
|
|
75
|
+
newImport: 'EmptyStateLayout',
|
|
76
|
+
newName: 'EmptyStateLayout',
|
|
77
|
+
oldDependency: '@strapi/helper-plugin',
|
|
78
|
+
newDependency: '@strapi/design-system',
|
|
79
|
+
toReplace: true,
|
|
80
|
+
toChangeImportSpecifier: true,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
oldName: 'NoPermissions',
|
|
84
|
+
newImport: 'Page',
|
|
85
|
+
newName: 'Page.NoPermissions',
|
|
86
|
+
oldDependency: '@strapi/helper-plugin',
|
|
87
|
+
newDependency: '@strapi/strapi/admin',
|
|
88
|
+
toReplace: true,
|
|
89
|
+
toChangeImportSpecifier: true,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
oldName: 'Status',
|
|
93
|
+
oldDependency: '@strapi/helper-plugin',
|
|
94
|
+
newDependency: '@strapi/design-system',
|
|
95
|
+
toChangeImportSpecifier: true,
|
|
96
|
+
toReplace: false,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
oldName: 'translatedErrors',
|
|
100
|
+
oldDependency: '@strapi/helper-plugin',
|
|
101
|
+
newDependency: '@strapi/strapi/admin',
|
|
102
|
+
toChangeImportSpecifier: true,
|
|
103
|
+
toReplace: false,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
oldName: 'useAPIErrorHandler',
|
|
107
|
+
oldDependency: '@strapi/helper-plugin',
|
|
108
|
+
newDependency: '@strapi/strapi/admin',
|
|
109
|
+
toChangeImportSpecifier: true,
|
|
110
|
+
toReplace: false,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
oldName: 'useCallbackRef',
|
|
114
|
+
oldDependency: '@strapi/helper-plugin',
|
|
115
|
+
newDependency: '@strapi/design-system',
|
|
116
|
+
toChangeImportSpecifier: true,
|
|
117
|
+
toReplace: false,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
oldName: 'useCollator',
|
|
121
|
+
oldDependency: '@strapi/helper-plugin',
|
|
122
|
+
newDependency: '@strapi/design-system',
|
|
123
|
+
toChangeImportSpecifier: true,
|
|
124
|
+
toReplace: false,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
oldName: 'useFetchClient',
|
|
128
|
+
oldDependency: '@strapi/helper-plugin',
|
|
129
|
+
newDependency: '@strapi/strapi/admin',
|
|
130
|
+
toChangeImportSpecifier: true,
|
|
131
|
+
toReplace: false,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
oldName: 'useFilter',
|
|
135
|
+
oldDependency: '@strapi/helper-plugin',
|
|
136
|
+
newDependency: '@strapi/design-system',
|
|
137
|
+
toChangeImportSpecifier: true,
|
|
138
|
+
toReplace: false,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
oldName: 'useQueryParams',
|
|
142
|
+
oldDependency: '@strapi/helper-plugin',
|
|
143
|
+
newDependency: '@strapi/strapi/admin',
|
|
144
|
+
toChangeImportSpecifier: true,
|
|
145
|
+
toReplace: false,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
oldName: 'useRBAC',
|
|
149
|
+
oldDependency: '@strapi/helper-plugin',
|
|
150
|
+
newDependency: '@strapi/strapi/admin',
|
|
151
|
+
toChangeImportSpecifier: true,
|
|
152
|
+
toReplace: false,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
oldName: 'SearchURLQuery',
|
|
156
|
+
oldDependency: '@strapi/helper-plugin',
|
|
157
|
+
newDependency: '@strapi/strapi/admin',
|
|
158
|
+
toChangeImportSpecifier: true,
|
|
159
|
+
toReplace: false,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
oldName: 'useSettingsForm',
|
|
163
|
+
oldDependency: '@strapi/helper-plugin',
|
|
164
|
+
newDependency: '@strapi/strapi/admin',
|
|
165
|
+
toChangeImportSpecifier: true,
|
|
166
|
+
toReplace: false,
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
replacements.forEach((replacement) => {
|
|
171
|
+
if (replacement.toReplace && replacement.newName) {
|
|
172
|
+
replaceJSXElement(root, j, {
|
|
173
|
+
oldElementName: replacement.oldName,
|
|
174
|
+
newElementName: replacement.newName,
|
|
175
|
+
oldDependency: replacement.oldDependency,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (replacement.toChangeImportSpecifier && replacement.newDependency) {
|
|
180
|
+
changeImportSpecifier(root, j, {
|
|
181
|
+
oldMethodName: replacement.oldName,
|
|
182
|
+
newMethodName: replacement.newImport,
|
|
183
|
+
oldDependency: replacement.oldDependency,
|
|
184
|
+
newDependency: replacement.newDependency,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
return root.toSource();
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export default transform;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
import type { modules } from '../../../dist';
|
|
4
|
+
|
|
5
|
+
const DEP_NAME = 'better-sqlite3';
|
|
6
|
+
const DEP_PATH = `dependencies.${DEP_NAME}`;
|
|
7
|
+
const DEP_VERSION = '11.3.0';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
const transform: modules.runner.json.JSONTransform = (file, params) => {
|
|
13
|
+
return upgradeIfExists(file, params, DEP_PATH, DEP_VERSION);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default transform;
|
|
17
|
+
|
|
18
|
+
// TODO: move this to a utility once we solve the issue where codemods are not transpiled properly
|
|
19
|
+
const upgradeIfExists = (
|
|
20
|
+
file: modules.runner.json.JSONSourceFile,
|
|
21
|
+
params: modules.runner.json.JSONTransformParams,
|
|
22
|
+
packagePath: string,
|
|
23
|
+
targetVersion: string
|
|
24
|
+
) => {
|
|
25
|
+
const { cwd, json } = params;
|
|
26
|
+
|
|
27
|
+
// Return early if the file path is not the root package.json
|
|
28
|
+
if (file.path !== path.join(cwd, 'package.json')) {
|
|
29
|
+
return file.json;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const packageJson = json(file.json);
|
|
33
|
+
|
|
34
|
+
// Check if the package exists
|
|
35
|
+
if (packageJson.has(packagePath)) {
|
|
36
|
+
const currentVersion = packageJson.get(packagePath);
|
|
37
|
+
// ensure we only upgrade, not downgrade
|
|
38
|
+
if (
|
|
39
|
+
typeof currentVersion === 'string' &&
|
|
40
|
+
semver.valid(currentVersion) &&
|
|
41
|
+
semver.lt(currentVersion, targetVersion)
|
|
42
|
+
) {
|
|
43
|
+
packageJson.set(packagePath, targetVersion);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return packageJson.root();
|
|
48
|
+
};
|
|
@@ -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;
|