3
3
// found in the LICENSE file.
4
4
5
5
import 'dart:async' ;
6
+ import 'dart:io' as io;
6
7
7
8
import 'package:colorize/colorize.dart' ;
8
9
import 'package:file/file.dart' ;
@@ -63,6 +64,44 @@ class PublishCheckCommand extends PluginCommand {
63
64
}
64
65
}
65
66
67
+ Future <bool > hasValidPublishCheckRun (Directory package) async {
68
+ final io.Process process = await io.Process .start (
69
+ 'flutter' ,
70
+ < String > ['pub' , 'publish' , '--' , '--dry-run' ],
71
+ workingDirectory: package.path,
72
+ );
73
+
74
+ final StringBuffer outputBuffer = StringBuffer ();
75
+
76
+ final Completer <void > stdOutCompleter = Completer <void >();
77
+ process.stdout.listen (
78
+ (List <int > event) {
79
+ io.stdout.add (event);
80
+ outputBuffer.write (String .fromCharCodes (event));
81
+ },
82
+ onDone: () => stdOutCompleter.complete (),
83
+ );
84
+
85
+ final Completer <void > stdInCompleter = Completer <void >();
86
+ process.stderr.listen (
87
+ (List <int > event) {
88
+ io.stderr.add (event);
89
+ outputBuffer.write (String .fromCharCodes (event));
90
+ },
91
+ onDone: () => stdInCompleter.complete (),
92
+ );
93
+
94
+ if (await process.exitCode == 0 ) return true ;
95
+
96
+ await stdOutCompleter.future;
97
+ await stdInCompleter.future;
98
+
99
+ final String output = outputBuffer.toString ();
100
+ return output.contains ('Package has 1 warning.' ) &&
101
+ output.contains (
102
+ 'Packages with an SDK constraint on a pre-release of the Dart SDK should themselves be published as a pre-release version.' );
103
+ }
104
+
66
105
Future <bool > passesPublishCheck (Directory package) async {
67
106
final String packageName = package.basename;
68
107
print ('Checking that $packageName can be published.' );
@@ -75,13 +114,7 @@ class PublishCheckCommand extends PluginCommand {
75
114
return true ;
76
115
}
77
116
78
- final int exitCode = await processRunner.runAndStream (
79
- 'flutter' ,
80
- < String > ['pub' , 'publish' , '--' , '--dry-run' ],
81
- workingDir: package,
82
- );
83
-
84
- if (exitCode == 0 ) {
117
+ if (await hasValidPublishCheckRun (package)) {
85
118
print ("Package $packageName is able to be published." );
86
119
return true ;
87
120
} else {
0 commit comments