fix: windows flutter.bat compatibility for update command#439
fix: windows flutter.bat compatibility for update command#439karnemanideep wants to merge 5 commits intoinvertase:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves Windows compatibility in the update command by correctly identifying the Flutter executable and handling file deletions. It also ensures that generated configuration files end with a trailing newline. Review feedback suggests using Dart's cross-platform File API for deleting pubspec.lock to simplify the code and avoid unnecessary process spawning, as well as removing redundant inline comments.
| if (Platform.isWindows) { | ||
| await File('pubspec.lock').delete(); | ||
| } else { | ||
| await Process.run( | ||
| 'rm', | ||
| ['pubspec.lock'], | ||
| ); | ||
| } |
There was a problem hiding this comment.
Instead of branching on the platform and spawning a shell process for rm, you can use Dart's built-in File API which is cross-platform. This is more efficient as it avoids the overhead of creating a new process. Additionally, checking for existence with existsSync() prevents potential exceptions if the file is already missing, maintaining the robustness of the command.
final pubspecLockFile = File('pubspec.lock');
if (pubspecLockFile.existsSync()) {
await pubspecLockFile.delete();
}Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Description
flutterfire updatecrashes on Windows withProcessException: System cannot find the specified filebecause the update command uses Linux/Mac-only commands.Two bugs found in
update.dart:fluttercommand needs to beflutter.baton Windowsrmcommand does not exist on WindowsHow I Found It
Searched issue #252 where users reported
flutterfire updatecrashing on Windows. The stack trace pointed directly toupdate.dartline 79 whereProcess.run('flutter', ...)fails because Windows requires the.batextension.User
jibbers42also identified the exact lines in the issue comments.What I Changed
File:
packages/flutterfire_cli/lib/src/commands/update.dartFix 1 — flutter.bat on Windows:
Fix 2 — Cross-platform file deletion:
Initial fix used
if/else Platform.isWindowsto handlermnot existing on Windows.After Gemini code review suggested a simpler approach, updated to use Dart's built-in
FileAPI which works across all platforms:flutterCmdis reused for all 3fluttercommand calls in the file.Fixes #252
Type of change
feat-- New feature (non-breaking change which adds functionality)fix-- Bug fix (non-breaking change which fixes an issue)!-- Breaking change (fix or feature that would cause existing functionality to change)refactor-- Code refactorci-- Build configuration changedocs-- Documentationchore-- Chore