mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-08 14:35:09 +00:00
fix(shadcn-ui): use @antfu/ni to detect package manager (#677)
* fix(cli): use @antfu/ni to detect package manager * chore(cli): cleanup imports * Create cyan-houses-dress.md --------- Co-authored-by: shadcn <m@shadcn.com>
This commit is contained in:
committed by
GitHub
parent
f8348621f4
commit
0f84973b4d
@@ -1,50 +1,13 @@
|
||||
import { promises as fs } from "fs"
|
||||
import path from "path"
|
||||
|
||||
async function fileExists(path: string) {
|
||||
try {
|
||||
await fs.access(path)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
import { detect } from "@antfu/ni"
|
||||
|
||||
export async function getPackageManager(
|
||||
targetDir: string
|
||||
): Promise<"yarn" | "pnpm" | "npm"> {
|
||||
const [yarnLock, npmLock, pnpmLock] = await Promise.all([
|
||||
fileExists(path.resolve(targetDir, "yarn.lock")),
|
||||
fileExists(path.resolve(targetDir, "package-lock.json")),
|
||||
fileExists(path.resolve(targetDir, "pnpm-lock.yaml")),
|
||||
])
|
||||
const packageManager = await detect({ programmatic: true, cwd: targetDir })
|
||||
|
||||
if (yarnLock) {
|
||||
return "yarn"
|
||||
}
|
||||
if (packageManager === "yarn@berry") return "yarn"
|
||||
if (packageManager === "pnpm@6") return "pnpm"
|
||||
if (packageManager === "bun") return "npm"
|
||||
|
||||
if (pnpmLock) {
|
||||
return "pnpm"
|
||||
}
|
||||
|
||||
if (npmLock) {
|
||||
return "npm"
|
||||
}
|
||||
|
||||
// Match based on used package manager
|
||||
const userAgent = process.env.npm_config_user_agent
|
||||
|
||||
if (!userAgent) {
|
||||
return "npm"
|
||||
}
|
||||
|
||||
if (userAgent.startsWith("yarn")) {
|
||||
return "yarn"
|
||||
}
|
||||
|
||||
if (userAgent.startsWith("pnpm")) {
|
||||
return "pnpm"
|
||||
}
|
||||
|
||||
return "npm"
|
||||
return packageManager ?? "npm"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user