From 046586ebe6500521fd9ebe6467c025e156850d05 Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Wed, 20 Nov 2024 13:29:10 +0100 Subject: [PATCH 1/4] feat(upgrade): add `--dedupe` as option --- .gitignore | 1 + src/commands/upgrade.ts | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 9c591c11..50c876d3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist nuxt-app .pnpm-store coverage +.idea diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts index a2e297b4..bf5f6bd2 100644 --- a/src/commands/upgrade.ts +++ b/src/commands/upgrade.ts @@ -87,6 +87,11 @@ export default defineCommand({ alias: 'f', description: 'Force upgrade to recreate lockfile and node_modules', }, + dedupe: { + type: 'boolean', + alias: 'ddp', + description: 'Dedupe dependencies after upgrading', + }, channel: { type: 'string', alias: 'ch', @@ -130,16 +135,32 @@ export default defineCommand({ const forceRemovals = ['node_modules', relative(process.cwd(), pmLockFile)] .map(p => colors.cyan(p)) .join(' and ') - if (ctx.args.force === undefined) { - ctx.args.force = await consola.prompt( - `Would you like to recreate ${forceRemovals} to fix problems with hoisted dependency versions and ensure you have the most up-to-date dependencies?`, + let methode: 'force' | 'dedupe' | 'skip' | undefined = ctx.args.force ? 'force' : ctx.args.dedupe ? 'dedupe' : undefined + if (!methode) { + methode = await consola.prompt( + `Would you like to dedupe your lockfile (recommended) or force recreate ${forceRemovals} to fix problems with hoisted dependency versions and ensure you have the most up-to-date dependencies?`, { - type: 'confirm', - default: true, + type: 'select', + initial: 'dedupe', + options: [ + { + label: 'dedupe', + value: 'dedupe', + hint: 'Recommended' + }, + { + label: 'force', + value: 'force', + }, + { + label: 'skip', + value: 'skip', + }, + ] }, ) } - if (ctx.args.force) { + if (methode === 'force') { consola.info( `Recreating ${forceRemovals}. If you encounter any issues, revert the changes and try with \`--no-force\``, ) @@ -160,6 +181,14 @@ export default defineCommand({ execSync(command, { stdio: 'inherit', cwd }) + if(methode === 'dedupe') { + if(packageManager !== 'bun') { + consola.info('Deduping dependencies...') + execSync(`${packageManager} dedupe`, { stdio: 'inherit', cwd }) + } + consola.info(`Deduping dependencies is not yet supported with ${packageManager}.`) + } + // Clean up after upgrade let buildDir: string = '.nuxt' try { From 90163d973b4e2beff19133c2809f7c434b6d948a Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:33:35 +0000 Subject: [PATCH 2/4] [autofix.ci] apply automated fixes --- src/commands/upgrade.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts index bf5f6bd2..340837bc 100644 --- a/src/commands/upgrade.ts +++ b/src/commands/upgrade.ts @@ -146,7 +146,7 @@ export default defineCommand({ { label: 'dedupe', value: 'dedupe', - hint: 'Recommended' + hint: 'Recommended', }, { label: 'force', @@ -156,7 +156,7 @@ export default defineCommand({ label: 'skip', value: 'skip', }, - ] + ], }, ) } @@ -181,8 +181,8 @@ export default defineCommand({ execSync(command, { stdio: 'inherit', cwd }) - if(methode === 'dedupe') { - if(packageManager !== 'bun') { + if (methode === 'dedupe') { + if (packageManager !== 'bun') { consola.info('Deduping dependencies...') execSync(`${packageManager} dedupe`, { stdio: 'inherit', cwd }) } From 15e4fa6ba2eceeb00f0aebf2662f3dbbdbe29717 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 28 Nov 2024 11:48:38 +0000 Subject: [PATCH 3/4] chore: slightly rework/reword --- src/commands/upgrade.ts | 62 +++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts index 340837bc..8a41d93e 100644 --- a/src/commands/upgrade.ts +++ b/src/commands/upgrade.ts @@ -89,7 +89,6 @@ export default defineCommand({ }, dedupe: { type: 'boolean', - alias: 'ddp', description: 'Dedupe dependencies after upgrading', }, channel: { @@ -135,35 +134,38 @@ export default defineCommand({ const forceRemovals = ['node_modules', relative(process.cwd(), pmLockFile)] .map(p => colors.cyan(p)) .join(' and ') - let methode: 'force' | 'dedupe' | 'skip' | undefined = ctx.args.force ? 'force' : ctx.args.dedupe ? 'dedupe' : undefined - if (!methode) { - methode = await consola.prompt( - `Would you like to dedupe your lockfile (recommended) or force recreate ${forceRemovals} to fix problems with hoisted dependency versions and ensure you have the most up-to-date dependencies?`, - { - type: 'select', - initial: 'dedupe', - options: [ - { - label: 'dedupe', - value: 'dedupe', - hint: 'Recommended', - }, - { - label: 'force', - value: 'force', - }, - { - label: 'skip', - value: 'skip', - }, - ], - }, - ) + + let method: 'force' | 'dedupe' | 'skip' | undefined = ctx.args.force ? 'force' : ctx.args.dedupe ? 'dedupe' : undefined + method ||= await consola.prompt( + `Would you like to dedupe your lockfile (recommended) or recreate ${forceRemovals}? This can fix problems with hoisted dependency versions and ensure you have the most up-to-date dependencies.`, + { + type: 'select', + initial: 'dedupe', + options: [ + { + label: 'dedupe lockfile', + value: 'dedupe' as const, + hint: 'recommended', + }, + { + label: `recreate ${forceRemovals}`, + value: 'force' as const, + }, + { + label: 'skip', + value: 'skip' as const, + }, + ], + }, + ) + + // user bails on the question with Ctrl+C + if (typeof method !== 'string') { + process.exit(1) } - if (methode === 'force') { - consola.info( - `Recreating ${forceRemovals}. If you encounter any issues, revert the changes and try with \`--no-force\``, - ) + + if (method === 'force') { + consola.info(`Recreating ${forceRemovals}. If you encounter any issues, revert the changes and try with \`--no-force\``) await rmRecursive([pmLockFile, resolve(cwd, 'node_modules')]) await touchFile(pmLockFile) } @@ -181,7 +183,7 @@ export default defineCommand({ execSync(command, { stdio: 'inherit', cwd }) - if (methode === 'dedupe') { + if (method === 'dedupe') { if (packageManager !== 'bun') { consola.info('Deduping dependencies...') execSync(`${packageManager} dedupe`, { stdio: 'inherit', cwd }) From 31866c75f84236f1ccf12283278d43043db3ffba Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 28 Nov 2024 11:49:08 +0000 Subject: [PATCH 4/4] chore: add expect error --- src/commands/upgrade.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts index 8a41d93e..6e316bd2 100644 --- a/src/commands/upgrade.ts +++ b/src/commands/upgrade.ts @@ -136,6 +136,7 @@ export default defineCommand({ .join(' and ') let method: 'force' | 'dedupe' | 'skip' | undefined = ctx.args.force ? 'force' : ctx.args.dedupe ? 'dedupe' : undefined + // @ts-expect-error can be removed on next consola release method ||= await consola.prompt( `Would you like to dedupe your lockfile (recommended) or recreate ${forceRemovals}? This can fix problems with hoisted dependency versions and ensure you have the most up-to-date dependencies.`, {