MCPcopy
hub / github.com/vercel/next.js / suggestCodemods

Function suggestCodemods

packages/next-codemod/bin/upgrade.ts:559–614  ·  view source on GitHub ↗
(
  initialNextVersion: string,
  targetNextVersion: string
)

Source from the content-addressed store, hash-verified

557}
558
559async function suggestCodemods(
560 initialNextVersion: string,
561 targetNextVersion: string
562): Promise<string[]> {
563 // example:
564 // codemod version: 15.0.0-canary.45
565 // 14.3 -> 15.0.0-canary.45: apply
566 // 14.3 -> 15.0.0-canary.44: don't apply
567 // 15.0.0-canary.44 -> 15.0.0-canary.45: apply
568 // 15.0.0-canary.45 -> 15.0.0-canary.46: don't apply
569 // 15.0.0-canary.45 -> 15.0.0 : don't apply
570 // 15.0.0-canary.44 -> 15.0.0 : apply
571 const initialVersionIndex = TRANSFORMER_INQUIRER_CHOICES.findIndex(
572 (codemod) => {
573 return compareVersions(codemod.version, initialNextVersion) > 0
574 }
575 )
576 if (initialVersionIndex === -1) {
577 return []
578 }
579
580 let targetVersionIndex = TRANSFORMER_INQUIRER_CHOICES.findIndex(
581 (codemod) => compareVersions(codemod.version, targetNextVersion) > 0
582 )
583 if (targetVersionIndex === -1) {
584 targetVersionIndex = TRANSFORMER_INQUIRER_CHOICES.length
585 }
586
587 const relevantCodemods = TRANSFORMER_INQUIRER_CHOICES.slice(
588 initialVersionIndex,
589 targetVersionIndex
590 )
591
592 if (relevantCodemods.length === 0) {
593 return []
594 }
595
596 const { codemods } = await prompts(
597 {
598 type: 'multiselect',
599 name: 'codemods',
600 message: `The following ${pc.blue('codemods')} are recommended for your upgrade. Select the ones to apply.`,
601 choices: relevantCodemods.reverse().map(({ title, value, version }) => {
602 return {
603 title: `(v${version}) ${value}`,
604 description: title,
605 value,
606 selected: true,
607 }
608 }),
609 },
610 { onCancel }
611 )
612
613 return codemods
614}
615
616async function suggestReactCodemods(): Promise<boolean> {

Callers 1

runUpgradeFunction · 0.85

Calls 4

compareVersionsFunction · 0.85
sliceMethod · 0.45
mapMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected