11import 'dart:convert' ;
22import 'dart:io' ;
33import 'package:collection/collection.dart' ;
4+ import 'package:pub_semver/pub_semver.dart' ;
45import 'package:pubspec_parse/pubspec_parse.dart' ;
56import 'package:args/args.dart' ;
67
@@ -66,14 +67,22 @@ void main(List<String> arguments) async {
6667 String sqlite3Version =
6768 "v${getPubspecVersion (packageConfigFile , sqlite3Pkg , sqlitePackageName )}" ;
6869
69- // String latestTag = await getLatestTagFromRelease(httpClient);
70+ //Sets the range of powersync core version that is compatible with the sqlite3 version
71+ VersionRange sqliteCoreRange = VersionRange (
72+ min: Version (0 , 1 , 0 ),
73+ max: Version (0 , 1 , 9 ),
74+ includeMin: true ,
75+ includeMax: true ,
76+ );
7077 List <String > tags = await getLatestTagsFromRelease (httpClient);
71- String ? matchTag =
72- tags.firstWhereOrNull ((element) => element.contains (sqlite3Version));
78+ String ? matchTag = tags.firstWhereOrNull ((element) =>
79+ element.contains (sqlite3Version) &&
80+ coreVersionIsInRange (element, sqliteCoreRange));
7381 if (matchTag != null ) {
7482 sqlite3Version = matchTag;
7583 } else {
76- sqlite3Version = tags[0 ];
84+ throw Exception (
85+ "No compatible powersync core version found for sqlite3 version $sqlite3Version , Please update your sqlite3 version" );
7786 }
7887
7988 final sqliteUrl =
@@ -86,6 +95,21 @@ void main(List<String> arguments) async {
8695 }
8796}
8897
98+ bool coreVersionIsInRange (String tag, VersionRange range) {
99+ if (! tag.contains ("-powersync" )) return false ;
100+ List <String > parts = tag.split ('-' );
101+ String powersyncPart = parts[1 ];
102+
103+ List <String > versionParts = powersyncPart.split ('.' );
104+ String extractedVersion =
105+ versionParts.sublist (versionParts.length - 3 ).join ('.' );
106+ final coreVersion = Version .parse (extractedVersion);
107+ if (range.allows (coreVersion)) {
108+ return true ;
109+ }
110+ return false ;
111+ }
112+
89113dynamic getPackageFromConfig (dynamic packageConfig, String packageName) {
90114 final pkg = (packageConfig['packages' ] ?? []).firstWhere (
91115 (e) => e['name' ] == packageName,
0 commit comments