Skip to content

Commit 1c1bf07

Browse files
fengmk2claude
andcommitted
fix: use npm config get prefix instead of deprecated npm bin -g
The `npm bin -g` command is deprecated in newer npm versions and fails with exit code 1. Use `npm config get prefix` and append /bin (or use prefix directly on Windows) to determine the global bin path. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ea2ed37 commit 1c1bf07

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

dist/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/install-viteplus.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,18 @@ async function getInstalledVersion(): Promise<string> {
9898

9999
async function ensureGlobalBinInPath(): Promise<void> {
100100
try {
101-
const result = await getExecOutput('npm', ['bin', '-g'], {
101+
// Use 'npm config get prefix' instead of deprecated 'npm bin -g'
102+
const result = await getExecOutput('npm', ['config', 'get', 'prefix'], {
102103
silent: true,
103104
})
104-
const globalBin = result.stdout.trim()
105-
if (globalBin && !process.env.PATH?.includes(globalBin)) {
105+
const prefix = result.stdout.trim()
106+
if (!prefix) {
107+
return
108+
}
109+
// On Unix-like systems, global binaries are in {prefix}/bin
110+
// On Windows, they're directly in {prefix}
111+
const globalBin = process.platform === 'win32' ? prefix : `${prefix}/bin`
112+
if (!process.env.PATH?.includes(globalBin)) {
106113
addPath(globalBin)
107114
debug(`Added ${globalBin} to PATH`)
108115
}

0 commit comments

Comments
 (0)