@@ -120,7 +120,10 @@ class PubContext {
120120 static final PubContext interactive = PubContext ._(< String > ['interactive' ]);
121121 static final PubContext pubGet = PubContext ._(< String > ['get' ]);
122122 static final PubContext pubUpgrade = PubContext ._(< String > ['upgrade' ]);
123+ static final PubContext pubAdd = PubContext ._(< String > ['add' ]);
124+ static final PubContext pubRemove = PubContext ._(< String > ['remove' ]);
123125 static final PubContext pubForward = PubContext ._(< String > ['forward' ]);
126+ static final PubContext pubPassThrough = PubContext ._(< String > ['passthrough' ]);
124127 static final PubContext runTest = PubContext ._(< String > ['run_test' ]);
125128 static final PubContext flutterTests = PubContext ._(< String > ['flutter_tests' ]);
126129 static final PubContext updatePackages = PubContext ._(< String > ['update_packages' ]);
@@ -161,7 +164,7 @@ abstract class Pub {
161164 required Stdio stdio,
162165 }) = _DefaultPub .test;
163166
164- /// Runs `pub get` or `pub upgrade` for [project] .
167+ /// Runs `pub get` for [project] .
165168 ///
166169 /// [context] provides extra information to package server requests to
167170 /// understand usage.
@@ -173,7 +176,6 @@ abstract class Pub {
173176 Future <void > get ({
174177 required PubContext context,
175178 required FlutterProject project,
176- bool skipIfAbsent = false ,
177179 bool upgrade = false ,
178180 bool offline = false ,
179181 String ? flutterRootOverride,
@@ -203,14 +205,23 @@ abstract class Pub {
203205
204206 /// Runs pub in 'interactive' mode.
205207 ///
206- /// directly piping the stdin stream of this process to that of pub, and the
207- /// stdout/stderr stream of pub to the corresponding streams of this process.
208+ /// This will run the pub process with StdioInherited (unless [_stdio] is set
209+ /// for testing).
210+ ///
211+ /// The pub process will be run in current working directory, so `--directory`
212+ /// should be passed appropriately in [arguments] . This ensures output from
213+ /// pub will refer to relative paths correctly.
214+ ///
215+ /// [touchesPackageConfig] should be true if this is a command expexted to
216+ /// create a new `.dart_tool/package_config.json` file.
208217 Future <void > interactively (
209218 List <String > arguments, {
210- String ? directory,
211- required io.Stdio stdio,
219+ FlutterProject ? project,
220+ required PubContext context,
221+ required String command,
212222 bool touchesPackageConfig = false ,
213223 bool generateSyntheticPackage = false ,
224+ bool printProgress = true ,
214225 });
215226}
216227
@@ -268,7 +279,6 @@ class _DefaultPub implements Pub {
268279 Future <void > get ({
269280 required PubContext context,
270281 required FlutterProject project,
271- bool skipIfAbsent = false ,
272282 bool upgrade = false ,
273283 bool offline = false ,
274284 bool generateSyntheticPackage = false ,
@@ -280,8 +290,6 @@ class _DefaultPub implements Pub {
280290 }) async {
281291 final String directory = project.directory.path;
282292 final File packageConfigFile = project.packageConfigFile;
283- final Directory generatedDirectory = _fileSystem.directory (
284- _fileSystem.path.join (directory, '.dart_tool' , 'flutter_gen' ));
285293 final File lastVersion = _fileSystem.file (
286294 _fileSystem.path.join (directory, '.dart_tool' , 'version' ));
287295 final File currentVersion = _fileSystem.file (
@@ -352,25 +360,7 @@ class _DefaultPub implements Pub {
352360 flutterRootOverride: flutterRootOverride,
353361 printProgress: printProgress
354362 );
355-
356- if (! packageConfigFile.existsSync ()) {
357- throwToolExit ('$directory : pub did not create .dart_tools/package_config.json file.' );
358- }
359- lastVersion.writeAsStringSync (currentVersion.readAsStringSync ());
360- await _updatePackageConfig (
361- packageConfigFile,
362- generatedDirectory,
363- project.manifest.generateSyntheticPackage,
364- );
365- if (project.hasExampleApp && project.example.pubspecFile.existsSync ()) {
366- final Directory exampleGeneratedDirectory = _fileSystem.directory (
367- _fileSystem.path.join (project.example.directory.path, '.dart_tool' , 'flutter_gen' ));
368- await _updatePackageConfig (
369- project.example.packageConfigFile,
370- exampleGeneratedDirectory,
371- project.example.manifest.generateSyntheticPackage,
372- );
373- }
363+ await _updateVersionAndPackageConfig (project);
374364 }
375365
376366 /// Runs pub with [arguments] and [ProcessStartMode.inheritStdio] mode.
@@ -392,9 +382,6 @@ class _DefaultPub implements Pub {
392382 String ? flutterRootOverride,
393383 }) async {
394384 int exitCode;
395- if (printProgress) {
396- _logger.printStatus ('Running "flutter pub $command " in ${_fileSystem .path .basename (directory )}...' );
397- }
398385
399386 final List <String > pubCommand = _pubCommand (arguments);
400387 final Map <String , String > pubEnvironment = await _createPubEnvironment (context, flutterRootOverride);
@@ -567,64 +554,22 @@ class _DefaultPub implements Pub {
567554 @override
568555 Future <void > interactively (
569556 List <String > arguments, {
570- String ? directory,
571- required io.Stdio stdio,
557+ FlutterProject ? project,
558+ required PubContext context,
559+ required String command,
572560 bool touchesPackageConfig = false ,
573561 bool generateSyntheticPackage = false ,
562+ bool printProgress = true ,
574563 }) async {
575- // Fully resolved pub or pub.bat is calculated based on current platform.
576- final io.Process process = await _processUtils.start (
577- _pubCommand (< String > [
578- if (_logger.supportsColor) '--color' ,
579- ...arguments,
580- ]),
581- workingDirectory: directory,
582- environment: await _createPubEnvironment (PubContext .interactive),
564+ await _runWithStdioInherited (
565+ arguments,
566+ command: command,
567+ directory: _fileSystem.currentDirectory.path,
568+ context: context,
569+ printProgress: printProgress,
583570 );
584-
585- // Pipe the Flutter tool stdin to the pub stdin.
586- unawaited (process.stdin.addStream (stdio.stdin)
587- // If pub exits unexpectedly with an error, that will be reported below
588- // by the tool exit after the exit code check.
589- .catchError ((dynamic err, StackTrace stack) {
590- _logger.printTrace ('Echoing stdin to the pub subprocess failed:' );
591- _logger.printTrace ('$err \n $stack ' );
592- }
593- ));
594-
595- // Pipe the pub stdout and stderr to the tool stdout and stderr.
596- try {
597- await Future .wait <dynamic >(< Future <dynamic >> [
598- stdio.addStdoutStream (process.stdout),
599- stdio.addStderrStream (process.stderr),
600- ]);
601- } on Exception catch (err, stack) {
602- _logger.printTrace ('Echoing stdout or stderr from the pub subprocess failed:' );
603- _logger.printTrace ('$err \n $stack ' );
604- }
605-
606- // Wait for pub to exit.
607- final int code = await process.exitCode;
608- if (code != 0 ) {
609- throwToolExit ('pub finished with exit code $code ' , exitCode: code);
610- }
611-
612- if (touchesPackageConfig) {
613- final String targetDirectory = directory ?? _fileSystem.currentDirectory.path;
614- final File packageConfigFile = _fileSystem.file (
615- _fileSystem.path.join (targetDirectory, '.dart_tool' , 'package_config.json' ));
616- final Directory generatedDirectory = _fileSystem.directory (
617- _fileSystem.path.join (targetDirectory, '.dart_tool' , 'flutter_gen' ));
618- final File lastVersion = _fileSystem.file (
619- _fileSystem.path.join (targetDirectory, '.dart_tool' , 'version' ));
620- final File currentVersion = _fileSystem.file (
621- _fileSystem.path.join (Cache .flutterRoot! , 'version' ));
622- lastVersion.writeAsStringSync (currentVersion.readAsStringSync ());
623- await _updatePackageConfig (
624- packageConfigFile,
625- generatedDirectory,
626- generateSyntheticPackage,
627- );
571+ if (touchesPackageConfig && project != null ) {
572+ await _updateVersionAndPackageConfig (project);
628573 }
629574 }
630575
@@ -766,23 +711,46 @@ class _DefaultPub implements Pub {
766711 return environment;
767712 }
768713
769- /// Update the package configuration file.
714+ /// Updates the .dart_tool/version file to be equal to current Flutter
715+ /// version.
716+ ///
717+ /// Calls [_updatePackageConfig] for [project] and [project.example] (if it
718+ /// exists).
719+ ///
720+ /// This should be called after pub invocations that are expected to update
721+ /// the packageConfig.
722+ Future <void > _updateVersionAndPackageConfig (FlutterProject project) async {
723+ if (! project.packageConfigFile.existsSync ()) {
724+ throwToolExit ('${project .directory }: pub did not create .dart_tools/package_config.json file.' );
725+ }
726+ final File lastVersion = _fileSystem.file (
727+ _fileSystem.path.join (project.directory.path, '.dart_tool' , 'version' ),
728+ );
729+ final File currentVersion = _fileSystem.file (
730+ _fileSystem.path.join (Cache .flutterRoot! , 'version' ));
731+ lastVersion.writeAsStringSync (currentVersion.readAsStringSync ());
732+
733+ await _updatePackageConfig (project);
734+ if (project.hasExampleApp && project.example.pubspecFile.existsSync ()) {
735+ await _updatePackageConfig (project.example);
736+ }
737+ }
738+
739+ /// Update the package configuration file in [project] .
770740 ///
771- /// Creates a corresponding `package_config_subset` file that is used by the build
772- /// system to avoid rebuilds caused by an updated pub timestamp.
741+ /// Creates a corresponding `package_config_subset` file that is used by the
742+ /// build system to avoid rebuilds caused by an updated pub timestamp.
773743 ///
774- /// if [generateSyntheticPackage] is true then insert flutter_gen synthetic
775- /// package into the package configuration. This is used by the l10n localization
776- /// tooling to insert a new reference into the package_config file, allowing the import
777- /// of a package URI that is not specified in the pubspec.yaml
744+ /// if `project.generateSyntheticPackage` is `true` then insert flutter_gen
745+ /// synthetic package into the package configuration. This is used by the l10n
746+ /// localization tooling to insert a new reference into the package_config
747+ /// file, allowing the import of a package URI that is not specified in the
748+ /// pubspec.yaml
778749 ///
779750 /// For more information, see:
780751 /// * [generateLocalizations] , `in lib/src/localizations/gen_l10n.dart`
781- Future <void > _updatePackageConfig (
782- File packageConfigFile,
783- Directory generatedDirectory,
784- bool generateSyntheticPackage,
785- ) async {
752+ Future <void > _updatePackageConfig (FlutterProject project) async {
753+ final File packageConfigFile = project.packageConfigFile;
786754 final PackageConfig packageConfig = await loadPackageConfigWithLogging (packageConfigFile, logger: _logger);
787755
788756 packageConfigFile.parent
@@ -792,7 +760,7 @@ class _DefaultPub implements Pub {
792760 _fileSystem,
793761 ));
794762
795- if (! generateSyntheticPackage) {
763+ if (! project.manifest. generateSyntheticPackage) {
796764 return ;
797765 }
798766 if (packageConfig.packages.any ((Package package) => package.name == 'flutter_gen' )) {
0 commit comments