1
0
mirror of https://github.com/pnpm/action-setup.git synced 2026-03-10 08:31:44 +08:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Ben McCann
2eb3a2bf7e
Merge d5bd7e8c9a into f2b2b233b5 2025-07-15 13:07:39 +01:00
Matthias
f2b2b233b5
Remove --frozen-lockfile from examples (#171) 2025-07-11 00:08:35 +02: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
2 changed files with 29 additions and 3 deletions

View File

@ -40,7 +40,7 @@ If `run_install` is a YAML string representation of either an object or an array
#### `run_install.args`
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--ignore-scripts, --strict-peer-dependencies]`.
### `package_json_file`
@ -119,7 +119,7 @@ jobs:
version: 10
run_install:
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
args: [--strict-peer-dependencies]
- args: [--global, gulp, prettier, typescript]
```

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 YAML from 'yaml'
@ -84,10 +85,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@')) {
@ -101,4 +110,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