1
0
mirror of https://github.com/pnpm/action-setup.git synced 2026-03-07 08:21:45 +08:00

Compare commits

..

No commits in common. "05cbfb6f027635eb69bf509688c73329aef55ba3" and "6217a9d8c4ed43da32ba581d4741b992cca189c3" have entirely different histories.

View File

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