Skip to content

Commit

Permalink
fix: change used API endpoint for querying versions (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmil authored Mar 8, 2023
1 parent 3cf783d commit 1a5c854
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions packages/melos/lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ class Package {

final pubHosted = publishTo ?? pubUrl;

final url = pubHosted.replace(path: '/packages/$name.json');
final url = pubHosted.replace(path: '/api/packages/$name');
final response = await http.get(url);

if (response.statusCode == 404) {
Expand All @@ -905,9 +905,11 @@ class Package {
}
final versions = <String>[];
final versionsRaw =
(json.decode(response.body) as Map)['versions'] as List<Object?>;
(json.decode(response.body) as Map)['versions'] as List<dynamic>;
for (final versionElement in versionsRaw) {
versions.add(versionElement! as String);
if (versionElement is Map<String, dynamic>) {
versions.add(versionElement['version'] as String);
}
}
versions.sort((String a, String b) {
return Version.prioritize(Version.parse(a), Version.parse(b));
Expand Down
8 changes: 5 additions & 3 deletions packages/melos/test/package_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import 'utils.dart';
const pubPackageJson = '''
{
"versions": [
"1.0.0"
{
"version": "1.0.0"
}
]
}
''';
Expand Down Expand Up @@ -85,7 +87,7 @@ void main() {
tearDownAll(() => testClient = null);

test('requests published packages from pub.dev by default', () async {
final uri = Uri.parse('https://pub.dev/packages/melos.json');
final uri = Uri.parse('https://pub.dev/api/packages/melos');
when(httpClientMock.get(uri))
.thenAnswer((_) async => http.Response(pubPackageJson, 200));

Expand All @@ -99,7 +101,7 @@ void main() {
'requests published packages from PUB_HOSTED_URL if present',
withMockPlatform(
() async {
final uri = Uri.parse('http://localhost:8080/packages/melos.json');
final uri = Uri.parse('http://localhost:8080/api/packages/melos');
when(httpClientMock.get(uri))
.thenAnswer((_) async => http.Response(pubPackageJson, 200));

Expand Down

0 comments on commit 1a5c854

Please sign in to comment.