1+ import 'dart:convert' ;
12import 'dart:io' ;
23
4+ import 'package:async/async.dart' ;
35import 'package:celest_cli/src/context.dart' ;
46import 'package:celest_cli/src/pub/project_dependency.dart' ;
57import 'package:celest_cli/src/sdk/dart_sdk.dart' ;
68import 'package:celest_cli/src/utils/process.dart' ;
79import 'package:collection/collection.dart' ;
10+ import 'package:crypto/crypto.dart' ;
811import 'package:file/file.dart' ;
912import 'package:logging/logging.dart' ;
1013import 'package:meta/meta.dart' ;
@@ -22,12 +25,19 @@ final class PubCache {
2225 // This is the only syntax that reliably works with both dart/flutter
2326 'native_storage' : '>=0.2.2 <1.0.0' ,
2427 'native_authentication' : '>=0.1.0 <1.0.0' ,
25- 'jni' : '>=0.11 .0 <1.0 .0' ,
28+ 'jni' : '>=0.14 .0 <0.15 .0' ,
2629 'celest_auth' : '>=$currentMinorVersion <2.0.0' ,
2730 'celest' : '>=$currentMinorVersion <2.0.0' ,
2831 'celest_core' : '>=$currentMinorVersion <2.0.0' ,
29- 'objective_c' : '>=2 .0.0 <8.0.0' ,
32+ 'objective_c' : '>=7 .0.0 <8.0.0' ,
3033 };
34+
35+ /// MD5 hash of the [packagesToFix] map.
36+ static final String packagesToFixDigest = () {
37+ final pubCacheFixJson = JsonUtf8Encoder ().convert (PubCache .packagesToFix);
38+ return md5.convert (pubCacheFixJson).toString ();
39+ }();
40+
3141 static final _logger = Logger ('PubCache' );
3242
3343 String ? _cachePath;
@@ -96,44 +106,66 @@ final class PubCache {
96106 /// Runs `pub cache add` for each package in [packagesToFix] .
97107 ///
98108 /// Returns the exit codes and output for each package.
99- Future <List <(int , String )>> hydrate () async {
100- final results = < (int , String )> [];
101- for (final package in packagesToFix.entries) {
102- // Run serially to avoid flutter lock
103- final result = await processManager.start (runInShell: true , [
104- Sdk .current.sdkType.name,
109+ Future <Result <void >> hydrate () async {
110+ Future <void > hydratePackage (String name, String constraint) async {
111+ final command = [
112+ Sdk .current.dart,
105113 'pub' ,
106114 'cache' ,
107115 'add' ,
108- package.key ,
116+ name ,
109117 '--version' ,
110- package.value ,
118+ constraint ,
111119 '--all' ,
112- ]).then ((process) async {
113- final combinedOutput = StringBuffer ();
114- process.captureStdout (
115- sink: (line) {
116- _logger.finest (line);
117- combinedOutput.writeln (line);
118- },
119- );
120- process.captureStderr (
121- sink: (line) {
122- _logger.finest (line);
123- combinedOutput.writeln (line);
124- },
120+ ];
121+ final process = await processManager.start (command, runInShell: true );
122+ final combinedOutput = StringBuffer ();
123+ process.captureStdout (
124+ sink: (line) {
125+ _logger.finest (line);
126+ combinedOutput.writeln (line);
127+ },
128+ );
129+ process.captureStderr (
130+ sink: (line) {
131+ _logger.finest (line);
132+ combinedOutput.writeln (line);
133+ },
134+ );
135+ if (await process.exitCode case final exitCode && != 0 ) {
136+ throw ProcessException (
137+ command.first,
138+ command.sublist (1 ),
139+ combinedOutput.toString (),
140+ exitCode,
125141 );
126- return (await process.exitCode, combinedOutput.toString ());
127- });
128- results.add (result);
142+ }
143+ }
144+
145+ final hydrations = < Future <void >> [];
146+ for (final package in packagesToFix.entries) {
147+ hydrations.add (hydratePackage (package.key, package.value));
148+ }
149+ final results = await Result .captureAll (hydrations);
150+
151+ var failed = false ;
152+ final errors = < Object > [];
153+ for (final result in results) {
154+ if (result.isError) {
155+ failed = true ;
156+ errors.add (result.asError! .error);
157+ }
158+ }
159+ if (failed) {
160+ return Result .error (ParallelWaitError (< Object ? > [], errors));
129161 }
130- return results ;
162+ return Result . value ( null ) ;
131163 }
132164
133165 /// Fixes the pubspec for each package in [packagesToFix] .
134166 ///
135167 /// Returns the number of packages fixed.
136- Future <int > fix ({@visibleForTesting bool throwOnError = false }) async {
168+ Future <int > fix ({bool throwOnError = false }) async {
137169 final cachePath = _cachePath ?? = findCachePath ();
138170 if (cachePath == null ) {
139171 if (throwOnError) {
0 commit comments