@payloadcms/codemod 4.0.0-internal.d21c039 → 4.0.0-internal.ea6e8f8

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 (241) hide show
  1. package/README.md +96 -30
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.help.d.ts +4 -0
  4. package/dist/cli.help.d.ts.map +1 -0
  5. package/dist/cli.help.js +29 -0
  6. package/dist/cli.help.js.map +1 -0
  7. package/dist/cli.js +49 -27
  8. package/dist/cli.js.map +1 -1
  9. package/dist/cli.parseFlags.d.ts +15 -0
  10. package/dist/cli.parseFlags.d.ts.map +1 -1
  11. package/dist/cli.parseFlags.js +35 -2
  12. package/dist/cli.parseFlags.js.map +1 -1
  13. package/dist/registry.d.ts.map +1 -1
  14. package/dist/registry.js +14 -0
  15. package/dist/registry.js.map +1 -1
  16. package/dist/runbook/payload-v4-upgrade.md +55 -0
  17. package/dist/runbook/v4.mdx +2453 -0
  18. package/dist/transforms/add-override-access-true/basic.input.js +41 -0
  19. package/dist/transforms/add-override-access-true/basic.input.js.map +1 -0
  20. package/dist/transforms/add-override-access-true/basic.output.js +50 -0
  21. package/dist/transforms/add-override-access-true/basic.output.js.map +1 -0
  22. package/dist/transforms/add-override-access-true/comment-between-properties.input.js +11 -0
  23. package/dist/transforms/add-override-access-true/comment-between-properties.input.js.map +1 -0
  24. package/dist/transforms/add-override-access-true/comment-between-properties.output.js +12 -0
  25. package/dist/transforms/add-override-access-true/comment-between-properties.output.js.map +1 -0
  26. package/dist/transforms/add-override-access-true/index.d.ts +20 -0
  27. package/dist/transforms/add-override-access-true/index.d.ts.map +1 -0
  28. package/dist/transforms/add-override-access-true/index.js +208 -0
  29. package/dist/transforms/add-override-access-true/index.js.map +1 -0
  30. package/dist/transforms/add-override-access-true/javascript.input.d.ts +6 -0
  31. package/dist/transforms/add-override-access-true/javascript.input.d.ts.map +1 -0
  32. package/dist/transforms/add-override-access-true/javascript.input.js +24 -0
  33. package/dist/transforms/add-override-access-true/javascript.input.js.map +1 -0
  34. package/dist/transforms/add-override-access-true/javascript.output.d.ts +6 -0
  35. package/dist/transforms/add-override-access-true/javascript.output.d.ts.map +1 -0
  36. package/dist/transforms/add-override-access-true/javascript.output.js +26 -0
  37. package/dist/transforms/add-override-access-true/javascript.output.js.map +1 -0
  38. package/dist/transforms/add-override-access-true/non-matching.input.js +42 -0
  39. package/dist/transforms/add-override-access-true/non-matching.input.js.map +1 -0
  40. package/dist/transforms/add-override-access-true/non-matching.output.js +42 -0
  41. package/dist/transforms/add-override-access-true/non-matching.output.js.map +1 -0
  42. package/dist/transforms/add-override-access-true/single-line.input.js +13 -0
  43. package/dist/transforms/add-override-access-true/single-line.input.js.map +1 -0
  44. package/dist/transforms/add-override-access-true/single-line.output.js +17 -0
  45. package/dist/transforms/add-override-access-true/single-line.output.js.map +1 -0
  46. package/dist/transforms/add-override-access-true/trailing-comment.input.js +10 -0
  47. package/dist/transforms/add-override-access-true/trailing-comment.input.js.map +1 -0
  48. package/dist/transforms/add-override-access-true/trailing-comment.output.js +12 -0
  49. package/dist/transforms/add-override-access-true/trailing-comment.output.js.map +1 -0
  50. package/dist/transforms/migrate-admin-context-properties/basic.input.js +32 -0
  51. package/dist/transforms/migrate-admin-context-properties/basic.input.js.map +1 -0
  52. package/dist/transforms/migrate-admin-context-properties/basic.output.js +30 -0
  53. package/dist/transforms/migrate-admin-context-properties/basic.output.js.map +1 -0
  54. package/dist/transforms/migrate-admin-context-properties/index.d.ts +3 -0
  55. package/dist/transforms/migrate-admin-context-properties/index.d.ts.map +1 -0
  56. package/dist/transforms/migrate-admin-context-properties/index.js +302 -0
  57. package/dist/transforms/migrate-admin-context-properties/index.js.map +1 -0
  58. package/dist/transforms/migrate-admin-context-properties/no-match.input.js +30 -0
  59. package/dist/transforms/migrate-admin-context-properties/no-match.input.js.map +1 -0
  60. package/dist/transforms/migrate-admin-context-properties/no-match.output.js +30 -0
  61. package/dist/transforms/migrate-admin-context-properties/no-match.output.js.map +1 -0
  62. package/dist/transforms/migrate-aliased-exports/index.d.ts.map +1 -1
  63. package/dist/transforms/migrate-aliased-exports/index.js +6 -5
  64. package/dist/transforms/migrate-aliased-exports/index.js.map +1 -1
  65. package/dist/transforms/migrate-aliased-exports/request.input.js +6 -0
  66. package/dist/transforms/migrate-aliased-exports/request.input.js.map +1 -0
  67. package/dist/transforms/migrate-aliased-exports/request.output.js +5 -0
  68. package/dist/transforms/migrate-aliased-exports/request.output.js.map +1 -0
  69. package/dist/transforms/migrate-authorship-default/already-set.input.js +15 -0
  70. package/dist/transforms/migrate-authorship-default/already-set.input.js.map +1 -0
  71. package/dist/transforms/migrate-authorship-default/already-set.output.js +15 -0
  72. package/dist/transforms/migrate-authorship-default/already-set.output.js.map +1 -0
  73. package/dist/transforms/migrate-authorship-default/basic.input.js +16 -0
  74. package/dist/transforms/migrate-authorship-default/basic.input.js.map +1 -0
  75. package/dist/transforms/migrate-authorship-default/basic.output.js +18 -0
  76. package/dist/transforms/migrate-authorship-default/basic.output.js.map +1 -0
  77. package/dist/transforms/migrate-authorship-default/build-config.input.js +32 -0
  78. package/dist/transforms/migrate-authorship-default/build-config.input.js.map +1 -0
  79. package/dist/transforms/migrate-authorship-default/build-config.output.js +35 -0
  80. package/dist/transforms/migrate-authorship-default/build-config.output.js.map +1 -0
  81. package/dist/transforms/migrate-authorship-default/globals.input.js +16 -0
  82. package/dist/transforms/migrate-authorship-default/globals.input.js.map +1 -0
  83. package/dist/transforms/migrate-authorship-default/globals.output.js +17 -0
  84. package/dist/transforms/migrate-authorship-default/globals.output.js.map +1 -0
  85. package/dist/transforms/migrate-authorship-default/index.d.ts +11 -0
  86. package/dist/transforms/migrate-authorship-default/index.d.ts.map +1 -0
  87. package/dist/transforms/migrate-authorship-default/index.js +141 -0
  88. package/dist/transforms/migrate-authorship-default/index.js.map +1 -0
  89. package/dist/transforms/migrate-authorship-default/non-matching.input.js +18 -0
  90. package/dist/transforms/migrate-authorship-default/non-matching.input.js.map +1 -0
  91. package/dist/transforms/migrate-authorship-default/non-matching.output.js +18 -0
  92. package/dist/transforms/migrate-authorship-default/non-matching.output.js.map +1 -0
  93. package/dist/transforms/migrate-authorship-default/satisfies.input.js +11 -0
  94. package/dist/transforms/migrate-authorship-default/satisfies.input.js.map +1 -0
  95. package/dist/transforms/migrate-authorship-default/satisfies.output.js +13 -0
  96. package/dist/transforms/migrate-authorship-default/satisfies.output.js.map +1 -0
  97. package/dist/transforms/migrate-field-component-types/basic.input.js +8 -0
  98. package/dist/transforms/migrate-field-component-types/basic.input.js.map +1 -0
  99. package/dist/transforms/migrate-field-component-types/basic.output.js +8 -0
  100. package/dist/transforms/migrate-field-component-types/basic.output.js.map +1 -0
  101. package/dist/transforms/migrate-field-component-types/index.d.ts +3 -0
  102. package/dist/transforms/migrate-field-component-types/index.d.ts.map +1 -0
  103. package/dist/transforms/migrate-field-component-types/index.js +620 -0
  104. package/dist/transforms/migrate-field-component-types/index.js.map +1 -0
  105. package/dist/transforms/migrate-payload-request-creation/aliases.input.js +8 -0
  106. package/dist/transforms/migrate-payload-request-creation/aliases.input.js.map +1 -0
  107. package/dist/transforms/migrate-payload-request-creation/aliases.output.js +31 -0
  108. package/dist/transforms/migrate-payload-request-creation/aliases.output.js.map +1 -0
  109. package/dist/transforms/migrate-payload-request-creation/collision.input.js +9 -0
  110. package/dist/transforms/migrate-payload-request-creation/collision.input.js.map +1 -0
  111. package/dist/transforms/migrate-payload-request-creation/comments.input.js +9 -0
  112. package/dist/transforms/migrate-payload-request-creation/comments.input.js.map +1 -0
  113. package/dist/transforms/migrate-payload-request-creation/comments.output.js +34 -0
  114. package/dist/transforms/migrate-payload-request-creation/comments.output.js.map +1 -0
  115. package/dist/transforms/migrate-payload-request-creation/empty.input.js +5 -0
  116. package/dist/transforms/migrate-payload-request-creation/empty.input.js.map +1 -0
  117. package/dist/transforms/migrate-payload-request-creation/empty.output.js +7 -0
  118. package/dist/transforms/migrate-payload-request-creation/empty.output.js.map +1 -0
  119. package/dist/transforms/migrate-payload-request-creation/evaluation-order.input.js +10 -0
  120. package/dist/transforms/migrate-payload-request-creation/evaluation-order.input.js.map +1 -0
  121. package/dist/transforms/migrate-payload-request-creation/expression.input.js +8 -0
  122. package/dist/transforms/migrate-payload-request-creation/expression.input.js.map +1 -0
  123. package/dist/transforms/migrate-payload-request-creation/expression.output.js +8 -0
  124. package/dist/transforms/migrate-payload-request-creation/expression.output.js.map +1 -0
  125. package/dist/transforms/migrate-payload-request-creation/getters.input.js +52 -0
  126. package/dist/transforms/migrate-payload-request-creation/getters.input.js.map +1 -0
  127. package/dist/transforms/migrate-payload-request-creation/index.d.ts +3 -0
  128. package/dist/transforms/migrate-payload-request-creation/index.d.ts.map +1 -0
  129. package/dist/transforms/migrate-payload-request-creation/index.js +236 -0
  130. package/dist/transforms/migrate-payload-request-creation/index.js.map +1 -0
  131. package/dist/transforms/migrate-payload-request-creation/internal.input.js +6 -0
  132. package/dist/transforms/migrate-payload-request-creation/internal.input.js.map +1 -0
  133. package/dist/transforms/migrate-payload-request-creation/internal.output.js +6 -0
  134. package/dist/transforms/migrate-payload-request-creation/internal.output.js.map +1 -0
  135. package/dist/transforms/migrate-payload-request-creation/non-matching.input.js +5 -0
  136. package/dist/transforms/migrate-payload-request-creation/non-matching.input.js.map +1 -0
  137. package/dist/transforms/migrate-payload-request-creation/populated.input.js +7 -0
  138. package/dist/transforms/migrate-payload-request-creation/populated.input.js.map +1 -0
  139. package/dist/transforms/migrate-payload-request-creation/populated.output.js +30 -0
  140. package/dist/transforms/migrate-payload-request-creation/populated.output.js.map +1 -0
  141. package/dist/transforms/migrate-payload-request-creation/shadowed.input.js +7 -0
  142. package/dist/transforms/migrate-payload-request-creation/shadowed.input.js.map +1 -0
  143. package/dist/transforms/migrate-payload-request-creation/shadowed.output.js +9 -0
  144. package/dist/transforms/migrate-payload-request-creation/shadowed.output.js.map +1 -0
  145. package/dist/transforms/migrate-payload-request-creation/shorthand.input.js +12 -0
  146. package/dist/transforms/migrate-payload-request-creation/shorthand.input.js.map +1 -0
  147. package/dist/transforms/migrate-payload-request-creation/shorthand.output.js +12 -0
  148. package/dist/transforms/migrate-payload-request-creation/shorthand.output.js.map +1 -0
  149. package/dist/transforms/migrate-payload-request-creation/unsupported.input.js +9 -0
  150. package/dist/transforms/migrate-payload-request-creation/unsupported.input.js.map +1 -0
  151. package/dist/transforms/migrate-sharp-to-transformer/basic.input.js +28 -0
  152. package/dist/transforms/migrate-sharp-to-transformer/basic.input.js.map +1 -0
  153. package/dist/transforms/migrate-sharp-to-transformer/basic.output.js +39 -0
  154. package/dist/transforms/migrate-sharp-to-transformer/basic.output.js.map +1 -0
  155. package/dist/transforms/migrate-sharp-to-transformer/existing-transformers.input.js +27 -0
  156. package/dist/transforms/migrate-sharp-to-transformer/existing-transformers.input.js.map +1 -0
  157. package/dist/transforms/migrate-sharp-to-transformer/existing-transformers.output.js +33 -0
  158. package/dist/transforms/migrate-sharp-to-transformer/existing-transformers.output.js.map +1 -0
  159. package/dist/transforms/migrate-sharp-to-transformer/index.d.ts +3 -0
  160. package/dist/transforms/migrate-sharp-to-transformer/index.d.ts.map +1 -0
  161. package/dist/transforms/migrate-sharp-to-transformer/index.js +430 -0
  162. package/dist/transforms/migrate-sharp-to-transformer/index.js.map +1 -0
  163. package/dist/transforms/migrate-sharp-to-transformer/no-match.input.js +11 -0
  164. package/dist/transforms/migrate-sharp-to-transformer/no-match.input.js.map +1 -0
  165. package/dist/transforms/migrate-sharp-to-transformer/no-match.output.js +11 -0
  166. package/dist/transforms/migrate-sharp-to-transformer/no-match.output.js.map +1 -0
  167. package/dist/transforms/migrate-versions-default/index.js +5 -5
  168. package/dist/transforms/migrate-versions-default/index.js.map +1 -1
  169. package/dist/transforms/remove-publish-specific-locale/index.d.ts.map +1 -1
  170. package/dist/transforms/remove-publish-specific-locale/index.js.map +1 -1
  171. package/dist/transforms/remove-storage-always-insert-fields/index.d.ts.map +1 -1
  172. package/dist/transforms/remove-storage-always-insert-fields/index.js +4 -0
  173. package/dist/transforms/remove-storage-always-insert-fields/index.js.map +1 -1
  174. package/dist/transforms/remove-versions-true/index.js +4 -4
  175. package/dist/transforms/remove-versions-true/index.js.map +1 -1
  176. package/dist/transforms/rename-diff-value-props/basic.input.js +38 -0
  177. package/dist/transforms/rename-diff-value-props/basic.input.js.map +1 -0
  178. package/dist/transforms/rename-diff-value-props/basic.output.js +38 -0
  179. package/dist/transforms/rename-diff-value-props/basic.output.js.map +1 -0
  180. package/dist/transforms/rename-diff-value-props/index.d.ts +3 -0
  181. package/dist/transforms/rename-diff-value-props/index.d.ts.map +1 -0
  182. package/dist/transforms/rename-diff-value-props/index.js +328 -0
  183. package/dist/transforms/rename-diff-value-props/index.js.map +1 -0
  184. package/dist/transforms/rename-diff-value-props/no-match.input.js +8 -0
  185. package/dist/transforms/rename-diff-value-props/no-match.input.js.map +1 -0
  186. package/dist/transforms/rename-experimental-table-feature/index.d.ts.map +1 -1
  187. package/dist/transforms/rename-experimental-table-feature/index.js +7 -1
  188. package/dist/transforms/rename-experimental-table-feature/index.js.map +1 -1
  189. package/dist/upgrade/defaultTag.d.ts +9 -0
  190. package/dist/upgrade/defaultTag.d.ts.map +1 -0
  191. package/dist/upgrade/defaultTag.js +25 -0
  192. package/dist/upgrade/defaultTag.js.map +1 -0
  193. package/dist/upgrade/detectPackageManager.d.ts +8 -0
  194. package/dist/upgrade/detectPackageManager.d.ts.map +1 -0
  195. package/dist/upgrade/detectPackageManager.js +38 -0
  196. package/dist/upgrade/detectPackageManager.js.map +1 -0
  197. package/dist/upgrade/dispatch.d.ts +38 -0
  198. package/dist/upgrade/dispatch.d.ts.map +1 -0
  199. package/dist/upgrade/dispatch.js +132 -0
  200. package/dist/upgrade/dispatch.js.map +1 -0
  201. package/dist/upgrade/index.d.ts +25 -0
  202. package/dist/upgrade/index.d.ts.map +1 -0
  203. package/dist/upgrade/index.js +209 -0
  204. package/dist/upgrade/index.js.map +1 -0
  205. package/dist/upgrade/prompt.d.ts +14 -0
  206. package/dist/upgrade/prompt.d.ts.map +1 -0
  207. package/dist/upgrade/prompt.js +77 -0
  208. package/dist/upgrade/prompt.js.map +1 -0
  209. package/dist/upgrade/report.d.ts +21 -0
  210. package/dist/upgrade/report.d.ts.map +1 -0
  211. package/dist/upgrade/report.js +47 -0
  212. package/dist/upgrade/report.js.map +1 -0
  213. package/dist/upgrade/resolveVersions.d.ts +13 -0
  214. package/dist/upgrade/resolveVersions.d.ts.map +1 -0
  215. package/dist/upgrade/resolveVersions.js +55 -0
  216. package/dist/upgrade/resolveVersions.js.map +1 -0
  217. package/dist/upgrade/rewritePackageJson.d.ts +32 -0
  218. package/dist/upgrade/rewritePackageJson.d.ts.map +1 -0
  219. package/dist/upgrade/rewritePackageJson.js +164 -0
  220. package/dist/upgrade/rewritePackageJson.js.map +1 -0
  221. package/dist/upgrade/runInstall.d.ts +16 -0
  222. package/dist/upgrade/runInstall.d.ts.map +1 -0
  223. package/dist/upgrade/runInstall.js +17 -0
  224. package/dist/upgrade/runInstall.js.map +1 -0
  225. package/dist/upgrade/selectAgent.d.ts +45 -0
  226. package/dist/upgrade/selectAgent.d.ts.map +1 -0
  227. package/dist/upgrade/selectAgent.js +54 -0
  228. package/dist/upgrade/selectAgent.js.map +1 -0
  229. package/dist/upgrade/selfCommand.d.ts +13 -0
  230. package/dist/upgrade/selfCommand.d.ts.map +1 -0
  231. package/dist/upgrade/selfCommand.js +17 -0
  232. package/dist/upgrade/selfCommand.js.map +1 -0
  233. package/dist/upgrade/types.d.ts +47 -0
  234. package/dist/upgrade/types.d.ts.map +1 -0
  235. package/dist/upgrade/types.js +11 -0
  236. package/dist/upgrade/types.js.map +1 -0
  237. package/dist/utils/project.d.ts +10 -0
  238. package/dist/utils/project.d.ts.map +1 -0
  239. package/dist/utils/project.js +43 -0
  240. package/dist/utils/project.js.map +1 -0
  241. package/package.json +8 -4
@@ -0,0 +1,620 @@
1
+ import { Node, SyntaxKind, VariableDeclarationKind } from 'ts-morph';
2
+ const FIELD_NAMES = [
3
+ 'Array',
4
+ 'Blocks',
5
+ 'Checkbox',
6
+ 'Code',
7
+ 'Collapsible',
8
+ 'Date',
9
+ 'Email',
10
+ 'Group',
11
+ 'Join',
12
+ 'JSON',
13
+ 'Number',
14
+ 'Point',
15
+ 'Radio',
16
+ 'Relationship',
17
+ 'RichText',
18
+ 'Row',
19
+ 'Select',
20
+ 'Tabs',
21
+ 'Text',
22
+ 'Textarea',
23
+ 'UI',
24
+ 'Upload'
25
+ ];
26
+ const FIELDS_WITH_SPECIALIZED_COMPONENTS = [
27
+ 'Array',
28
+ 'Blocks',
29
+ 'Checkbox',
30
+ 'Code',
31
+ 'Collapsible',
32
+ 'Date',
33
+ 'Email',
34
+ 'Group',
35
+ 'Join',
36
+ 'JSON',
37
+ 'Number',
38
+ 'Point',
39
+ 'Radio',
40
+ 'Relationship',
41
+ 'RichText',
42
+ 'Row',
43
+ 'Select',
44
+ 'Tabs',
45
+ 'Text',
46
+ 'Textarea',
47
+ 'Upload'
48
+ ];
49
+ const SPECIALIZED_COMPONENT_NAMES = [
50
+ 'FieldDescriptionClient',
51
+ 'FieldDescriptionServer',
52
+ 'FieldDiffClient',
53
+ 'FieldDiffServer',
54
+ 'FieldErrorClient',
55
+ 'FieldErrorServer',
56
+ 'FieldLabelClient',
57
+ 'FieldLabelServer'
58
+ ];
59
+ const COMPONENT_TO_PROPS = new Map([
60
+ [
61
+ 'BlockRowLabelClientComponent',
62
+ 'BlockRowLabelClientProps'
63
+ ],
64
+ [
65
+ 'BlockRowLabelServerComponent',
66
+ 'BlockRowLabelServerProps'
67
+ ],
68
+ [
69
+ 'FieldClientComponent',
70
+ 'FieldClientProps'
71
+ ],
72
+ [
73
+ 'FieldDescriptionClientComponent',
74
+ 'FieldDescriptionClientProps'
75
+ ],
76
+ [
77
+ 'FieldDescriptionServerComponent',
78
+ 'FieldDescriptionServerProps'
79
+ ],
80
+ [
81
+ 'FieldDiffClientComponent',
82
+ 'FieldDiffClientProps'
83
+ ],
84
+ [
85
+ 'FieldDiffServerComponent',
86
+ 'FieldDiffServerProps'
87
+ ],
88
+ [
89
+ 'FieldErrorClientComponent',
90
+ 'FieldErrorClientProps'
91
+ ],
92
+ [
93
+ 'FieldErrorServerComponent',
94
+ 'FieldErrorServerProps'
95
+ ],
96
+ [
97
+ 'FieldLabelClientComponent',
98
+ 'FieldLabelClientProps'
99
+ ],
100
+ [
101
+ 'FieldLabelServerComponent',
102
+ 'FieldLabelServerProps'
103
+ ],
104
+ [
105
+ 'FieldServerComponent',
106
+ 'FieldServerProps'
107
+ ],
108
+ ...FIELD_NAMES.flatMap((fieldName)=>[
109
+ [
110
+ `${fieldName}FieldClientComponent`,
111
+ `${fieldName}FieldClientProps`
112
+ ],
113
+ [
114
+ `${fieldName}FieldServerComponent`,
115
+ `${fieldName}FieldServerProps`
116
+ ]
117
+ ]),
118
+ ...FIELDS_WITH_SPECIALIZED_COMPONENTS.flatMap((fieldName)=>SPECIALIZED_COMPONENT_NAMES.map((componentName)=>[
119
+ `${fieldName}${componentName}Component`,
120
+ `${fieldName}${componentName}Props`
121
+ ])),
122
+ [
123
+ 'UIFieldDiffClientComponent',
124
+ 'UIFieldDiffClientProps'
125
+ ],
126
+ [
127
+ 'UIFieldDiffServerComponent',
128
+ 'UIFieldDiffServerProps'
129
+ ]
130
+ ]);
131
+ const COMPONENT_GENERIC_DEFAULTS = new Map([
132
+ [
133
+ 'FieldDiffClientComponent',
134
+ [
135
+ 'ClientFieldWithOptionalType'
136
+ ]
137
+ ],
138
+ [
139
+ 'FieldDiffServerComponent',
140
+ [
141
+ 'Field',
142
+ 'ClientFieldWithOptionalType'
143
+ ]
144
+ ],
145
+ [
146
+ 'FieldErrorServerComponent',
147
+ [
148
+ 'Field',
149
+ 'ClientFieldWithOptionalType'
150
+ ]
151
+ ],
152
+ [
153
+ 'FieldLabelClientComponent',
154
+ [
155
+ 'ClientFieldWithOptionalType'
156
+ ]
157
+ ],
158
+ [
159
+ 'FieldLabelServerComponent',
160
+ [
161
+ 'Field',
162
+ 'ClientFieldWithOptionalType'
163
+ ]
164
+ ]
165
+ ]);
166
+ export const migrateFieldComponentTypes = {
167
+ name: 'migrate-field-component-types',
168
+ apply: ({ project })=>{
169
+ const filesChanged = new Set();
170
+ const notes = [];
171
+ for (const file of project.getSourceFiles()){
172
+ collectUnsupportedImportNotes({
173
+ file,
174
+ notes
175
+ });
176
+ let mutated = false;
177
+ let reactBinding;
178
+ for (const importDeclaration of [
179
+ ...file.getImportDeclarations()
180
+ ]){
181
+ if (importDeclaration.getModuleSpecifierValue() !== 'payload') {
182
+ continue;
183
+ }
184
+ const componentImports = importDeclaration.getNamedImports().filter((specifier)=>COMPONENT_TO_PROPS.has(specifier.getName())).map((specifier)=>({
185
+ componentName: specifier.getName(),
186
+ localName: specifier.getAliasNode()?.getText() ?? specifier.getName()
187
+ }));
188
+ let importMutated = false;
189
+ for (const componentImport of componentImports){
190
+ const { componentName, localName } = componentImport;
191
+ const propsName = COMPONENT_TO_PROPS.get(componentName);
192
+ if (!propsName) {
193
+ continue;
194
+ }
195
+ const specifier = importDeclaration.getNamedImports().find((namedImport)=>namedImport.getName() === componentName && (namedImport.getAliasNode()?.getText() ?? namedImport.getName()) === localName);
196
+ if (!specifier) {
197
+ continue;
198
+ }
199
+ const binding = specifier.getAliasNode() ?? specifier.getNameNode();
200
+ // Always an Identifier in valid code: a string-literal import name requires an alias.
201
+ if (!Node.isIdentifier(binding)) {
202
+ continue;
203
+ }
204
+ const references = binding.findReferencesAsNodes().filter((node)=>node !== binding && node.getSourceFile() === file);
205
+ const unsupportedReference = references.find((reference)=>{
206
+ const parent = reference.getParent();
207
+ return !Node.isTypeReference(parent) || parent.getTypeName() !== reference;
208
+ });
209
+ if (unsupportedReference) {
210
+ notes.push(`${file.getFilePath()}:${unsupportedReference.getStartLineNumber()}: Unsupported use of \`${componentName}\`. Replace it with the corresponding props type manually.`);
211
+ continue;
212
+ }
213
+ const classDeclaration = references.map((reference)=>reference.getFirstAncestorByKind(SyntaxKind.VariableDeclaration)).find((declaration, referenceIndex)=>{
214
+ const initializer = declaration?.getInitializer();
215
+ const reference = references[referenceIndex];
216
+ const componentPropertyPath = reference ? getComponentPropertyPath({
217
+ reference
218
+ }) : undefined;
219
+ return initializer ? initializerContainsClassComponent({
220
+ componentPropertyPath,
221
+ initializer
222
+ }) : false;
223
+ });
224
+ if (classDeclaration) {
225
+ notes.push(`${file.getFilePath()}:${classDeclaration.getStartLineNumber()}: Cannot automatically migrate \`${componentName}\` because it types a class component. Replace it with a compatible props annotation manually.`);
226
+ continue;
227
+ }
228
+ if (references.length === 0) {
229
+ specifier.remove();
230
+ importMutated = true;
231
+ mutated = true;
232
+ continue;
233
+ }
234
+ const propsImport = resolvePropsImport({
235
+ file,
236
+ propsName
237
+ });
238
+ reactBinding ??= resolveReactTypeBinding(file);
239
+ for (const reference of references.reverse()){
240
+ const typeReference = reference.getParentIfKindOrThrow(SyntaxKind.TypeReference);
241
+ const typeArguments = typeReference.getTypeArguments().map((typeArgument)=>typeArgument.getText());
242
+ const propsTypeArguments = materializeGenericDefaults({
243
+ componentName,
244
+ file,
245
+ importDeclaration,
246
+ typeArguments
247
+ });
248
+ const propsType = propsTypeArguments.length > 0 ? `${propsImport.localName}<${propsTypeArguments.join(', ')}>` : propsImport.localName;
249
+ typeReference.replaceWithText(`${reactBinding.localName}.FC<${propsType}>`);
250
+ }
251
+ const currentSpecifier = importDeclaration.getNamedImports().find((namedImport)=>namedImport.getName() === componentName && (namedImport.getAliasNode()?.getText() ?? namedImport.getName()) === localName);
252
+ if (propsImport.exists) {
253
+ currentSpecifier?.remove();
254
+ } else if (currentSpecifier) {
255
+ currentSpecifier.setName(propsName);
256
+ if (propsImport.localName === propsName) {
257
+ currentSpecifier.removeAlias();
258
+ } else {
259
+ currentSpecifier.setAlias(propsImport.localName);
260
+ }
261
+ }
262
+ importMutated = true;
263
+ mutated = true;
264
+ }
265
+ if (importMutated) {
266
+ removeEmptyImport(importDeclaration);
267
+ }
268
+ }
269
+ if (reactBinding?.shouldAddImport) {
270
+ addReactTypeImport({
271
+ file,
272
+ reactName: reactBinding.localName
273
+ });
274
+ }
275
+ if (mutated) {
276
+ filesChanged.add(file.getFilePath());
277
+ }
278
+ }
279
+ return {
280
+ filesChanged: [
281
+ ...filesChanged
282
+ ],
283
+ ...notes.length > 0 ? {
284
+ notes
285
+ } : {}
286
+ };
287
+ },
288
+ description: 'Replace field component aliases imported from `payload` with the corresponding props types wrapped in `React.FC`. Generic arguments are preserved. Explicit class components and unsupported import forms are left unchanged with notes for manual migration.'
289
+ };
290
+ function materializeGenericDefaults({ componentName, file, importDeclaration, typeArguments }) {
291
+ const genericDefaults = COMPONENT_GENERIC_DEFAULTS.get(componentName);
292
+ if (!genericDefaults || typeArguments.length >= genericDefaults.length) {
293
+ return typeArguments;
294
+ }
295
+ return [
296
+ ...typeArguments,
297
+ ...genericDefaults.slice(typeArguments.length).map((typeName)=>resolvePayloadTypeImport({
298
+ file,
299
+ importDeclaration,
300
+ typeName
301
+ }))
302
+ ];
303
+ }
304
+ function resolvePayloadTypeImport({ file, importDeclaration, typeName }) {
305
+ for (const declaration of file.getImportDeclarations()){
306
+ if (declaration.getModuleSpecifierValue() !== 'payload') {
307
+ continue;
308
+ }
309
+ const existing = declaration.getNamedImports().find((namedImport)=>namedImport.getName() === typeName);
310
+ if (existing) {
311
+ const localName = existing.getAliasNode()?.getText() ?? typeName;
312
+ if (!hasCompetingDeclaration({
313
+ file,
314
+ importDeclaration: declaration,
315
+ localName
316
+ })) {
317
+ return localName;
318
+ }
319
+ }
320
+ }
321
+ const localName = getAvailableName({
322
+ file,
323
+ preferredName: typeName,
324
+ suffix: 'Type'
325
+ });
326
+ importDeclaration.addNamedImport({
327
+ name: typeName,
328
+ alias: localName === typeName ? undefined : localName,
329
+ isTypeOnly: !importDeclaration.isTypeOnly()
330
+ });
331
+ return localName;
332
+ }
333
+ function resolvePropsImport({ file, propsName }) {
334
+ for (const declaration of file.getImportDeclarations()){
335
+ if (declaration.getModuleSpecifierValue() !== 'payload') {
336
+ continue;
337
+ }
338
+ const existing = declaration.getNamedImports().find((namedImport)=>namedImport.getName() === propsName);
339
+ if (existing) {
340
+ const localName = existing.getAliasNode()?.getText() ?? propsName;
341
+ if (!hasCompetingDeclaration({
342
+ file,
343
+ importDeclaration: declaration,
344
+ localName
345
+ })) {
346
+ return {
347
+ exists: true,
348
+ localName
349
+ };
350
+ }
351
+ }
352
+ }
353
+ const localName = getAvailableName({
354
+ file,
355
+ preferredName: propsName,
356
+ suffix: 'Type'
357
+ });
358
+ return {
359
+ exists: false,
360
+ localName
361
+ };
362
+ }
363
+ function resolveReactTypeBinding(file) {
364
+ const reactImports = file.getImportDeclarations().filter((declaration)=>declaration.getModuleSpecifierValue() === 'react');
365
+ for (const declaration of reactImports){
366
+ const namespaceImport = declaration.getNamespaceImport();
367
+ if (namespaceImport && !hasCompetingDeclaration({
368
+ file,
369
+ importDeclaration: declaration,
370
+ localName: namespaceImport.getText()
371
+ })) {
372
+ return {
373
+ localName: namespaceImport.getText(),
374
+ shouldAddImport: false
375
+ };
376
+ }
377
+ const defaultImport = declaration.getDefaultImport();
378
+ if (defaultImport && !hasCompetingDeclaration({
379
+ file,
380
+ importDeclaration: declaration,
381
+ localName: defaultImport.getText()
382
+ })) {
383
+ return {
384
+ localName: defaultImport.getText(),
385
+ shouldAddImport: false
386
+ };
387
+ }
388
+ }
389
+ return {
390
+ localName: getAvailableName({
391
+ file,
392
+ preferredName: 'React',
393
+ suffix: 'Type'
394
+ }),
395
+ shouldAddImport: true
396
+ };
397
+ }
398
+ function hasCompetingDeclaration({ file, importDeclaration, localName }) {
399
+ return file.getDescendantsOfKind(SyntaxKind.Identifier).some((identifier)=>{
400
+ if (identifier.getText() !== localName || identifier.getFirstAncestorByKind(SyntaxKind.ImportDeclaration) === importDeclaration) {
401
+ return false;
402
+ }
403
+ const parent = identifier.getParent();
404
+ return (Node.isTypeParameterDeclaration(parent) || Node.isParameterDeclaration(parent) || Node.isVariableDeclaration(parent) || Node.isFunctionDeclaration(parent) || Node.isClassDeclaration(parent) || Node.isTypeAliasDeclaration(parent) || Node.isInterfaceDeclaration(parent)) && parent.getNameNode() === identifier;
405
+ });
406
+ }
407
+ function addReactTypeImport({ file, reactName }) {
408
+ const importDeclarations = file.getImportDeclarations();
409
+ const lastImport = importDeclarations.at(-1);
410
+ const statements = file.getStatements();
411
+ const insertionIndex = lastImport ? statements.indexOf(lastImport) + 1 : 0;
412
+ const nextStatement = statements.at(insertionIndex);
413
+ const needsTerminator = lastImport && nextStatement ? lastImport.getEndLineNumber() === nextStatement.getStartLineNumber() : false;
414
+ file.insertStatements(insertionIndex, `import type ${reactName} from 'react'${needsTerminator ? ';' : ''}`);
415
+ }
416
+ function initializerContainsClassComponent({ componentPropertyPath, initializer, visitedExpressions = new Set() }) {
417
+ let expression = initializer;
418
+ while(Node.isParenthesizedExpression(expression) || Node.isAsExpression(expression) || Node.isSatisfiesExpression(expression) || Node.isTypeAssertion(expression) || Node.isNonNullExpression(expression)){
419
+ expression = expression.getExpression();
420
+ }
421
+ if (visitedExpressions.has(expression)) {
422
+ return false;
423
+ }
424
+ visitedExpressions.add(expression);
425
+ if (Node.isClassExpression(expression)) {
426
+ return true;
427
+ }
428
+ if (Node.isArrayLiteralExpression(expression)) {
429
+ return expression.getElements().some((element)=>{
430
+ const nestedExpression = Node.isSpreadElement(element) ? element.getExpression() : element;
431
+ return Node.isExpression(nestedExpression) ? initializerContainsClassComponent({
432
+ componentPropertyPath,
433
+ initializer: nestedExpression,
434
+ visitedExpressions
435
+ }) : false;
436
+ });
437
+ }
438
+ if (Node.isConditionalExpression(expression)) {
439
+ return [
440
+ expression.getWhenTrue(),
441
+ expression.getWhenFalse()
442
+ ].some((nestedExpression)=>initializerContainsClassComponent({
443
+ componentPropertyPath,
444
+ initializer: nestedExpression,
445
+ visitedExpressions
446
+ }));
447
+ }
448
+ if (Node.isObjectLiteralExpression(expression)) {
449
+ const properties = expression.getProperties();
450
+ const componentPropertyName = componentPropertyPath?.[0];
451
+ const remainingComponentPropertyPath = componentPropertyPath?.slice(1);
452
+ const propertiesToInspect = componentPropertyName ? properties.filter((property)=>{
453
+ if (Node.isSpreadAssignment(property)) {
454
+ return true;
455
+ }
456
+ if (!Node.isPropertyAssignment(property) && !Node.isShorthandPropertyAssignment(property)) {
457
+ return false;
458
+ }
459
+ const propertyName = getStaticPropertyName({
460
+ nameNode: property.getNameNode()
461
+ });
462
+ return propertyName === undefined || propertyName === componentPropertyName;
463
+ }) : properties;
464
+ return propertiesToInspect.some((property)=>{
465
+ if (Node.isPropertyAssignment(property)) {
466
+ const propertyInitializer = property.getInitializer();
467
+ return propertyInitializer && Node.isExpression(propertyInitializer) ? initializerContainsClassComponent({
468
+ componentPropertyPath: remainingComponentPropertyPath,
469
+ initializer: propertyInitializer,
470
+ visitedExpressions
471
+ }) : false;
472
+ }
473
+ if (Node.isShorthandPropertyAssignment(property)) {
474
+ return initializerContainsClassComponent({
475
+ componentPropertyPath: remainingComponentPropertyPath,
476
+ initializer: property.getNameNode(),
477
+ visitedExpressions
478
+ });
479
+ }
480
+ return Node.isSpreadAssignment(property) ? initializerContainsClassComponent({
481
+ componentPropertyPath,
482
+ initializer: property.getExpression(),
483
+ visitedExpressions
484
+ }) : false;
485
+ });
486
+ }
487
+ if (!Node.isIdentifier(expression)) {
488
+ return false;
489
+ }
490
+ return expression.getDefinitions().some((definition)=>{
491
+ const declaration = definition.getDeclarationNode();
492
+ if (Node.isClassDeclaration(declaration)) {
493
+ return true;
494
+ }
495
+ if (Node.isVariableDeclaration(declaration)) {
496
+ const referencedInitializer = declaration.getInitializer();
497
+ return referencedInitializer ? initializerContainsClassComponent({
498
+ componentPropertyPath,
499
+ initializer: referencedInitializer,
500
+ visitedExpressions
501
+ }) : false;
502
+ }
503
+ return false;
504
+ });
505
+ }
506
+ function getComponentPropertyPath({ reference }) {
507
+ const propertySignatures = reference.getAncestors().filter(Node.isPropertySignature).reverse();
508
+ if (propertySignatures.length === 0) {
509
+ return undefined;
510
+ }
511
+ const propertyPath = propertySignatures.map((property)=>getStaticPropertyName({
512
+ nameNode: property.getNameNode()
513
+ }));
514
+ return propertyPath.every((propertyName)=>propertyName !== undefined) ? propertyPath : undefined;
515
+ }
516
+ function getStaticPropertyName({ nameNode }) {
517
+ if (Node.isComputedPropertyName(nameNode)) {
518
+ return getStaticComputedPropertyName({
519
+ expression: nameNode.getExpression()
520
+ });
521
+ }
522
+ if (Node.isStringLiteral(nameNode) || Node.isNoSubstitutionTemplateLiteral(nameNode)) {
523
+ return nameNode.getLiteralText();
524
+ }
525
+ if (Node.isNumericLiteral(nameNode)) {
526
+ return String(nameNode.getLiteralValue());
527
+ }
528
+ return Node.isIdentifier(nameNode) ? nameNode.getText() : undefined;
529
+ }
530
+ function getStaticComputedPropertyName({ expression: initialExpression, visitedExpressions = new Set() }) {
531
+ let expression = initialExpression;
532
+ while(Node.isParenthesizedExpression(expression) || Node.isAsExpression(expression) || Node.isSatisfiesExpression(expression) || Node.isTypeAssertion(expression) || Node.isNonNullExpression(expression)){
533
+ expression = expression.getExpression();
534
+ }
535
+ if (visitedExpressions.has(expression)) {
536
+ return undefined;
537
+ }
538
+ visitedExpressions.add(expression);
539
+ if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) {
540
+ return expression.getLiteralText();
541
+ }
542
+ if (Node.isNumericLiteral(expression)) {
543
+ return String(expression.getLiteralValue());
544
+ }
545
+ if (!Node.isIdentifier(expression)) {
546
+ return undefined;
547
+ }
548
+ for (const definition of expression.getDefinitions()){
549
+ const declaration = definition.getDeclarationNode();
550
+ if (Node.isVariableDeclaration(declaration) && declaration.getVariableStatement()?.getDeclarationKind() === VariableDeclarationKind.Const) {
551
+ const initializer = declaration.getInitializer();
552
+ const propertyName = initializer && Node.isExpression(initializer) ? getStaticComputedPropertyName({
553
+ expression: initializer,
554
+ visitedExpressions
555
+ }) : undefined;
556
+ if (propertyName !== undefined) {
557
+ return propertyName;
558
+ }
559
+ }
560
+ }
561
+ return undefined;
562
+ }
563
+ function getAvailableName({ file, preferredName, suffix }) {
564
+ const usedNames = new Set(file.getDescendantsOfKind(SyntaxKind.Identifier).map((identifier)=>identifier.getText()));
565
+ if (!usedNames.has(preferredName)) {
566
+ return preferredName;
567
+ }
568
+ let candidate = `${preferredName}${suffix}`;
569
+ let index = 2;
570
+ while(usedNames.has(candidate)){
571
+ candidate = `${preferredName}${suffix}${index}`;
572
+ index++;
573
+ }
574
+ return candidate;
575
+ }
576
+ function collectUnsupportedImportNotes({ file, notes }) {
577
+ for (const exportDeclaration of file.getExportDeclarations()){
578
+ if (exportDeclaration.getModuleSpecifierValue() !== 'payload') {
579
+ continue;
580
+ }
581
+ for (const namedExport of exportDeclaration.getNamedExports()){
582
+ if (COMPONENT_TO_PROPS.has(namedExport.getName())) {
583
+ notes.push(`${file.getFilePath()}:${namedExport.getStartLineNumber()}: Unsupported re-export of \`${namedExport.getName()}\`. Replace it with the corresponding props type manually.`);
584
+ }
585
+ }
586
+ }
587
+ for (const importDeclaration of file.getImportDeclarations()){
588
+ if (importDeclaration.getModuleSpecifierValue() !== 'payload') {
589
+ continue;
590
+ }
591
+ const namespaceImport = importDeclaration.getNamespaceImport();
592
+ if (!namespaceImport) {
593
+ continue;
594
+ }
595
+ const namespaceName = namespaceImport.getText();
596
+ for (const qualifiedName of file.getDescendantsOfKind(SyntaxKind.QualifiedName)){
597
+ const componentName = qualifiedName.getRight().getText();
598
+ if (qualifiedName.getLeft().getText() === namespaceName && COMPONENT_TO_PROPS.has(componentName)) {
599
+ notes.push(`${file.getFilePath()}:${qualifiedName.getStartLineNumber()}: Unsupported namespace reference to \`${componentName}\`. Replace it with the corresponding props type manually.`);
600
+ }
601
+ }
602
+ }
603
+ for (const importType of file.getDescendantsOfKind(SyntaxKind.ImportType)){
604
+ const argument = importType.getArgument();
605
+ const literal = Node.isLiteralTypeNode(argument) ? argument.getLiteral() : undefined;
606
+ const qualifier = importType.getQualifier();
607
+ if (Node.isStringLiteral(literal) && literal.getLiteralText() === 'payload' && qualifier && COMPONENT_TO_PROPS.has(qualifier.getText())) {
608
+ const componentName = qualifier.getText();
609
+ notes.push(`${file.getFilePath()}:${importType.getStartLineNumber()}: Unsupported inline import of \`${componentName}\`. Replace it with the corresponding props type manually.`);
610
+ }
611
+ }
612
+ }
613
+ function removeEmptyImport(importDeclaration) {
614
+ if (importDeclaration.wasForgotten() || importDeclaration.getNamedImports().length > 0 || importDeclaration.getDefaultImport() || importDeclaration.getNamespaceImport()) {
615
+ return;
616
+ }
617
+ importDeclaration.remove();
618
+ }
619
+
620
+ //# sourceMappingURL=index.js.map