Skip to content

Commit

Permalink
Improve package manager detection using @antfu/ni (#85)
Browse files Browse the repository at this point in the history
* feat: improved package manager detection using @antfu/ni

`detect-package-manager` is too naive
relates to: #38.

* Create tall-pans-drive.md

---------

Co-authored-by: Stefan E-K <[email protected]>
  • Loading branch information
wesleycoder and stefan-karger authored May 2, 2024
1 parent 74dc9ed commit 6b36e0b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-pans-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solidui-cli": patch
---

Improve package manager detection using @antfu/ni
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"pub:release": "pnpm build && pnpm publish --access public"
},
"dependencies": {
"@antfu/ni": "^0.21.12",
"@babel/core": "^7.22.20",
"@babel/parser": "^7.22.16",
"@babel/plugin-transform-typescript": "^7.22.15",
Expand All @@ -48,7 +49,6 @@
"@types/babel__core": "^7.20.2",
"chalk": "^5.3.0",
"commander": "^11.0.0",
"detect-package-manager": "^3.0.1",
"json5": "^2.2.3",
"prompts": "^2.4.2",
"recast": "^0.23.4",
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { execSync } from "child_process"
import { readFile } from "fs"

import { detect } from "@antfu/ni"
import { log, spinner } from "@clack/prompts"
import { detect } from "detect-package-manager"
import JSON5 from "json5"

export function readJsonFile(
Expand Down Expand Up @@ -44,11 +44,14 @@ export function removeExtension(value: string) {
}

export async function installPackages(...packages: string[]) {
const packageManager = await detect()
const packageManager = await detect({ programmatic: true })

switch (packageManager) {
case "yarn":
case "bun":
case "pnpm":
case "pnpm@6":
case "yarn":
case "yarn@berry":
runCommand(`${packageManager} add ${packages.join(" ")}`, "Installing dependencies")
break
default:
Expand Down
41 changes: 27 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b36e0b

Please sign in to comment.