From 3428175d2f21d5b4f2a34727ff74d1a72fc68989 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 20 Sep 2023 16:20:59 +0200 Subject: [PATCH] fix: prompt to abort `module add` if install failed (#208) --- src/commands/module/add.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/commands/module/add.ts b/src/commands/module/add.ts index 18f413fe..fbbfb381 100644 --- a/src/commands/module/add.ts +++ b/src/commands/module/add.ts @@ -12,6 +12,7 @@ import { getNuxtVersion, } from './_utils' import { satisfies } from 'semver' +import { colors } from 'consola/utils' export default defineCommand({ meta: { @@ -44,12 +45,25 @@ export default defineCommand({ // Add npm dependency if (!ctx.args.skipInstall) { consola.info(`Installing dev dependency \`${r.pkg}\``) - await addDependency(r.pkg, { cwd, dev: true }).catch((err) => { - consola.error(err) - consola.error( - `Please manually install \`${r.pkg}\` as a dev dependency`, - ) - }) + const res = await addDependency(r.pkg, { cwd, dev: true }).catch( + (error) => { + consola.error(error) + return consola.prompt( + `Install failed for ${colors.cyan( + r.pkg, + )}. Do you want to continue adding the module to ${colors.cyan( + 'nuxt.config', + )}?`, + { + type: 'confirm', + initial: false, + }, + ) + }, + ) + if (res === false) { + return + } } // Update nuxt.config.ts