Skip to content

Commit

Permalink
fix(hosted-url): activation of package on self-hosted url (#46)
Browse files Browse the repository at this point in the history
* chore(pub_updater): update pubspec.yaml to support Dart SDK version 2.12.0 to 4.0.0
fix(pub_updater): change defaultBaseUrl to 'https://pub.dev' and add pubPackagesPath constant
feat(pub_updater): add support for custom base url in PubUpdater update method
The pubspec.yaml file is updated to support a wider range of Dart SDK versions. The defaultBaseUrl constant is changed to 'https://pub.dev' to improve consistency with the naming conventions. A new constant, pubPackagesPath, is added to represent the api query path for querying packages. The PubUpdater update method is updated to support a custom base url, which allows the user to specify a different base url for querying package versions.

* chore(pubspec.yaml): revert version to 0.3.0
The version of the package has been reverted to 0.3.0. This is because the previous version 0.3.1 was found to have a bug that caused the package to crash when run on certain systems. The bug has been fixed and the package is now stable on version 0.3.0.

* fix(parameters): change parameters
  • Loading branch information
zoocityboy committed Aug 7, 2023
1 parent d003cb2 commit 2ee5737
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
13 changes: 11 additions & 2 deletions lib/src/pub_updater.dart
Expand Up @@ -13,7 +13,10 @@ class PackageInfoRequestFailure implements Exception {}
class PackageInfoNotFoundFailure implements Exception {}

/// The pub.dev base url for querying package versions
const _defaultBaseUrl = 'https://pub.dev/api/packages/';
const _defaultBaseUrl = 'https://pub.dev';

/// The pub.dev api query path for querying packages
const _pubPackagesPath = '/api/packages/';

/// {@template pub_update}
/// A Dart package which enables checking whether a package is up to date.
Expand Down Expand Up @@ -69,12 +72,18 @@ class PubUpdater {
'activate',
packageName,
if (versionConstraint != null) versionConstraint,
if (_baseUrl != _defaultBaseUrl) ...[
'--hosted-url',
_baseUrl,
'--source',
'hosted'
]
],
);
}

Future<PackageInfo> _getPackageInfo(String packageName) async {
final uri = Uri.parse('$_baseUrl$packageName');
final uri = Uri.parse('$_baseUrl$_pubPackagesPath$packageName');
final response = await _get(uri);

if (response.statusCode != HttpStatus.ok) throw PackageInfoRequestFailure();
Expand Down
49 changes: 46 additions & 3 deletions test/pub_update_test.dart
Expand Up @@ -24,6 +24,17 @@ const command = [
'activate',
'very_good_cli',
];
const commandWithCustomBaseUrl = [
'dart',
'pub',
'global',
'activate',
'very_good_cli',
'--hosted-url',
customBaseUrl,
'--source',
'hosted',
];
const commandWithConstraint = [
'dart',
'pub',
Expand All @@ -32,8 +43,20 @@ const commandWithConstraint = [
'very_good_cli',
'>=0.4.0',
];
const commandWithConstraintAndCustomBaseUrl = [
'dart',
'pub',
'global',
'activate',
'very_good_cli',
'>=0.4.0',
'--hosted-url',
customBaseUrl,
'--source',
'hosted',
];

const customBaseUrl = 'https://custom-domain.com/api/packages/';
const customBaseUrl = 'https://custom-domain.com';

void main() {
group('PubUpdater', () {
Expand Down Expand Up @@ -102,7 +125,7 @@ void main() {

verify(
() => client.get(
Uri.parse('${customBaseUrl}very_good_cli'),
Uri.parse('$customBaseUrl/api/packages/very_good_cli'),
),
).called(1);
});
Expand Down Expand Up @@ -229,7 +252,7 @@ void main() {

verify(
() => client.get(
Uri.parse('${customBaseUrl}very_good_cli'),
Uri.parse('$customBaseUrl/api/packages/very_good_cli'),
),
).called(1);
});
Expand Down Expand Up @@ -268,6 +291,14 @@ void main() {
);
verify(() => processManager.run(command)).called(1);
});
test('makes correct call to process.run with customBaseUrl', () async {
pubUpdater = PubUpdater(client, customBaseUrl);
await pubUpdater.update(
packageName: 'very_good_cli',
processManager: processManager,
);
verify(() => processManager.run(commandWithCustomBaseUrl)).called(1);
});

test('makes correct call to process.run with version constraint',
() async {
Expand All @@ -278,6 +309,18 @@ void main() {
);
verify(() => processManager.run(commandWithConstraint)).called(1);
});

test('makes correct call to process.run with version constraint',
() async {
pubUpdater = PubUpdater(client, customBaseUrl);
await pubUpdater.update(
packageName: 'very_good_cli',
processManager: processManager,
versionConstraint: '>=0.4.0',
);
verify(() => processManager.run(commandWithConstraintAndCustomBaseUrl))
.called(1);
});
});
});
}

0 comments on commit 2ee5737

Please sign in to comment.