mirror of
https://github.com/pnpm/action-setup.git
synced 2024-11-12 12:38:05 +00:00
feat: nodejs_bundled
This commit is contained in:
commit
9695a8b930
59
.github/workflows/test.yaml
vendored
59
.github/workflows/test.yaml
vendored
@ -35,8 +35,8 @@ jobs:
|
|||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
test_explicit_inputs:
|
test_dest:
|
||||||
name: Test with explicit inputs
|
name: Test with dest
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
@ -65,6 +65,61 @@ jobs:
|
|||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm 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:
|
||||||
|
# pnpm@7.0.0 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:
|
test_run_install:
|
||||||
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
||||||
|
|
||||||
|
@ -40,7 +40,13 @@ If `run_install` is a YAML string representation of either an object or an array
|
|||||||
|
|
||||||
### `package_json_file`
|
### `package_json_file`
|
||||||
|
|
||||||
**Optional** File path to the `package.json` to read "packageManager" configutation. If not specified, `package.json` in the project root directory is used.
|
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json` to read "packageManager" configuration.
|
||||||
|
|
||||||
|
### `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
|
## Outputs
|
||||||
|
|
||||||
|
@ -16,9 +16,13 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: 'null'
|
default: 'null'
|
||||||
package_json_file:
|
package_json_file:
|
||||||
description: File path to the package.json to read "packageManager" configutation
|
description: File path to the package.json to read "packageManager" configuration
|
||||||
required: false
|
required: false
|
||||||
default: 'package.json'
|
default: 'package.json'
|
||||||
|
nodejs_bundled:
|
||||||
|
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed.
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
runs:
|
runs:
|
||||||
using: node16
|
using: node16
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
|
BIN
dist/index.js
vendored
BIN
dist/index.js
vendored
Binary file not shown.
1
run.sh
1
run.sh
@ -4,4 +4,5 @@ export HOME="$(pwd)"
|
|||||||
export INPUT_VERSION=4.11.1
|
export INPUT_VERSION=4.11.1
|
||||||
export INPUT_DEST='~/pnpm.temp'
|
export INPUT_DEST='~/pnpm.temp'
|
||||||
export INPUT_RUN_INSTALL=null
|
export INPUT_RUN_INSTALL=null
|
||||||
|
export INPUT_NODEJS_BUNDLED=false
|
||||||
exec node dist/index.js
|
exec node dist/index.js
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { getInput, InputOptions } from '@actions/core'
|
import { getBooleanInput, getInput, InputOptions } from '@actions/core'
|
||||||
import expandTilde from 'expand-tilde'
|
import expandTilde from 'expand-tilde'
|
||||||
import { RunInstall, parseRunInstall } from './run-install'
|
import { RunInstall, parseRunInstall } from './run-install'
|
||||||
|
|
||||||
@ -7,6 +7,7 @@ export interface Inputs {
|
|||||||
readonly dest: string
|
readonly dest: string
|
||||||
readonly runInstall: RunInstall[]
|
readonly runInstall: RunInstall[]
|
||||||
readonly packageJsonFile: string
|
readonly packageJsonFile: string
|
||||||
|
readonly nodeJsBundled: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: InputOptions = {
|
const options: InputOptions = {
|
||||||
@ -20,6 +21,7 @@ export const getInputs = (): Inputs => ({
|
|||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
runInstall: parseRunInstall('run_install'),
|
runInstall: parseRunInstall('run_install'),
|
||||||
packageJsonFile: parseInputPath('package_json_file'),
|
packageJsonFile: parseInputPath('package_json_file'),
|
||||||
|
nodeJsBundled: getBooleanInput('nodejs_bundled'),
|
||||||
})
|
})
|
||||||
|
|
||||||
export default getInputs
|
export default getInputs
|
||||||
|
@ -6,7 +6,7 @@ import { execPath } from 'process'
|
|||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
const { version, dest, packageJsonFile } = inputs
|
const { version, dest, packageJsonFile, nodeJsBundled } = inputs
|
||||||
|
|
||||||
// prepare self install
|
// prepare self install
|
||||||
await remove(dest)
|
await remove(dest)
|
||||||
@ -15,7 +15,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||||
|
|
||||||
// prepare target pnpm
|
// prepare target pnpm
|
||||||
const target = await readTarget(packageJsonFile, version)
|
const target = await readTarget({ version, packageJsonFile, nodeJsBundled })
|
||||||
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
|
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
|
||||||
cwd: dest,
|
cwd: dest,
|
||||||
stdio: ['pipe', 'inherit', 'inherit'],
|
stdio: ['pipe', 'inherit', 'inherit'],
|
||||||
@ -33,8 +33,14 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
return exitCode
|
return exitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readTarget(packageJsonFile: string, version?: string | undefined) {
|
async function readTarget(opts: {
|
||||||
if (version) return `pnpm@${version}`
|
readonly version?: string | undefined
|
||||||
|
readonly packageJsonFile: string
|
||||||
|
readonly nodeJsBundled: boolean
|
||||||
|
}) {
|
||||||
|
const { version, packageJsonFile, nodeJsBundled } = opts
|
||||||
|
|
||||||
|
if (version) return `${ nodeJsBundled ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||||
|
|
||||||
const { GITHUB_WORKSPACE } = process.env
|
const { GITHUB_WORKSPACE } = process.env
|
||||||
if (!GITHUB_WORKSPACE) {
|
if (!GITHUB_WORKSPACE) {
|
||||||
@ -55,6 +61,11 @@ Please specify it by one of the following ways:
|
|||||||
if (!packageManager.startsWith('pnpm@')) {
|
if (!packageManager.startsWith('pnpm@')) {
|
||||||
throw new Error('Invalid packageManager field in package.json')
|
throw new Error('Invalid packageManager field in package.json')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(nodeJsBundled){
|
||||||
|
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
||||||
|
}
|
||||||
|
|
||||||
return packageManager
|
return packageManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user