diff --git a/lib/modules/manager/npm/post-update/yarn.spec.ts b/lib/modules/manager/npm/post-update/yarn.spec.ts index 7497948b0dc1c1295b368af737d475c54eda9692..bdf1c1cf4baa52de211ea67117351a5cb87e703b 100644 --- a/lib/modules/manager/npm/post-update/yarn.spec.ts +++ b/lib/modules/manager/npm/post-update/yarn.spec.ts @@ -151,6 +151,11 @@ describe('modules/manager/npm/post-update/yarn', () => { newValue: '^1.0.0', isLockfileUpdate: true, }, + { + depName: 'some-dep', + newValue: '^1.0.0', + isLockfileUpdate: true, + }, ]); expect(res.lockFile).toBe('package-lock-contents'); expect(fixSnapshots(execSnapshots)).toMatchSnapshot(); diff --git a/lib/modules/manager/npm/post-update/yarn.ts b/lib/modules/manager/npm/post-update/yarn.ts index 27fc5e69b6bb8be3c9bcb21c7eaa3409cde501a3..b76fb9fd300c2402cc18edb23cb3d1224e28c783 100644 --- a/lib/modules/manager/npm/post-update/yarn.ts +++ b/lib/modules/manager/npm/post-update/yarn.ts @@ -13,6 +13,7 @@ import { exec } from '../../../../util/exec'; import type { ExecOptions } from '../../../../util/exec/types'; import { exists, readFile, remove, writeFile } from '../../../../util/fs'; import { newlineRegex, regEx } from '../../../../util/regex'; +import { uniqueStrings } from '../../../../util/string'; import { NpmDatasource } from '../../../datasource/npm'; import type { PostUpdateConfig, Upgrade } from '../../types'; import { getNodeConstraint } from './node-version'; @@ -178,6 +179,7 @@ export async function generateLockFile( commands.push( `yarn upgrade ${lockUpdates .map((update) => update.depName) + .filter(uniqueStrings) .join(' ')}${cmdOptions}` ); } else { @@ -185,6 +187,7 @@ export async function generateLockFile( commands.push( `yarn up ${lockUpdates .map((update) => `${update.depName}@${update.newValue}`) + .filter(uniqueStrings) .join(' ')}${cmdOptions}` ); } diff --git a/lib/util/string.ts b/lib/util/string.ts index d62cbddfc75d03e13860034800d0e5def3665550..a0f455bfe39b9528f9e6584c604946b3928a0040 100644 --- a/lib/util/string.ts +++ b/lib/util/string.ts @@ -37,3 +37,11 @@ export function toBase64(input: string): string { export function fromBase64(input: string): string { return Buffer.from(input, 'base64').toString(); } + +export function uniqueStrings( + element: string, + index: number, + elements: string[] +): boolean { + return elements.indexOf(element) === index; +}