constrain method

bool constrain(
  1. String path, {
  2. bool includeDevDependencies = false,
  3. VersionBump bump = VersionBump.breaking,
  4. bool dryRun = false,
  5. Iterable<String> packages = const [],
  6. bool pin = false,
})

Implementation

bool constrain(
  String path, {
  bool includeDevDependencies = false,
  VersionBump bump = VersionBump.breaking,
  bool dryRun = false,
  Iterable<String> packages = const [],
  bool pin = false,
}) {
  final file = fs.file(path);

  if (!file.existsSync()) {
    return false;
  }

  final content = file.readAsStringSync();

  final result = applyConstraintsTo(
    content,
    bump: bump,
    packages: packages,
    pin: pin,
    additionalKeys: [
      if (includeDevDependencies) 'dev_dependencies',
    ],
  );

  if (result == null) {
    return false;
  }

  if (dryRun) {
    return true;
  }

  file.writeAsStringSync(result);

  return true;
}