Skip to content

Commit

Permalink
Null safety migration, and dependency upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Mar 25, 2021
1 parent e024d59 commit 911c67a
Show file tree
Hide file tree
Showing 38 changed files with 1,003 additions and 751 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
- name: Test Coverage
run: pub run test_coverage
- name: Remove generated files from Coverage
run: pub run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.g.dart$'
run: pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.g.dart$'
- name: Remove freezed files from Coverage
run: pub run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.freezed.dart$'
run: pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.freezed.dart$'
- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ coverage/lcov.info
.fvm
.vscode/settings.json
_notes.md
.env
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1.0

- Deprecated checkUpdatePrinter
- Changed latest version to display stable version only

## 1.0.9

- Ability to pass custom http Client as param.
Expand Down
14 changes: 14 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# # Read about `build.yaml` at https://pub.dev/packages/build_config
# targets:
# $default:
# builders:
# build_google_deps:
# enabled: false

# builders:
# build_google_deps:
# import: "package:pub_api_client/src/helpers/deps_builder.dart"
# builder_factories: ["googleDepsBuilder"]
# build_extensions: {"$lib$": ["src/helpers/google_packages_list.dart"]}
# build_to: source
# auto_apply: dependents
1 change: 0 additions & 1 deletion lib/pub_api_client.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export 'src/helpers/console_helper.dart';
export 'src/helpers/google_packages.dart';
export 'src/models/barrel.dart';
export 'src/pub_api_client_base.dart';
12 changes: 6 additions & 6 deletions lib/src/endpoints.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/// Pub.dev api Endpoints
class Endpoint {
String baseUrl;
String apiUrl;
String searchUrl;
String packageUrl;
String accountUrl;
late String baseUrl;
late String apiUrl;
late String searchUrl;
late String packageUrl;
late String accountUrl;

/// Constructor for API endpoints based on an [url]
Endpoint(String url) {
Endpoint(String? url) {
baseUrl = url ?? 'https://pub.dartlang.org'; // Use pub.dev instead?
apiUrl = '$baseUrl/api';
searchUrl = '$apiUrl/search';
Expand Down
6 changes: 3 additions & 3 deletions lib/src/helpers/console_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import '../../pub_api_client.dart';
/// is not the latest version.
Future<bool> checkUpdatePrinter(
String package, {
String currentVersion,
required String currentVersion,
}) async {
final api = PubClient();
final latest = await api.checkLatest(package, currentVersion: currentVersion);
final latest =
await PubClient().checkLatest(package, currentVersion: currentVersion);
final latestVersion = latest.latestVersion;

if (latest.needUpdate) {
Expand Down
27 changes: 27 additions & 0 deletions lib/src/helpers/deps_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:async';
import 'dart:convert';

import 'package:build/build.dart';
import 'package:pub_api_client/src/helpers/google_packages.dart';

Builder googleDepsBuilder([BuilderOptions? options]) => _DepsBuilder();

class _DepsBuilder implements Builder {
@override
Future build(BuildStep buildStep) async {
final googleDeps = await getGooglePackages();
final deps = jsonEncode(googleDeps);
await buildStep.writeAsString(
AssetId(buildStep.inputId.package,
'lib/src/helpers/google_packages_list.dart'),
'''
// Generated code. Do not modify.
const googlePackagesList = $googleDeps ;
''');
}

@override
final buildExtensions = const {
r'$lib$': ['src/helpers/google_packages_list.dart']
};
}
14 changes: 5 additions & 9 deletions lib/src/helpers/google_packages.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import '../models/search_results_model.dart';
import '../pub_api_client_base.dart';
import 'google_packages_list.dart';

/// List of Google publishers on pub.dev
const _publishers = [
Expand All @@ -10,16 +9,11 @@ const _publishers = [
'firebase.google.com'
];

final _googleDependencies = {for (var v in googlePackagesList) v: true};

/// Check is [package] is from Google
bool isGooglePubPackage(String package) => _googleDependencies[package] == true;

/// Retrieves all Google packages from pub.dev
/// Mostly used as an internal tool to generate
/// google_packages_list.dart
/// You should probably use that instead
Future<List<String>> getGooglePackages() async {
Future<List<String?>> getGooglePackages() async {
final futures = <Future<List<PackageResult>>>[];
for (var publisher in _publishers) {
futures.add(getPublisherPackages(publisher));
Expand All @@ -35,11 +29,13 @@ Future<List<PackageResult>> getPublisherPackages(String publisherName) async {
}

Future<List<PackageResult>> _recursivePaging(SearchResults prevResults) async {
final packages = prevResults.packages ?? [];
final packages = prevResults.packages;
if (prevResults.next != null) {
final results = await prevResults.nextResults();
// TODO: Check why linting not working for nullable and remove ?? ''
final results = await PubClient().nextPage(prevResults.next ?? '');
final nextResults = await _recursivePaging(results);
packages.addAll(nextResults);
}

return packages;
}
59 changes: 30 additions & 29 deletions lib/src/helpers/google_packages_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const googlePackagesList = [
'video_player',
'animations',
'palette_generator',
'image_picker',
'connectivity',
'device_info',
'pointer_interceptor',
Expand All @@ -18,41 +19,40 @@ const googlePackagesList = [
'camera',
'android_intent',
'sensors',
'cross_file',
'battery',
'android_alarm_manager',
'quick_actions',
'integration_test',
'multicast_dns',
'path_provider',
'xdg_directories',
'extension_google_sign_in_as_googleapis_auth',
'multicast_dns',
'share',
'devtools',
'local_auth',
'in_app_purchase',
'cross_file',
'devtools_shared',
'xdg_directories',
'flutter_plugin_android_lifecycle',
'devtools',
'extension_google_sign_in_as_googleapis_auth',
'shared_preferences_windows',
'devtools_shared',
'file_selector',
'connectivity_for_web',
'wifi_info_flutter',
'path_provider_windows',
'url_launcher_windows',
'ios_platform_images',
'espresso',
'image_picker_for_web',
'url_launcher_windows',
'google_maps_flutter_web',
'web_benchmarks',
'ios_platform_images',
'espresso',
'file_selector_web',
'devtools_server',
'image_picker',
'devtools_app',
'quick_actions_platform_interface',
'devtools_testing',
'devtools_app',
'http',
'path',
'crypto',
'built_value',
'built_collection',
'yaml',
'googleapis',
Expand All @@ -68,50 +68,51 @@ const googlePackagesList = [
'markdown',
'protobuf',
'googleapis_auth',
'built_value_generator',
'matcher',
'typed_data',
'meta',
'typed_data',
'html',
'mockito',
'dart_style',
'grpc',
'build_runner',
'ffigen',
'test',
'build_runner',
'http2',
'mockito',
'intl_translation',
'protoc_plugin',
'native_stack_traces',
'os_detect',
'vm_snapshot_analysis',
'protoc_plugin',
'os_detect',
'test_core',
'built_value_test',
'_fe_analyzer_shared',
'ffigen',
'built_value',
'built_value_generator',
'google_fonts',
'adaptive_breakpoints',
'adaptive_navigation',
'adaptive_components',
'firebase_analytics',
'firebase_core',
'firebase_auth',
'cloud_firestore',
'firebase_dynamic_links',
'firebase_remote_config',
'firebase_ml_vision',
'cloud_functions',
'firebase_performance',
'firebase_messaging',
'firebase_remote_config',
'firebase_storage',
'firebase_analytics',
'firebase_crashlytics',
'firebase_dynamic_links',
'firebase_ml_vision',
'firebase_performance',
'firebase_database',
'firebase_in_app_messaging',
'firebase_ml_custom',
'firebase_core_web',
'firebase_messaging_web',
'firebase_auth_web',
'firebase_ml_custom',
'cloud_firestore_web',
'cloud_functions_web',
'firebase_storage_web',
'firebase_analytics_web',
'firebase_storage_web'
'firebase_core',
'cloud_firestore',
'firebase_messaging'
];
6 changes: 3 additions & 3 deletions lib/src/models/latest_version_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class LatestVersion {

/// Constructor
LatestVersion({
this.needUpdate,
this.latestVersion,
this.packageInfo,
required this.needUpdate,
required this.latestVersion,
required this.packageInfo,
});
}
16 changes: 8 additions & 8 deletions lib/src/models/package_documentation_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ part 'package_documentation_model.g.dart';

/// Package Documentation Model
@freezed
abstract class PackageDocumentation with _$PackageDocumentation {
class PackageDocumentation with _$PackageDocumentation {
factory PackageDocumentation({
final String name,
final String latestStableVersion,
final List<PackageDocumentationVersion> versions,
required final String name,
required final String latestStableVersion,
@Default([]) final List<PackageDocumentationVersion> versions,
}) = _PackageDocumentation;

factory PackageDocumentation.fromJson(Map<String, dynamic> json) =>
Expand All @@ -18,11 +18,11 @@ abstract class PackageDocumentation with _$PackageDocumentation {

/// Package Documentation Version Model
@freezed
abstract class PackageDocumentationVersion with _$PackageDocumentationVersion {
class PackageDocumentationVersion with _$PackageDocumentationVersion {
factory PackageDocumentationVersion({
final String version,
final String status,
final bool hasDocumentation,
required final String version,
required final String status,
required final bool hasDocumentation,
}) = _PackageDocumentationVersion;

factory PackageDocumentationVersion.fromJson(Map<String, dynamic> json) =>
Expand Down
Loading

0 comments on commit 911c67a

Please sign in to comment.