@tamagui/codemod-flat-values 3.0.0-beta.831.1 → 3.0.0-beta.889.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/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
@@ -286,6 +314,8 @@ function inspectFile(
286
314
  const containers = planContainers(sourceFile, registry)
287
315
  const targets = conversionTargets(sourceFile.getFilePath())
288
316
  const sites: SiteReport[] = []
317
+ const functionalVariants: FunctionalVariantReport[] = []
318
+ const requiredTypeImports: RequiredTypeImport[] = []
289
319
  const styledCalls = sourceFile
290
320
  .getDescendantsOfKind(SyntaxKind.CallExpression)
291
321
  .filter((call) => provenance.isTamaguiStyledCall(call))
@@ -318,6 +348,9 @@ function inspectFile(
318
348
  if (!Node.isObjectLiteralExpression(config)) continue
319
349
  const label = `styled(${compact(call.getArguments()[0]?.getText() ?? 'unknown')}, …)`
320
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)
321
354
  const site = convertStyleObject(
322
355
  config,
323
356
  'styled',
@@ -334,7 +367,15 @@ function inspectFile(
334
367
  sites.sort(
335
368
  (left, right) => left.line - right.line || left.label.localeCompare(right.label)
336
369
  )
337
- return { file: relative(projectRoot, sourceFile.getFilePath()), sites }
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
+ }
338
379
  }
339
380
 
340
381
  const usage = `Converts Tamagui style syntax to V3 flat property values and reports what it cannot convert.
@@ -487,5 +528,5 @@ if (write) {
487
528
  console.log(`wrote ${reportPath}`)
488
529
  if (write) console.log(`rewrote ${written} source files`)
489
530
  console.log(
490
- `${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`
491
532
  )
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) => file.sites.length > 0 && file.sites.every((site) => site.legacyLeft === 0)
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((file) => file.sites.length > 0).length
81
+ const filesWithSites = files.filter(
82
+ (file) => file.sites.length > 0 || file.functionalVariants.length > 0
83
+ ).length
70
84
  const blockedFiles = files
71
- .filter((file) => file.sites.some((site) => site.legacyLeft > 0))
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
  }