From 2367b4241335cab66762ed6efdfc8a5a72dde87a Mon Sep 17 00:00:00 2001
From: RahulGautamSingh <rahultesnik@gmail.com>
Date: Fri, 4 Aug 2023 11:31:40 +0545
Subject: [PATCH] feat: warn if multiple lock files detected (#23562)

---
 lib/modules/manager/npm/extract/index.spec.ts | 27 +++++++++++++++++++
 lib/modules/manager/npm/extract/index.ts      | 10 +++++++
 2 files changed, 37 insertions(+)

diff --git a/lib/modules/manager/npm/extract/index.spec.ts b/lib/modules/manager/npm/extract/index.spec.ts
index 9d1ebbb876..f9c34b2c4a 100644
--- a/lib/modules/manager/npm/extract/index.spec.ts
+++ b/lib/modules/manager/npm/extract/index.spec.ts
@@ -1,5 +1,6 @@
 import { Fixtures } from '../../../../../test/fixtures';
 import { fs } from '../../../../../test/util';
+import { logger } from '../../../../logger';
 import type { ExtractConfig } from '../../types';
 import * as npmExtract from '.';
 
@@ -164,6 +165,32 @@ describe('modules/manager/npm/extract/index', () => {
       });
     });
 
+    it('warns when multiple lock files found', async () => {
+      fs.readLocalFile.mockImplementation((fileName): Promise<any> => {
+        if (fileName === 'yarn.lock') {
+          return Promise.resolve('# yarn.lock');
+        }
+        if (fileName === 'package-lock.json') {
+          return Promise.resolve('# package-lock.json');
+        }
+        return Promise.resolve(null);
+      });
+      const res = await npmExtract.extractPackageFile(
+        input01Content,
+        'package.json',
+        defaultExtractConfig
+      );
+      expect(logger.warn).toHaveBeenCalledWith(
+        'Updating multiple npm lock files is deprecated and support will be removed in future versions.'
+      );
+      expect(res).toMatchObject({
+        managerData: {
+          npmLock: 'package-lock.json',
+          yarnLock: 'yarn.lock',
+        },
+      });
+    });
+
     it('finds and filters .npmrc', async () => {
       fs.readLocalFile.mockImplementation((fileName): Promise<any> => {
         if (fileName === '.npmrc') {
diff --git a/lib/modules/manager/npm/extract/index.ts b/lib/modules/manager/npm/extract/index.ts
index 963a085d6d..61431443be 100644
--- a/lib/modules/manager/npm/extract/index.ts
+++ b/lib/modules/manager/npm/extract/index.ts
@@ -36,6 +36,10 @@ function parseDepName(depType: string, key: string): string {
   return depName;
 }
 
+function hasMultipleLockFiles(lockFiles: NpmLockFiles): boolean {
+  return Object.values(lockFiles).filter(is.string).length > 1;
+}
+
 const RE_REPOSITORY_GITHUB_SSH_FORMAT = regEx(
   /(?:git@)github.com:([^/]+)\/([^/.]+)(?:\.git)?/
 );
@@ -101,6 +105,12 @@ export async function extractPackageFile(
   delete lockFiles.packageLock;
   delete lockFiles.shrinkwrapJson;
 
+  if (hasMultipleLockFiles(lockFiles)) {
+    logger.warn(
+      'Updating multiple npm lock files is deprecated and support will be removed in future versions.'
+    );
+  }
+
   let npmrc: string | undefined;
   const npmrcFileName = getSiblingFileName(packageFile, '.npmrc');
   let repoNpmrc = await readLocalFile(npmrcFileName, 'utf8');
-- 
GitLab