@strapi/upgrade 0.0.0-experimental.e3e48deb89bd0a1b6cc69b698696566fa7854a95 → 0.0.0-experimental.e9122b401c96877b6707775c4f893660eab93ae3
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 +1482 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.js +366 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +367 -106
- 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 +6 -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 +3 -0
- 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 +6 -0
- package/dist/modules/format/formats.d.ts.map +1 -1
- package/dist/modules/project/constants.d.ts +6 -3
- package/dist/modules/project/constants.d.ts.map +1 -1
- package/dist/modules/project/index.d.ts +2 -0
- package/dist/modules/project/index.d.ts.map +1 -1
- package/dist/modules/project/project.d.ts +27 -5
- package/dist/modules/project/project.d.ts.map +1 -1
- package/dist/modules/project/types.d.ts +3 -10
- package/dist/modules/project/types.d.ts.map +1 -1
- package/dist/modules/project/utils.d.ts +6 -0
- package/dist/modules/project/utils.d.ts.map +1 -0
- package/dist/modules/report/report.d.ts.map +1 -1
- package/dist/modules/requirement/types.d.ts +2 -2
- package/dist/modules/requirement/types.d.ts.map +1 -1
- package/dist/modules/runner/json/transform.d.ts.map +1 -1
- package/dist/modules/upgrader/upgrader.d.ts +3 -3
- 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/dist/tasks/upgrade/upgrade.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-remove-strapi-plugin-i18n.json.ts +31 -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-react-router-dom.json.ts +59 -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/nocontent-migrate-to-emptystatelayout.code.ts +30 -0
- package/resources/codemods/5.0.0/s3-keys-wrapped-in-credentials.code.ts +1 -1
- package/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts +5 -2
- package/resources/codemods/5.0.0/strapi-public-interface.code.ts +126 -0
- package/resources/codemods/5.0.0/use-uid-for-config-namespace.code.ts +1 -1
- 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/examples/console.log-to-console.info.code.ts +1 -1
- package/resources/examples/disable-jsx-buttons.code.ts +42 -0
- package/resources/utils/change-import.ts +105 -0
- package/resources/utils/replace-jsx.ts +49 -0
- package/dist/_chunks/codemod-runner-B5OeSMTQ.js +0 -730
- package/dist/_chunks/codemod-runner-B5OeSMTQ.js.map +0 -1
- package/dist/_chunks/codemods-10ZKewQx.js +0 -108
- package/dist/_chunks/codemods-10ZKewQx.js.map +0 -1
- package/dist/_chunks/index-uxCwtuH1.js +0 -103
- package/dist/_chunks/index-uxCwtuH1.js.map +0 -1
- package/dist/_chunks/upgrade-A4T1OWs5.js +0 -357
- package/dist/_chunks/upgrade-A4T1OWs5.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,59 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
|
|
4
|
+
import type { modules } from '../../../dist';
|
|
5
|
+
|
|
6
|
+
const REACT_ROUTER_DEP_NAME = 'react-router-dom';
|
|
7
|
+
const REACT_ROUTER_DEP_PATH = `dependencies.${REACT_ROUTER_DEP_NAME}`;
|
|
8
|
+
|
|
9
|
+
const DEP_NEW_VERSION_RANGE = '^6.0.0';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Specifically targets the root package.json and updates the react-router-dom dependency version.
|
|
13
|
+
*
|
|
14
|
+
* We first check if the react-router-dom dependency is listed in the package.json. If the dependency is
|
|
15
|
+
* found, we verify its version.
|
|
16
|
+
*
|
|
17
|
+
* If the detected version does not satisfy the new version range, we replace it with the new one.
|
|
18
|
+
*
|
|
19
|
+
* Conversely, if no react-router-dom dependency is listed, we add it with the new version range.
|
|
20
|
+
*/
|
|
21
|
+
const transform: modules.runner.json.JSONTransform = (file, params) => {
|
|
22
|
+
const { cwd, json } = params;
|
|
23
|
+
|
|
24
|
+
const rootPackageJsonPath = path.join(cwd, 'package.json');
|
|
25
|
+
|
|
26
|
+
if (file.path !== rootPackageJsonPath) {
|
|
27
|
+
return file.json;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const j = json(file.json);
|
|
31
|
+
|
|
32
|
+
if (j.has(REACT_ROUTER_DEP_PATH)) {
|
|
33
|
+
const currentVersion = j.get(REACT_ROUTER_DEP_PATH);
|
|
34
|
+
|
|
35
|
+
// If the current version is not a string, then something is wrong, abort
|
|
36
|
+
if (typeof currentVersion !== 'string') {
|
|
37
|
+
return j.root();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const currentSatisfiesNew = semver.satisfies(currentVersion, DEP_NEW_VERSION_RANGE);
|
|
41
|
+
|
|
42
|
+
// if the current version satisfies the new range, keep it as is and abort
|
|
43
|
+
if (currentSatisfiesNew) {
|
|
44
|
+
return j.root();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// else, update the version with the new one
|
|
48
|
+
j.set(REACT_ROUTER_DEP_PATH, DEP_NEW_VERSION_RANGE);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// If the dependency is not listed yet, add it
|
|
52
|
+
else {
|
|
53
|
+
j.set(REACT_ROUTER_DEP_PATH, DEP_NEW_VERSION_RANGE);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return j.root();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default transform;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
|
|
4
|
+
import type { modules } from '../../../dist';
|
|
5
|
+
|
|
6
|
+
const DEP_NAME = 'styled-components';
|
|
7
|
+
const DEP_PATH = `dependencies.${DEP_NAME}`;
|
|
8
|
+
|
|
9
|
+
const DEP_NEW_VERSION_RANGE = '^6.0.0';
|
|
10
|
+
|
|
11
|
+
const transform: modules.runner.json.JSONTransform = (file, params) => {
|
|
12
|
+
const { cwd, json } = params;
|
|
13
|
+
|
|
14
|
+
const rootPackageJsonPath = path.join(cwd, 'package.json');
|
|
15
|
+
|
|
16
|
+
if (file.path !== rootPackageJsonPath) {
|
|
17
|
+
return file.json;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const j = json(file.json);
|
|
21
|
+
|
|
22
|
+
if (j.has(DEP_PATH)) {
|
|
23
|
+
const currentVersion = j.get(DEP_PATH);
|
|
24
|
+
|
|
25
|
+
// If the current version is not a string, then something is wrong, abort
|
|
26
|
+
if (typeof currentVersion !== 'string') {
|
|
27
|
+
return j.root();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const currentSatisfiesNew = semver.satisfies(currentVersion, DEP_NEW_VERSION_RANGE);
|
|
31
|
+
|
|
32
|
+
// if the current version satisfies the new range, keep it as is and abort
|
|
33
|
+
if (currentSatisfiesNew) {
|
|
34
|
+
return j.root();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// else, update the version with the new one
|
|
38
|
+
j.set(DEP_PATH, DEP_NEW_VERSION_RANGE);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// If the dependency is not listed yet, add it
|
|
42
|
+
else {
|
|
43
|
+
j.set(DEP_PATH, DEP_NEW_VERSION_RANGE);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return j.root();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default transform;
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import type { Transform, JSCodeshift, ASTPath, ObjectExpression } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This codemod transforms entity service calls to match the new document service interface.
|
|
5
|
+
It supports all kind of argument parsing, including spread elements & deeply nested objects.
|
|
6
|
+
|
|
7
|
+
Here is a list of scenarios this was tested against
|
|
8
|
+
|
|
9
|
+
const uid = "api::xxx.xxx";
|
|
10
|
+
const entityId = 1;
|
|
11
|
+
|
|
12
|
+
Case: basic call
|
|
13
|
+
|
|
14
|
+
strapi.entityService.findOne(uid, entityId, {
|
|
15
|
+
fields: ["id", "name", "description"],
|
|
16
|
+
populate: ["author", "comments"],
|
|
17
|
+
publicationState: "preview",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Case: using a variable declared somewhere else
|
|
22
|
+
|
|
23
|
+
const objectParam_2 = {
|
|
24
|
+
fields: ["id", "name", "description"],
|
|
25
|
+
populate: ["author", "comments"],
|
|
26
|
+
publicationState: "preview",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
strapi.entityService.findOne(uid, entityId, objectParam_2);
|
|
30
|
+
|
|
31
|
+
Case: using a variable declared somewhere else with a spread element
|
|
32
|
+
|
|
33
|
+
const objectParam_3 = {
|
|
34
|
+
fields: ["id", "name", "description"],
|
|
35
|
+
populate: ["author", "comments"],
|
|
36
|
+
publicationState: "preview",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
strapi.entityService.findOne(uid, entityId, {
|
|
40
|
+
...objectParam_3,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Case: using a variable declared somewhere else with a spread element and overwritten properties
|
|
45
|
+
|
|
46
|
+
const objectParam_4_1 = {
|
|
47
|
+
fields: ["id", "name", "description"],
|
|
48
|
+
populate: ["author", "comments"],
|
|
49
|
+
publicationState: "preview",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const objectParam_4 = {
|
|
53
|
+
publicationState: "live",
|
|
54
|
+
...objectParam_4_1,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
strapi.entityService.findOne(uid, entityId, {
|
|
58
|
+
...objectParam_4,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
Case: using a variable declared somewhere else with a spread array element while that need its 1st element to be moved
|
|
62
|
+
|
|
63
|
+
const objectParam_5 = [
|
|
64
|
+
uid,
|
|
65
|
+
entityId,
|
|
66
|
+
{
|
|
67
|
+
fields: ["id", "name", "description"],
|
|
68
|
+
populate: ["author", "comments"],
|
|
69
|
+
publicationState: "preview",
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
strapi.entityService.findOne(...objectParam_5);
|
|
74
|
+
|
|
75
|
+
Case: using a variable declared somewhere else with a partial spread array
|
|
76
|
+
|
|
77
|
+
const objectParam_6 = [
|
|
78
|
+
entityId,
|
|
79
|
+
{
|
|
80
|
+
fields: ["id", "name", "description"],
|
|
81
|
+
populate: ["author", "comments"],
|
|
82
|
+
publicationState: "preview",
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
strapi.entityService.findOne(uid, ...objectParam_6);
|
|
87
|
+
|
|
88
|
+
Case: using a variable declared somewhere else with a partial & nested spread arrays
|
|
89
|
+
|
|
90
|
+
const objectParam_7_1 = [
|
|
91
|
+
{
|
|
92
|
+
fields: ["id", "name", "description"],
|
|
93
|
+
populate: ["author", "comments"],
|
|
94
|
+
publicationState: "preview",
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const objectParam_7 = [entityId, ...objectParam_7_1];
|
|
99
|
+
|
|
100
|
+
strapi.entityService.findOne(uid, ...objectParam_7);
|
|
101
|
+
|
|
102
|
+
Case: using a variable declared somewhere else with a partial & nested spread arrays & objects
|
|
103
|
+
|
|
104
|
+
const objectParam_8_1 = {
|
|
105
|
+
publicationState: "preview",
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const objectParam_8 = [
|
|
109
|
+
entityId,
|
|
110
|
+
{
|
|
111
|
+
fields: ["id", "name", "description"],
|
|
112
|
+
populate: ["author", "comments"],
|
|
113
|
+
...objectParam_8_1,
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
strapi.entityService.findOne(uid, ...objectParam_8);
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
Case: some sort of mix of all the above
|
|
121
|
+
|
|
122
|
+
const objectParam_9_1 = {
|
|
123
|
+
publicationState: "preview",
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const objectParam_9 = {
|
|
127
|
+
fields: ["id", "name", "description"],
|
|
128
|
+
populate: ["author", "comments"],
|
|
129
|
+
...objectParam_9_1,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
strapi.entityService.findOne(uid, ...[entityId, [objectParam_9]]);
|
|
133
|
+
|
|
134
|
+
Case: even more complex
|
|
135
|
+
|
|
136
|
+
const objectParam_10_1 = {
|
|
137
|
+
publicationState: "preview",
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const objectParam_10_2 = [uid, ...[12], ...[objectParam_10_1]];
|
|
141
|
+
const objectParam_10 = [...objectParam_10_2];
|
|
142
|
+
|
|
143
|
+
strapi.entityService.findOne(...[...objectParam_10]);
|
|
144
|
+
|
|
145
|
+
Case: find, create, update, delete with entityId as first argument
|
|
146
|
+
|
|
147
|
+
strapi.entityService.findMany(uid, {
|
|
148
|
+
fields: ["id", "name", "description"],
|
|
149
|
+
populate: ["author", "comments"],
|
|
150
|
+
publicationState: "preview",
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
strapi.entityService.create(uid, {
|
|
154
|
+
data: {
|
|
155
|
+
name: "John Doe",
|
|
156
|
+
age: 30,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
strapi.entityService.update(uid, entityId, {
|
|
161
|
+
data: {
|
|
162
|
+
name: "John Doe",
|
|
163
|
+
age: 30,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
strapi.entityService.delete(uid, entityId);
|
|
168
|
+
strapi.entityService.findOne(uid, entityId);
|
|
169
|
+
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
const movedFunctions = ['findOne', 'findMany', 'count', 'create', 'update', 'delete'];
|
|
173
|
+
|
|
174
|
+
const functionsWithEntityId = ['findOne', 'update', 'delete'];
|
|
175
|
+
|
|
176
|
+
const transformDeclaration = (path: ASTPath<any>, name: any, j: JSCodeshift) => {
|
|
177
|
+
const declaration = findClosestDeclaration(path, name, j);
|
|
178
|
+
|
|
179
|
+
if (!declaration) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
transformElement(path, declaration.init, j);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const transformElement = (path: ASTPath<any>, element: any, j: JSCodeshift) => {
|
|
187
|
+
switch (true) {
|
|
188
|
+
case j.ObjectExpression.check(element): {
|
|
189
|
+
transformObjectParam(path, element, j);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
case j.Identifier.check(element): {
|
|
194
|
+
transformDeclaration(path, element.name, j);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
case j.SpreadElement.check(element): {
|
|
199
|
+
transformElement(path, element.argument, j);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
case j.ArrayExpression.check(element): {
|
|
204
|
+
element.elements.forEach((element) => {
|
|
205
|
+
transformElement(path, element, j);
|
|
206
|
+
});
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
default: {
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const transformObjectParam = (path: ASTPath<any>, expression: ObjectExpression, j: JSCodeshift) => {
|
|
216
|
+
expression.properties.forEach((prop) => {
|
|
217
|
+
switch (true) {
|
|
218
|
+
case j.ObjectProperty.check(prop): {
|
|
219
|
+
if (!j.Identifier.check(prop.key) && !j.Literal.check(prop.key)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (j.Identifier.check(prop.key) && prop.key.name !== 'publicationState') {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (j.Literal.check(prop.key) && prop.key.value !== 'publicationState') {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (j.Identifier.check(prop.key) && prop.key.name === 'publicationState') {
|
|
232
|
+
if (!prop.computed && !prop.shorthand) {
|
|
233
|
+
prop.key.name = 'status';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (prop.shorthand && !prop.computed) {
|
|
237
|
+
prop.shorthand = false;
|
|
238
|
+
prop.key = j.identifier('status');
|
|
239
|
+
prop.value = j.identifier('publicationState');
|
|
240
|
+
}
|
|
241
|
+
} else if (j.Literal.check(prop.key) && prop.key.value === 'publicationState') {
|
|
242
|
+
prop.key.value = 'status';
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
switch (true) {
|
|
246
|
+
case j.Literal.check(prop.value): {
|
|
247
|
+
prop.value = prop.value.value === 'live' ? j.literal('published') : j.literal('draft');
|
|
248
|
+
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case j.Identifier.check(prop.value): {
|
|
252
|
+
const declaration = findClosestDeclaration(path, prop.value.name, j);
|
|
253
|
+
|
|
254
|
+
if (!declaration) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (j.Literal.check(declaration.init)) {
|
|
259
|
+
declaration.init =
|
|
260
|
+
declaration.init.value === 'live' ? j.literal('published') : j.literal('draft');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
default: {
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case j.SpreadElement.check(prop): {
|
|
273
|
+
transformElement(path, prop.argument, j);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
default: {
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const findClosestDeclaration = (path: ASTPath<any>, name: string, j) => {
|
|
284
|
+
// find Identifier declaration
|
|
285
|
+
const scope = path.scope.lookup(name);
|
|
286
|
+
|
|
287
|
+
if (!scope) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return j(scope.path)
|
|
292
|
+
.find(j.VariableDeclarator, { id: { type: 'Identifier', name } })
|
|
293
|
+
.nodes()[0];
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const transform: Transform = (file, api) => {
|
|
297
|
+
const j = api.jscodeshift;
|
|
298
|
+
|
|
299
|
+
const root = j(file.source);
|
|
300
|
+
|
|
301
|
+
root
|
|
302
|
+
.find(j.CallExpression, {
|
|
303
|
+
callee: {
|
|
304
|
+
type: 'MemberExpression',
|
|
305
|
+
object: {
|
|
306
|
+
type: 'MemberExpression',
|
|
307
|
+
object: {
|
|
308
|
+
type: 'Identifier',
|
|
309
|
+
name: 'strapi',
|
|
310
|
+
},
|
|
311
|
+
property: {
|
|
312
|
+
type: 'Identifier',
|
|
313
|
+
name: 'entityService',
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
property: {
|
|
317
|
+
type: 'Identifier',
|
|
318
|
+
name: (name) => movedFunctions.includes(name),
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
.replaceWith((path) => {
|
|
323
|
+
if (!j.MemberExpression.check(path.value.callee)) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const args = path.value.arguments;
|
|
328
|
+
|
|
329
|
+
if (args.length === 0) {
|
|
330
|
+
// we don't know how to transform this
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
type Args = typeof path.value.arguments;
|
|
335
|
+
|
|
336
|
+
function resolveArgs(args: Args): Args {
|
|
337
|
+
return args.flatMap((arg: Args[number]) => {
|
|
338
|
+
switch (true) {
|
|
339
|
+
case j.Identifier.check(arg):
|
|
340
|
+
case j.Literal.check(arg): {
|
|
341
|
+
return arg;
|
|
342
|
+
}
|
|
343
|
+
case j.SpreadElement.check(arg): {
|
|
344
|
+
switch (true) {
|
|
345
|
+
case j.Identifier.check(arg.argument): {
|
|
346
|
+
const identifier = arg.argument;
|
|
347
|
+
|
|
348
|
+
const declaration = findClosestDeclaration(path, identifier.name, j);
|
|
349
|
+
|
|
350
|
+
if (!declaration) {
|
|
351
|
+
return arg;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
switch (true) {
|
|
355
|
+
case j.ArrayExpression.check(declaration.init): {
|
|
356
|
+
return resolveArgs(declaration.init.elements);
|
|
357
|
+
}
|
|
358
|
+
default:
|
|
359
|
+
return arg;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
case j.ArrayExpression.check(arg.argument): {
|
|
363
|
+
return resolveArgs(arg.argument.elements as Args);
|
|
364
|
+
}
|
|
365
|
+
default: {
|
|
366
|
+
return arg;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
default: {
|
|
371
|
+
return arg;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const resolvedArgs = resolveArgs(args);
|
|
378
|
+
|
|
379
|
+
const [docUID, ...rest] = resolvedArgs;
|
|
380
|
+
|
|
381
|
+
// function with entityId as first argument
|
|
382
|
+
if (
|
|
383
|
+
j.Identifier.check(path.value.callee.property) &&
|
|
384
|
+
functionsWithEntityId.includes(path.value.callee.property.name)
|
|
385
|
+
) {
|
|
386
|
+
rest.splice(0, 1);
|
|
387
|
+
|
|
388
|
+
// in case no extra params are passed in the function e.g delete(uid, entityId)
|
|
389
|
+
if (rest.length === 0) {
|
|
390
|
+
rest.push(
|
|
391
|
+
j.objectExpression.from({
|
|
392
|
+
properties: [],
|
|
393
|
+
})
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const params = rest[0];
|
|
398
|
+
|
|
399
|
+
const placeholder = j.objectProperty(j.identifier('documentId'), j.literal('__TODO__'));
|
|
400
|
+
|
|
401
|
+
// add documentId to params with a placeholder
|
|
402
|
+
if (j.ObjectExpression.check(params)) {
|
|
403
|
+
params.properties.unshift(placeholder);
|
|
404
|
+
} else if (j.Identifier.check(params)) {
|
|
405
|
+
const declaration = findClosestDeclaration(path, params.name, j);
|
|
406
|
+
|
|
407
|
+
if (!declaration) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (j.ObjectExpression.check(declaration.init)) {
|
|
412
|
+
declaration.init.properties.unshift(placeholder);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
path.value.arguments.forEach((arg) => {
|
|
418
|
+
transformElement(path, arg, j);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
return j.callExpression(
|
|
422
|
+
j.memberExpression(
|
|
423
|
+
j.callExpression(j.memberExpression(j.identifier('strapi'), j.identifier('documents')), [
|
|
424
|
+
docUID,
|
|
425
|
+
]),
|
|
426
|
+
path.value.callee.property
|
|
427
|
+
),
|
|
428
|
+
rest
|
|
429
|
+
);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
return root.toSource();
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
export const parser = 'tsx';
|
|
436
|
+
|
|
437
|
+
export default transform;
|
|
@@ -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;
|
|
@@ -17,18 +17,21 @@ const transform: modules.runner.json.JSONTransform = (file, params) => {
|
|
|
17
17
|
|
|
18
18
|
const j = json(file.json);
|
|
19
19
|
|
|
20
|
+
let removed = false;
|
|
21
|
+
|
|
20
22
|
const targetProperties = ['sqlite3', '@vscode/sqlite3'];
|
|
21
23
|
|
|
22
24
|
targetProperties.forEach((targetProperty) => {
|
|
23
25
|
const oldSqliteDependency = `dependencies.${targetProperty}`;
|
|
24
26
|
if (j.has(oldSqliteDependency)) {
|
|
25
27
|
j.remove(oldSqliteDependency);
|
|
28
|
+
removed = true;
|
|
26
29
|
}
|
|
27
30
|
});
|
|
28
31
|
|
|
29
|
-
if (!j.has('dependencies.better-sqlite3')) {
|
|
32
|
+
if (removed && !j.has('dependencies.better-sqlite3')) {
|
|
30
33
|
// TODO check this version when releasing V5
|
|
31
|
-
j.set('dependencies.better-sqlite3', '9.
|
|
34
|
+
j.set('dependencies.better-sqlite3', '9.4.3');
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
return j.root();
|