diff --git a/bin/link.dart b/bin/link.dart index 86e5676..01e451d 100644 --- a/bin/link.dart +++ b/bin/link.dart @@ -31,7 +31,8 @@ Future linkDependencies( project.resolveWithCommand(Command(['pub', 'get', '--offline'])); if (resolved.exclude) return; - final flutterVersionOverride = resolved.getFlutterVersionOverride(); + final flutterVersionOverride = + await resolved.getFlutterVersionOverride(); final entry = Entrypoint(resolved.path, _pubCache); try { diff --git a/bin/projects.dart b/bin/projects.dart index 0716081..ec0c2ef 100644 --- a/bin/projects.dart +++ b/bin/projects.dart @@ -144,15 +144,16 @@ extension ProjectExtension on Project { return copyWith(engine: resolvedEngine, exclude: exclude); } - Version? getFlutterVersionOverride() { + Future getFlutterVersionOverride() async { if (engine != Engine.fvm) return null; - final result = Process.runSync( - 'fvm', - ['flutter', '--version', '--machine'], - workingDirectory: path, - ); try { + // TODO: Do this a better way (https://github.com/leoafarias/fvm/issues/710) + final result = await Process.run( + 'fvm', + ['flutter', '--version', '--machine'], + workingDirectory: path, + ).timeout(Duration(seconds: 1)); final versionString = jsonDecode(result.stdout as String)['frameworkVersion'] as String?; if (versionString == null) { diff --git a/bin/puby.dart b/bin/puby.dart index aad58dc..e32d6e8 100644 --- a/bin/puby.dart +++ b/bin/puby.dart @@ -174,7 +174,7 @@ Future runInProject({ if (!command.silent) { stdout.write(line); } - if (!command.raw && shouldKill(resolved, line)) { + if (!command.raw && shouldKill(resolved, command, line)) { killed = process.kill(); } }).asFuture(); @@ -234,7 +234,7 @@ Future runInProject({ } /// Check if we should continue after this line is received -bool shouldKill(Project project, String line) { +bool shouldKill(Project project, Command command, String line) { if (project.engine == Engine.fvm) { final flutterVersionNotInstalledMatch = RegExp(r'Flutter SDK: SDK Version : (.+?) is not installed\.') @@ -242,11 +242,13 @@ bool shouldKill(Project project, String line) { if (flutterVersionNotInstalledMatch != null) { // FVM will ask for input from the user, kill the process to avoid // hanging - print( - redPen( - '\nRun `fvm install ${flutterVersionNotInstalledMatch[1]}` first', - ), - ); + if (!command.silent) { + print( + redPen( + '\nRun `fvm install ${flutterVersionNotInstalledMatch[1]}` first', + ), + ); + } return true; } } diff --git a/lib/engine.dart b/lib/engine.dart index 52f8911..bebe784 100644 --- a/lib/engine.dart +++ b/lib/engine.dart @@ -19,7 +19,7 @@ enum Engine { case Engine.flutter: return [name]; case Engine.fvm: - return ['fvm' 'flutter']; + return ['fvm', 'flutter']; } } } diff --git a/test/link_test.dart b/test/link_test.dart index 83b63c2..5f7b03f 100644 --- a/test/link_test.dart +++ b/test/link_test.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:path/path.dart' as p; import 'package:test/test.dart'; @@ -22,5 +24,11 @@ void main() { // fvm expectLine(stdout, ['fvm_puby_test', 'fvm flutter pub get --offline']); + // Ensure the correct flutter version was used + expect( + File('test_resources/fvm_puby_test/.dart_tool/version') + .readAsStringSync(), + '3.10.0', + ); }); } diff --git a/test_resources/fvm_puby_test/.fvmrc b/test_resources/fvm_puby_test/.fvmrc index a6427fd..ceeca18 100644 --- a/test_resources/fvm_puby_test/.fvmrc +++ b/test_resources/fvm_puby_test/.fvmrc @@ -1,4 +1,4 @@ { - "flutter": "stable", + "flutter": "3.10.0", "flavors": {} } \ No newline at end of file diff --git a/test_resources/fvm_puby_test/example/.fvmrc b/test_resources/fvm_puby_test/example/.fvmrc index a6427fd..ceeca18 100644 --- a/test_resources/fvm_puby_test/example/.fvmrc +++ b/test_resources/fvm_puby_test/example/.fvmrc @@ -1,4 +1,4 @@ { - "flutter": "stable", + "flutter": "3.10.0", "flavors": {} } \ No newline at end of file diff --git a/test_resources/fvm_puby_test/example/pubspec.lock b/test_resources/fvm_puby_test/example/pubspec.lock index 1986fd4..0de9451 100644 --- a/test_resources/fvm_puby_test/example/pubspec.lock +++ b/test_resources/fvm_puby_test/example/pubspec.lock @@ -13,31 +13,39 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.17.1" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.2.0" meta: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.9.1" sky_engine: dependency: transitive description: flutter @@ -52,4 +60,4 @@ packages: source: hosted version: "2.1.4" sdks: - dart: ">=3.2.0-0 <4.0.0" + dart: ">=3.0.0 <4.0.0" diff --git a/test_resources/fvm_puby_test/example/pubspec.yaml b/test_resources/fvm_puby_test/example/pubspec.yaml index 3776aab..0aa57e8 100644 --- a/test_resources/fvm_puby_test/example/pubspec.yaml +++ b/test_resources/fvm_puby_test/example/pubspec.yaml @@ -2,7 +2,7 @@ name: example publish_to: none environment: - sdk: ">=2.16.2 <3.0.0" + sdk: ^3.0.0 dependencies: flutter: diff --git a/test_resources/fvm_puby_test/pubspec.lock b/test_resources/fvm_puby_test/pubspec.lock index 1986fd4..0de9451 100644 --- a/test_resources/fvm_puby_test/pubspec.lock +++ b/test_resources/fvm_puby_test/pubspec.lock @@ -13,31 +13,39 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.17.1" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.2.0" meta: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.9.1" sky_engine: dependency: transitive description: flutter @@ -52,4 +60,4 @@ packages: source: hosted version: "2.1.4" sdks: - dart: ">=3.2.0-0 <4.0.0" + dart: ">=3.0.0 <4.0.0"