diff --git a/lib/modules/manager/npm/post-update/index.spec.ts b/lib/modules/manager/npm/post-update/index.spec.ts index cf845f8ff697815c970931197f1e42cbb2b11200..19b2b2d4f1f6d98c4873b4f210e68c39916ac8e8 100644 --- a/lib/modules/manager/npm/post-update/index.spec.ts +++ b/lib/modules/manager/npm/post-update/index.spec.ts @@ -1,7 +1,7 @@ // TODO: add tests import upath from 'upath'; import { Fixtures } from '../../../../../test/fixtures'; -import { fs, git, partial } from '../../../../../test/util'; +import { fs, git, logger, partial } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { FileChange } from '../../../../util/git/types'; import type { PostUpdateConfig } from '../../types'; @@ -302,6 +302,22 @@ describe('modules/manager/npm/post-update/index', () => { expect(existingYarnrcYmlContent).toMatch(oldYarnrcYml); expect(updatedArtifacts).toBeEmpty(); }); + + it('should support Yarn with corepack', async () => { + git.getFile.mockResolvedValueOnce(''); + fs.readLocalFile.mockResolvedValueOnce(''); + fs.readLocalFile.mockResolvedValueOnce(''); + const updatedArtifacts: FileChange[] = []; + const yarnrcYmlContent = await updateYarnBinary( + lockFileDir, + updatedArtifacts, + '' + ); + expect(yarnrcYmlContent).toBe(''); + expect(updatedArtifacts).toEqual([]); + expect(logger.logger.debug).not.toHaveBeenCalled(); + expect(logger.logger.error).not.toHaveBeenCalled(); + }); }); describe('getAdditionalFiles()', () => { diff --git a/lib/modules/manager/npm/post-update/index.ts b/lib/modules/manager/npm/post-update/index.ts index ee8697e385266aa1a135fa88c94bd5626b23ed9a..f1c8636996e9043735bfaecc9cba1302b6370a56 100644 --- a/lib/modules/manager/npm/post-update/index.ts +++ b/lib/modules/manager/npm/post-update/index.ts @@ -36,6 +36,7 @@ import type { ArtifactError, DetermineLockFileDirsResult, WriteExistingFilesResult, + YarnRcYmlFile, } from './types'; import * as yarn from './yarn'; @@ -408,6 +409,7 @@ async function updateYarnOffline( } } +// TODO: move to ./yarn.ts // exported for testing export async function updateYarnBinary( lockFileDir: string, @@ -423,8 +425,15 @@ export async function updateYarnBinary( return existingYarnrcYmlContent; } - const oldYarnPath = (load(yarnrcYml) as Record<string, string>).yarnPath; - const newYarnPath = (load(newYarnrcYml) as Record<string, string>).yarnPath; + const oldYarnPath = (load(yarnrcYml) as YarnRcYmlFile)?.yarnPath; + const newYarnPath = (load(newYarnrcYml) as YarnRcYmlFile)?.yarnPath; + if ( + !is.nonEmptyStringAndNotWhitespace(oldYarnPath) || + !is.nonEmptyStringAndNotWhitespace(newYarnPath) + ) { + return existingYarnrcYmlContent; + } + const oldYarnFullPath = upath.join(lockFileDir, oldYarnPath); const newYarnFullPath = upath.join(lockFileDir, newYarnPath); logger.debug({ oldYarnPath, newYarnPath }, 'Found updated Yarn binary'); diff --git a/lib/modules/manager/npm/post-update/types.ts b/lib/modules/manager/npm/post-update/types.ts index 7ba05ca902ec467797b0edcfc93df146a0e11099..cf282628da972109e5c8230eb08ad5dfe4b5fd8d 100644 --- a/lib/modules/manager/npm/post-update/types.ts +++ b/lib/modules/manager/npm/post-update/types.ts @@ -32,3 +32,7 @@ export interface GenerateLockFileResult { export interface PnpmLockFile { lockfileVersion?: number; } + +export interface YarnRcYmlFile { + yarnPath?: string | null; +}