From 40479abb807a57d36e6609e450d31a30c3180840 Mon Sep 17 00:00:00 2001 From: OrbisK Date: Fri, 4 Apr 2025 15:49:00 +0200 Subject: [PATCH 1/4] feat(init): detect current pm and use as initial value --- packages/nuxi/src/commands/init.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index c020f07a0..139378ec2 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -1,17 +1,18 @@ +import type { SelectPromptOptions } from 'consola' import type { DownloadTemplateResult } from 'giget' -import type { PackageManagerName } from 'nypm' +import type { PackageManagerName } from 'nypm' import { existsSync } from 'node:fs' -import process from 'node:process' +import process from 'node:process' import { defineCommand } from 'citty' import { colors } from 'consola/utils' import { downloadTemplate, startShell } from 'giget' import { installDependencies } from 'nypm' import { $fetch } from 'ofetch' import { join, relative, resolve } from 'pathe' -import { hasTTY } from 'std-env' +import { hasTTY } from 'std-env' import { x } from 'tinyexec' import { runCommand } from '../run' import { nuxtIcon, themeColor } from '../utils/ascii' @@ -168,13 +169,31 @@ export default defineCommand({ process.exit(1) } + function detectCurrentPackageManager() { + const userAgent = process.env.npm_config_user_agent + if (!userAgent) { + return + } + const [name] = userAgent.split('/') + if (packageManagerOptions.includes(name as PackageManagerName)) { + return name as PackageManagerName + } + } + + const currentPackageManager = detectCurrentPackageManager() // Resolve package manager const packageManagerArg = ctx.args.packageManager as PackageManagerName + const packageMangerSelectOptions = packageManagerOptions.map(pm => ({ + label: pm, + value: pm, + hint: currentPackageManager === pm ? 'current' : undefined, + } satisfies SelectPromptOptions['options'][number])) const selectedPackageManager = packageManagerOptions.includes(packageManagerArg) ? packageManagerArg : await logger.prompt('Which package manager would you like to use?', { type: 'select', - options: packageManagerOptions, + options: packageMangerSelectOptions, + initial: currentPackageManager, cancel: 'reject', }).catch(() => process.exit(1)) From a3f31252f6b32e04f6690db02d02b2f404addfe2 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 4 Apr 2025 16:45:47 +0100 Subject: [PATCH 2/4] chore: revert reordering imports --- packages/nuxi/src/commands/init.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index 139378ec2..d29e8f6ae 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -2,17 +2,18 @@ import type { SelectPromptOptions } from 'consola' import type { DownloadTemplateResult } from 'giget' import type { PackageManagerName } from 'nypm' -import { existsSync } from 'node:fs' +import { existsSync } from 'node:fs' import process from 'node:process' + import { defineCommand } from 'citty' import { colors } from 'consola/utils' import { downloadTemplate, startShell } from 'giget' import { installDependencies } from 'nypm' import { $fetch } from 'ofetch' import { join, relative, resolve } from 'pathe' - import { hasTTY } from 'std-env' + import { x } from 'tinyexec' import { runCommand } from '../run' import { nuxtIcon, themeColor } from '../utils/ascii' From d8de23bcc6dfc44084c7617e80c31535358851bc Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 4 Apr 2025 16:46:18 +0100 Subject: [PATCH 3/4] chore: typo --- packages/nuxi/src/commands/init.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index d29e8f6ae..4401a76bc 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -184,7 +184,7 @@ export default defineCommand({ const currentPackageManager = detectCurrentPackageManager() // Resolve package manager const packageManagerArg = ctx.args.packageManager as PackageManagerName - const packageMangerSelectOptions = packageManagerOptions.map(pm => ({ + const packageManagerSelectOptions = packageManagerOptions.map(pm => ({ label: pm, value: pm, hint: currentPackageManager === pm ? 'current' : undefined, @@ -193,7 +193,7 @@ export default defineCommand({ ? packageManagerArg : await logger.prompt('Which package manager would you like to use?', { type: 'select', - options: packageMangerSelectOptions, + options: packageManagerSelectOptions, initial: currentPackageManager, cancel: 'reject', }).catch(() => process.exit(1)) From b1719b9717f79fae0f5c0d4b3ab3071c8d5e1d61 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 4 Apr 2025 16:46:37 +0100 Subject: [PATCH 4/4] chore: space --- packages/nuxi/src/commands/init.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index 4401a76bc..ae4e6d57d 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -1,6 +1,5 @@ import type { SelectPromptOptions } from 'consola' import type { DownloadTemplateResult } from 'giget' - import type { PackageManagerName } from 'nypm' import { existsSync } from 'node:fs'