From 226fa6a1724db36177a0813f26d2928f44c153c8 Mon Sep 17 00:00:00 2001 From: "Sebastian \"Sebbie\" Silbermann" Date: Tue, 1 Oct 2024 00:47:45 +0200 Subject: [PATCH] next-upgrade: Hide install output by default (#70632) --- packages/next-codemod/bin/next-codemod.ts | 1 + packages/next-codemod/bin/upgrade.ts | 11 +++++++++-- packages/next-codemod/lib/handle-package.ts | 13 +++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/next-codemod/bin/next-codemod.ts b/packages/next-codemod/bin/next-codemod.ts index 3af9030bbc46e..58f4964b365e1 100644 --- a/packages/next-codemod/bin/next-codemod.ts +++ b/packages/next-codemod/bin/next-codemod.ts @@ -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) diff --git a/packages/next-codemod/bin/upgrade.ts b/packages/next-codemod/bin/upgrade.ts index f571a4d8147f2..f66cfdc11af62 100644 --- a/packages/next-codemod/bin/upgrade.ts +++ b/packages/next-codemod/bin/upgrade.ts @@ -35,7 +35,11 @@ async function loadHighestNPMVersionMatching(query: string) { return versions[versions.length - 1] } -export async function runUpgrade(revision: string | undefined): Promise { +export async function runUpgrade( + revision: string | undefined, + options: { verbose: boolean } +): Promise { + const { verbose } = options const appPackageJsonPath = path.resolve(process.cwd(), 'package.json') let appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, 'utf8')) @@ -183,7 +187,10 @@ export async function runUpgrade(revision: string | undefined): Promise { `Upgrading your project to ${chalk.blue('Next.js ' + targetVersionSpecifier)}...\n` ) - installPackages([nextDependency, ...reactDependencies], packageManager) + installPackages([nextDependency, ...reactDependencies], { + packageManager, + silent: !verbose, + }) await suggestCodemods(installedNextVersion, targetNextVersion) diff --git a/packages/next-codemod/lib/handle-package.ts b/packages/next-codemod/lib/handle-package.ts index 5d1999524849c..d4b298642f216 100644 --- a/packages/next-codemod/lib/handle-package.ts +++ b/packages/next-codemod/lib/handle-package.ts @@ -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.`,