Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/flutterfire_cli/lib/src/common/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ class Package {
late final bool isFlutterPackage = dependencies.contains('flutter') ||
dependencies.contains('flutter_localizations');

/// Returns whether this package is compatible with Flutter plugins, even
/// if it doesn't depend on the Flutter SDK directly.
///
/// This is currently only true for packages that depend on Jaspr.
late final bool isFlutterCompatiblePackage = dependencies.contains('jaspr');

/// Returns whether this package is a Flutter app.
/// This is determined by ensuring all the following conditions are met:
/// a) the package depends on the Flutter SDK.
/// a) the package depends on the Flutter SDK or is a Flutter compatible package.
/// b) the package does not define itself as a Flutter plugin inside pubspec.yaml.
/// c) a lib/main.dart file exists in the package.
bool get isFlutterApp {
// Must directly depend on the Flutter SDK.
if (!isFlutterPackage) return false;
// Must directly depend on the Flutter SDK or be a Flutter compatible package.
if (!isFlutterPackage && !isFlutterCompatiblePackage) return false;

// Must not have a Flutter plugin definition in it's pubspec.yaml.
if (isFlutterPlugin) return false;
Expand Down
112 changes: 112 additions & 0 deletions packages/flutterfire_cli/test/unit_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:convert';

import 'package:flutterfire_cli/src/common/package.dart';
import 'package:flutterfire_cli/src/common/strings.dart';
import 'package:flutterfire_cli/src/common/utils.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:test/test.dart';

void main() {
Expand Down Expand Up @@ -233,4 +235,114 @@ void main() {
});
},
);

group('Package class', () {
test(
'isFlutterPackage returns true if depends on flutter or flutter_localizations',
() {
final package1 = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
flutter:
sdk: flutter
'''),
);
expect(package1.isFlutterPackage, isTrue);

final package2 = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
flutter_localizations:
sdk: flutter
'''),
);
expect(package2.isFlutterPackage, isTrue);

final package3 = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
http: ^0.13.0
'''),
);
expect(package3.isFlutterPackage, isFalse);
});

test('isFlutterCompatiblePackage returns true if depends on jaspr', () {
final package1 = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
jaspr: ^0.23.0
'''),
);
expect(package1.isFlutterCompatiblePackage, isTrue);

final package2 = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
http: ^0.13.0
'''),
);
expect(package2.isFlutterCompatiblePackage, isFalse);
});

test(
'isFlutterApp returns correctly based on dependencies and plugin definition',
() {
final flutterApp = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
flutter:
sdk: flutter
'''),
);
expect(flutterApp.isFlutterApp, isTrue);

final jasprApp = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
jaspr: ^0.1.0
'''),
);
expect(jasprApp.isFlutterApp, isTrue);

final dartApp = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
http: ^0.13.0
'''),
);
expect(dartApp.isFlutterApp, isFalse);

final flutterPlugin = Package(
path: '',
pubSpec: Pubspec.parse('''
name: test_pkg
dependencies:
flutter:
sdk: flutter
flutter:
plugin:
platforms:
android:
'''),
);
expect(flutterPlugin.isFlutterApp, isFalse);
});
});
}
Loading