From 0aabe9da571584c533dbcadd20c07e5b6b852756 Mon Sep 17 00:00:00 2001 From: Takashi Sato Date: Fri, 31 Mar 2023 11:13:42 +0900 Subject: [PATCH 1/3] 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 } From c51cc03cc33efffbcf10e6f70214c7cec211f89d Mon Sep 17 00:00:00 2001 From: Takashi Sato Date: Fri, 31 Mar 2023 11:13:42 +0900 Subject: [PATCH 2/3] test: add a test about nodejs_bundled --- .github/workflows/test.yaml | 59 +++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 95489f7..a1b3c2d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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 }} @@ -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: + # 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: name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})' From 036b6bb81c3d5543c78c2733842674de0940a296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=E1=BA=A3i?= Date: Wed, 26 Jul 2023 13:35:48 +0700 Subject: [PATCH 3/3] style: remove an empty line --- src/install-pnpm/run.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/install-pnpm/run.ts b/src/install-pnpm/run.ts index 42bfd0c..2fd8dfe 100644 --- a/src/install-pnpm/run.ts +++ b/src/install-pnpm/run.ts @@ -34,7 +34,6 @@ export async function runSelfInstaller(inputs: Inputs): Promise { } async function readTarget(nodeJsBundled: boolean, version?: string | undefined) { - if (version) return `${ nodeJsBundled ? '@pnpm/exe' : 'pnpm' }@${version}` const { GITHUB_WORKSPACE } = process.env