packageLanguageVersion function

Version? packageLanguageVersion({
  1. Directory? startDirectory,
})

The language version of the Dart package startDirectory belongs to, resolved the way dart format and the analyzer resolve it: the lower bound of the environment.sdk constraint in the pubspec.yaml of startDirectory, which defaults to the current directory, or of its nearest ancestor. Returns null when no such pubspec exists or it has no SDK constraint.

Throws a FormatException when the pubspec is not valid YAML or its SDK constraint is not a valid version constraint.

Implementation

Version? packageLanguageVersion({Directory? startDirectory}) {
  final pubspec = _nearestPubspec(startDirectory ?? Directory.current);
  if (pubspec == null) return null;
  final lowerBound = _sdkLowerBound(pubspec);
  if (lowerBound == null) return null;
  return Version(lowerBound.major, lowerBound.minor, 0);
}