From fd918e3aa103cb40d643e322eb50fa3ce646afb0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 17 Jan 2025 21:45:38 +0000 Subject: [PATCH] fix(init,module,upgrade): validate response from `consola.prompt` (#687) --- packages/nuxi/src/commands/init.ts | 7 ++++++- packages/nuxi/src/commands/module/add.ts | 5 ++++- packages/nuxi/src/commands/upgrade.ts | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index 5ff91597..94cb899e 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -152,6 +152,11 @@ export default defineCommand({ options: packageManagerOptions, }) + if (!packageManagerOptions.includes(selectedPackageManager)) { + logger.error('Invalid package manager selected.') + process.exit(1) + } + // Install project dependencies // or skip installation based on the '--no-install' flag if (ctx.args.install === false) { @@ -183,7 +188,7 @@ export default defineCommand({ if (ctx.args.gitInit === undefined) { ctx.args.gitInit = await logger.prompt('Initialize git repository?', { type: 'confirm', - }) + }) === true } if (ctx.args.gitInit) { logger.info('Initializing git repository...\n') diff --git a/packages/nuxi/src/commands/module/add.ts b/packages/nuxi/src/commands/module/add.ts index 8891dfe3..7766790c 100644 --- a/packages/nuxi/src/commands/module/add.ts +++ b/packages/nuxi/src/commands/module/add.ts @@ -145,7 +145,7 @@ async function addModules(modules: ResolvedModule[], { skipInstall, skipConfig, }, ) - if (res === false) { + if (res !== true) { return } } @@ -268,6 +268,9 @@ async function resolveModule(moduleName: string, cwd: string): Promise