Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(next-codemod): add prompts for (un)installing packages #71038

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions packages/next-codemod/bin/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,30 @@ export async function runTransform(
}

if (!dry && transformer === 'built-in-next-font') {
console.log('Uninstalling `@next/font`')
try {
const { uninstallNextFont } = await prompts({
type: 'confirm',
name: 'uninstallNextFont',
message: 'Do you want to uninstall `@next/font`?',
initial: true,
})

if (uninstallNextFont) {
console.log('Uninstalling `@next/font`')
uninstallPackage('@next/font')
} catch {
console.error(
"Couldn't uninstall `@next/font`, please uninstall it manually"
)
}
}

if (!dry && transformer === 'next-request-geo-ip') {
console.log('Installing `@vercel/functions`...')
installPackages(['@vercel/functions'])
const { installVercelFunctions } = await prompts({
type: 'confirm',
name: 'installVercelFunctions',
message: 'Do you want to install `@vercel/functions`?',
initial: true,
})

if (installVercelFunctions) {
console.log('Installing `@vercel/functions`...')
installPackages(['@vercel/functions'])
}
}
}
9 changes: 8 additions & 1 deletion packages/next-codemod/lib/handle-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export function uninstallPackage(
command = 'remove'
}

execa.sync(pkgManager, [command, packageToUninstall], { stdio: 'inherit' })
try {
execa.sync(pkgManager, [command, packageToUninstall], { stdio: 'inherit' })
} catch (error) {
throw new Error(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved error handling to util function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the error will go into stdio?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK yes as stderr but wouldn't swallow it, will be caught on catch.

`Failed to uninstall "${packageToUninstall}". Please uninstall it manually.`,
{ cause: error }
)
}
}

export function installPackages(
Expand Down
Loading