getDependencies function
What dpk get does between its hooks: rename deprecated config keys,
apply the catalog and sorting to pubspecs, run dart pub get, and sync
the project cache in project mode.
project is passed in, rather than read from context, so a caller that
just changed dpk.yaml can pass a freshly loaded project.
Implementation
Future<int> getDependencies(
DpkContext context,
Project project, {
List<String> pubArguments = const [],
bool dryRun = false,
HookStack stack = const HookStack(),
}) async {
final console = context.console;
for (final config in configFiles(project)) {
final before = File(config).readAsStringSync();
final after = migrateConfig(before);
if (after != before) {
if (dryRun) {
console.step(
'> Would rename deprecated keys in ${displayPath(config)}',
);
} else {
File(config).writeAsStringSync(after);
console.step('> Renamed deprecated keys in ${displayPath(config)}');
}
}
}
final updates = planPubspecUpdates(
project,
).where((update) => update.changed).toList();
if (updates.isNotEmpty) {
final verb = dryRun ? 'Would update' : 'Updated';
if (!dryRun) {
writePubspecUpdates(updates);
}
console.step(
'> $verb ${updates.map((u) => displayPath(u.path)).join(', ')}',
);
}
final exitCode = await context.runDart(
['pub', ...context.pubFlags, 'get', ...pubArguments],
workingDirectory: project.workspace.current.path,
environment: {...project.pubEnvironment, ...stack.toEnvironment()},
);
if (exitCode != 0 || dryRun || !project.isProjectMode) {
return exitCode;
}
return ProjectCache.forProject(project, context).sync();
}