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:
Samuel Corsi-House
2023-06-24 13:01:22 -04:00
committed by GitHub
parent f8348621f4
commit 0f84973b4d
4 changed files with 21 additions and 44 deletions

View File

@@ -0,0 +1,5 @@
---
"shadcn-ui": patch
---
fix(cli): use `@antfu/ni` to detect package manager

View File

@@ -44,6 +44,7 @@
"test": "vitest run"
},
"dependencies": {
"@antfu/ni": "^0.21.4",
"chalk": "5.2.0",
"commander": "^10.0.0",
"cosmiconfig": "^8.1.3",

View File

@@ -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"
}

10
pnpm-lock.yaml generated
View File

@@ -1,4 +1,4 @@
lockfileVersion: '6.1'
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
@@ -336,6 +336,9 @@ importers:
packages/cli:
dependencies:
'@antfu/ni':
specifier: ^0.21.4
version: 0.21.4
chalk:
specifier: 5.2.0
version: 5.2.0
@@ -493,6 +496,11 @@ packages:
'@jridgewell/gen-mapping': 0.3.3
'@jridgewell/trace-mapping': 0.3.18
/@antfu/ni@0.21.4:
resolution: {integrity: sha512-O0Uv9LbLDSoEg26fnMDdDRiPwFJnQSoD4WnrflDwKCJm8Cx/0mV4cGxwBLXan5mGIrpK4Dd7vizf4rQm0QCEAA==}
hasBin: true
dev: false
/@babel/code-frame@7.21.4:
resolution: {integrity: sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==}
engines: {node: '>=6.9.0'}