1
0
mirror of https://github.com/pnpm/action-setup.git synced 2026-06-14 15:43:46 +08:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Ben McCann
b9cbf5dd9e Merge d5bd7e8c9a into 9b5745cdf0 2026-02-19 01:50:03 -08:00
Ben McCann
d5bd7e8c9a Update src/install-pnpm/run.ts 2024-06-12 08:37:26 -07:00
Ben McCann
44def7846a feat: detect pnpm version from lockfile 2024-05-28 12:08:13 -07:00
4 changed files with 32 additions and 35 deletions

View File

@@ -1,28 +0,0 @@
name: pr-check
on: [ pull_request ]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Setup pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
run_install: true
version: 9
- name: Update dist/index.js
run: pnpm run build
- name: Check for uncommitted changes in dist
run: git diff --exit-code dist/index.js

8
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -5,6 +5,7 @@ import { readFileSync } from 'fs'
import path from 'path'
import { execPath } from 'process'
import util from 'util'
import * as yaml from 'yaml'
import { Inputs } from '../inputs'
import { parse as parseYaml } from 'yaml'
@@ -44,7 +45,6 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
if (exitCode === 0) {
const pnpmHome = path.join(dest, 'node_modules/.bin')
addPath(pnpmHome)
addPath(path.join(pnpmHome, 'bin'))
exportVariable('PNPM_HOME', pnpmHome)
}
return exitCode
@@ -96,10 +96,18 @@ Otherwise, please specify the pnpm version in the action configuration.`)
}
if (typeof packageManager !== 'string') {
throw new Error(`No pnpm version is specified.
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.
Please specify it by one of the following ways:
- in the GitHub Action config with the key "version"
- in the package.json with the key "packageManager"`)
}
}
}
if (!packageManager.startsWith('pnpm@')) {
@@ -113,4 +121,21 @@ Please specify it by one of the following ways:
return packageManager
}
function getPnpmVersionFromLockfile(
lockfileVersion: string | undefined
): string | undefined {
switch (true) {
case lockfileVersion === '5.3':
return 'latest-6';
case lockfileVersion === '5.4':
return 'latest-7';
case lockfileVersion === '6.0' || lockfileVersion === '6.1':
return 'latest-8';
case lockfileVersion === '7.0' || lockfileVersion === '9.0':
return 'latest-9';
default:
return undefined;
}
}
export default runSelfInstaller

View File

@@ -6,5 +6,5 @@ export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'no
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
...process.env,
PATH: path.join(getBinDest(inputs), 'bin') + path.delimiter + getBinDest(inputs) + path.delimiter + process.env.PATH,
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH,
})