Skip to content

Commit 558714a

Browse files
authored
pub command: allow any subcommand+args, prints a summary while executing (#330)
1 parent 23c8203 commit 558714a

File tree

4 files changed

+41
-75
lines changed

4 files changed

+41
-75
lines changed

mono_repo/CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
## 4.1.0-dev
22

33
- Improve the stability of ordering in Github workflow definitions.
4-
- Drop `--no-precompile` as the default for `pub` `get` and `upgrade` commands.
5-
It's now the default across Dart tools.
64
- Use latest `actions/cache@v2.1.6`.
7-
- Migrate to new command pattern supported in Dart 2.10+
5+
- Migrate to new command pattern supported in Dart 2.10
6+
- `pub` command
7+
- Now allows any `pub` command and argument combination to be provided.
8+
- Dropped `--no-precompile` since it is now the default.
9+
- Now prints a summary of execution progress. Useful for repositories with
10+
many packages.
811

912
## 4.0.0
1013

mono_repo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Available commands:
3535
check Check the state of the repository.
3636
generate Generates the CI configuration for child packages.
3737
presubmit Run the CI presubmits locally.
38-
pub Run `dart pub get` or `dart pub upgrade` against all packages.
38+
pub Runs the `pub` command with the provided arguments across all packages.
3939
travis (Deprecated, use `generate`) Configure Travis-CI for child packages.
4040
4141
Run "mono_repo help <command>" for more information about a command.

mono_repo/lib/src/commands/pub.dart

Lines changed: 33 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,114 +5,60 @@
55
import 'dart:async';
66
import 'dart:io';
77

8-
import 'package:args/command_runner.dart';
8+
import 'package:args/args.dart';
99
import 'package:io/ansi.dart';
1010
import 'package:path/path.dart' as p;
1111

1212
import '../root_config.dart';
1313
import 'mono_repo_command.dart';
1414

15-
class PubCommand extends Command<void> {
16-
PubCommand() {
17-
addSubcommand(_PubSubCommand('get'));
18-
addSubcommand(_PubSubCommand('upgrade'));
19-
}
15+
class PubCommand extends MonoRepoCommand {
16+
@override
17+
final ArgParser argParser = ArgParser.allowAnything();
2018

2119
@override
2220
String get name => 'pub';
2321

2422
@override
2523
String get description =>
26-
'Run `dart pub get` or `dart pub upgrade` against all packages.';
27-
}
28-
29-
const _offline = 'offline';
30-
const _dryRun = 'dry-run';
31-
const _precompile = 'precompile';
32-
33-
class _PubSubCommand extends MonoRepoCommand {
34-
@override
35-
final String name;
36-
37-
_PubSubCommand(this.name) {
38-
argParser
39-
..addFlag(
40-
_offline,
41-
help: 'Use cached packages instead of accessing the network.',
42-
)
43-
..addFlag(
44-
_dryRun,
45-
abbr: 'n',
46-
negatable: false,
47-
help: "Report what dependencies would change but don't change any.",
48-
)
49-
..addFlag(
50-
_precompile,
51-
help: 'Precompile executables and transformed dependencies.',
52-
);
53-
}
54-
55-
@override
56-
String get description => 'Run `dart pub $name` against all packages.';
24+
'Runs the `pub` command with the provided arguments across all packages.';
5725

5826
@override
5927
Future<void> run() => pub(
6028
rootConfig(),
61-
name,
62-
offline: argResults![_offline] as bool,
63-
dryRun: argResults![_dryRun] as bool,
64-
preCompile: argResults![_precompile] as bool,
29+
argResults?.rest ?? const [],
6530
);
6631
}
6732

68-
Future<void> pub(
69-
RootConfig rootConfig,
70-
String pubCommand, {
71-
required bool offline,
72-
required bool dryRun,
73-
required bool preCompile,
74-
}) async {
33+
Future<void> pub(RootConfig rootConfig, List<String> args) async {
7534
final pkgDirs = rootConfig.map((pc) => pc.relativePath).toList();
7635

77-
// TODO(kevmoo): use UI-as-code features when min SDK is >= 2.3.0
78-
final args = [pubCommand];
79-
if (offline) {
80-
args.add('--$_offline');
81-
}
82-
83-
if (dryRun) {
84-
args.add('--$_dryRun');
85-
}
86-
87-
// Note: the default is `false`
88-
if (preCompile) {
89-
args.add('--$_precompile');
90-
}
91-
9236
print(
9337
lightBlue.wrap(
9438
'Running `dart pub ${args.join(' ')}` across ${pkgDirs.length} '
9539
'package(s).',
9640
),
9741
);
9842

43+
final packageArgs = ['pub', ...args];
44+
45+
var successCount = 0;
46+
final failSet = <String>{};
47+
9948
for (var config in rootConfig) {
10049
final dir = config.relativePath;
101-
List<String> packageArgs;
10250
String executable;
10351

10452
if (config.hasFlutterDependency) {
10553
executable = _flutterPath;
106-
packageArgs = ['packages', ...args];
10754
} else {
108-
executable = _pubPath;
109-
packageArgs = args;
55+
executable = _dartPath;
11056
}
11157

11258
print('');
11359
print(
11460
wrapWith(
115-
'Starting `$executable ${packageArgs.join(' ')}` in `$dir`...',
61+
'`$dir`: Starting `$executable ${packageArgs.join(' ')}`',
11662
[styleBold, lightBlue],
11763
),
11864
);
@@ -124,10 +70,27 @@ Future<void> pub(
12470
final exit = await proc.exitCode;
12571

12672
if (exit == 0) {
73+
successCount++;
12774
print(wrapWith('`$dir`: success!', [styleBold, green]));
12875
} else {
76+
failSet.add(dir);
12977
print(wrapWith('`$dir`: failed!', [styleBold, red]));
13078
}
79+
80+
if (rootConfig.length > 1) {
81+
print('');
82+
print('Successes: $successCount');
83+
if (failSet.isNotEmpty) {
84+
print(
85+
'Failures: ${failSet.length}\n'
86+
'${failSet.map((e) => ' $e').join('\n')}',
87+
);
88+
}
89+
final remaining = rootConfig.length - (successCount + failSet.length);
90+
if (remaining > 0) {
91+
print('Remaining: $remaining');
92+
}
93+
}
13194
}
13295
}
13396

@@ -140,8 +103,8 @@ final String _sdkDir = (() {
140103
return aboveExecutable;
141104
})();
142105

143-
final String _pubPath =
144-
p.join(_sdkDir, 'bin', Platform.isWindows ? 'pub.bat' : 'pub');
106+
final String _dartPath =
107+
p.join(_sdkDir, 'bin', Platform.isWindows ? 'dart.bat' : 'dart');
145108

146109
/// The "flutter[.bat]" command.
147110
final String _flutterPath = Platform.isWindows ? 'flutter.bat' : 'flutter';

mono_repo/test/mono_repo_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Available commands:
4444
check Check the state of the repository.
4545
generate Generates the CI configuration for child packages.
4646
presubmit Run the CI presubmits locally.
47-
pub Run `dart pub get` or `dart pub upgrade` against all packages.
47+
pub Runs the `pub` command with the provided arguments across all packages.
4848
travis (Deprecated, use `generate`) Configure Travis-CI for child packages.
4949
5050
Run "mono_repo help <command>" for more information about a command.''';

0 commit comments

Comments
 (0)