@strapi/upgrade 0.0.0-experimental.f75e3c6d67cc47c64ab37479efdbb7b43be50b78 → 0.0.0-experimental.f86041c89a8c1545c6437a881dc613e98bc52bd7

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 (280) hide show
  1. package/LICENSE +19 -4
  2. package/README.md +1 -1
  3. package/dist/cli.js +13 -1451
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cli.mjs +14 -0
  6. package/dist/cli.mjs.map +1 -0
  7. package/dist/index.js +9 -1428
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +4 -1420
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/modules/codemod-repository/constants.d.ts.map +1 -1
  12. package/dist/modules/error/utils.d.ts +8 -0
  13. package/dist/modules/error/utils.d.ts.map +1 -1
  14. package/dist/modules/file-scanner/scanner.d.ts.map +1 -1
  15. package/dist/modules/format/formats.d.ts +2 -1
  16. package/dist/modules/format/formats.d.ts.map +1 -1
  17. package/dist/modules/npm/package.d.ts +7 -3
  18. package/dist/modules/npm/package.d.ts.map +1 -1
  19. package/dist/modules/project/constants.d.ts +6 -5
  20. package/dist/modules/project/constants.d.ts.map +1 -1
  21. package/dist/modules/project/project.d.ts +16 -2
  22. package/dist/modules/project/project.d.ts.map +1 -1
  23. package/dist/modules/project/types.d.ts +3 -0
  24. package/dist/modules/project/types.d.ts.map +1 -1
  25. package/dist/modules/runner/json/transform.d.ts.map +1 -1
  26. package/dist/modules/upgrader/types.d.ts +6 -0
  27. package/dist/modules/upgrader/types.d.ts.map +1 -1
  28. package/dist/modules/upgrader/upgrader.d.ts +4 -0
  29. package/dist/modules/upgrader/upgrader.d.ts.map +1 -1
  30. package/dist/modules/version/range.d.ts.map +1 -1
  31. package/dist/modules/version/types.d.ts +2 -1
  32. package/dist/modules/version/types.d.ts.map +1 -1
  33. package/dist/package.json.js +6 -0
  34. package/dist/package.json.js.map +1 -0
  35. package/dist/package.json.mjs +4 -0
  36. package/dist/package.json.mjs.map +1 -0
  37. package/dist/src/cli/commands/codemods.js +121 -0
  38. package/dist/src/cli/commands/codemods.js.map +1 -0
  39. package/dist/src/cli/commands/codemods.mjs +117 -0
  40. package/dist/src/cli/commands/codemods.mjs.map +1 -0
  41. package/dist/src/cli/commands/upgrade.js +99 -0
  42. package/dist/src/cli/commands/upgrade.js.map +1 -0
  43. package/dist/src/cli/commands/upgrade.mjs +96 -0
  44. package/dist/src/cli/commands/upgrade.mjs.map +1 -0
  45. package/dist/src/cli/errors.js +18 -0
  46. package/dist/src/cli/errors.js.map +1 -0
  47. package/dist/src/cli/errors.mjs +16 -0
  48. package/dist/src/cli/errors.mjs.map +1 -0
  49. package/dist/src/cli/options.js +25 -0
  50. package/dist/src/cli/options.js.map +1 -0
  51. package/dist/src/cli/options.mjs +18 -0
  52. package/dist/src/cli/options.mjs.map +1 -0
  53. package/dist/src/modules/codemod/codemod.js +44 -0
  54. package/dist/src/modules/codemod/codemod.js.map +1 -0
  55. package/dist/src/modules/codemod/codemod.mjs +41 -0
  56. package/dist/src/modules/codemod/codemod.mjs.map +1 -0
  57. package/dist/src/modules/codemod/constants.js +17 -0
  58. package/dist/src/modules/codemod/constants.js.map +1 -0
  59. package/dist/src/modules/codemod/constants.mjs +11 -0
  60. package/dist/src/modules/codemod/constants.mjs.map +1 -0
  61. package/dist/src/modules/codemod/index.js +10 -0
  62. package/dist/src/modules/codemod/index.js.map +1 -0
  63. package/dist/src/modules/codemod/index.mjs +4 -0
  64. package/dist/src/modules/codemod/index.mjs.map +1 -0
  65. package/dist/src/modules/codemod-repository/constants.js +9 -0
  66. package/dist/src/modules/codemod-repository/constants.js.map +1 -0
  67. package/dist/src/modules/codemod-repository/constants.mjs +7 -0
  68. package/dist/src/modules/codemod-repository/constants.mjs.map +1 -0
  69. package/dist/src/modules/codemod-repository/index.js +10 -0
  70. package/dist/src/modules/codemod-repository/index.js.map +1 -0
  71. package/dist/src/modules/codemod-repository/index.mjs +4 -0
  72. package/dist/src/modules/codemod-repository/index.mjs.map +1 -0
  73. package/dist/src/modules/codemod-repository/repository.js +126 -0
  74. package/dist/src/modules/codemod-repository/repository.js.map +1 -0
  75. package/dist/src/modules/codemod-repository/repository.mjs +122 -0
  76. package/dist/src/modules/codemod-repository/repository.mjs.map +1 -0
  77. package/dist/src/modules/codemod-runner/codemod-runner.js +112 -0
  78. package/dist/src/modules/codemod-runner/codemod-runner.js.map +1 -0
  79. package/dist/src/modules/codemod-runner/codemod-runner.mjs +109 -0
  80. package/dist/src/modules/codemod-runner/codemod-runner.mjs.map +1 -0
  81. package/dist/src/modules/error/index.js +11 -0
  82. package/dist/src/modules/error/index.js.map +1 -0
  83. package/dist/src/modules/error/index.mjs +2 -0
  84. package/dist/src/modules/error/index.mjs.map +1 -0
  85. package/dist/src/modules/error/utils.js +33 -0
  86. package/dist/src/modules/error/utils.js.map +1 -0
  87. package/dist/src/modules/error/utils.mjs +28 -0
  88. package/dist/src/modules/error/utils.mjs.map +1 -0
  89. package/dist/src/modules/file-scanner/index.js +8 -0
  90. package/dist/src/modules/file-scanner/index.js.map +1 -0
  91. package/dist/src/modules/file-scanner/index.mjs +2 -0
  92. package/dist/src/modules/file-scanner/index.mjs.map +1 -0
  93. package/dist/src/modules/file-scanner/scanner.js +23 -0
  94. package/dist/src/modules/file-scanner/scanner.js.map +1 -0
  95. package/dist/src/modules/file-scanner/scanner.mjs +20 -0
  96. package/dist/src/modules/file-scanner/scanner.mjs.map +1 -0
  97. package/dist/src/modules/format/formats.js +107 -0
  98. package/dist/src/modules/format/formats.js.map +1 -0
  99. package/dist/src/modules/format/formats.mjs +94 -0
  100. package/dist/src/modules/format/formats.mjs.map +1 -0
  101. package/dist/src/modules/format/index.js +19 -0
  102. package/dist/src/modules/format/index.js.map +1 -0
  103. package/dist/src/modules/format/index.mjs +2 -0
  104. package/dist/src/modules/format/index.mjs.map +1 -0
  105. package/dist/src/modules/index.js +32 -0
  106. package/dist/src/modules/index.js.map +1 -0
  107. package/dist/src/modules/index.mjs +27 -0
  108. package/dist/src/modules/index.mjs.map +1 -0
  109. package/dist/src/modules/json/file.js +16 -0
  110. package/dist/src/modules/json/file.js.map +1 -0
  111. package/dist/src/modules/json/file.mjs +13 -0
  112. package/dist/src/modules/json/file.mjs.map +1 -0
  113. package/dist/src/modules/json/transform-api.js +38 -0
  114. package/dist/src/modules/json/transform-api.js.map +1 -0
  115. package/dist/src/modules/json/transform-api.mjs +35 -0
  116. package/dist/src/modules/json/transform-api.mjs.map +1 -0
  117. package/dist/src/modules/logger/index.js +8 -0
  118. package/dist/src/modules/logger/index.js.map +1 -0
  119. package/dist/src/modules/logger/index.mjs +2 -0
  120. package/dist/src/modules/logger/index.mjs.map +1 -0
  121. package/dist/src/modules/logger/logger.js +76 -0
  122. package/dist/src/modules/logger/logger.js.map +1 -0
  123. package/dist/src/modules/logger/logger.mjs +73 -0
  124. package/dist/src/modules/logger/logger.mjs.map +1 -0
  125. package/dist/src/modules/npm/constants.js +6 -0
  126. package/dist/src/modules/npm/constants.js.map +1 -0
  127. package/dist/src/modules/npm/constants.mjs +4 -0
  128. package/dist/src/modules/npm/constants.mjs.map +1 -0
  129. package/dist/src/modules/npm/package.js +107 -0
  130. package/dist/src/modules/npm/package.js.map +1 -0
  131. package/dist/src/modules/npm/package.mjs +104 -0
  132. package/dist/src/modules/npm/package.mjs.map +1 -0
  133. package/dist/src/modules/project/constants.js +45 -0
  134. package/dist/src/modules/project/constants.js.map +1 -0
  135. package/dist/src/modules/project/constants.mjs +35 -0
  136. package/dist/src/modules/project/constants.mjs.map +1 -0
  137. package/dist/src/modules/project/index.js +15 -0
  138. package/dist/src/modules/project/index.js.map +1 -0
  139. package/dist/src/modules/project/index.mjs +5 -0
  140. package/dist/src/modules/project/index.mjs.map +1 -0
  141. package/dist/src/modules/project/project.js +205 -0
  142. package/dist/src/modules/project/project.js.map +1 -0
  143. package/dist/src/modules/project/project.mjs +200 -0
  144. package/dist/src/modules/project/project.mjs.map +1 -0
  145. package/dist/src/modules/project/utils.js +26 -0
  146. package/dist/src/modules/project/utils.js.map +1 -0
  147. package/dist/src/modules/project/utils.mjs +21 -0
  148. package/dist/src/modules/project/utils.mjs.map +1 -0
  149. package/dist/src/modules/report/index.js +9 -0
  150. package/dist/src/modules/report/index.js.map +1 -0
  151. package/dist/src/modules/report/index.mjs +2 -0
  152. package/dist/src/modules/report/index.mjs.map +1 -0
  153. package/dist/src/modules/report/report.js +13 -0
  154. package/dist/src/modules/report/report.js.map +1 -0
  155. package/dist/src/modules/report/report.mjs +10 -0
  156. package/dist/src/modules/report/report.mjs.map +1 -0
  157. package/dist/src/modules/requirement/index.js +8 -0
  158. package/dist/src/modules/requirement/index.js.map +1 -0
  159. package/dist/src/modules/requirement/index.mjs +2 -0
  160. package/dist/src/modules/requirement/index.mjs.map +1 -0
  161. package/dist/src/modules/requirement/requirement.js +55 -0
  162. package/dist/src/modules/requirement/requirement.js.map +1 -0
  163. package/dist/src/modules/requirement/requirement.mjs +52 -0
  164. package/dist/src/modules/requirement/requirement.mjs.map +1 -0
  165. package/dist/src/modules/runner/code/code.js +20 -0
  166. package/dist/src/modules/runner/code/code.js.map +1 -0
  167. package/dist/src/modules/runner/code/code.mjs +17 -0
  168. package/dist/src/modules/runner/code/code.mjs.map +1 -0
  169. package/dist/src/modules/runner/code/index.js +8 -0
  170. package/dist/src/modules/runner/code/index.js.map +1 -0
  171. package/dist/src/modules/runner/code/index.mjs +2 -0
  172. package/dist/src/modules/runner/code/index.mjs.map +1 -0
  173. package/dist/src/modules/runner/index.js +10 -0
  174. package/dist/src/modules/runner/index.js.map +1 -0
  175. package/dist/src/modules/runner/index.mjs +5 -0
  176. package/dist/src/modules/runner/index.mjs.map +1 -0
  177. package/dist/src/modules/runner/json/index.js +8 -0
  178. package/dist/src/modules/runner/json/index.js.map +1 -0
  179. package/dist/src/modules/runner/json/index.mjs +2 -0
  180. package/dist/src/modules/runner/json/index.mjs.map +1 -0
  181. package/dist/src/modules/runner/json/json.js +20 -0
  182. package/dist/src/modules/runner/json/json.js.map +1 -0
  183. package/dist/src/modules/runner/json/json.mjs +17 -0
  184. package/dist/src/modules/runner/json/json.mjs.map +1 -0
  185. package/dist/src/modules/runner/json/transform.js +85 -0
  186. package/dist/src/modules/runner/json/transform.js.map +1 -0
  187. package/dist/src/modules/runner/json/transform.mjs +83 -0
  188. package/dist/src/modules/runner/json/transform.mjs.map +1 -0
  189. package/dist/src/modules/runner/runner.js +22 -0
  190. package/dist/src/modules/runner/runner.js.map +1 -0
  191. package/dist/src/modules/runner/runner.mjs +20 -0
  192. package/dist/src/modules/runner/runner.mjs.map +1 -0
  193. package/dist/src/modules/timer/constants.js +6 -0
  194. package/dist/src/modules/timer/constants.js.map +1 -0
  195. package/dist/src/modules/timer/constants.mjs +4 -0
  196. package/dist/src/modules/timer/constants.mjs.map +1 -0
  197. package/dist/src/modules/timer/index.js +10 -0
  198. package/dist/src/modules/timer/index.js.map +1 -0
  199. package/dist/src/modules/timer/index.mjs +4 -0
  200. package/dist/src/modules/timer/index.mjs.map +1 -0
  201. package/dist/src/modules/timer/timer.js +33 -0
  202. package/dist/src/modules/timer/timer.js.map +1 -0
  203. package/dist/src/modules/timer/timer.mjs +30 -0
  204. package/dist/src/modules/timer/timer.mjs.map +1 -0
  205. package/dist/src/modules/upgrader/constants.js +6 -0
  206. package/dist/src/modules/upgrader/constants.js.map +1 -0
  207. package/dist/src/modules/upgrader/constants.mjs +4 -0
  208. package/dist/src/modules/upgrader/constants.mjs.map +1 -0
  209. package/dist/src/modules/upgrader/index.js +10 -0
  210. package/dist/src/modules/upgrader/index.js.map +1 -0
  211. package/dist/src/modules/upgrader/index.mjs +4 -0
  212. package/dist/src/modules/upgrader/index.mjs.map +1 -0
  213. package/dist/src/modules/upgrader/upgrader.js +265 -0
  214. package/dist/src/modules/upgrader/upgrader.js.map +1 -0
  215. package/dist/src/modules/upgrader/upgrader.mjs +262 -0
  216. package/dist/src/modules/upgrader/upgrader.mjs.map +1 -0
  217. package/dist/src/modules/version/index.js +20 -0
  218. package/dist/src/modules/version/index.js.map +1 -0
  219. package/dist/src/modules/version/index.mjs +5 -0
  220. package/dist/src/modules/version/index.mjs.map +1 -0
  221. package/dist/src/modules/version/range.js +81 -0
  222. package/dist/src/modules/version/range.js.map +1 -0
  223. package/dist/src/modules/version/range.mjs +75 -0
  224. package/dist/src/modules/version/range.mjs.map +1 -0
  225. package/dist/src/modules/version/semver.js +26 -0
  226. package/dist/src/modules/version/semver.js.map +1 -0
  227. package/dist/src/modules/version/semver.mjs +20 -0
  228. package/dist/src/modules/version/semver.mjs.map +1 -0
  229. package/dist/src/modules/version/types.js +14 -0
  230. package/dist/src/modules/version/types.js.map +1 -0
  231. package/dist/src/modules/version/types.mjs +12 -0
  232. package/dist/src/modules/version/types.mjs.map +1 -0
  233. package/dist/src/tasks/codemods/list-codemods.js +40 -0
  234. package/dist/src/tasks/codemods/list-codemods.js.map +1 -0
  235. package/dist/src/tasks/codemods/list-codemods.mjs +38 -0
  236. package/dist/src/tasks/codemods/list-codemods.mjs.map +1 -0
  237. package/dist/src/tasks/codemods/run-codemods.js +36 -0
  238. package/dist/src/tasks/codemods/run-codemods.js.map +1 -0
  239. package/dist/src/tasks/codemods/run-codemods.mjs +34 -0
  240. package/dist/src/tasks/codemods/run-codemods.mjs.map +1 -0
  241. package/dist/src/tasks/codemods/utils.js +54 -0
  242. package/dist/src/tasks/codemods/utils.js.map +1 -0
  243. package/dist/src/tasks/codemods/utils.mjs +50 -0
  244. package/dist/src/tasks/codemods/utils.mjs.map +1 -0
  245. package/dist/src/tasks/index.js +14 -0
  246. package/dist/src/tasks/index.js.map +1 -0
  247. package/dist/src/tasks/index.mjs +6 -0
  248. package/dist/src/tasks/index.mjs.map +1 -0
  249. package/dist/src/tasks/upgrade/prompts/latest.js +48 -0
  250. package/dist/src/tasks/upgrade/prompts/latest.js.map +1 -0
  251. package/dist/src/tasks/upgrade/prompts/latest.mjs +46 -0
  252. package/dist/src/tasks/upgrade/prompts/latest.mjs.map +1 -0
  253. package/dist/src/tasks/upgrade/requirements/common.js +40 -0
  254. package/dist/src/tasks/upgrade/requirements/common.js.map +1 -0
  255. package/dist/src/tasks/upgrade/requirements/common.mjs +35 -0
  256. package/dist/src/tasks/upgrade/requirements/common.mjs.map +1 -0
  257. package/dist/src/tasks/upgrade/requirements/major.js +28 -0
  258. package/dist/src/tasks/upgrade/requirements/major.js.map +1 -0
  259. package/dist/src/tasks/upgrade/requirements/major.mjs +25 -0
  260. package/dist/src/tasks/upgrade/requirements/major.mjs.map +1 -0
  261. package/dist/src/tasks/upgrade/upgrade.js +69 -0
  262. package/dist/src/tasks/upgrade/upgrade.js.map +1 -0
  263. package/dist/src/tasks/upgrade/upgrade.mjs +67 -0
  264. package/dist/src/tasks/upgrade/upgrade.mjs.map +1 -0
  265. package/dist/tasks/codemods/utils.d.ts.map +1 -1
  266. package/dist/tasks/upgrade/prompts/index.d.ts +2 -0
  267. package/dist/tasks/upgrade/prompts/index.d.ts.map +1 -0
  268. package/dist/tasks/upgrade/prompts/latest.d.ts +9 -0
  269. package/dist/tasks/upgrade/prompts/latest.d.ts.map +1 -0
  270. package/dist/tasks/upgrade/requirements/major.d.ts.map +1 -1
  271. package/dist/tasks/upgrade/upgrade.d.ts.map +1 -1
  272. package/package.json +16 -14
  273. package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
  274. package/resources/codemods/5.0.0/dependency-upgrade-react-and-react-dom.json.ts +67 -0
  275. package/resources/codemods/5.0.0/dependency-upgrade-styled-components.json.ts +49 -0
  276. package/resources/codemods/5.0.0/deprecate-helper-plugin.code.ts +192 -0
  277. package/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts +0 -1
  278. package/resources/codemods/5.1.0/dependency-better-sqlite3.json.ts +48 -0
  279. package/resources/utils/change-import.ts +118 -0
  280. package/resources/utils/replace-jsx.ts +49 -0
@@ -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;
@@ -30,7 +30,6 @@ const transform: modules.runner.json.JSONTransform = (file, params) => {
30
30
  });
31
31
 
32
32
  if (removed && !j.has('dependencies.better-sqlite3')) {
33
- // TODO check this version when releasing V5
34
33
  j.set('dependencies.better-sqlite3', '9.4.3');
35
34
  }
36
35
 
@@ -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
+ };
@@ -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
+ };