diff --git a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap index fb0411899769f479403d58b6e093eac9e6c596d6..1917689508f564826b7dcf032a3b9d3e84ecf1d8 100644 --- a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap +++ b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap @@ -1,14 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`workers/branch/get-updated getUpdatedPackageFiles() does not update artifacts on update-lockfile if packageFile already updated 1`] = ` -Object { - "artifactErrors": Array [], - "reuseExistingBranch": undefined, - "updatedArtifacts": Array [], - "updatedPackageFiles": Array [], -} -`; - exports[`workers/branch/get-updated getUpdatedPackageFiles() handles autoreplace base updated 1`] = ` Object { "artifactErrors": Array [], diff --git a/lib/workers/branch/get-updated.spec.ts b/lib/workers/branch/get-updated.spec.ts index ac51df6d1a2a776aa1400ce4b9bb976f2f9dc97a..2fcf25c41a7e1e98fe007cbde2976365ff96854c 100644 --- a/lib/workers/branch/get-updated.spec.ts +++ b/lib/workers/branch/get-updated.spec.ts @@ -168,28 +168,6 @@ describe('workers/branch/get-updated', () => { ]); const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot(); - expect(res.updatedPackageFiles).toHaveLength(1); - }); - it(' does not update artifacts on update-lockfile if packageFile already updated', async () => { - config.upgrades.push({ - manager: 'composer', - branchName: undefined, - rangeStrategy: 'update-lockfile', - currentValue: '^1.0.0', - newValue: '^2.0.0', - }); - autoReplace.doAutoReplace.mockResolvedValueOnce('existing content'); - composer.updateArtifacts.mockResolvedValueOnce([ - { - file: { - name: 'composer.lock', - contents: 'some contents', - }, - }, - ]); - const res = await getUpdatedPackageFiles(config); - expect(res).toMatchSnapshot(); - expect(res.updatedPackageFiles).toHaveLength(0); }); }); }); diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts index b05a24800414eaabee6fcead4f51f7410c43c0d6..66a2c8b04a099e53163f6a1825f0572a81e4d246 100644 --- a/lib/workers/branch/get-updated.ts +++ b/lib/workers/branch/get-updated.ts @@ -25,6 +25,7 @@ export async function getUpdatedPackageFiles( 'manager.getUpdatedPackageFiles()' ); const updatedFileContents: Record<string, string> = {}; + const nonUpdatedFileContents: Record<string, string> = {}; const packageFileManagers: Record<string, string> = {}; const packageFileUpdatedDeps: Record<string, string[]> = {}; const lockFileMaintenanceFiles = []; @@ -65,12 +66,9 @@ export async function getUpdatedPackageFiles( if (res) { if (res === existingContent) { logger.debug({ packageFile, depName }, 'No content changed'); - if ( - upgrade.currentValue === upgrade.newValue && - upgrade.rangeStrategy === 'update-lockfile' - ) { + if (upgrade.rangeStrategy === 'update-lockfile') { logger.debug({ packageFile, depName }, 'update-lockfile add'); - updatedFileContents[packageFile] = res; + nonUpdatedFileContents[packageFile] = res; } } else { logger.debug({ packageFile, depName }, 'Contents updated'); @@ -123,16 +121,11 @@ export async function getUpdatedPackageFiles( updatedFileContents[packageFile] = newContent; } if (newContent === existingContent) { + // istanbul ignore else if (upgrade.datasource === datasourceGitSubmodules.id) { updatedFileContents[packageFile] = newContent; - } - // istanbul ignore next - if ( - upgrade.rangeStrategy === 'update-lockfile' && - upgrade.currentValue === upgrade.newValue - ) { - // Treat the file as modified because we need to update artifacts - updatedFileContents[packageFile] = newContent; + } else if (upgrade.rangeStrategy === 'update-lockfile') { + nonUpdatedFileContents[packageFile] = newContent; } } } @@ -166,6 +159,37 @@ export async function getUpdatedPackageFiles( } } } + const nonUpdatedPackageFiles = Object.keys(nonUpdatedFileContents).map( + (name) => ({ + name, + contents: nonUpdatedFileContents[name], + }) + ); + for (const packageFile of nonUpdatedPackageFiles) { + const manager = packageFileManagers[packageFile.name]; + const updatedDeps = packageFileUpdatedDeps[packageFile.name]; + const updateArtifacts = get(manager, 'updateArtifacts'); + if (updateArtifacts) { + const results = await updateArtifacts({ + packageFileName: packageFile.name, + updatedDeps, + newPackageFileContent: packageFile.contents, + config, + }); + if (is.nonEmptyArray(results)) { + updatedPackageFiles.push(packageFile); + for (const res of results) { + const { file, artifactError } = res; + // istanbul ignore else + if (file) { + updatedArtifacts.push(file); + } else if (artifactError) { + artifactErrors.push(artifactError); + } + } + } + } + } if (!config.reuseExistingBranch) { // Only perform lock file maintenance if it's a fresh commit for (const packageFile of lockFileMaintenanceFiles) {