Skip to content

Commit

Permalink
fix: Naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorOhashi committed Jan 9, 2024
1 parent c615f3b commit 6d37f58
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/melos/lib/src/common/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';

@visibleForTesting
http.Client innerHttpClient = http.Client();
http.Client internalHttpClient = http.Client();

http.Client get globalHttpClient => innerHttpClient;
http.Client get httpClient => internalHttpClient;
9 changes: 5 additions & 4 deletions packages/melos/lib/src/common/pub_credential.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import 'package:path/path.dart' as path;
import 'io.dart';
import 'pub_hosted.dart';

const _kPubTokenFileName = 'pub-tokens.json';
const _pubTokenFileName = 'pub-tokens.json';

@visibleForTesting
PubCredentialStore pubCredentialStore = PubCredentialStore.fromConfigFile();
PubCredentialStore internalPubCredentialStore =
PubCredentialStore.fromConfigFile();

PubCredentialStore get pubGlobalCredentialStore => pubCredentialStore;
PubCredentialStore get pubCredentialStore => internalPubCredentialStore;

class PubCredentialStore {
PubCredentialStore(this.credentials);

factory PubCredentialStore.fromConfigFile({String? configDir}) {
configDir ??= applicationConfigHome('dart');
final tokenFilePath = path.join(configDir, _kPubTokenFileName);
final tokenFilePath = path.join(configDir, _pubTokenFileName);

if (!fileExists(tokenFilePath)) {
return PubCredentialStore([]);
Expand Down
8 changes: 4 additions & 4 deletions packages/melos/lib/src/common/pub_hosted.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'pub_hosted_package.dart';
/// The default is `pub.dev`, but it can be overridden using the
/// `PUB_HOSTED_URL` environment variable.
/// https://dart.dev/tools/pub/environment-variables
Uri get kDefaultPubUrl => Uri.parse(
Uri get defaultPubUrl => Uri.parse(
currentPlatform.environment['PUB_HOSTED_URL'] ?? 'https://pub.dev',
);

Expand All @@ -24,9 +24,9 @@ class PubHostedClient extends http.BaseClient {
PubHostedClient(this.pubHosted, this._inner, this._credentialStore);

factory PubHostedClient.fromUri({required Uri? pubHosted}) {
final store = pubGlobalCredentialStore;
final innerClient = globalHttpClient;
final uri = normalizeHostedUrl(pubHosted ?? kDefaultPubUrl);
final store = pubCredentialStore;
final innerClient = httpClient;
final uri = normalizeHostedUrl(pubHosted ?? defaultPubUrl);

return PubHostedClient(uri, innerClient, store);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/melos/test/package_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ void main() {
final pubCredentialStoreMock = PubCredentialStore([]);

setUpAll(() {
pubCredentialStore = pubCredentialStoreMock;
internalPubCredentialStore = pubCredentialStoreMock;
});

tearDownAll(() {
pubCredentialStore = PubCredentialStore([]);
internalPubCredentialStore = PubCredentialStore([]);
});

test('Should fetch package from pub.dev by default', () async {
final uri = Uri.parse('https://pub.dev/api/packages/melos');
innerHttpClient = HttpClientMock(
internalHttpClient = HttpClientMock(
(request) {
expect(request.url, uri);
return HttpClientMock.parseResponse(pubPackageJson);
Expand All @@ -111,7 +111,7 @@ void main() {
withMockPlatform(
() async {
final uri = Uri.parse('http://localhost:8080/api/packages/melos');
innerHttpClient = HttpClientMock(
internalHttpClient = HttpClientMock(
(request) {
expect(request.url, uri);
return HttpClientMock.parseResponse(pubPackageJson);
Expand Down Expand Up @@ -160,18 +160,18 @@ void main() {
final pubCredentialStoreMock = PubCredentialStore([fakeCredential]);

setUpAll(() {
pubCredentialStore = pubCredentialStoreMock;
internalPubCredentialStore = pubCredentialStoreMock;
});

tearDownAll(() {
pubCredentialStore = PubCredentialStore([]);
internalPubCredentialStore = PubCredentialStore([]);
});

test(
'Should fetch without credentials',
() async {
final uri = Uri.parse('https://pub.dev/api/packages/melos');
innerHttpClient = HttpClientMock(
internalHttpClient = HttpClientMock(
(request) {
expect(request.url, uri);
expect(
Expand All @@ -194,7 +194,7 @@ void main() {
withMockPlatform(
() async {
final uri = fakeCredential.url.resolve('api/packages/melos');
innerHttpClient = HttpClientMock(
internalHttpClient = HttpClientMock(
(request) {
expect(request.url, uri);
expect(
Expand Down

0 comments on commit 6d37f58

Please sign in to comment.