Files
setup-pnpm/README.md
T

245 lines
7.4 KiB
Markdown
Raw Normal View History

> [!IMPORTANT]
> **This action has a successor: [`pnpm/setup`](https://github.com/pnpm/setup).**
2024-07-05 14:37:28 +02:00
>
> For pnpm v11 and newer, use [`pnpm/setup`](https://github.com/pnpm/setup) instead. It downloads pnpm's self-contained release binary (no Node.js or npm required) and can install a JavaScript runtime (Node.js, Bun, or Deno) in the same step, replacing `actions/setup-node`.
>
> `pnpm/action-setup` remains the action to use for installing pnpm v10 and older. See [Migrating to pnpm/setup](#migrating-to-pnpmsetup) below.
2024-07-05 14:37:28 +02:00
2021-03-27 13:45:01 +02:00
# Setup pnpm
2020-05-08 14:44:30 +07:00
2021-03-27 13:45:01 +02:00
Install pnpm package manager.
2020-05-08 14:44:30 +07:00
> ## :warning: Upgrade from v2!
>
> The v2 version of this action [has stopped working](https://github.com/pnpm/action-setup/issues/135) with newer Node.js versions. Please, upgrade to the latest version to fix any issues.
## Migrating to pnpm/setup
[`pnpm/setup`](https://github.com/pnpm/setup) installs pnpm v11+ as a native standalone executable and can install Node.js, Bun, or Deno in the same step, so a typical workflow no longer needs `actions/setup-node` or an explicit `pnpm install` step:
```yaml
steps:
- uses: actions/checkout@v6
# Before:
# - uses: pnpm/action-setup@v6
# with:
# version: 10
# cache: true
# - uses: actions/setup-node@v4
# with:
# node-version: 22
# - run: pnpm install
# After:
- uses: pnpm/setup@v1
with:
version: 11
runtime: node@22
cache: true
```
The `version` input can be omitted only when `packageManager` (or `devEngines.packageManager`) in `package.json` declares pnpm v11 or newer; otherwise keep it explicit, since `pnpm/setup` requires pnpm v11+.
Input and output changes:
| `pnpm/action-setup` | `pnpm/setup` | Notes |
| ------------------- | ------------ | ----- |
| `version` | `version` | Must resolve to pnpm v11 or newer. As before, it can be omitted when `packageManager` (or `devEngines.packageManager`) is set in `package.json`. |
| `dest` | `dest` | Unchanged. |
| `run_install` | `install` | `pnpm/setup` runs `pnpm install` automatically when a `package.json` is present (`install: true` by default); set `install: false` to skip it. The object/array form (`recursive`, `cwd`, `args`) is not supported — run those commands in separate steps. |
| `cache` | `cache` | Unchanged. |
| `cache_dependency_path` | `cache-dependency-path` | Renamed to kebab-case. |
| `package_json_file` | `package-json-file` | Renamed to kebab-case. |
| `standalone` | removed | `pnpm/setup` always installs the standalone native executable. |
| n/a | `runtime` | New: installs Node.js, Bun, or Deno (e.g. `node@22`, `bun@latest`, `deno@2`), or reads `devEngines.runtime` from `package.json`. |
| n/a | `token` | New: GitHub token for release lookup; defaults to `${{ github.token }}` and rarely needs to be set. |
| `bin_dest` (output) | `bin-dest` (output) | Renamed to kebab-case. New outputs `runtime-name` and `runtime-version` describe the installed runtime. |
2020-05-08 14:44:30 +07:00
## Inputs
### `version`
2022-02-22 12:26:05 +08:00
Version of pnpm to install.
**Optional** when there is a [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
2026-04-10 22:48:51 +02:00
otherwise, this field is **required** It supports npm versioning scheme, it could be an exact version (such as `10.9.8`), or a version range (such as `10`, `10.x.x`, `10.9.x`, `^10.9.8`, `*`, etc.), or `latest`.
2020-05-08 14:44:30 +07:00
### `dest`
2021-03-27 13:45:01 +02:00
**Optional** Where to store pnpm files.
2020-05-08 14:44:30 +07:00
2020-05-09 19:13:46 +07:00
### `run_install`
2020-05-10 12:00:23 +07:00
**Optional** (_default:_ `null`) If specified, run `pnpm install`.
2020-05-09 19:13:46 +07:00
2020-05-10 12:08:45 +07:00
If `run_install` is either `null` or `false`, pnpm will not install any npm package.
If `run_install` is `true`, pnpm will install dependencies recursively.
2020-05-10 12:14:27 +07:00
If `run_install` is a YAML string representation of either an object or an array, pnpm will execute every install commands.
2020-05-10 12:08:45 +07:00
#### `run_install.recursive`
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to use `pnpm recursive install`.
#### `run_install.cwd`
**Optional** (_type:_ `string`) Working directory when run `pnpm [recursive] install`.
#### `run_install.args`
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--ignore-scripts, --strict-peer-dependencies]`.
2020-05-10 12:08:45 +07:00
2025-12-07 22:16:49 +01:00
### `cache`
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to cache the pnpm store directory.
### `cache_dependency_path`
**Optional** (_type:_ `string`, _default:_ `pnpm-lock.yaml`) File path to the pnpm lockfile, whose contents hash will be used as a cache key. Accepts multiple paths delimited by newlines.
2025-12-07 22:16:49 +01:00
2023-07-08 07:02:46 +08:00
### `package_json_file`
2025-02-06 21:13:04 +00:00
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json`/[`package.yaml`](https://github.com/pnpm/pnpm/pull/1799) to read "packageManager" configuration.
2023-07-26 18:50:04 +07:00
### `standalone`
**Optional** (_type:_ `boolean`, _default:_ `false`) When set to true, [@pnpm/exe](https://www.npmjs.com/package/@pnpm/exe), which is a Node.js bundled package, will be installed, enabling using `pnpm` without Node.js.
This is useful when you want to use a incompatible pair of Node.js and pnpm.
2023-07-08 07:02:46 +08:00
2020-05-08 14:44:30 +07:00
## Outputs
### `dest`
Expanded path of inputs#dest.
### `bin_dest`
2021-03-23 12:53:37 +07:00
Location of `pnpm` and `pnpx` command.
2020-05-08 14:44:30 +07:00
## 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`.
2020-05-10 12:14:27 +07:00
```yaml
on:
- push
- pull_request
jobs:
2022-01-29 08:17:29 -08:00
install:
runs-on: ubuntu-latest
2020-05-10 12:14:27 +07:00
2022-01-29 08:17:29 -08:00
steps:
2026-04-10 23:08:33 +02:00
- uses: pnpm/action-setup@v6
2022-01-29 08:17:29 -08:00
with:
version: 10
2020-05-10 12:14:27 +07:00
```
### 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:
2026-04-10 23:08:33 +02:00
- uses: pnpm/action-setup@v6
```
2021-03-27 13:45:01 +02:00
### Install pnpm and a few npm packages
2020-05-10 12:14:27 +07:00
2020-05-08 14:44:30 +07:00
```yaml
on:
- push
- pull_request
jobs:
2022-01-29 08:17:29 -08:00
install:
runs-on: ubuntu-latest
2020-05-08 14:44:30 +07:00
2022-01-29 08:17:29 -08:00
steps:
2026-04-10 22:48:51 +02:00
- uses: actions/checkout@v6
2020-05-08 14:44:30 +07:00
2026-04-10 23:08:33 +02:00
- uses: pnpm/action-setup@v6
2022-01-29 08:17:29 -08:00
with:
version: 10
2025-12-05 16:32:46 +02:00
run_install: |
2022-01-29 08:17:29 -08:00
- recursive: true
args: [--strict-peer-dependencies]
2022-01-29 08:17:29 -08:00
- args: [--global, gulp, prettier, typescript]
2020-05-08 14:44:30 +07:00
```
2021-02-18 08:30:07 +07:00
### Use cache to reduce installation time
```yaml
on:
- push
- pull_request
jobs:
2022-01-29 08:17:29 -08:00
cache-and-install:
2022-05-07 09:59:56 +07:00
runs-on: ubuntu-latest
2022-01-29 08:17:29 -08:00
steps:
2022-05-06 21:25:47 -05:00
- name: Checkout
2026-04-10 22:48:51 +02:00
uses: actions/checkout@v6
2026-04-10 23:08:33 +02:00
- uses: pnpm/action-setup@v6
2022-05-06 21:25:47 -05:00
name: Install pnpm
with:
version: 10
2025-12-07 22:16:49 +01:00
cache: true
2022-05-06 21:25:47 -05:00
- name: Install dependencies
run: pnpm install
```
2021-02-18 08:30:07 +07:00
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
### Cache dependencies from multiple lockfiles
```yaml
on:
- push
- pull_request
jobs:
cache-and-install-multiple:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- uses: pnpm/action-setup@v6
with:
version: 10
cache: true
cache_dependency_path: |
one/pnpm-lock.yaml
two/pnpm-lock.yaml
run_install: |
- cwd: one
- cwd: two
```
2020-05-08 14:44:30 +07:00
## Notes
This action does not set up Node.js. Use [actions/setup-node](https://github.com/actions/setup-node) yourself. If you are on pnpm v11 or newer, [`pnpm/setup`](https://github.com/pnpm/setup) can install pnpm and Node.js in a single step.
2020-05-08 14:44:30 +07:00
## License
2024-03-27 22:17:57 +01:00
[MIT](https://github.com/pnpm/action-setup/blob/master/LICENSE.md) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)