diff --git a/lib/modules/manager/npm/extract/index.spec.ts b/lib/modules/manager/npm/extract/index.spec.ts index 9d1ebbb87611c35dd9aa96ca6307312ea17fc9fa..f9c34b2c4a7a34a5a7a0631ae93463f5da22603b 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 963a085d6db0a89c07dac6685514286fdace0176..61431443be10e5139fb545dba08cf4d97b48a4d0 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');