mirror of
https://github.com/pnpm/action-setup.git
synced 2026-06-17 15:53:45 +08:00
Compare commits
7 Commits
v4.1.0
...
a376caa22a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a376caa22a | ||
|
|
41ff726559 | ||
|
|
f2b2b233b5 | ||
|
|
77504a59bc | ||
|
|
d648c2dd06 | ||
|
|
d5bd7e8c9a | ||
|
|
44def7846a |
@@ -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
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,15 +1,17 @@
|
||||
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'
|
||||
import util from 'util'
|
||||
import * as yaml from 'yaml'
|
||||
import { Inputs } from '../inputs'
|
||||
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 +21,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 +76,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:
|
||||
@@ -83,10 +96,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@')) {
|
||||
@@ -100,4 +121,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
|
||||
|
||||
Reference in New Issue
Block a user