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

Compare commits

..

2 Commits

Author SHA1 Message Date
Zoltan Kochan
fe02b34f77 docs: bump action-setup version in README 2024-05-07 15:16:48 +02:00
Karl Horky
bee1f099e5 feat: throw error when multiple versions specified (#122)
* Throw error when multiple versions specified

* fix: fmt

* fix: fmt

* Swallow error on ENOENT

* Match versions

* refactor: install pnpm

---------

Co-authored-by: Khải <hvksmr1996@gmail.com>
Co-authored-by: Zoltan Kochan <z@kochan.io>
2024-05-06 23:24:46 +02:00
3 changed files with 22 additions and 12 deletions

View File

@@ -72,7 +72,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: pnpm/action-setup@v3 - uses: pnpm/action-setup@v4
with: with:
version: 8 version: 8
``` ```
@@ -91,7 +91,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: pnpm/action-setup@v3 - uses: pnpm/action-setup@v4
with: with:
version: 8 version: 8
run_install: | run_install: |
@@ -120,7 +120,7 @@ jobs:
with: with:
node-version: 20 node-version: 20
- uses: pnpm/action-setup@v3 - uses: pnpm/action-setup@v4
name: Install pnpm name: Install pnpm
with: with:
version: 8 version: 8

8
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +1,10 @@
import { addPath, exportVariable } from '@actions/core' import { addPath, exportVariable } from '@actions/core'
import { spawn } from 'child_process' import { spawn } from 'child_process'
import { rm, writeFile, readFile, mkdir } from 'fs/promises' import { rm, writeFile, mkdir } from 'fs/promises'
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 { Inputs } from '../inputs' import { Inputs } from '../inputs'
export async function runSelfInstaller(inputs: Inputs): Promise<number> { export async function runSelfInstaller(inputs: Inputs): Promise<number> {
@@ -43,14 +45,22 @@ async function readTarget(opts: {
const { version, packageJsonFile, standalone } = opts const { version, packageJsonFile, standalone } = opts
const { GITHUB_WORKSPACE } = process.env const { GITHUB_WORKSPACE } = process.env
let packageManager; let packageManager
if (GITHUB_WORKSPACE) { if (GITHUB_WORKSPACE) {
({ packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8'))) try {
({ packageManager } = JSON.parse(readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8')))
} catch (error: unknown) {
// Swallow error if package.json doesn't exist in root
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
}
} }
if (version) { if (version) {
if (typeof packageManager === 'string') { if (
typeof packageManager === 'string' &&
packageManager.replace('pnpm@', '') !== version
) {
throw new Error(`Multiple versions of pnpm specified: throw new Error(`Multiple versions of pnpm specified:
- version ${version} in the GitHub Action config with the key "version" - version ${version} 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"
@@ -78,7 +88,7 @@ Please specify it by one of the following ways:
throw new Error('Invalid packageManager field in package.json') throw new Error('Invalid packageManager field in package.json')
} }
if (standalone){ if (standalone) {
return packageManager.replace('pnpm@', '@pnpm/exe@') return packageManager.replace('pnpm@', '@pnpm/exe@')
} }