Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
- name: 'Test: install'
run: pnpm install

test_explicit_inputs:
name: Test with explicit inputs
test_dest:
name: Test with dest

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -65,6 +65,61 @@ jobs:
- name: 'Test: install'
run: pnpm install

test_nodejs_bundled:
name: Test with nodejs_bundled

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest

nodejs_bundled:
- true
- false

steps:
- uses: actions/checkout@v3

- name: Run the action
uses: ./
with:
version: 7.0.0
nodejs_bundled: ${{ matrix.nodejs_bundled }}

- name: install Node.js
uses: actions/setup-node@v3
with:
# [email protected] is not compatible with Node.js 12
node-version: 12.22.12

- name: 'Test: which (pnpm)'
run: which pnpm

- name: 'Test: which (pnpx)'
if: matrix.nodejs_bundled == false
run: which pnpx

- name: 'Test: install when nodejs_bundled is true'
if: matrix.nodejs_bundled
run: pnpm install

- name: 'Test: install when nodejs_bundled is false'
if: matrix.nodejs_bundled == false
# Since the default shell on windows runner is pwsh, we specify bash explicitly
shell: bash
run: |
if pnpm install; then
echo "pnpm install should fail"
exit 1
else
echo "pnpm install failed as expected"
fi

test_run_install:
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ If `run_install` is a YAML string representation of either an object or an array

**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.

### `nodejs_bundled`

**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.

This is useful when you want to use a incompatible pair of Node.js and pnpm.

## Outputs

### `dest`
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
description: If specified, run `pnpm install`
required: false
default: 'null'
nodejs_bundled:
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed.
required: false
default: 'false'
runs:
using: node16
main: dist/index.js
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export HOME="$(pwd)"
export INPUT_VERSION=4.11.1
export INPUT_DEST='~/pnpm.temp'
export INPUT_RUN_INSTALL=null
export INPUT_NODEJS_BUNDLED=false
exec node dist/index.js
4 changes: 3 additions & 1 deletion src/inputs/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { getInput, InputOptions } from '@actions/core'
import { getBooleanInput, getInput, InputOptions } from '@actions/core'
import expandTilde from 'expand-tilde'
import { RunInstall, parseRunInstall } from './run-install'

export interface Inputs {
readonly version?: string
readonly dest: string
readonly runInstall: RunInstall[]
readonly nodeJsBundled: boolean
}

const options: InputOptions = {
Expand All @@ -18,6 +19,7 @@ export const getInputs = (): Inputs => ({
version: getInput('version'),
dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'),
nodeJsBundled: getBooleanInput('nodejs_bundled'),
})

export default getInputs
14 changes: 10 additions & 4 deletions src/install-pnpm/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { execPath } from 'process'
import { Inputs } from '../inputs'

export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest } = inputs
const { version, dest, nodeJsBundled } = inputs

// prepare self install
await remove(dest)
Expand All @@ -15,7 +15,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
await writeFile(pkgJson, JSON.stringify({ private: true }))

// prepare target pnpm
const target = await readTarget(version)
const target = await readTarget(nodeJsBundled, version)
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
Expand All @@ -33,8 +33,9 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
return exitCode
}

async function readTarget(version?: string | undefined) {
if (version) return `pnpm@${version}`
async function readTarget(nodeJsBundled: boolean, version?: string | undefined) {

if (version) return `${ nodeJsBundled ? '@pnpm/exe' : 'pnpm' }@${version}`

const { GITHUB_WORKSPACE } = process.env
if (!GITHUB_WORKSPACE) {
Expand All @@ -55,6 +56,11 @@ Please specify it by one of the following ways:
if (!packageManager.startsWith('pnpm@')) {
throw new Error('Invalid packageManager field in package.json')
}

if(nodeJsBundled){
return packageManager.replace('pnpm@', '@pnpm/exe@')
}

return packageManager
}

Expand Down