fix(shorebird_cli): only redirect powershell stderr output if it won't cause the script to terminate (#1089)
This commit is contained in:
+32
-5
@@ -16,6 +16,28 @@ $flutter = [IO.Path]::Combine($shorebirdCacheDir, "flutter", $flutterVersion, "b
|
||||
$shorebirdScript = [IO.Path]::Combine($shorebirdCliDir, "bin", "shorebird.dart")
|
||||
$dart = [IO.Path]::Combine($flutterPath, "bin", "cache", "dart-sdk", "bin", "dart.exe")
|
||||
|
||||
# Executes $command and redirects as much output to $null as possible.
|
||||
#
|
||||
# This is a workaround for old versions of Powershell treating any write to
|
||||
# the Error stream with $ErrorActionPreference = "Stop" as a terminating error.
|
||||
# This is fixed in Powershell 7.1.
|
||||
#
|
||||
# See https://github.com/PowerShell/PowerShell/issues/4002 for more info.
|
||||
function Invoke-SilentlyIfPossible($command) {
|
||||
$psVersion = $PSVersionTable.PSVersion
|
||||
$shouldRedirectStdErr = $psVersion.Major -ge 7 -and $psVersion.Minor -ge 1
|
||||
if ($shouldRedirectStdErr) {
|
||||
# Redirect everything to $null.
|
||||
& $command *> $null
|
||||
}
|
||||
else {
|
||||
# Otherwise redirect everything _but_ the Error stream to $null. See
|
||||
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_output_streams?view=powershell-7.3#long-description
|
||||
# for a description of these streams.
|
||||
& $command 1> $null 3> $null 4> $null 5> $null 6> $null
|
||||
}
|
||||
}
|
||||
|
||||
function Test-GitInstalled {
|
||||
if (Get-Command git -ErrorAction SilentlyContinue) {
|
||||
Write-Debug "Git is installed."
|
||||
@@ -78,15 +100,20 @@ function Update-Flutter {
|
||||
Write-Output "Updating Flutter..."
|
||||
|
||||
if (!(Test-Path $flutterPath)) {
|
||||
Write-Output "Cloning flutter, this may take a bit..."
|
||||
git clone --filter=tree:0 https://github.com/shorebirdtech/flutter.git --no-checkout "$flutterPath" *> $null
|
||||
Invoke-SilentlyIfPossible {
|
||||
git clone --filter=tree:0 https://github.com/shorebirdtech/flutter.git --no-checkout "$flutterPath"
|
||||
}
|
||||
}
|
||||
else {
|
||||
git -C "$flutterPath" fetch *> $null
|
||||
Invoke-SilentlyIfPossible {
|
||||
git -C "$flutterPath" fetch
|
||||
}
|
||||
}
|
||||
|
||||
# -c to avoid printing a warning about being in a detached head state.
|
||||
git -C "$flutterPath" -c advice.detachedHead=false checkout "$flutterVersion" *> $null
|
||||
Invoke-SilentlyIfPossible {
|
||||
# -c to avoid printing a warning about being in a detached head state.
|
||||
git -C "$flutterPath" -c advice.detachedHead=false checkout "$flutterVersion"
|
||||
}
|
||||
|
||||
# Set FLUTTER_STORAGE_BASE_URL=https://download.shorebird.dev and execute
|
||||
# a `flutter` command to trigger a download of Dart, etc.
|
||||
|
||||
Reference in New Issue
Block a user