mirror of
https://github.com/pnpm/action-setup.git
synced 2025-03-15 15:05:12 +08:00
Throw error when multiple versions specified
This commit is contained in:
parent
ce859e384f
commit
1ecf7e8d5f
@ -41,10 +41,25 @@ async function readTarget(opts: {
|
||||
readonly standalone: boolean
|
||||
}) {
|
||||
const { version, packageJsonFile, standalone } = opts
|
||||
|
||||
if (version) return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||
|
||||
const { GITHUB_WORKSPACE } = process.env
|
||||
|
||||
let packageManager;
|
||||
|
||||
if (GITHUB_WORKSPACE) {
|
||||
({ packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8')))
|
||||
}
|
||||
|
||||
if (version) {
|
||||
if (typeof packageManager === 'string') {
|
||||
throw new Error(`Multiple versions of pnpm specified:
|
||||
- version ${version} in the GitHub Action config with the key "version"
|
||||
- version ${packageManager} in the package.json with the key "packageManager"
|
||||
Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_PM_VERSION`)
|
||||
}
|
||||
|
||||
return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||
}
|
||||
|
||||
if (!GITHUB_WORKSPACE) {
|
||||
throw new Error(`No workspace is found.
|
||||
If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
|
||||
@ -52,7 +67,6 @@ please run the actions/checkout before pnpm/action-setup.
|
||||
Otherwise, please specify the pnpm version in the action configuration.`)
|
||||
}
|
||||
|
||||
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8'))
|
||||
if (typeof packageManager !== 'string') {
|
||||
throw new Error(`No pnpm version is specified.
|
||||
Please specify it by one of the following ways:
|
||||
@ -64,7 +78,7 @@ Please specify it by one of the following ways:
|
||||
throw new Error('Invalid packageManager field in package.json')
|
||||
}
|
||||
|
||||
if(standalone){
|
||||
if (standalone){
|
||||
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user