Skip to content

Commit

Permalink
next-upgrade: Hide install output by default (#70632)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Sep 30, 2024
1 parent 2b62b32 commit 226fa6a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/next-codemod/bin/next-codemod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ program
'[revision]',
'NPM dist tag or exact version to upgrade to (e.g. "latest" or "15.0.0-canary.167"). Prompts to choose a dist tag if omitted.'
)
.option('--verbose', 'Verbose output', false)
.action(runUpgrade)

program.parse(process.argv)
11 changes: 9 additions & 2 deletions packages/next-codemod/bin/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ async function loadHighestNPMVersionMatching(query: string) {
return versions[versions.length - 1]
}

export async function runUpgrade(revision: string | undefined): Promise<void> {
export async function runUpgrade(
revision: string | undefined,
options: { verbose: boolean }
): Promise<void> {
const { verbose } = options
const appPackageJsonPath = path.resolve(process.cwd(), 'package.json')
let appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, 'utf8'))

Expand Down Expand Up @@ -183,7 +187,10 @@ export async function runUpgrade(revision: string | undefined): Promise<void> {
`Upgrading your project to ${chalk.blue('Next.js ' + targetVersionSpecifier)}...\n`
)

installPackages([nextDependency, ...reactDependencies], packageManager)
installPackages([nextDependency, ...reactDependencies], {
packageManager,
silent: !verbose,
})

await suggestCodemods(installedNextVersion, targetNextVersion)

Expand Down
13 changes: 9 additions & 4 deletions packages/next-codemod/lib/handle-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ export function uninstallPackage(

export function installPackages(
packageToInstall: string[],
pkgManager?: PackageManager
options: { packageManager?: PackageManager; silent?: boolean } = {}
) {
pkgManager ??= getPkgManager(process.cwd())
if (!pkgManager) throw new Error('Failed to find package manager')
const { packageManager = getPkgManager(process.cwd()), silent = false } =
options

if (!packageManager) throw new Error('Failed to find package manager')

try {
execa.sync(pkgManager, ['add', ...packageToInstall], { stdio: 'inherit' })
execa.sync(packageManager, ['add', ...packageToInstall], {
// Keeping stderr since it'll likely be relevant later when it fails.
stdio: silent ? ['ignore', 'ignore', 'inherit'] : 'inherit',
})
} catch (error) {
throw new Error(
`Failed to install "${packageToInstall}". Please install it manually.`,
Expand Down

0 comments on commit 226fa6a

Please sign in to comment.