reduce pub output from flutter create (#118285)
* reduce pub output from flutter create * fix fake Pub implementations * fix tests * Update pub.dart * replace enum with simpler boolean * fix tests * Revert "fix tests" This reverts commit 8a3182d3b95d4f2bf337343cdb76e88c2f428ca8. * Revert "replace enum with simpler boolean" This reverts commit 445dbc443db4eb5ce284f76749f60e81208b8783. * go back to using an enum
This commit is contained in:
parent
c7a3f0fed7
commit
ee1c59d462
@ -414,6 +414,7 @@ class CreateCommand extends CreateBase {
|
||||
context: pubContext,
|
||||
project: project,
|
||||
offline: boolArgDeprecated('offline'),
|
||||
outputMode: PubOutputMode.summaryOnly,
|
||||
);
|
||||
await project.ensureReadyForPlatformSpecificTooling(
|
||||
androidPlatform: includeAndroid,
|
||||
|
@ -444,7 +444,7 @@ class UpdatePackagesCommand extends FlutterCommand {
|
||||
upgrade: doUpgrade,
|
||||
offline: boolArgDeprecated('offline'),
|
||||
flutterRootOverride: temporaryFlutterSdk?.path,
|
||||
printProgress: false,
|
||||
outputMode: PubOutputMode.none,
|
||||
);
|
||||
|
||||
if (doUpgrade) {
|
||||
@ -538,7 +538,7 @@ class UpdatePackagesCommand extends FlutterCommand {
|
||||
// All dependencies should already have been downloaded by the fake
|
||||
// package, so the concurrent checks can all happen offline.
|
||||
offline: true,
|
||||
printProgress: false,
|
||||
outputMode: PubOutputMode.none,
|
||||
);
|
||||
stopwatch.stop();
|
||||
final double seconds = stopwatch.elapsedMilliseconds / 1000.0;
|
||||
|
@ -140,6 +140,17 @@ class PubContext {
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the amount of output that should get printed from a `pub` command.
|
||||
/// [PubOutputMode.all] indicates that the complete output is printed. This is
|
||||
/// typically the default.
|
||||
/// [PubOutputMode.none] indicates that no output should be printed.
|
||||
/// [PubOutputMode.summaryOnly] indicates that only summary information should be printed.
|
||||
enum PubOutputMode {
|
||||
none,
|
||||
all,
|
||||
summaryOnly,
|
||||
}
|
||||
|
||||
/// A handle for interacting with the pub tool.
|
||||
abstract class Pub {
|
||||
/// Create a default [Pub] instance.
|
||||
@ -172,6 +183,14 @@ abstract class Pub {
|
||||
/// If [shouldSkipThirdPartyGenerator] is true, the overall pub get will be
|
||||
/// skipped if the package config file has a "generator" other than "pub".
|
||||
/// Defaults to true.
|
||||
///
|
||||
/// [outputMode] determines how verbose the output from `pub get` will be.
|
||||
/// If [PubOutputMode.all] is used, `pub get` will print its typical output
|
||||
/// which includes information about all changed dependencies. If
|
||||
/// [PubOutputMode.summaryOnly] is used, only summary information will be printed.
|
||||
/// This is useful for cases where the user is typically not interested in
|
||||
/// what dependencies were changed, such as when running `flutter create`.
|
||||
///
|
||||
/// Will also resolve dependencies in the example folder if present.
|
||||
Future<void> get({
|
||||
required PubContext context,
|
||||
@ -181,7 +200,7 @@ abstract class Pub {
|
||||
String? flutterRootOverride,
|
||||
bool checkUpToDate = false,
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all
|
||||
});
|
||||
|
||||
/// Runs pub in 'batch' mode.
|
||||
@ -221,7 +240,7 @@ abstract class Pub {
|
||||
required String command,
|
||||
bool touchesPackageConfig = false,
|
||||
bool generateSyntheticPackage = false,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all
|
||||
});
|
||||
}
|
||||
|
||||
@ -286,7 +305,7 @@ class _DefaultPub implements Pub {
|
||||
String? flutterRootOverride,
|
||||
bool checkUpToDate = false,
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all
|
||||
}) async {
|
||||
final String directory = project.directory.path;
|
||||
final File packageConfigFile = project.packageConfigFile;
|
||||
@ -358,7 +377,7 @@ class _DefaultPub implements Pub {
|
||||
directory: directory,
|
||||
failureMessage: 'pub $command failed',
|
||||
flutterRootOverride: flutterRootOverride,
|
||||
printProgress: printProgress
|
||||
outputMode: outputMode,
|
||||
);
|
||||
await _updateVersionAndPackageConfig(project);
|
||||
}
|
||||
@ -375,7 +394,7 @@ class _DefaultPub implements Pub {
|
||||
Future<void> _runWithStdioInherited(
|
||||
List<String> arguments, {
|
||||
required String command,
|
||||
required bool printProgress,
|
||||
required PubOutputMode outputMode,
|
||||
required PubContext context,
|
||||
required String directory,
|
||||
String failureMessage = 'pub failed',
|
||||
@ -384,10 +403,10 @@ class _DefaultPub implements Pub {
|
||||
int exitCode;
|
||||
|
||||
final List<String> pubCommand = _pubCommand(arguments);
|
||||
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride);
|
||||
final Map<String, String> pubEnvironment = await _createPubEnvironment(context: context, flutterRootOverride: flutterRootOverride, summaryOnly: outputMode == PubOutputMode.summaryOnly);
|
||||
|
||||
try {
|
||||
if (printProgress) {
|
||||
if (outputMode != PubOutputMode.none) {
|
||||
final io.Stdio? stdio = _stdio;
|
||||
if (stdio == null) {
|
||||
// Let pub inherit stdio and output directly to the tool's stdout and
|
||||
@ -450,8 +469,7 @@ class _DefaultPub implements Pub {
|
||||
? 'exists'
|
||||
: 'does not exist';
|
||||
buffer.writeln('Working directory: "$directory" ($directoryExistsMessage)');
|
||||
final Map<String, String> env = await _createPubEnvironment(context, flutterRootOverride);
|
||||
buffer.write(_stringifyPubEnv(env));
|
||||
buffer.write(_stringifyPubEnv(pubEnvironment));
|
||||
throw io.ProcessException(
|
||||
exception.executable,
|
||||
exception.arguments,
|
||||
@ -517,7 +535,7 @@ class _DefaultPub implements Pub {
|
||||
if (showTraceForErrors) {
|
||||
arguments.insert(0, '--trace');
|
||||
}
|
||||
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride);
|
||||
final Map<String, String> pubEnvironment = await _createPubEnvironment(context: context, flutterRootOverride: flutterRootOverride);
|
||||
final List<String> pubCommand = _pubCommand(arguments);
|
||||
final int code = await _processUtils.stream(
|
||||
pubCommand,
|
||||
@ -557,14 +575,14 @@ class _DefaultPub implements Pub {
|
||||
required String command,
|
||||
bool touchesPackageConfig = false,
|
||||
bool generateSyntheticPackage = false,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all
|
||||
}) async {
|
||||
await _runWithStdioInherited(
|
||||
arguments,
|
||||
command: command,
|
||||
directory: _fileSystem.currentDirectory.path,
|
||||
context: context,
|
||||
printProgress: printProgress,
|
||||
outputMode: outputMode,
|
||||
);
|
||||
if (touchesPackageConfig && project != null) {
|
||||
await _updateVersionAndPackageConfig(project);
|
||||
@ -697,10 +715,15 @@ class _DefaultPub implements Pub {
|
||||
///
|
||||
/// [context] provides extra information to package server requests to
|
||||
/// understand usage.
|
||||
Future<Map<String, String>> _createPubEnvironment(PubContext context, [ String? flutterRootOverride ]) async {
|
||||
Future<Map<String, String>> _createPubEnvironment({
|
||||
required PubContext context,
|
||||
String? flutterRootOverride,
|
||||
bool? summaryOnly = false,
|
||||
}) async {
|
||||
final Map<String, String> environment = <String, String>{
|
||||
'FLUTTER_ROOT': flutterRootOverride ?? Cache.flutterRoot!,
|
||||
_kPubEnvironmentKey: await _getPubEnvironmentValue(context),
|
||||
if (summaryOnly ?? false) 'PUB_SUMMARY_ONLY': '1',
|
||||
};
|
||||
final String? pubCache = _getPubCacheIfAvailable();
|
||||
if (pubCache != null) {
|
||||
|
@ -36,7 +36,7 @@ class FakePub extends Fake implements Pub {
|
||||
String? flutterRootOverride,
|
||||
bool checkUpToDate = false,
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) async {
|
||||
project.directory.childFile('.packages').createSync();
|
||||
if (offline == true) {
|
||||
|
@ -486,7 +486,7 @@ class FakePub extends Fake implements Pub {
|
||||
String? flutterRootOverride,
|
||||
bool checkUpToDate = false,
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) async { }
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ class FakePub extends Fake implements Pub {
|
||||
required String command,
|
||||
bool touchesPackageConfig = false,
|
||||
bool generateSyntheticPackage = false,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) async {
|
||||
if (project != null) {
|
||||
fileSystem.directory(project.directory)
|
||||
|
@ -282,7 +282,7 @@ class FakePub extends Fake implements Pub {
|
||||
String? flutterRootOverride,
|
||||
bool checkUpToDate = false,
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) async {
|
||||
pubGetDirectories.add(project.directory.path);
|
||||
project.directory.childFile('pubspec.lock')
|
||||
|
@ -1215,6 +1215,7 @@ class FakePub extends Fake implements Pub {
|
||||
bool checkUpToDate = false,
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) async {
|
||||
calledGet += 1;
|
||||
}
|
||||
|
@ -676,7 +676,7 @@ exit code: 66
|
||||
await pub.get(
|
||||
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
|
||||
context: PubContext.flutterTests,
|
||||
printProgress: false
|
||||
outputMode: PubOutputMode.none,
|
||||
);
|
||||
} on ToolExit {
|
||||
// Ignore.
|
||||
|
@ -956,7 +956,7 @@ class FakePub extends Fake implements Pub {
|
||||
String? flutterRootOverride,
|
||||
bool checkUpToDate = false,
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) async { }
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ class ThrowingPub implements Pub {
|
||||
String? flutterRootOverride,
|
||||
bool checkUpToDate = false,
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) {
|
||||
throw UnsupportedError('Attempted to invoke pub during test.');
|
||||
}
|
||||
@ -42,7 +42,7 @@ class ThrowingPub implements Pub {
|
||||
required String command,
|
||||
bool touchesPackageConfig = false,
|
||||
bool generateSyntheticPackage = false,
|
||||
bool printProgress = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) {
|
||||
throw UnsupportedError('Attempted to invoke pub during test.');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user