Commit c2c184e
fix: restore Windows PowerShell 5.1 import compatibility (#126)
## Summary
PowerShellBuild 0.8.0 fails to **import** under Windows PowerShell 5.1
(Desktop). `Get-PSBuildCertificate` (added in #92) used the PowerShell
7+-only ternary operator; since the module loader dot-sources every
`Public/*.ps1` at import, the parse failure broke import of the whole
module on 5.1 — even though the manifest still declares
`PowerShellVersion = '3.0'`.
## Fix
- **Ternary → `if/else` expression** in `Get-PSBuildCertificate`
(5.1-safe; identical PS7 behavior).
- **`$IsWindows` guard made 5.1-safe** using the repo's existing idiom
(`$null -ne $IsWindows -and -not $IsWindows`, as in
`Build-PSBuildUpdatableHelp`). On Desktop edition the automatic variable
is absent and the platform is always Windows.
## Audit
Swept all `.ps1/.psm1/.psd1` under `PowerShellBuild/`, `build/`, and
`tests/` (and re-parsed every module file on a real 5.1 engine) for
PS7-only constructs (ternary, `??`/`??=`, `?.`/`?[ ]`, `&&`/`||`,
`clean{}`, `-Parallel`, Core-only `$Is*` vars, Core-only cmdlets/types).
The two issues in `Get-PSBuildCertificate.ps1` were the only real
incompatibilities.
## Guardrails
- **PSScriptAnalyzer compatibility rules**
(`PSUseCompatibleSyntax`/`Commands`/`Types`) enabled in
`ScriptAnalyzerSettings.psd1`, targeting Windows PowerShell 5.1
(Desktop) and PowerShell 7. `PSUseCompatibleSyntax` checks the target
language version regardless of the engine it runs on, so it catches a
ternary even from `pwsh`. Two documented false positives are suppressed
with justifications (`Get-ChildItem -CodeSigningCert` provider dynamic
parameter; `Invoke-Pester -Configuration` from the required Pester 5+).
- **`Analyze` build task fails on any compatibility violation** (these
rules are Warning-severity, which the existing Error-only gate would not
catch).
- **New `import-smoke` CI job** parses and imports the module on the
real Windows PowerShell 5.1 engine (`shell: powershell`).
## Verification
- Parse + dot-source + `Import-Module` on **real Windows PowerShell
5.1**: clean (original failed with the documented parse errors).
- PSScriptAnalyzer with the new settings: 0 compatibility findings;
confirmed it flags a reintroduced ternary.
- psake `Test` (Analyze + Pester) on pwsh 7: Analyze clean of
compatibility issues; **304 Pester tests pass**, including all of
`Get-PSBuildCertificate.tests.ps1`.
## Support contract
Per maintainer direction, the manifest
(`PowerShellVersion`/`CompatiblePSEditions`) is **left unchanged** in
this PR; the code is fixed to comply with the existing 5.1/Desktop
contract. Formalizing the declared floor is tracked for the v1.0.0
roadmap (#120).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 08b191a commit c2c184e
7 files changed
Lines changed: 63 additions & 28 deletions
File tree
- .github/workflows
- PowerShellBuild
- Public
- instructions
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | | - | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
10 | 30 | | |
11 | 31 | | |
12 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
127 | 130 | | |
128 | 131 | | |
129 | 132 | | |
| |||
195 | 198 | | |
196 | 199 | | |
197 | 200 | | |
198 | | - | |
| 201 | + | |
| 202 | + | |
199 | 203 | | |
200 | 204 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | | - | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
79 | 83 | | |
80 | | - | |
| 84 | + | |
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
| |||
0 commit comments