Skip to content

Commit

Permalink
fix: properly detect and install yarn@>1 and pnpm@<7 (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
auvred authored Nov 27, 2023
1 parent 1bb91b3 commit 2fbcea6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ export async function detect({ autoInstall, programmatic, cwd }: DetectOptions =
if (typeof pkg.packageManager === 'string') {
const [name, ver] = pkg.packageManager.replace(/^\^/, '').split('@')
version = ver
if (name === 'yarn' && Number.parseInt(ver) > 1)
if (name === 'yarn' && Number.parseInt(ver) > 1) {
agent = 'yarn@berry'
else if (name === 'pnpm' && Number.parseInt(ver) < 7)
// the version in packageManager isn't the actual yarn package version
version = 'berry'
}
else if (name === 'pnpm' && Number.parseInt(ver) < 7) {
agent = 'pnpm@6'
else if (name in AGENTS)
}
else if (name in AGENTS) {
agent = name
else if (!programmatic)
}
else if (!programmatic) {
console.warn('[ni] Unknown packageManager:', pkg.packageManager)
}
}
}
catch {}
Expand Down Expand Up @@ -69,7 +75,7 @@ export async function detect({ autoInstall, programmatic, cwd }: DetectOptions =
process.exit(1)
}

await execaCommand(`npm i -g ${agent}${version ? `@${version}` : ''}`, { stdio: 'inherit', cwd })
await execaCommand(`npm i -g ${agent.split('@')[0]}${version ? `@${version}` : ''}`, { stdio: 'inherit', cwd })
}

return agent
Expand Down

0 comments on commit 2fbcea6

Please sign in to comment.