diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index 8435b4e9b9d4673a8b2eea0b9e5f0fdd92aa2500..f3743f241a50a79e6ea0023c0beb32a0fe5e8ad3 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -235,6 +235,7 @@ export interface ManagerApi extends ModuleApi { content: string, currentValue: string, bumpVersion: ReleaseType, + packageFile: string, ): Result<BumpPackageVersionResult>; detectGlobalConfig?(): Result<GlobalManagerConfig>; diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts index 648f107c25b2138fd7ba04fc90f1d7dfcdaf1f03..1adfb25bd34637c3168d2d280df52b4920f50bc8 100644 --- a/lib/workers/repository/update/branch/get-updated.ts +++ b/lib/workers/repository/update/branch/get-updated.ts @@ -20,6 +20,21 @@ export interface PackageFilesResult { updatedArtifacts: FileChange[]; } +async function getFileContent( + updatedFileContents: Record<string, string>, + filePath: string, + config: BranchConfig, +): Promise<string | null> { + let fileContent: string | null = updatedFileContents[filePath]; + if (!fileContent) { + fileContent = await getFile( + filePath, + config.reuseExistingBranch ? config.branchName : config.baseBranch, + ); + } + return fileContent; +} + export async function getUpdatedPackageFiles( config: BranchConfig, ): Promise<PackageFilesResult> { @@ -46,23 +61,19 @@ export async function getUpdatedPackageFiles( packageFileUpdatedDeps[packageFile] = packageFileUpdatedDeps[packageFile] || []; packageFileUpdatedDeps[packageFile].push({ ...upgrade }); - let packageFileContent: string | null = updatedFileContents[packageFile]; - if (!packageFileContent) { - packageFileContent = await getFile( - packageFile, - reuseExistingBranch ? config.branchName : config.baseBranch, - ); - } + const packageFileContent = await getFileContent( + updatedFileContents, + packageFile, + config, + ); let lockFileContent: string | null = null; const lockFile = upgrade.lockFile ?? upgrade.lockFiles?.[0] ?? ''; if (lockFile) { - lockFileContent = updatedFileContents[lockFile]; - if (!lockFileContent) { - lockFileContent = await getFile( - lockFile, - reuseExistingBranch ? config.branchName : config.baseBranch, - ); - } + lockFileContent = await getFileContent( + updatedFileContents, + lockFile, + config, + ); } // istanbul ignore if if ( @@ -183,6 +194,7 @@ export async function getUpdatedPackageFiles( res, upgrade.packageFileVersion, upgrade.bumpVersion, + packageFile, ); res = bumpedContent; } @@ -217,6 +229,7 @@ export async function getUpdatedPackageFiles( newContent, upgrade.packageFileVersion, upgrade.bumpVersion, + packageFile, ); newContent = bumpedContent; }