Skip to content

Commit

Permalink
feat(manager/pub): update to only changed dependencies (#19825)
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Closes #19653
  • Loading branch information
zeshuaro committed Jan 20, 2023
1 parent c5db2dc commit 6be73f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
11 changes: 6 additions & 5 deletions lib/modules/manager/pub/artifacts.spec.ts
Expand Up @@ -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);

Expand All @@ -32,7 +33,7 @@ const config: UpdateArtifactsConfig = {};

const updateArtifact: UpdateArtifact = {
packageFileName: 'pubspec.yaml',
updatedDeps: [{ depName: 'dep1' }],
updatedDeps: [{ depName }],
newPackageFileContent: '',
config,
};
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('modules/manager/pub/artifacts', () => {
).toBeNull();
expect(execSnapshots).toMatchObject([
{
cmd: `${params.sdk} pub upgrade`,
cmd: `${params.sdk} pub upgrade ${depName}`,
},
]);
});
Expand All @@ -107,7 +108,7 @@ describe('modules/manager/pub/artifacts', () => {
]);
expect(execSnapshots).toMatchObject([
{
cmd: `${params.sdk} pub upgrade`,
cmd: `${params.sdk} pub upgrade ${depName}`,
},
]);
});
Expand Down Expand Up @@ -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}` +
'"',
},
]);
Expand Down Expand Up @@ -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}` },
]);
});

Expand Down
40 changes: 26 additions & 14 deletions 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,
Expand All @@ -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;
}

Expand All @@ -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: [
Expand All @@ -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: {
Expand Down

0 comments on commit 6be73f1

Please sign in to comment.