Skip to content

Commit da12c4f

Browse files
cirvine-MSFTCopilot
andcommitted
Fix PS 5.1 compat: robust copy, typed arrays, no ternary
- Replace Copy-Item glob with Get-ChildItem pipe (more reliable in PS 5.1) - Use [string[]] typed arrays for and - Replace ternary-style if expression with if/else block (PS 5.1 compat) - Replace em-dash with ASCII dash in warnings (encoding safety) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3b1aa8a commit da12c4f

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

install-extensions.ps1

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ $ErrorActionPreference = "Stop"
66
$repoRoot = $PSScriptRoot
77
$sourceDir = Join-Path $repoRoot "extensions"
88
# Respect COPILOT_HOME if set (same env var the Copilot CLI uses)
9-
$copilotHome = if ($env:COPILOT_HOME) { $env:COPILOT_HOME } else { Join-Path $HOME ".copilot" }
9+
if ($env:COPILOT_HOME) {
10+
$copilotHome = $env:COPILOT_HOME
11+
} else {
12+
$copilotHome = Join-Path $HOME ".copilot"
13+
}
1014
$targetDir = Join-Path $copilotHome "extensions"
1115

1216
if (-not (Test-Path $sourceDir)) {
@@ -16,37 +20,37 @@ if (-not (Test-Path $sourceDir)) {
1620

1721
$extensions = @("ado-pr-watcher", "ado-build-watcher")
1822
$sharedDirs = @("lib")
19-
$installed = @()
23+
[string[]]$installed = @()
2024

2125
foreach ($ext in $extensions) {
2226
$src = Join-Path $sourceDir $ext
2327
$dst = Join-Path $targetDir $ext
2428
if (-not (Test-Path $src)) {
25-
Write-Warning "Skipping '$ext' source not found at '$src'"
29+
Write-Warning "Skipping '$ext' - source not found at '$src'"
2630
continue
2731
}
2832
# Clean target first so stale files from previous versions are removed
2933
if (Test-Path $dst) { Remove-Item $dst -Recurse -Force }
3034
New-Item -ItemType Directory -Path $dst -Force | Out-Null
31-
Copy-Item (Join-Path $src "*") $dst -Force -Recurse
32-
$installed += $ext
35+
Get-ChildItem $src | Copy-Item -Destination $dst -Recurse -Force
36+
$installed += [string]$ext
3337
}
3438

3539
foreach ($dir in $sharedDirs) {
3640
$src = Join-Path $sourceDir $dir
3741
$dst = Join-Path $targetDir $dir
3842
if (-not (Test-Path $src)) {
39-
Write-Warning "Skipping shared dir '$dir' source not found at '$src'"
43+
Write-Warning "Skipping shared dir '$dir' - source not found at '$src'"
4044
continue
4145
}
4246
if (Test-Path $dst) { Remove-Item $dst -Recurse -Force }
4347
New-Item -ItemType Directory -Path $dst -Force | Out-Null
44-
Copy-Item (Join-Path $src "*") $dst -Force -Recurse
45-
$installed += $dir
48+
Get-ChildItem $src | Copy-Item -Destination $dst -Recurse -Force
49+
$installed += [string]$dir
4650
}
4751

4852
# Preflight warnings
49-
$missingTools = @()
53+
[string[]]$missingTools = @()
5054
if (-not (Get-Command copilot -ErrorAction SilentlyContinue)) { $missingTools += "copilot (GitHub Copilot CLI)" }
5155
if (-not (Get-Command az -ErrorAction SilentlyContinue)) { $missingTools += "az (Azure CLI)" }
5256

0 commit comments

Comments
 (0)