4 Commits

Author SHA1 Message Date
Adrian Riedel
41ff726559 feat: support installation from custom NPM registry (#179)
copy .npmrc from GitHub workspace if it exists so that PNPM respects custom
registry configurations when self-installing
2025-10-08 10:48:14 +02:00
Matthias
f2b2b233b5 Remove --frozen-lockfile from examples (#171) 2025-07-11 00:08:35 +02:00
Matthias
77504a59bc Fix multiline run_install example in README.md (#167) 2025-06-25 18:10:02 +02:00
Kevin Cui
d648c2dd06 fix: not allow install multiple package manager (#161)
When a project has both npm and pnpm, using pnpm/action-setup will result in an error: `Multiple versions of pnpm specified`.

The previous implementation was only meant to avoid the "ERR_PNPM_BAD_PM_VERSION" error, but it did not take into account the situation of multiple different package managers.

Signed-off-by: Kevin Cui <bh@bugs.cc>
2025-03-28 08:37:14 +08:00
3 changed files with 17 additions and 5 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`
@@ -117,9 +117,9 @@ jobs:
- uses: pnpm/action-setup@v4
with:
version: 10
run_install: |
run_install:
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
args: [--strict-peer-dependencies]
- args: [--global, gulp, prettier, typescript]
```

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
import { addPath, exportVariable } from '@actions/core'
import { spawn } from 'child_process'
import { rm, writeFile, mkdir } from 'fs/promises'
import { rm, writeFile, mkdir, copyFile } from 'fs/promises'
import { readFileSync } from 'fs'
import path from 'path'
import { execPath } from 'process'
@@ -10,6 +10,7 @@ import YAML from 'yaml'
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest, packageJsonFile, standalone } = inputs
const { GITHUB_WORKSPACE } = process.env
// prepare self install
await rm(dest, { recursive: true, force: true })
@@ -19,6 +20,16 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
// we have ensured the dest directory exists, we can write the file directly
await writeFile(pkgJson, JSON.stringify({ private: true }))
// copy .npmrc if it exists to install from custom registry
if (GITHUB_WORKSPACE) {
try {
await copyFile(path.join(GITHUB_WORKSPACE, '.npmrc'), path.join(dest, '.npmrc'))
} catch (error) {
// Swallow error if .npmrc doesn't exist
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
}
}
// prepare target pnpm
const target = await readTarget({ version, packageJsonFile, standalone })
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
@@ -64,6 +75,7 @@ async function readTarget(opts: {
if (version) {
if (
typeof packageManager === 'string' &&
packageManager.startsWith('pnpm@') &&
packageManager.replace('pnpm@', '') !== version
) {
throw new Error(`Multiple versions of pnpm specified: