diff --git a/lib/modules/manager/pub/artifacts.spec.ts b/lib/modules/manager/pub/artifacts.spec.ts index 4f0823aee2cc41f8b1b3a0653923a76c4b573030..857f67cd3d850d374480ce3dff1136e75a2f8d10 100644 --- a/lib/modules/manager/pub/artifacts.spec.ts +++ b/lib/modules/manager/pub/artifacts.spec.ts @@ -19,6 +19,7 @@ process.env.BUILDPACK = 'true'; const lockFile = 'pubspec.lock'; const oldLockFileContent = 'Old pubspec.lock'; const newLockFileContent = 'New pubspec.lock'; +const depName = 'depName'; const datasource = mocked(_datasource); @@ -32,7 +33,7 @@ const config: UpdateArtifactsConfig = {}; const updateArtifact: UpdateArtifact = { packageFileName: 'pubspec.yaml', - updatedDeps: [{ depName: 'dep1' }], + updatedDeps: [{ depName }], newPackageFileContent: '', config, }; @@ -81,7 +82,7 @@ describe('modules/manager/pub/artifacts', () => { ).toBeNull(); expect(execSnapshots).toMatchObject([ { - cmd: `${params.sdk} pub upgrade`, + cmd: `${params.sdk} pub upgrade ${depName}`, }, ]); }); @@ -107,7 +108,7 @@ describe('modules/manager/pub/artifacts', () => { ]); expect(execSnapshots).toMatchObject([ { - cmd: `${params.sdk} pub upgrade`, + cmd: `${params.sdk} pub upgrade ${depName}`, }, ]); }); @@ -178,7 +179,7 @@ describe('modules/manager/pub/artifacts', () => { 'bash -l -c "' + `install-tool ${params.sdk} 3.3.9` + ' && ' + - `${params.sdk} pub upgrade` + + `${params.sdk} pub upgrade ${depName}` + '"', }, ]); @@ -207,7 +208,7 @@ describe('modules/manager/pub/artifacts', () => { ]); expect(execSnapshots).toMatchObject([ { cmd: `install-tool ${params.sdk} 3.3.9` }, - { cmd: `${params.sdk} pub upgrade` }, + { cmd: `${params.sdk} pub upgrade ${depName}` }, ]); }); diff --git a/lib/modules/manager/pub/artifacts.ts b/lib/modules/manager/pub/artifacts.ts index 2a3155dbbea474b6a2f2d25217ba42c53e7f033a..16cdae0a8f72ffd974bacea8b122dae3f71dacb0 100644 --- a/lib/modules/manager/pub/artifacts.ts +++ b/lib/modules/manager/pub/artifacts.ts @@ -1,6 +1,9 @@ +import is from '@sindresorhus/is'; +import { quote } from 'shlex'; import { TEMPORARY_ERROR } from '../../../constants/error-messages'; import { logger } from '../../../logger'; import { exec } from '../../../util/exec'; +import type { ExecOptions } from '../../../util/exec/types'; import { getSiblingFileName, readLocalFile, @@ -26,19 +29,18 @@ export async function updateArtifacts({ newPackageFileContent, config, }: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> { - if ( - !( - config.updateType === 'lockFileMaintenance' || - config.updateType === 'lockfileUpdate' - ) && - updatedDeps.length < 1 - ) { + logger.debug(`pub.updateArtifacts(${packageFileName})`); + const isLockFileMaintenance = config.updateType === 'lockFileMaintenance'; + + if (is.emptyArray(updatedDeps) && !isLockFileMaintenance) { + logger.debug('No updated pub deps - returning null'); return null; } const lockFileName = getSiblingFileName(packageFileName, 'pubspec.lock'); const oldLockFileContent = await readLocalFile(lockFileName, 'utf8'); if (!oldLockFileContent) { + logger.debug('No pubspec.lock found'); return null; } @@ -47,11 +49,24 @@ export async function updateArtifacts({ const isFlutter = newPackageFileContent.includes('sdk: flutter'); const toolName = isFlutter ? 'flutter' : 'dart'; + const cmd: string[] = []; + + if (isLockFileMaintenance) { + cmd.push(`${toolName} pub upgrade`); + } else { + cmd.push( + `${toolName} pub upgrade ${updatedDeps + .map((dep) => dep.depName) + .filter(is.string) + .map((dep) => quote(dep)) + .join(' ')}` + ); + } const constraint = isFlutter ? config.constraints?.flutter ?? getFlutterConstraint(oldLockFileContent) : config.constraints?.dart ?? getDartConstraint(oldLockFileContent); - await exec(`${toolName} pub upgrade`, { + const execOptions: ExecOptions = { cwdFile: packageFileName, docker: {}, toolConstraints: [ @@ -60,16 +75,13 @@ export async function updateArtifacts({ constraint, }, ], - }); + }; + await exec(cmd, execOptions); const newLockFileContent = await readLocalFile(lockFileName, 'utf8'); - if ( - oldLockFileContent === newLockFileContent || - newLockFileContent === undefined - ) { + if (oldLockFileContent === newLockFileContent) { return null; } - return [ { file: {