Skip to content

Commit

Permalink
fix: prompt to abort module add if install failed (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Sep 20, 2023
1 parent 68ba094 commit 3428175
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/commands/module/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getNuxtVersion,
} from './_utils'
import { satisfies } from 'semver'
import { colors } from 'consola/utils'

export default defineCommand({
meta: {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3428175

Please sign in to comment.