forked from shadcn-ui/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(shadcn-ui): use
@antfu/ni
to detect package manager (shadcn-ui#677
) * fix(cli): use @antfu/ni to detect package manager * chore(cli): cleanup imports * Create cyan-houses-dress.md --------- Co-authored-by: shadcn <[email protected]>
- Loading branch information
Showing
4 changed files
with
21 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"shadcn-ui": patch | ||
--- | ||
|
||
fix(cli): use `@antfu/ni` to detect package manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")), | ||
]) | ||
|
||
if (yarnLock) { | ||
return "yarn" | ||
} | ||
|
||
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" | ||
} | ||
const packageManager = await detect({ programmatic: true, cwd: targetDir }) | ||
|
||
if (userAgent.startsWith("pnpm")) { | ||
return "pnpm" | ||
} | ||
if (packageManager === "yarn@berry") return "yarn" | ||
if (packageManager === "pnpm@6") return "pnpm" | ||
if (packageManager === "bun") return "npm" | ||
|
||
return "npm" | ||
return packageManager ?? "npm" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.