@payloadcms/codemod 4.0.0-internal.77191e5 → 4.0.0-internal.8001944
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -30
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.help.d.ts +4 -0
- package/dist/cli.help.d.ts.map +1 -0
- package/dist/cli.help.js +29 -0
- package/dist/cli.help.js.map +1 -0
- package/dist/cli.js +49 -27
- package/dist/cli.js.map +1 -1
- package/dist/cli.parseFlags.d.ts +15 -0
- package/dist/cli.parseFlags.d.ts.map +1 -1
- package/dist/cli.parseFlags.js +35 -2
- package/dist/cli.parseFlags.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +8 -0
- package/dist/registry.js.map +1 -1
- package/dist/runbook/payload-v4-upgrade.md +55 -0
- package/dist/runbook/v4.mdx +2179 -0
- package/dist/transforms/add-override-access-true/basic.input.js +41 -0
- package/dist/transforms/add-override-access-true/basic.input.js.map +1 -0
- package/dist/transforms/add-override-access-true/basic.output.js +50 -0
- package/dist/transforms/add-override-access-true/basic.output.js.map +1 -0
- package/dist/transforms/add-override-access-true/comment-between-properties.input.js +11 -0
- package/dist/transforms/add-override-access-true/comment-between-properties.input.js.map +1 -0
- package/dist/transforms/add-override-access-true/comment-between-properties.output.js +12 -0
- package/dist/transforms/add-override-access-true/comment-between-properties.output.js.map +1 -0
- package/dist/transforms/add-override-access-true/index.d.ts +20 -0
- package/dist/transforms/add-override-access-true/index.d.ts.map +1 -0
- package/dist/transforms/add-override-access-true/index.js +208 -0
- package/dist/transforms/add-override-access-true/index.js.map +1 -0
- package/dist/transforms/add-override-access-true/javascript.input.d.ts +6 -0
- package/dist/transforms/add-override-access-true/javascript.input.d.ts.map +1 -0
- package/dist/transforms/add-override-access-true/javascript.input.js +24 -0
- package/dist/transforms/add-override-access-true/javascript.input.js.map +1 -0
- package/dist/transforms/add-override-access-true/javascript.output.d.ts +6 -0
- package/dist/transforms/add-override-access-true/javascript.output.d.ts.map +1 -0
- package/dist/transforms/add-override-access-true/javascript.output.js +26 -0
- package/dist/transforms/add-override-access-true/javascript.output.js.map +1 -0
- package/dist/transforms/add-override-access-true/non-matching.input.js +42 -0
- package/dist/transforms/add-override-access-true/non-matching.input.js.map +1 -0
- package/dist/transforms/add-override-access-true/non-matching.output.js +42 -0
- package/dist/transforms/add-override-access-true/non-matching.output.js.map +1 -0
- package/dist/transforms/add-override-access-true/single-line.input.js +13 -0
- package/dist/transforms/add-override-access-true/single-line.input.js.map +1 -0
- package/dist/transforms/add-override-access-true/single-line.output.js +17 -0
- package/dist/transforms/add-override-access-true/single-line.output.js.map +1 -0
- package/dist/transforms/add-override-access-true/trailing-comment.input.js +10 -0
- package/dist/transforms/add-override-access-true/trailing-comment.input.js.map +1 -0
- package/dist/transforms/add-override-access-true/trailing-comment.output.js +12 -0
- package/dist/transforms/add-override-access-true/trailing-comment.output.js.map +1 -0
- package/dist/transforms/migrate-aliased-exports/index.d.ts.map +1 -1
- package/dist/transforms/migrate-aliased-exports/index.js +6 -5
- package/dist/transforms/migrate-aliased-exports/index.js.map +1 -1
- package/dist/transforms/migrate-aliased-exports/request.input.js +6 -0
- package/dist/transforms/migrate-aliased-exports/request.input.js.map +1 -0
- package/dist/transforms/migrate-aliased-exports/request.output.js +5 -0
- package/dist/transforms/migrate-aliased-exports/request.output.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/already-set.input.js +15 -0
- package/dist/transforms/migrate-authorship-default/already-set.input.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/already-set.output.js +15 -0
- package/dist/transforms/migrate-authorship-default/already-set.output.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/basic.input.js +16 -0
- package/dist/transforms/migrate-authorship-default/basic.input.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/basic.output.js +18 -0
- package/dist/transforms/migrate-authorship-default/basic.output.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/build-config.input.js +32 -0
- package/dist/transforms/migrate-authorship-default/build-config.input.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/build-config.output.js +35 -0
- package/dist/transforms/migrate-authorship-default/build-config.output.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/globals.input.js +16 -0
- package/dist/transforms/migrate-authorship-default/globals.input.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/globals.output.js +17 -0
- package/dist/transforms/migrate-authorship-default/globals.output.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/index.d.ts +11 -0
- package/dist/transforms/migrate-authorship-default/index.d.ts.map +1 -0
- package/dist/transforms/migrate-authorship-default/index.js +141 -0
- package/dist/transforms/migrate-authorship-default/index.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/non-matching.input.js +18 -0
- package/dist/transforms/migrate-authorship-default/non-matching.input.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/non-matching.output.js +18 -0
- package/dist/transforms/migrate-authorship-default/non-matching.output.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/satisfies.input.js +11 -0
- package/dist/transforms/migrate-authorship-default/satisfies.input.js.map +1 -0
- package/dist/transforms/migrate-authorship-default/satisfies.output.js +13 -0
- package/dist/transforms/migrate-authorship-default/satisfies.output.js.map +1 -0
- package/dist/transforms/migrate-field-component-types/basic.input.js +8 -0
- package/dist/transforms/migrate-field-component-types/basic.input.js.map +1 -0
- package/dist/transforms/migrate-field-component-types/basic.output.js +8 -0
- package/dist/transforms/migrate-field-component-types/basic.output.js.map +1 -0
- package/dist/transforms/migrate-field-component-types/index.d.ts +3 -0
- package/dist/transforms/migrate-field-component-types/index.d.ts.map +1 -0
- package/dist/transforms/migrate-field-component-types/index.js +620 -0
- package/dist/transforms/migrate-field-component-types/index.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/aliases.input.js +8 -0
- package/dist/transforms/migrate-payload-request-creation/aliases.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/aliases.output.js +31 -0
- package/dist/transforms/migrate-payload-request-creation/aliases.output.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/collision.input.js +9 -0
- package/dist/transforms/migrate-payload-request-creation/collision.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/comments.input.js +9 -0
- package/dist/transforms/migrate-payload-request-creation/comments.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/comments.output.js +34 -0
- package/dist/transforms/migrate-payload-request-creation/comments.output.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/empty.input.js +5 -0
- package/dist/transforms/migrate-payload-request-creation/empty.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/empty.output.js +7 -0
- package/dist/transforms/migrate-payload-request-creation/empty.output.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/evaluation-order.input.js +10 -0
- package/dist/transforms/migrate-payload-request-creation/evaluation-order.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/expression.input.js +8 -0
- package/dist/transforms/migrate-payload-request-creation/expression.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/expression.output.js +8 -0
- package/dist/transforms/migrate-payload-request-creation/expression.output.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/getters.input.js +52 -0
- package/dist/transforms/migrate-payload-request-creation/getters.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/index.d.ts +3 -0
- package/dist/transforms/migrate-payload-request-creation/index.d.ts.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/index.js +236 -0
- package/dist/transforms/migrate-payload-request-creation/index.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/internal.input.js +6 -0
- package/dist/transforms/migrate-payload-request-creation/internal.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/internal.output.js +6 -0
- package/dist/transforms/migrate-payload-request-creation/internal.output.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/non-matching.input.js +5 -0
- package/dist/transforms/migrate-payload-request-creation/non-matching.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/populated.input.js +7 -0
- package/dist/transforms/migrate-payload-request-creation/populated.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/populated.output.js +30 -0
- package/dist/transforms/migrate-payload-request-creation/populated.output.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/shadowed.input.js +7 -0
- package/dist/transforms/migrate-payload-request-creation/shadowed.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/shadowed.output.js +9 -0
- package/dist/transforms/migrate-payload-request-creation/shadowed.output.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/shorthand.input.js +12 -0
- package/dist/transforms/migrate-payload-request-creation/shorthand.input.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/shorthand.output.js +12 -0
- package/dist/transforms/migrate-payload-request-creation/shorthand.output.js.map +1 -0
- package/dist/transforms/migrate-payload-request-creation/unsupported.input.js +9 -0
- package/dist/transforms/migrate-payload-request-creation/unsupported.input.js.map +1 -0
- package/dist/transforms/migrate-versions-default/index.js +5 -5
- package/dist/transforms/migrate-versions-default/index.js.map +1 -1
- package/dist/transforms/remove-publish-specific-locale/index.d.ts.map +1 -1
- package/dist/transforms/remove-publish-specific-locale/index.js.map +1 -1
- package/dist/transforms/remove-storage-always-insert-fields/index.d.ts.map +1 -1
- package/dist/transforms/remove-storage-always-insert-fields/index.js +4 -0
- package/dist/transforms/remove-storage-always-insert-fields/index.js.map +1 -1
- package/dist/transforms/remove-versions-true/index.js +4 -4
- package/dist/transforms/remove-versions-true/index.js.map +1 -1
- package/dist/transforms/rename-experimental-table-feature/index.d.ts.map +1 -1
- package/dist/transforms/rename-experimental-table-feature/index.js +7 -1
- package/dist/transforms/rename-experimental-table-feature/index.js.map +1 -1
- package/dist/upgrade/defaultTag.d.ts +9 -0
- package/dist/upgrade/defaultTag.d.ts.map +1 -0
- package/dist/upgrade/defaultTag.js +25 -0
- package/dist/upgrade/defaultTag.js.map +1 -0
- package/dist/upgrade/detectPackageManager.d.ts +8 -0
- package/dist/upgrade/detectPackageManager.d.ts.map +1 -0
- package/dist/upgrade/detectPackageManager.js +38 -0
- package/dist/upgrade/detectPackageManager.js.map +1 -0
- package/dist/upgrade/dispatch.d.ts +38 -0
- package/dist/upgrade/dispatch.d.ts.map +1 -0
- package/dist/upgrade/dispatch.js +132 -0
- package/dist/upgrade/dispatch.js.map +1 -0
- package/dist/upgrade/index.d.ts +25 -0
- package/dist/upgrade/index.d.ts.map +1 -0
- package/dist/upgrade/index.js +209 -0
- package/dist/upgrade/index.js.map +1 -0
- package/dist/upgrade/prompt.d.ts +14 -0
- package/dist/upgrade/prompt.d.ts.map +1 -0
- package/dist/upgrade/prompt.js +77 -0
- package/dist/upgrade/prompt.js.map +1 -0
- package/dist/upgrade/report.d.ts +21 -0
- package/dist/upgrade/report.d.ts.map +1 -0
- package/dist/upgrade/report.js +47 -0
- package/dist/upgrade/report.js.map +1 -0
- package/dist/upgrade/resolveVersions.d.ts +13 -0
- package/dist/upgrade/resolveVersions.d.ts.map +1 -0
- package/dist/upgrade/resolveVersions.js +55 -0
- package/dist/upgrade/resolveVersions.js.map +1 -0
- package/dist/upgrade/rewritePackageJson.d.ts +32 -0
- package/dist/upgrade/rewritePackageJson.d.ts.map +1 -0
- package/dist/upgrade/rewritePackageJson.js +164 -0
- package/dist/upgrade/rewritePackageJson.js.map +1 -0
- package/dist/upgrade/runInstall.d.ts +16 -0
- package/dist/upgrade/runInstall.d.ts.map +1 -0
- package/dist/upgrade/runInstall.js +17 -0
- package/dist/upgrade/runInstall.js.map +1 -0
- package/dist/upgrade/selectAgent.d.ts +45 -0
- package/dist/upgrade/selectAgent.d.ts.map +1 -0
- package/dist/upgrade/selectAgent.js +54 -0
- package/dist/upgrade/selectAgent.js.map +1 -0
- package/dist/upgrade/selfCommand.d.ts +13 -0
- package/dist/upgrade/selfCommand.d.ts.map +1 -0
- package/dist/upgrade/selfCommand.js +17 -0
- package/dist/upgrade/selfCommand.js.map +1 -0
- package/dist/upgrade/types.d.ts +47 -0
- package/dist/upgrade/types.d.ts.map +1 -0
- package/dist/upgrade/types.js +11 -0
- package/dist/upgrade/types.js.map +1 -0
- package/dist/utils/project.d.ts +10 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +43 -0
- package/dist/utils/project.js.map +1 -0
- package/package.json +8 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/transforms/migrate-authorship-default/satisfies.output.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nexport const Posts = {\n slug: 'posts',\n fields: [],\n authorship: false,\n} satisfies CollectionConfig\n\nexport const Media = {\n slug: 'media',\n fields: [],\n upload: true,\n authorship: false,\n} satisfies CollectionConfig\n"],"names":["Posts","slug","fields","authorship","Media","upload"],"mappings":"AAEA,OAAO,MAAMA,QAAQ;IACnBC,MAAM;IACNC,QAAQ,EAAE;IACVC,YAAY;AACd,EAA4B;AAE5B,OAAO,MAAMC,QAAQ;IACnBH,MAAM;IACNC,QAAQ,EAAE;IACVG,QAAQ;IACRF,YAAY;AACd,EAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/transforms/migrate-field-component-types/basic.input.ts"],"sourcesContent":["import type {\n TextFieldClientComponent,\n UploadFieldServerComponent,\n} from 'payload'\n\nexport const CustomTextField: TextFieldClientComponent = (props) => {\n return props.value\n}\n\nexport const CustomUploadField: UploadFieldServerComponent = async function (props) {\n return props.path\n}\n"],"names":["CustomTextField","props","value","CustomUploadField","path"],"mappings":"AAKA,OAAO,MAAMA,kBAA4C,CAACC;IACxD,OAAOA,MAAMC,KAAK;AACpB,EAAC;AAED,OAAO,MAAMC,oBAAgD,eAAgBF,KAAK;IAChF,OAAOA,MAAMG,IAAI;AACnB,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/transforms/migrate-field-component-types/basic.output.ts"],"sourcesContent":["import type {\n TextFieldClientProps,\n UploadFieldServerProps,\n} from 'payload'\nimport type React from 'react'\n\nexport const CustomTextField: React.FC<TextFieldClientProps> = (props) => {\n return props.value\n}\n\nexport const CustomUploadField: React.FC<UploadFieldServerProps> = async function (props) {\n return props.path\n}\n"],"names":["CustomTextField","props","value","CustomUploadField","path"],"mappings":"AAMA,OAAO,MAAMA,kBAAkD,CAACC;IAC9D,OAAOA,MAAMC,KAAK;AACpB,EAAC;AAED,OAAO,MAAMC,oBAAsD,eAAgBF,KAAK;IACtF,OAAOA,MAAMG,IAAI;AACnB,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transforms/migrate-field-component-types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAiG/C,eAAO,MAAM,0BAA0B,EAAE,SAwKxC,CAAA"}
|
|
@@ -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
|