1
0
mirror of https://github.com/pnpm/action-setup.git synced 2026-03-04 08:01:02 +08:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Don Denton
05cbfb6f02 fixup! feat: add version_file_path option
Added more logging
2025-01-20 23:59:50 -05:00
Don Denton
c9ad2a3942 fixup! feat: add version_file_path option 2025-01-20 21:40:04 -05:00

View File

@ -84,14 +84,22 @@ function getPnpmVersionFromFile(versionFilePath: string) {
//
// And because we've reached here, we know the contents
// *are* JSON, so no further string parsing makes sense.
return
throw new Error(`${versionFilePath} was supplied for 'version_file_path', but does not contain a pnpm version in a recognized property.`)
}
} catch {
console.info('pnpm version file is not JSON file')
console.info('pnpm version file is not JSON file, trying to parse as text')
}
const found = contents.match(/^(?:pnpm\s+)?v?(?<version>[^\s]+)$/m)
return found?.groups?.version ?? contents.trim()
// If not JSON, try and grab a version from a few possible text formats.
const matched = contents.match(/^(?:pnpm\s+)?v?(?<version>[^\s]+)$/m)
const found = matched?.groups?.version ?? contents.trim()
// Check that the first character is at least a digit.
if (!/^d/.test(found[0])) {
throw new Error(`${versionFilePath} was supplied for 'version_file_path', but does not contain a pnpm version in a recognized format.`)
}
return found
}
async function readTarget(opts: {
@ -100,8 +108,7 @@ async function readTarget(opts: {
readonly packageJsonFile: string
readonly standalone: boolean
}) {
const { versionFilePath, packageJsonFile, standalone } = opts
let { version } = opts
let { versionFilePath, packageJsonFile, standalone, version } = opts
const { GITHUB_WORKSPACE } = process.env
let packageManager
@ -121,6 +128,7 @@ async function readTarget(opts: {
if (versionFilePath) {
version = getPnpmVersionFromFile(versionFilePath)
console.info(`Using pnpm version ${version} from ${versionFilePath}`)
}
if (version) {
@ -129,7 +137,9 @@ async function readTarget(opts: {
packageManager.replace('pnpm@', '') !== version
) {
throw new Error(`Multiple versions of pnpm specified:
- version ${version} in the GitHub Action config with the key "version"
- version ${version} ${versionFilePath
? `found in ${versionFilePath}, supplied as "version_file_path"`
: `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`)
}