@strapi/upgrade 0.0.0-experimental.e3e48deb89bd0a1b6cc69b698696566fa7854a95 → 0.0.0-experimental.e576af447d9f97e89e24c6daa32d8f714376cd5f

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.
Files changed (101) hide show
  1. package/LICENSE +19 -4
  2. package/README.md +1 -1
  3. package/dist/chunks/logger-DGi224NW.js +1649 -0
  4. package/dist/chunks/logger-DGi224NW.js.map +1 -0
  5. package/dist/chunks/logger-np_r7rTc.mjs +1599 -0
  6. package/dist/chunks/logger-np_r7rTc.mjs.map +1 -0
  7. package/dist/cli.js +212 -6
  8. package/dist/cli.js.map +1 -1
  9. package/dist/cli.mjs +211 -0
  10. package/dist/cli.mjs.map +1 -0
  11. package/dist/index.js +133 -1172
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +131 -1165
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/modules/codemod/codemod.d.ts +4 -2
  16. package/dist/modules/codemod/codemod.d.ts.map +1 -1
  17. package/dist/modules/codemod/types.d.ts +8 -1
  18. package/dist/modules/codemod/types.d.ts.map +1 -1
  19. package/dist/modules/codemod-repository/repository.d.ts +6 -5
  20. package/dist/modules/codemod-repository/repository.d.ts.map +1 -1
  21. package/dist/modules/codemod-repository/types.d.ts +7 -3
  22. package/dist/modules/codemod-repository/types.d.ts.map +1 -1
  23. package/dist/modules/codemod-runner/codemod-runner.d.ts +3 -0
  24. package/dist/modules/codemod-runner/codemod-runner.d.ts.map +1 -1
  25. package/dist/modules/codemod-runner/index.d.ts +1 -0
  26. package/dist/modules/codemod-runner/index.d.ts.map +1 -1
  27. package/dist/modules/codemod-runner/types.d.ts +1 -0
  28. package/dist/modules/codemod-runner/types.d.ts.map +1 -1
  29. package/dist/modules/error/utils.d.ts +8 -0
  30. package/dist/modules/error/utils.d.ts.map +1 -1
  31. package/dist/modules/file-scanner/scanner.d.ts.map +1 -1
  32. package/dist/modules/format/formats.d.ts +6 -0
  33. package/dist/modules/format/formats.d.ts.map +1 -1
  34. package/dist/modules/project/constants.d.ts +6 -3
  35. package/dist/modules/project/constants.d.ts.map +1 -1
  36. package/dist/modules/project/index.d.ts +2 -0
  37. package/dist/modules/project/index.d.ts.map +1 -1
  38. package/dist/modules/project/project.d.ts +27 -5
  39. package/dist/modules/project/project.d.ts.map +1 -1
  40. package/dist/modules/project/types.d.ts +3 -10
  41. package/dist/modules/project/types.d.ts.map +1 -1
  42. package/dist/modules/project/utils.d.ts +6 -0
  43. package/dist/modules/project/utils.d.ts.map +1 -0
  44. package/dist/modules/report/report.d.ts.map +1 -1
  45. package/dist/modules/requirement/types.d.ts +2 -2
  46. package/dist/modules/requirement/types.d.ts.map +1 -1
  47. package/dist/modules/runner/json/transform.d.ts.map +1 -1
  48. package/dist/modules/upgrader/types.d.ts +6 -0
  49. package/dist/modules/upgrader/types.d.ts.map +1 -1
  50. package/dist/modules/upgrader/upgrader.d.ts +7 -3
  51. package/dist/modules/upgrader/upgrader.d.ts.map +1 -1
  52. package/dist/modules/version/range.d.ts +2 -0
  53. package/dist/modules/version/range.d.ts.map +1 -1
  54. package/dist/modules/version/types.d.ts +2 -1
  55. package/dist/modules/version/types.d.ts.map +1 -1
  56. package/dist/tasks/codemods/index.d.ts +2 -1
  57. package/dist/tasks/codemods/index.d.ts.map +1 -1
  58. package/dist/tasks/codemods/list-codemods.d.ts +3 -0
  59. package/dist/tasks/codemods/list-codemods.d.ts.map +1 -0
  60. package/dist/tasks/codemods/run-codemods.d.ts +3 -0
  61. package/dist/tasks/codemods/run-codemods.d.ts.map +1 -0
  62. package/dist/tasks/codemods/types.d.ts +9 -3
  63. package/dist/tasks/codemods/types.d.ts.map +1 -1
  64. package/dist/tasks/codemods/utils.d.ts +6 -0
  65. package/dist/tasks/codemods/utils.d.ts.map +1 -0
  66. package/dist/tasks/index.d.ts +1 -1
  67. package/dist/tasks/index.d.ts.map +1 -1
  68. package/dist/tasks/upgrade/prompts/index.d.ts +2 -0
  69. package/dist/tasks/upgrade/prompts/index.d.ts.map +1 -0
  70. package/dist/tasks/upgrade/prompts/latest.d.ts +9 -0
  71. package/dist/tasks/upgrade/prompts/latest.d.ts.map +1 -0
  72. package/dist/tasks/upgrade/requirements/major.d.ts.map +1 -1
  73. package/dist/tasks/upgrade/upgrade.d.ts.map +1 -1
  74. package/package.json +16 -15
  75. package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
  76. package/resources/codemods/5.0.0/dependency-remove-strapi-plugin-i18n.json.ts +31 -0
  77. package/resources/codemods/5.0.0/dependency-upgrade-react-and-react-dom.json.ts +67 -0
  78. package/resources/codemods/5.0.0/dependency-upgrade-react-router-dom.json.ts +59 -0
  79. package/resources/codemods/5.0.0/dependency-upgrade-styled-components.json.ts +49 -0
  80. package/resources/codemods/5.0.0/deprecate-helper-plugin.code.ts +192 -0
  81. package/resources/codemods/5.0.0/entity-service-document-service.code.ts +437 -0
  82. package/resources/codemods/5.0.0/s3-keys-wrapped-in-credentials.code.ts +1 -1
  83. package/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts +5 -3
  84. package/resources/codemods/5.0.0/strapi-public-interface.code.ts +126 -0
  85. package/resources/codemods/5.0.0/use-uid-for-config-namespace.code.ts +1 -1
  86. package/resources/codemods/5.0.0/utils-public-interface.code.ts +320 -0
  87. package/resources/codemods/5.1.0/dependency-better-sqlite3.json.ts +48 -0
  88. package/resources/examples/console.log-to-console.info.code.ts +1 -1
  89. package/resources/examples/disable-jsx-buttons.code.ts +42 -0
  90. package/resources/utils/change-import.ts +118 -0
  91. package/resources/utils/replace-jsx.ts +49 -0
  92. package/dist/_chunks/codemod-runner-B5OeSMTQ.js +0 -730
  93. package/dist/_chunks/codemod-runner-B5OeSMTQ.js.map +0 -1
  94. package/dist/_chunks/codemods-10ZKewQx.js +0 -108
  95. package/dist/_chunks/codemods-10ZKewQx.js.map +0 -1
  96. package/dist/_chunks/index-uxCwtuH1.js +0 -103
  97. package/dist/_chunks/index-uxCwtuH1.js.map +0 -1
  98. package/dist/_chunks/upgrade-A4T1OWs5.js +0 -357
  99. package/dist/_chunks/upgrade-A4T1OWs5.js.map +0 -1
  100. package/dist/tasks/codemods/codemods.d.ts +0 -3
  101. package/dist/tasks/codemods/codemods.d.ts.map +0 -1
@@ -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,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;
@@ -59,7 +59,7 @@ const transform: Transform = (file, api) => {
59
59
  }
60
60
 
61
61
  const { j } = api;
62
- const root = j(file.source);
62
+ const root = j.withParser('tsx')(file.source);
63
63
 
64
64
  root
65
65
  .find(j.ArrowFunctionExpression)
@@ -17,18 +17,20 @@ 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')) {
30
- // TODO check this version when releasing V5
31
- j.set('dependencies.better-sqlite3', '9.0.0');
32
+ if (removed && !j.has('dependencies.better-sqlite3')) {
33
+ j.set('dependencies.better-sqlite3', '9.4.3');
32
34
  }
33
35
 
34
36
  return j.root();