diff --git a/README.md b/README.md index e24f1ee..0566eea 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/action.yml b/action.yml index c99a823..360a6ca 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/dist/index.js b/dist/index.js index 97128e3..d9f8a8a 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/run.sh b/run.sh index 8af79df..c85c7c3 100755 --- a/run.sh +++ b/run.sh @@ -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 diff --git a/src/inputs/index.ts b/src/inputs/index.ts index db07108..c19c36b 100644 --- a/src/inputs/index.ts +++ b/src/inputs/index.ts @@ -1,4 +1,4 @@ -import { getInput, InputOptions } from '@actions/core' +import { getBooleanInput, getInput, InputOptions } from '@actions/core' import expandTilde from 'expand-tilde' import { RunInstall, parseRunInstall } from './run-install' @@ -6,6 +6,7 @@ export interface Inputs { readonly version?: string readonly dest: string readonly runInstall: RunInstall[] + readonly nodeJsBundled: boolean } const options: InputOptions = { @@ -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 diff --git a/src/install-pnpm/run.ts b/src/install-pnpm/run.ts index 9feafba..42bfd0c 100644 --- a/src/install-pnpm/run.ts +++ b/src/install-pnpm/run.ts @@ -6,7 +6,7 @@ import { execPath } from 'process' import { Inputs } from '../inputs' export async function runSelfInstaller(inputs: Inputs): Promise { - const { version, dest } = inputs + const { version, dest, nodeJsBundled } = inputs // prepare self install await remove(dest) @@ -15,7 +15,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise { 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'], @@ -33,8 +33,9 @@ export async function runSelfInstaller(inputs: Inputs): Promise { 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) { @@ -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 }