Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/nuxi/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { SelectPromptOptions } from 'consola'
import type { DownloadTemplateResult } from 'giget'
import type { PackageManagerName } from 'nypm'

Expand Down Expand Up @@ -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 packageManagerSelectOptions = packageManagerOptions.map(pm => ({
label: pm,
value: pm,
hint: currentPackageManager === pm ? 'current' : undefined,
} satisfies SelectPromptOptions['options'][number]))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as i know there is no exported type for this

const selectedPackageManager = packageManagerOptions.includes(packageManagerArg)
? packageManagerArg
: await logger.prompt('Which package manager would you like to use?', {
type: 'select',
options: packageManagerOptions,
options: packageManagerSelectOptions,
initial: currentPackageManager,
cancel: 'reject',
}).catch(() => process.exit(1))

Expand Down
Loading