-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect pnpm correctly when installing missing dependencies (#37813)
This ensures we properly detect `pnpm` when installing missing dependencies. This also adds test coverage to ensure we properly detect the correct package manager. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1655568091661719)
- Loading branch information
Showing
10 changed files
with
109 additions
and
78 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
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,36 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { execSync } from 'child_process' | ||
|
||
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | ||
|
||
export function getPkgManager(baseDir: string): PackageManager { | ||
try { | ||
for (const { lockFile, packageManager } of [ | ||
{ lockFile: 'yarn.lock', packageManager: 'yarn' }, | ||
{ lockFile: 'pnpm-lock.yaml', packageManager: 'pnpm' }, | ||
{ lockFile: 'package-lock.json', packageManager: 'npm' }, | ||
]) { | ||
if (fs.existsSync(path.join(baseDir, lockFile))) { | ||
return packageManager as PackageManager | ||
} | ||
} | ||
const userAgent = process.env.npm_config_user_agent | ||
if (userAgent) { | ||
if (userAgent.startsWith('yarn')) { | ||
return 'yarn' | ||
} else if (userAgent.startsWith('pnpm')) { | ||
return 'pnpm' | ||
} | ||
} | ||
try { | ||
execSync('yarn --version', { stdio: 'ignore' }) | ||
return 'yarn' | ||
} catch { | ||
execSync('pnpm --version', { stdio: 'ignore' }) | ||
return 'pnpm' | ||
} | ||
} catch { | ||
return 'npm' | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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