From 0aabe9da571584c533dbcadd20c07e5b6b852756 Mon Sep 17 00:00:00 2001 From: Takashi Sato Date: Fri, 31 Mar 2023 11:13:42 +0900 Subject: [PATCH] feat: add an option to install the self-contained binary version of pnpm --- README.md | 6 ++++++ action.yml | 4 ++++ dist/index.js | Bin 272325 -> 272463 bytes run.sh | 1 + src/inputs/index.ts | 4 +++- src/install-pnpm/run.ts | 14 ++++++++++---- 6 files changed, 24 insertions(+), 5 deletions(-) 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 97128e389fd4492d62557e4b9d1d66cbf9c6c9d9..d9f8a8add223cab4194809d3d24c1d2fd7e3b520 100644 GIT binary patch delta 452 zcmZ9I%}N6?5P;cQRNC4qihmbtD45_$T5;Kv2Ol60 z;43IS_yT&AdhAR14rZ;Qco>)&zWHXD*WP&Vef)7gz3MXFgafr5vSt9y4P0^k@+IhP z&I6!qpNUWtj1uTdom~v5?rgd`T=_Ri;~G?Hhx*z&R9QlsUjxCKR6Wj=E`~;B*5^X< zhv`UP!;T+VEHp2fr3J6{B`8Xu%_A!99hkcE$IvpP*34& z2Klk1d0RMMvlNhMu%Srpn?yi8z+dhggnued}Zd2#@^J7ekO8Qd<6X_N1A%cv*o z<>zTAr4|+C7b)q0)PecQIr+t@N;;{UwVImNnQ0nnlNERhfI24fIEZOh0|inwi&9HU zi}Df*@(OYtRH{=a|KX7mDXO(CD9TSxEiTqe%_{?GR4m%8#p}VySTebo&w#OL@)AB3 s#**oGdzfV>KjZrV6u! ({ 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 }