From 2e0e69c954ac3725e19ef8455338f10b9d0611ed Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Wed, 3 Jun 2020 07:13:36 +0200
Subject: [PATCH] feat(pnpm): dynamic version selection

Closes #6361
---
 lib/manager/npm/post-update/pnpm.spec.ts | 2 +-
 lib/manager/npm/post-update/pnpm.ts      | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/manager/npm/post-update/pnpm.spec.ts b/lib/manager/npm/post-update/pnpm.spec.ts
index 0c2991a401..ce28dd90ef 100644
--- a/lib/manager/npm/post-update/pnpm.spec.ts
+++ b/lib/manager/npm/post-update/pnpm.spec.ts
@@ -20,7 +20,7 @@ delete process.env.NPM_CONFIG_CACHE;
 describe('generateLockFile', () => {
   let config: PostUpdateConfig;
   beforeEach(() => {
-    config = { cacheDir: 'some-cache-dir' };
+    config = { cacheDir: 'some-cache-dir', compatibility: { pnpm: '^2.0.0' } };
     env.getChildProcessEnv.mockReturnValue(envMock.basic);
   });
   it('generates lock files', async () => {
diff --git a/lib/manager/npm/post-update/pnpm.ts b/lib/manager/npm/post-update/pnpm.ts
index bec674a9b4..c3ea779307 100644
--- a/lib/manager/npm/post-update/pnpm.ts
+++ b/lib/manager/npm/post-update/pnpm.ts
@@ -1,4 +1,6 @@
 import { readFile } from 'fs-extra';
+import { validRange } from 'semver';
+import { quote } from 'shlex';
 import { join } from 'upath';
 import { logger } from '../../../logger';
 import { ExecOptions, exec } from '../../../util/exec';
@@ -23,7 +25,12 @@ export async function generateLockFile(
   let stderr: string;
   let cmd = 'pnpm';
   try {
-    const preCommands = ['npm i -g pnpm'];
+    let installPnpm = 'npm i -g pnpm';
+    const pnpmCompatibility = config.compatibility?.pnpm;
+    if (validRange(pnpmCompatibility)) {
+      installPnpm += `@${quote(pnpmCompatibility)}`;
+    }
+    const preCommands = [installPnpm];
     const tagConstraint = await getNodeConstraint(config);
     const execOptions: ExecOptions = {
       cwd,
-- 
GitLab