applyChanges method
Unless dryRun
, loads pubspec.yaml
of each package
in changeSet
and applies the
changes to its (dev)-dependencies using yaml_edit to preserve textual structure.
Outputs a summary of changes done or would have been done if not dryRun
.
Implementation
void applyChanges(ChangeSet changeSet, bool dryRun) {
if (!dryRun) {
for (final package in workspaceRoot.transitiveWorkspace) {
final changesForPackage = changeSet[package];
if (changesForPackage == null || changesForPackage.isEmpty) {
continue;
}
final yamlEditor = YamlEditor(readTextFile(package.pubspecPath));
final deps = package.dependencies.keys;
for (final change in changesForPackage.values) {
final section =
deps.contains(change.name) ? 'dependencies' : 'dev_dependencies';
yamlEditor.update(
[section, change.name],
pubspecDescription(change, cache, package),
);
}
writeTextFile(package.pubspecPath, yamlEditor.toString());
}
}
_outputChangeSummary(changeSet, dryRun: dryRun);
}