Skip to content

Commit

Permalink
fix: prefer pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenQingchuan committed May 3, 2024
1 parent 5f273c0 commit 42bea09
Show file tree
Hide file tree
Showing 5 changed files with 7,148 additions and 5,764 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-vine-workspace",
"private": true,
"packageManager": "pnpm@8.7.0",
"packageManager": "pnpm@9.0.6",
"description": "Yet another style to write Vue.js components",
"author": "ShenQingchuan",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vue-vine/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getTemplateDirectory, renderTemplate } from './utils'

export interface ProjectOptions {
path: string
name: string // TODO
name: string
templateDir: string

templates: string[]
Expand Down
52 changes: 43 additions & 9 deletions packages/create-vue-vine/src/utils/pm.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
import process from 'node:process'
import { execa } from 'execa'
import { execa, execaSync } from 'execa'

const userAgent = process.env.npm_config_user_agent ?? ''
const userAgentEnv = process.env.npm_config_user_agent ?? ''

const packageManager = /pnpm/.test(userAgent)
? 'pnpm'
: /yarn/.test(userAgent)
? /bun/.test(userAgent)
? 'bun'
: 'yarn'
: 'npm'
function detectPackageManager() {
const fromUserAgent = /pnpm/.test(userAgentEnv)
? 'pnpm'
: /yarn/.test(userAgentEnv)
? /bun/.test(userAgentEnv)
? 'bun'
: 'yarn'
: undefined

if (fromUserAgent)
return fromUserAgent

let pnpmVersionExitCode: number,
yarnVersionExitCode: number

// Run 'pnpm --version' to check if pnpm is installed
try {
pnpmVersionExitCode = execaSync('pnpm', ['--version'], { stdio: 'ignore' }).exitCode
}
catch (error) {
pnpmVersionExitCode = -1
}
// Run 'yarn --version' to check if yarn is installed
try {
yarnVersionExitCode = execaSync('yarn', ['--version'], { stdio: 'ignore' }).exitCode
}
catch (error) {
yarnVersionExitCode = -1
}

if (pnpmVersionExitCode === 0) {
return 'pnpm'
}
else if (yarnVersionExitCode === 0) {
return 'yarn'
}

return 'npm'
}

const packageManager = detectPackageManager()

type Command = 'install' | 'dev'

Expand Down
2 changes: 1 addition & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vue-vine/playground",
"private": true,
"packageManager": "pnpm@8.7.0",
"packageManager": "pnpm@9.0.6",
"scripts": {
"dev": "vite --port 3333",
"build": "vite build",
Expand Down
Loading

0 comments on commit 42bea09

Please sign in to comment.