From b7d79f89f6892c4ed5f67601bffff6294a273cfa Mon Sep 17 00:00:00 2001 From: Damian Glowala Date: Sat, 8 Mar 2025 09:49:55 +0100 Subject: [PATCH] fix(init): forward log level to `module add` command and do not run `prepare` when `skipInstall` is true --- packages/nuxi/src/commands/init.ts | 21 +++++++++++---------- packages/nuxi/src/commands/module/add.ts | 9 ++++++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index 867a3ef2e..c020f07a0 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -16,7 +16,7 @@ import { x } from 'tinyexec' import { runCommand } from '../run' import { nuxtIcon, themeColor } from '../utils/ascii' import { logger } from '../utils/logger' -import { cwdArgs } from './_shared' +import { cwdArgs, logLevelArgs } from './_shared' const DEFAULT_REGISTRY = 'https://raw.githubusercontent.com/nuxt/starter/templates/templates' const DEFAULT_TEMPLATE_NAME = 'v3' @@ -39,6 +39,7 @@ export default defineCommand({ }, args: { ...cwdArgs, + ...logLevelArgs, dir: { type: 'positional', description: 'Project directory', @@ -245,15 +246,14 @@ export default defineCommand({ }>('https://api.nuxt.com/modules') const officialModules = response.modules - .filter(module => module.type === 'official') - .filter(module => module.npm !== '@nuxt/devtools') + .filter(module => module.type === 'official' && module.npm !== '@nuxt/devtools') const selectedOfficialModules = await logger.prompt( `Would you like to install any of the official modules?`, { type: 'multiselect', options: officialModules.map(module => ({ - label: `${colors.bold(colors.greenBright(module.npm))} – ${module.description.split('.')[0]}`, + label: `${colors.bold(colors.greenBright(module.npm))} – ${module.description.replace(/\.$/, '')}`, value: module.npm, })), required: false, @@ -271,14 +271,15 @@ export default defineCommand({ // Add modules if (modulesToAdd.length > 0) { - await runCommand('module', [ + const args: string[] = [ 'add', ...modulesToAdd, - '--cwd', - join(ctx.args.cwd, ctx.args.dir), - '--skipInstall', - ctx.args.install ? 'false' : 'true', - ]) + `--cwd=${join(ctx.args.cwd, ctx.args.dir)}`, + ctx.args.install ? '' : '--skipInstall', + ctx.args.logLevel ? `--logLevel=${ctx.args.logLevel}` : '', + ].filter(Boolean) + + await runCommand('module', args) } // Display next steps diff --git a/packages/nuxi/src/commands/module/add.ts b/packages/nuxi/src/commands/module/add.ts index 99624d32e..2086604df 100644 --- a/packages/nuxi/src/commands/module/add.ts +++ b/packages/nuxi/src/commands/module/add.ts @@ -90,9 +90,12 @@ export default defineCommand({ await addModules(resolvedModules, { ...ctx.args, cwd }, projectPkg) - // update the types for new module - const args = Object.entries(ctx.args).filter(([k]) => k in cwdArgs || k in logLevelArgs).map(([k, v]) => `--${k}=${v}`) - await runCommand('prepare', args) + // Run prepare command if install is not skipped + if (!ctx.args.skipInstall) { + const args = Object.entries(ctx.args).filter(([k]) => k in cwdArgs || k in logLevelArgs).map(([k, v]) => `--${k}=${v}`) + + await runCommand('prepare', args) + } }, })