mirror of
https://github.com/pnpm/action-setup.git
synced 2026-07-14 18:03:44 +08:00
Compare commits
1 Commits
remove-v2-
...
1ecf7e8d5f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ecf7e8d5f |
47
README.md
47
README.md
@@ -60,9 +60,7 @@ Location of `pnpm` and `pnpx` command.
|
||||
|
||||
## Usage example
|
||||
|
||||
### Install only pnpm without `packageManager`
|
||||
|
||||
This works when the repo either doesn't have a `package.json` or has a `package.json` but it doesn't specify `packageManager`.
|
||||
### Just install pnpm
|
||||
|
||||
```yaml
|
||||
on:
|
||||
@@ -74,28 +72,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: pnpm/action-setup@v3
|
||||
with:
|
||||
version: 8
|
||||
```
|
||||
|
||||
### Install only pnpm with `packageManager`
|
||||
|
||||
Omit `version` input to use the version in the [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
|
||||
|
||||
```yaml
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v4
|
||||
```
|
||||
|
||||
### Install pnpm and a few npm packages
|
||||
|
||||
```yaml
|
||||
@@ -110,7 +91,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
- uses: pnpm/action-setup@v3
|
||||
with:
|
||||
version: 8
|
||||
run_install: |
|
||||
@@ -134,17 +115,29 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- uses: pnpm/action-setup@v3
|
||||
name: Install pnpm
|
||||
with:
|
||||
version: 8
|
||||
run_install: false
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v4
|
||||
- name: Get pnpm store directory
|
||||
shell: bash
|
||||
run: |
|
||||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||||
|
||||
- uses: actions/cache@v4
|
||||
name: Setup pnpm cache
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'pnpm'
|
||||
path: ${{ env.STORE_PATH }}
|
||||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
@@ -23,11 +23,6 @@ inputs:
|
||||
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed, enabling using pnpm without Node.js.
|
||||
required: false
|
||||
default: 'false'
|
||||
outputs:
|
||||
dest:
|
||||
description: Expanded path of inputs#dest
|
||||
bin_dest:
|
||||
description: Location of `pnpm` and `pnpx` command
|
||||
runs:
|
||||
using: node20
|
||||
main: dist/index.js
|
||||
|
||||
8
dist/index.js
vendored
8
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,10 +1,8 @@
|
||||
import { addPath, exportVariable } from '@actions/core'
|
||||
import { spawn } from 'child_process'
|
||||
import { rm, writeFile, mkdir } from 'fs/promises'
|
||||
import { readFileSync } from 'fs'
|
||||
import { rm, writeFile, readFile, mkdir } from 'fs/promises'
|
||||
import path from 'path'
|
||||
import { execPath } from 'process'
|
||||
import util from 'util'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
@@ -45,22 +43,14 @@ async function readTarget(opts: {
|
||||
const { version, packageJsonFile, standalone } = opts
|
||||
const { GITHUB_WORKSPACE } = process.env
|
||||
|
||||
let packageManager
|
||||
let packageManager;
|
||||
|
||||
if (GITHUB_WORKSPACE) {
|
||||
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
|
||||
}
|
||||
({ packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8')))
|
||||
}
|
||||
|
||||
if (version) {
|
||||
if (
|
||||
typeof packageManager === 'string' &&
|
||||
packageManager.replace('pnpm@', '') !== version
|
||||
) {
|
||||
if (typeof packageManager === 'string') {
|
||||
throw new Error(`Multiple versions of pnpm specified:
|
||||
- version ${version} in the GitHub Action config with the key "version"
|
||||
- version ${packageManager} in the package.json with the key "packageManager"
|
||||
@@ -72,7 +62,7 @@ Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_
|
||||
|
||||
if (!GITHUB_WORKSPACE) {
|
||||
throw new Error(`No workspace is found.
|
||||
If you've intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
|
||||
If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
|
||||
please run the actions/checkout before pnpm/action-setup.
|
||||
Otherwise, please specify the pnpm version in the action configuration.`)
|
||||
}
|
||||
@@ -88,7 +78,7 @@ Please specify it by one of the following ways:
|
||||
throw new Error('Invalid packageManager field in package.json')
|
||||
}
|
||||
|
||||
if (standalone) {
|
||||
if (standalone){
|
||||
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user