Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1fa3372

Browse files
committed
bun: Add defaultPrefix.
1 parent 707dcb2 commit 1fa3372

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ export async function run(
287287
}
288288

289289
if (!options.prefix) {
290-
options.prefix = await packageManagers[options.packageManager === 'yarn' ? 'yarn' : 'npm'].defaultPrefix!(options)
290+
const defaultPrefix =
291+
packageManagers[options.packageManager || 'npm'].defaultPrefix || packageManagers.npm.defaultPrefix!
292+
options.prefix = await defaultPrefix(options)
291293
}
292294

293295
let timeout: NodeJS.Timeout | undefined

src/package-managers/bun.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Options } from 'pacote'
2+
import path from 'path'
23
import spawn from 'spawn-please'
34
import keyValueBy from '../lib/keyValueBy'
45
import programError from '../lib/programError'
@@ -28,6 +29,18 @@ async function spawnBun(
2829

2930
return spawn('bun', fullArgs, spawnOptions)
3031
}
32+
33+
/** Returns the global directory of bun. */
34+
export const defaultPrefix = async (options: Options): Promise<string> => {
35+
if (options.prefix) {
36+
return options.prefix
37+
} else if (process.env.BUN_INSTALL) {
38+
return process.env.BUN_INSTALL
39+
}
40+
const bin = await spawn('bun', ['pm', '-g', 'bin'])
41+
return path.dirname(bin)
42+
}
43+
3144
/**
3245
* (Bun) Fetches the list of all installed packages.
3346
*/

0 commit comments

Comments
 (0)