mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 17:28:42 +08:00
[flutter_plugin_tools] Introduce a class for packages (#4252)
Packages are the primary conceptual object in the tool, but currently they are represented simply as Directory (or occasionally a path string). This introduces an object for packages and: - moves a number of existing utility methods into it - sweeps the code for the obvious cases of using `Directory` to represent a package, especially in method signatures and migrates them - notes a few places where we should migrate later, to avoid ballooning the size of the PR There are no doubt other cases not caught in the sweep, but this gives us a foundation both for new code, and to migrate incrementally toward as we find existing code that was missed.
This commit is contained in:
@ -16,6 +16,7 @@ import 'common/core.dart';
|
||||
import 'common/package_looping_command.dart';
|
||||
import 'common/process_runner.dart';
|
||||
import 'common/pub_version_finder.dart';
|
||||
import 'common/repository_package.dart';
|
||||
|
||||
/// A command to check that packages are publishable via 'dart publish'.
|
||||
class PublishCheckCommand extends PackageLoopingCommand {
|
||||
@ -75,7 +76,7 @@ class PublishCheckCommand extends PackageLoopingCommand {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PackageResult> runForPackage(Directory package) async {
|
||||
Future<PackageResult> runForPackage(RepositoryPackage package) async {
|
||||
final _PublishCheckResult? result = await _passesPublishCheck(package);
|
||||
if (result == null) {
|
||||
return PackageResult.skip('Package is marked as unpublishable.');
|
||||
@ -114,8 +115,8 @@ class PublishCheckCommand extends PackageLoopingCommand {
|
||||
}
|
||||
}
|
||||
|
||||
Pubspec? _tryParsePubspec(Directory package) {
|
||||
final File pubspecFile = package.childFile('pubspec.yaml');
|
||||
Pubspec? _tryParsePubspec(RepositoryPackage package) {
|
||||
final File pubspecFile = package.pubspecFile;
|
||||
|
||||
try {
|
||||
return Pubspec.parse(pubspecFile.readAsStringSync());
|
||||
@ -127,12 +128,12 @@ class PublishCheckCommand extends PackageLoopingCommand {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _hasValidPublishCheckRun(Directory package) async {
|
||||
Future<bool> _hasValidPublishCheckRun(RepositoryPackage package) async {
|
||||
print('Running pub publish --dry-run:');
|
||||
final io.Process process = await processRunner.start(
|
||||
flutterCommand,
|
||||
<String>['pub', 'publish', '--', '--dry-run'],
|
||||
workingDirectory: package,
|
||||
workingDirectory: package.directory,
|
||||
);
|
||||
|
||||
final StringBuffer outputBuffer = StringBuffer();
|
||||
@ -183,8 +184,9 @@ class PublishCheckCommand extends PackageLoopingCommand {
|
||||
|
||||
/// Returns the result of the publish check, or null if the package is marked
|
||||
/// as unpublishable.
|
||||
Future<_PublishCheckResult?> _passesPublishCheck(Directory package) async {
|
||||
final String packageName = package.basename;
|
||||
Future<_PublishCheckResult?> _passesPublishCheck(
|
||||
RepositoryPackage package) async {
|
||||
final String packageName = package.directory.basename;
|
||||
final Pubspec? pubspec = _tryParsePubspec(package);
|
||||
if (pubspec == null) {
|
||||
print('no pubspec');
|
||||
@ -219,7 +221,7 @@ class PublishCheckCommand extends PackageLoopingCommand {
|
||||
Future<_PublishCheckResult> _checkPublishingStatus(
|
||||
{required String packageName, required Version? version}) async {
|
||||
final PubVersionFinderResponse pubVersionFinderResponse =
|
||||
await _pubVersionFinder.getPackageVersion(package: packageName);
|
||||
await _pubVersionFinder.getPackageVersion(packageName: packageName);
|
||||
switch (pubVersionFinderResponse.result) {
|
||||
case PubVersionFinderResult.success:
|
||||
return pubVersionFinderResponse.versions.contains(version)
|
||||
|
Reference in New Issue
Block a user