mirror of
https://github.com/pnpm/action-setup.git
synced 2024-12-23 08:26:29 +08:00
feat: detect pnpm version from lockfile
This commit is contained in:
parent
fe02b34f77
commit
44def7846a
|
@ -5,6 +5,7 @@ import { readFileSync } from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { execPath } from 'process'
|
import { execPath } from 'process'
|
||||||
import util from 'util'
|
import util from 'util'
|
||||||
|
import * as yaml from 'yaml'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
|
@ -78,11 +79,19 @@ Otherwise, please specify the pnpm version in the action configuration.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof packageManager !== 'string') {
|
if (typeof packageManager !== 'string') {
|
||||||
|
if (GITHUB_WORKSPACE) {
|
||||||
|
try {
|
||||||
|
const { lockfileVersion } = yaml.parse(readFileSync(path.join(GITHUB_WORKSPACE, 'pnpm-lock.yaml'), 'utf8'))
|
||||||
|
const version = getPnpmVersionFromLockfile(lockfileVersion);
|
||||||
|
return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||||
|
} catch (error: unknown) {
|
||||||
throw new Error(`No pnpm version is specified.
|
throw new Error(`No pnpm version is specified.
|
||||||
Please specify it by one of the following ways:
|
Please specify it by one of the following ways:
|
||||||
- in the GitHub Action config with the key "version"
|
- in the GitHub Action config with the key "version"
|
||||||
- in the package.json with the key "packageManager"`)
|
- in the package.json with the key "packageManager"`)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!packageManager.startsWith('pnpm@')) {
|
if (!packageManager.startsWith('pnpm@')) {
|
||||||
throw new Error('Invalid packageManager field in package.json')
|
throw new Error('Invalid packageManager field in package.json')
|
||||||
|
@ -95,4 +104,21 @@ Please specify it by one of the following ways:
|
||||||
return packageManager
|
return packageManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPnpmVersionFromLockfile(
|
||||||
|
lockfileVersion: string | undefined
|
||||||
|
): string | undefined {
|
||||||
|
switch (true) {
|
||||||
|
case lockfileVersion === '5.3':
|
||||||
|
return '6';
|
||||||
|
case lockfileVersion === '5.4':
|
||||||
|
return '7';
|
||||||
|
case lockfileVersion === '6.0' || lockfileVersion === '6.1':
|
||||||
|
return '8';
|
||||||
|
case lockfileVersion === '7.0' || lockfileVersion === '9.0':
|
||||||
|
return '9';
|
||||||
|
default:
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default runSelfInstaller
|
export default runSelfInstaller
|
||||||
|
|
Loading…
Reference in New Issue
Block a user