resolve static method

UpdateInfo resolve({
  1. required String packageName,
  2. required Version currentVersion,
  3. required ReleaseChannel channel,
  4. Release? latest,
  5. List<Asset> assets = const [],
  6. String? platform,
})

Builds the answer for a client on currentVersion and channel, given the newest release the registry would offer it.

The rules:

  • No offerable release at all → not an error, updateAvailable: false. A package with only drafts is a real state, not a failure.
  • latest not strictly newer than currentVersionfalse. Equal versions are current; an older registry version means the client is ahead (a developer on a local build), and offering a downgrade would be worse than saying nothing.
  • Otherwise → true, carrying the release and the asset matching platform.

Comparison uses Versions.compare, so 1.0.0+build2 is correctly newer than 1.0.0+build1 — semver calls those equal, which would strand a fleet on a broken build of the same version.

Implementation

static UpdateInfo resolve({
  required String packageName,
  required Version currentVersion,
  required ReleaseChannel channel,
  Release? latest,
  List<Asset> assets = const [],
  String? platform,
}) {
  if (latest == null) {
    return UpdateInfo.upToDate(
      currentVersion: currentVersion,
      channel: channel,
      packageName: packageName,
    );
  }

  final isNewer = Versions.compare(latest.version, currentVersion) > 0;
  if (!isNewer) {
    return UpdateInfo.upToDate(
      currentVersion: currentVersion,
      channel: channel,
      packageName: packageName,
      latestVersion: latest.version,
      release: latest,
    );
  }

  return UpdateInfo(
    currentVersion: currentVersion,
    latestVersion: latest.version,
    updateAvailable: true,
    channel: channel,
    release: latest,
    asset: selectAsset(assets, platform: platform),
    packageName: packageName,
    notes: latest.notes,
  );
}