isCompatibleWithRange function

bool isCompatibleWithRange(
  1. String? compatRange,
  2. String engineVersion
)

Utility for checking engine version compatibility against a range string.

Parses the compatRange string and checks if the given engine version falls within it. Supports semver range operators: >=, >, <, <=.

Example range: ">= 1.0.0 < 2.0.0"

Implementation

bool isCompatibleWithRange(String? compatRange, String engineVersion) {
  if (compatRange == null) return true;

  final parts = compatRange.split(' ');
  String? minVersion;
  String? maxVersion;
  var minInclusive = true;
  var maxInclusive = false;

  for (var i = 0; i < parts.length - 1; i++) {
    final op = parts[i];
    final ver = parts[i + 1];
    if (op == '>=' || op == '>') {
      minVersion = ver;
      minInclusive = (op == '>=');
    } else if (op == '<' || op == '<=') {
      maxVersion = ver;
      maxInclusive = (op == '<=');
    }
  }

  final engine = _parseVersion(engineVersion);
  if (engine == null) return false;

  if (minVersion != null) {
    final min = _parseVersion(minVersion);
    if (min == null) return false;
    final cmp = _compareTo(engine, min);
    if (minInclusive ? cmp < 0 : cmp <= 0) return false;
  }

  if (maxVersion != null) {
    final max = _parseVersion(maxVersion);
    if (max == null) return false;
    final cmp = _compareTo(engine, max);
    if (maxInclusive ? cmp > 0 : cmp >= 0) return false;
  }

  return true;
}