@tamagui/codemod-flat-values 3.0.0-beta.807.1 → 3.0.0-beta.881.1
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 +13 -3
- package/dist/functionalVariants.mjs +469 -0
- package/dist/functionalVariants.mjs.map +1 -0
- package/dist/index.mjs +24 -18
- package/dist/index.mjs.map +1 -1
- package/dist/legacyConditions.mjs +0 -1
- package/dist/legacyConditions.mjs.map +1 -1
- package/dist/report.mjs +36 -6
- package/dist/report.mjs.map +1 -1
- package/package.json +6 -6
- package/src/functionalVariants.ts +642 -0
- package/src/index.ts +43 -28
- package/src/legacyConditions.ts +0 -1
- package/src/report.ts +70 -5
package/src/index.ts
CHANGED
|
@@ -18,6 +18,12 @@ import {
|
|
|
18
18
|
import { planContainers, type ContainerPlan } from './containers'
|
|
19
19
|
import { convertJsxSite, convertStyleObject, type SiteReport } from './convert'
|
|
20
20
|
import { compact, unwrapExpression } from './expressions'
|
|
21
|
+
import {
|
|
22
|
+
addFunctionalVariantTypeImports,
|
|
23
|
+
convertFunctionalVariants,
|
|
24
|
+
type FunctionalVariantReport,
|
|
25
|
+
type RequiredTypeImport,
|
|
26
|
+
} from './functionalVariants'
|
|
21
27
|
import {
|
|
22
28
|
codemodMediaNames,
|
|
23
29
|
createModifierRegistry,
|
|
@@ -228,6 +234,28 @@ function variantSites(
|
|
|
228
234
|
if (!Node.isPropertyAssignment(variant)) continue
|
|
229
235
|
const variantName = compact(variant.getNameNode().getText())
|
|
230
236
|
const branches = unwrapExpression(variant.getInitializerOrThrow())
|
|
237
|
+
if (Node.isCallExpression(branches)) {
|
|
238
|
+
const callee = branches.getExpression()
|
|
239
|
+
if (Node.isPropertyAccessExpression(callee) && callee.getName() === 'dynamic') {
|
|
240
|
+
const body = branches.getArguments()[0]
|
|
241
|
+
if (body && Node.isExpression(body)) {
|
|
242
|
+
for (const style of variantStyleObjects(body)) {
|
|
243
|
+
const site = convertStyleObject(
|
|
244
|
+
style,
|
|
245
|
+
'styled',
|
|
246
|
+
`${label} variants.${variantName}`,
|
|
247
|
+
registry,
|
|
248
|
+
containers,
|
|
249
|
+
targets,
|
|
250
|
+
host,
|
|
251
|
+
write
|
|
252
|
+
)
|
|
253
|
+
if (site) sites.push(site)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
continue
|
|
258
|
+
}
|
|
231
259
|
if (!Node.isObjectLiteralExpression(branches)) continue
|
|
232
260
|
for (const branch of branches.getProperties()) {
|
|
233
261
|
if (!Node.isPropertyAssignment(branch)) continue
|
|
@@ -250,32 +278,6 @@ function variantSites(
|
|
|
250
278
|
}
|
|
251
279
|
}
|
|
252
280
|
|
|
253
|
-
const compound = config.getProperty('compoundVariants')
|
|
254
|
-
if (Node.isPropertyAssignment(compound)) {
|
|
255
|
-
const array = unwrapExpression(compound.getInitializerOrThrow())
|
|
256
|
-
if (Node.isArrayLiteralExpression(array)) {
|
|
257
|
-
for (const [index, element] of array.getElements().entries()) {
|
|
258
|
-
const entry = unwrapExpression(element)
|
|
259
|
-
if (!Node.isObjectLiteralExpression(entry)) continue
|
|
260
|
-
const style = entry.getProperty('style')
|
|
261
|
-
if (!Node.isPropertyAssignment(style)) continue
|
|
262
|
-
for (const object of variantStyleObjects(style.getInitializerOrThrow())) {
|
|
263
|
-
const site = convertStyleObject(
|
|
264
|
-
object,
|
|
265
|
-
'styled',
|
|
266
|
-
`${label} compoundVariants[${index}]`,
|
|
267
|
-
registry,
|
|
268
|
-
containers,
|
|
269
|
-
targets,
|
|
270
|
-
host,
|
|
271
|
-
write
|
|
272
|
-
)
|
|
273
|
-
if (site) sites.push(site)
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
281
|
return sites
|
|
280
282
|
}
|
|
281
283
|
|
|
@@ -312,6 +314,8 @@ function inspectFile(
|
|
|
312
314
|
const containers = planContainers(sourceFile, registry)
|
|
313
315
|
const targets = conversionTargets(sourceFile.getFilePath())
|
|
314
316
|
const sites: SiteReport[] = []
|
|
317
|
+
const functionalVariants: FunctionalVariantReport[] = []
|
|
318
|
+
const requiredTypeImports: RequiredTypeImport[] = []
|
|
315
319
|
const styledCalls = sourceFile
|
|
316
320
|
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
317
321
|
.filter((call) => provenance.isTamaguiStyledCall(call))
|
|
@@ -344,6 +348,9 @@ function inspectFile(
|
|
|
344
348
|
if (!Node.isObjectLiteralExpression(config)) continue
|
|
345
349
|
const label = `styled(${compact(call.getArguments()[0]?.getText() ?? 'unknown')}, …)`
|
|
346
350
|
sites.push(...variantSites(config, label, registry, containers, targets, host, write))
|
|
351
|
+
const functional = convertFunctionalVariants(config, label, write)
|
|
352
|
+
functionalVariants.push(...functional.sites)
|
|
353
|
+
requiredTypeImports.push(...functional.requiredTypeImports)
|
|
347
354
|
const site = convertStyleObject(
|
|
348
355
|
config,
|
|
349
356
|
'styled',
|
|
@@ -360,7 +367,15 @@ function inspectFile(
|
|
|
360
367
|
sites.sort(
|
|
361
368
|
(left, right) => left.line - right.line || left.label.localeCompare(right.label)
|
|
362
369
|
)
|
|
363
|
-
|
|
370
|
+
functionalVariants.sort(
|
|
371
|
+
(left, right) => left.line - right.line || left.label.localeCompare(right.label)
|
|
372
|
+
)
|
|
373
|
+
if (write) addFunctionalVariantTypeImports(sourceFile, requiredTypeImports)
|
|
374
|
+
return {
|
|
375
|
+
file: relative(projectRoot, sourceFile.getFilePath()),
|
|
376
|
+
sites,
|
|
377
|
+
functionalVariants,
|
|
378
|
+
}
|
|
364
379
|
}
|
|
365
380
|
|
|
366
381
|
const usage = `Converts Tamagui style syntax to V3 flat property values and reports what it cannot convert.
|
|
@@ -513,5 +528,5 @@ if (write) {
|
|
|
513
528
|
console.log(`wrote ${reportPath}`)
|
|
514
529
|
if (write) console.log(`rewrote ${written} source files`)
|
|
515
530
|
console.log(
|
|
516
|
-
`${summary.sites} sites: ${summary.clean - summary.waiting} clean, ${summary.needsRelocation} need relocation, ${summary.unknownHost} unknown host, ${summary.ineligible} ineligible, ${summary.waiting} waiting on runtime support, ${summary.flagged} syntax-flagged; ${summary.ignoredFiles} source files ignored`
|
|
531
|
+
`${summary.sites} style sites: ${summary.clean - summary.waiting} clean, ${summary.needsRelocation} need relocation, ${summary.unknownHost} unknown host, ${summary.ineligible} ineligible, ${summary.waiting} waiting on runtime support, ${summary.flagged} syntax-flagged; ${summary.functionalVariantSites} functional variants: ${summary.functionalVariantConverted} automatic, ${summary.functionalVariantFlagged} flagged; ${summary.ignoredFiles} source files ignored`
|
|
517
532
|
)
|
package/src/legacyConditions.ts
CHANGED
|
@@ -319,7 +319,6 @@ export function convertLegacyConditionProp(
|
|
|
319
319
|
const modifiers = root.modifiers.slice()
|
|
320
320
|
const visit = (object: Record<string, unknown>, objectPath: string): void => {
|
|
321
321
|
for (const childProp in object) {
|
|
322
|
-
if (!Object.prototype.hasOwnProperty.call(object, childProp)) continue
|
|
323
322
|
const childValue = object[childProp]
|
|
324
323
|
const childPath = `${objectPath}.${childProp}`
|
|
325
324
|
const condition = resolveLegacyCondition(childProp, options.registry)
|
package/src/report.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Flag, SiteReport } from './convert'
|
|
2
|
+
import type { FunctionalVariantReport } from './functionalVariants'
|
|
2
3
|
|
|
3
4
|
export interface FileReport {
|
|
4
5
|
file: string
|
|
5
6
|
sites: SiteReport[]
|
|
7
|
+
functionalVariants: FunctionalVariantReport[]
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
function countCodes(flags: Iterable<Flag>): Array<[string, number]> {
|
|
@@ -25,6 +27,10 @@ export interface ReportSummary {
|
|
|
25
27
|
/** sites with nothing to convert until the runtime catches up */
|
|
26
28
|
waiting: number
|
|
27
29
|
ignoredFiles: number
|
|
30
|
+
functionalVariantSites: number
|
|
31
|
+
functionalVariantConverted: number
|
|
32
|
+
functionalVariantFlagged: number
|
|
33
|
+
functionalVariantFlags: Record<string, number>
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
export function renderReport(
|
|
@@ -35,6 +41,9 @@ export function renderReport(
|
|
|
35
41
|
write = false
|
|
36
42
|
): { text: string; summary: ReportSummary } {
|
|
37
43
|
const sites = files.flatMap((file) => file.sites)
|
|
44
|
+
const functionalVariants = files.flatMap((file) => file.functionalVariants)
|
|
45
|
+
const convertedFunctionalVariants = functionalVariants.filter((site) => site.converted)
|
|
46
|
+
const flaggedFunctionalVariants = functionalVariants.filter((site) => !site.converted)
|
|
38
47
|
const clean = sites.filter(
|
|
39
48
|
(site) =>
|
|
40
49
|
site.flags.length === 0 &&
|
|
@@ -64,12 +73,26 @@ export function renderReport(
|
|
|
64
73
|
site.assessmentVerdict === 'clean'
|
|
65
74
|
).length
|
|
66
75
|
const readyFiles = files.filter(
|
|
67
|
-
(file) =>
|
|
76
|
+
(file) =>
|
|
77
|
+
(file.sites.length > 0 || file.functionalVariants.length > 0) &&
|
|
78
|
+
file.sites.every((site) => site.legacyLeft === 0) &&
|
|
79
|
+
file.functionalVariants.every((site) => site.converted)
|
|
68
80
|
)
|
|
69
|
-
const filesWithSites = files.filter(
|
|
81
|
+
const filesWithSites = files.filter(
|
|
82
|
+
(file) => file.sites.length > 0 || file.functionalVariants.length > 0
|
|
83
|
+
).length
|
|
70
84
|
const blockedFiles = files
|
|
71
|
-
.filter(
|
|
85
|
+
.filter(
|
|
86
|
+
(file) =>
|
|
87
|
+
file.sites.some((site) => site.legacyLeft > 0) ||
|
|
88
|
+
file.functionalVariants.some((site) => !site.converted)
|
|
89
|
+
)
|
|
72
90
|
.map((file) => file.file)
|
|
91
|
+
const functionalFlagCounts = countCodes(
|
|
92
|
+
flaggedFunctionalVariants.flatMap((site) => [
|
|
93
|
+
...new Map(site.flags.map((flag) => [flag.code, flag])).values(),
|
|
94
|
+
])
|
|
95
|
+
)
|
|
73
96
|
|
|
74
97
|
const lines = [
|
|
75
98
|
'# Flat-values codemod dry-run',
|
|
@@ -93,10 +116,19 @@ export function renderReport(
|
|
|
93
116
|
`- ${ignoredFiles} source files skipped by \`.tamagui-flat-values-ignore\` markers`,
|
|
94
117
|
`- ${jsx.length} JSX sites: ${cleanJsx} clean, ${jsx.length - cleanJsx} need review`,
|
|
95
118
|
`- ${styled.length} styled config sites: ${cleanStyled} clean, ${styled.length - cleanStyled} need review`,
|
|
119
|
+
`- ${functionalVariants.length} functional variant sites found`,
|
|
120
|
+
`- ${convertedFunctionalVariants.length} functional variants have automatic styled.dynamic rewrites`,
|
|
121
|
+
`- ${flaggedFunctionalVariants.length} functional variants need manual migration`,
|
|
122
|
+
'',
|
|
123
|
+
'### Functional variant flag reasons',
|
|
124
|
+
'',
|
|
125
|
+
...(functionalFlagCounts.length
|
|
126
|
+
? functionalFlagCounts.map(([code, count]) => `- ${code}: ${count}`)
|
|
127
|
+
: ['- none']),
|
|
96
128
|
'',
|
|
97
129
|
'### Remaining manual migration',
|
|
98
130
|
'',
|
|
99
|
-
`${readyFiles.length} of ${filesWithSites} files have no legacy condition object left after`,
|
|
131
|
+
`${readyFiles.length} of ${filesWithSites} files have no legacy condition object or flagged functional variant left after`,
|
|
100
132
|
'conversion. V3 has no compatibility setting; finish the remaining files directly:',
|
|
101
133
|
blockedFiles.length
|
|
102
134
|
? blockedFiles.map((file) => `\`${file}\``).join(', ')
|
|
@@ -156,8 +188,37 @@ export function renderReport(
|
|
|
156
188
|
}
|
|
157
189
|
|
|
158
190
|
for (const file of files) {
|
|
159
|
-
if (!file.sites.length) continue
|
|
191
|
+
if (!file.sites.length && !file.functionalVariants.length) continue
|
|
160
192
|
lines.push('', `## \`${file.file}\``, '')
|
|
193
|
+
for (const site of file.functionalVariants) {
|
|
194
|
+
lines.push(
|
|
195
|
+
`### ${site.label} functional variant at line ${site.line} (${site.converted ? 'automatic' : 'manual'})`,
|
|
196
|
+
'',
|
|
197
|
+
'Before:',
|
|
198
|
+
'',
|
|
199
|
+
'```tsx',
|
|
200
|
+
site.before,
|
|
201
|
+
'```',
|
|
202
|
+
'',
|
|
203
|
+
site.converted ? 'Automatic rewrite:' : 'Left authored:',
|
|
204
|
+
'',
|
|
205
|
+
'```tsx',
|
|
206
|
+
site.after,
|
|
207
|
+
'```'
|
|
208
|
+
)
|
|
209
|
+
if (site.flags.length) {
|
|
210
|
+
lines.push('', 'Flags:', '')
|
|
211
|
+
for (const flag of site.flags) lines.push(`- **${flag.code}**: ${flag.detail}`)
|
|
212
|
+
}
|
|
213
|
+
if (site.draft) {
|
|
214
|
+
lines.push('', 'Generated `.resolve` draft:', '', '```tsx', site.draft, '```')
|
|
215
|
+
}
|
|
216
|
+
if (site.notes.length) {
|
|
217
|
+
lines.push('', 'Notes:', '')
|
|
218
|
+
for (const note of site.notes) lines.push(`- ${note}`)
|
|
219
|
+
}
|
|
220
|
+
lines.push('')
|
|
221
|
+
}
|
|
161
222
|
for (const site of file.sites) {
|
|
162
223
|
const status = [
|
|
163
224
|
site.assessmentVerdict === 'clean' ? null : site.assessmentVerdict,
|
|
@@ -230,6 +291,10 @@ export function renderReport(
|
|
|
230
291
|
warnings: warnings.length,
|
|
231
292
|
waiting: waiting.length,
|
|
232
293
|
ignoredFiles,
|
|
294
|
+
functionalVariantSites: functionalVariants.length,
|
|
295
|
+
functionalVariantConverted: convertedFunctionalVariants.length,
|
|
296
|
+
functionalVariantFlagged: flaggedFunctionalVariants.length,
|
|
297
|
+
functionalVariantFlags: Object.fromEntries(functionalFlagCounts),
|
|
233
298
|
},
|
|
234
299
|
}
|
|
235
300
|
}
|