From 97a0a32978f47f85e02d3d41e79953ebc49db427 Mon Sep 17 00:00:00 2001
From: ylemkimon <y@ylem.kim>
Date: Sun, 5 Sep 2021 15:07:00 +0900
Subject: [PATCH] fix(npm): inherit `yarnZeroInstall` and `skipInstalls`
 (#11582)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 .../__snapshots__/monorepo.spec.ts.snap       | 58 +++++++++++++++++++
 lib/manager/npm/extract/monorepo.spec.ts      | 30 ++++++++++
 lib/manager/npm/extract/monorepo.ts           |  5 +-
 3 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/lib/manager/npm/extract/__snapshots__/monorepo.spec.ts.snap b/lib/manager/npm/extract/__snapshots__/monorepo.spec.ts.snap
index b9a7056544..0804bdebec 100644
--- a/lib/manager/npm/extract/__snapshots__/monorepo.spec.ts.snap
+++ b/lib/manager/npm/extract/__snapshots__/monorepo.spec.ts.snap
@@ -43,20 +43,24 @@ Array [
     "lernaClient": undefined,
     "managerData": Object {
       "lernaJsonFile": "lerna.json",
+      "yarnZeroInstall": undefined,
     },
     "npmLock": undefined,
     "packageFile": "packages/a/package.json",
     "packageJsonName": "@org/a",
+    "skipInstalls": undefined,
     "yarnLock": undefined,
   },
   Object {
     "lernaClient": undefined,
     "managerData": Object {
       "lernaJsonFile": "lerna.json",
+      "yarnZeroInstall": undefined,
     },
     "npmLock": undefined,
     "packageFile": "packages/b/package.json",
     "packageJsonName": "@org/b",
+    "skipInstalls": undefined,
     "yarnLock": undefined,
   },
 ]
@@ -108,20 +112,24 @@ Array [
     "lernaClient": undefined,
     "managerData": Object {
       "lernaJsonFile": "lerna.json",
+      "yarnZeroInstall": undefined,
     },
     "npmLock": undefined,
     "packageFile": "packages/a/package.json",
     "packageJsonName": "@org/a",
+    "skipInstalls": undefined,
     "yarnLock": undefined,
   },
   Object {
     "lernaClient": undefined,
     "managerData": Object {
       "lernaJsonFile": "lerna.json",
+      "yarnZeroInstall": undefined,
     },
     "npmLock": undefined,
     "packageFile": "packages/b/package.json",
     "packageJsonName": "@org/b",
+    "skipInstalls": undefined,
     "yarnLock": undefined,
   },
 ]
@@ -146,20 +154,24 @@ Array [
     "lernaClient": "yarn",
     "managerData": Object {
       "lernaJsonFile": "lerna.json",
+      "yarnZeroInstall": undefined,
     },
     "npmLock": undefined,
     "packageFile": "packages/a/package.json",
     "packageJsonName": "@org/a",
+    "skipInstalls": undefined,
     "yarnLock": undefined,
   },
   Object {
     "lernaClient": "yarn",
     "managerData": Object {
       "lernaJsonFile": "lerna.json",
+      "yarnZeroInstall": undefined,
     },
     "npmLock": undefined,
     "packageFile": "packages/b/package.json",
     "packageJsonName": "@org/b",
+    "skipInstalls": undefined,
     "yarnLock": undefined,
   },
 ]
@@ -178,22 +190,68 @@ Array [
     "lernaClient": undefined,
     "managerData": Object {
       "lernaJsonFile": undefined,
+      "yarnZeroInstall": undefined,
     },
     "npmLock": undefined,
     "npmrc": "@org:registry=//registry.some.org
 ",
     "packageFile": "packages/a/package.json",
     "packageJsonName": "@org/a",
+    "skipInstalls": undefined,
     "yarnLock": "yarn.lock",
   },
   Object {
     "lernaClient": undefined,
     "managerData": Object {
       "lernaJsonFile": undefined,
+      "yarnZeroInstall": undefined,
     },
     "npmLock": undefined,
     "packageFile": "packages/b/package.json",
     "packageJsonName": "@org/b",
+    "skipInstalls": undefined,
+    "yarnLock": undefined,
+  },
+]
+`;
+
+exports[`manager/npm/extract/monorepo .extractPackageFile() uses yarnZeroInstall and skipInstalls from yarn workspaces package settings 1`] = `
+Array [
+  Object {
+    "managerData": Object {
+      "yarnZeroInstall": true,
+    },
+    "npmrc": "@org:registry=//registry.some.org
+",
+    "packageFile": "package.json",
+    "skipInstalls": false,
+    "yarnWorkspacesPackages": "packages/*",
+  },
+  Object {
+    "hasYarnWorkspaces": true,
+    "lernaClient": undefined,
+    "managerData": Object {
+      "lernaJsonFile": undefined,
+      "yarnZeroInstall": true,
+    },
+    "npmLock": undefined,
+    "npmrc": "@org:registry=//registry.some.org
+",
+    "packageFile": "packages/a/package.json",
+    "packageJsonName": "@org/a",
+    "skipInstalls": false,
+    "yarnLock": "yarn.lock",
+  },
+  Object {
+    "lernaClient": undefined,
+    "managerData": Object {
+      "lernaJsonFile": undefined,
+      "yarnZeroInstall": true,
+    },
+    "npmLock": undefined,
+    "packageFile": "packages/b/package.json",
+    "packageJsonName": "@org/b",
+    "skipInstalls": false,
     "yarnLock": undefined,
   },
 ]
diff --git a/lib/manager/npm/extract/monorepo.spec.ts b/lib/manager/npm/extract/monorepo.spec.ts
index 8fd569946f..62121992b1 100644
--- a/lib/manager/npm/extract/monorepo.spec.ts
+++ b/lib/manager/npm/extract/monorepo.spec.ts
@@ -57,6 +57,7 @@ describe('manager/npm/extract/monorepo', () => {
         )
       ).toBe(true);
     });
+
     it('updates internal packages', async () => {
       const packageFiles = [
         {
@@ -110,6 +111,7 @@ describe('manager/npm/extract/monorepo', () => {
         )
       ).toBe(false);
     });
+
     it('uses yarn workspaces package settings with lerna', async () => {
       const packageFiles = [
         {
@@ -134,6 +136,7 @@ describe('manager/npm/extract/monorepo', () => {
       expect(packageFiles).toMatchSnapshot();
       expect(packageFiles[1].managerData.lernaJsonFile).toEqual('lerna.json');
     });
+
     it('uses yarn workspaces package settings without lerna', async () => {
       const packageFiles = [
         {
@@ -155,5 +158,32 @@ describe('manager/npm/extract/monorepo', () => {
       // FIXME: explicit assert condition
       expect(packageFiles).toMatchSnapshot();
     });
+
+    it('uses yarnZeroInstall and skipInstalls from yarn workspaces package settings', async () => {
+      const packageFiles = [
+        {
+          packageFile: 'package.json',
+          managerData: {
+            yarnZeroInstall: true,
+          },
+          skipInstalls: false,
+          npmrc: '@org:registry=//registry.some.org\n',
+          yarnWorkspacesPackages: 'packages/*',
+        },
+        {
+          packageFile: 'packages/a/package.json',
+          packageJsonName: '@org/a',
+          yarnLock: 'yarn.lock',
+        },
+        {
+          packageFile: 'packages/b/package.json',
+          packageJsonName: '@org/b',
+          skipInstalls: true,
+        },
+      ];
+      await detectMonorepos(packageFiles, false);
+      // FIXME: explicit assert condition
+      expect(packageFiles).toMatchSnapshot();
+    });
   });
 });
diff --git a/lib/manager/npm/extract/monorepo.ts b/lib/manager/npm/extract/monorepo.ts
index 1181375a66..f8128902e7 100644
--- a/lib/manager/npm/extract/monorepo.ts
+++ b/lib/manager/npm/extract/monorepo.ts
@@ -22,8 +22,9 @@ export async function detectMonorepos(
       lernaClient,
       lernaPackages,
       yarnWorkspacesPackages,
+      skipInstalls,
     } = p;
-    const { lernaJsonFile } = managerData;
+    const { lernaJsonFile, yarnZeroInstall } = managerData;
     const packages = yarnWorkspacesPackages || lernaPackages;
     if (packages?.length) {
       const internalPackagePatterns = (
@@ -48,9 +49,11 @@ export async function detectMonorepos(
       for (const subPackage of internalPackageFiles) {
         subPackage.managerData = subPackage.managerData || {};
         subPackage.managerData.lernaJsonFile = lernaJsonFile;
+        subPackage.managerData.yarnZeroInstall = yarnZeroInstall;
         subPackage.lernaClient = lernaClient;
         subPackage.yarnLock = subPackage.yarnLock || yarnLock;
         subPackage.npmLock = subPackage.npmLock || npmLock;
+        subPackage.skipInstalls = skipInstalls && subPackage.skipInstalls; // skip if both are true
         if (subPackage.yarnLock) {
           subPackage.hasYarnWorkspaces = !!yarnWorkspacesPackages;
           subPackage.npmrc = subPackage.npmrc || npmrc;
-- 
GitLab