Skip to content

Commit 3457281

Browse files
🩹 [Patch]: IsWindows PS 5.1 compatibility shim removed (#132)
Built modules no longer include the `$IsWindows = $true` shim or its PSScriptAnalyzer suppression attributes. PSModule targets PowerShell LTS (7.6+), where `$IsWindows` is a built-in automatic variable — the Desktop edition fallback is unnecessary. ## Changed: Built module root files are smaller and cleaner The generated `.psm1` files no longer contain the following block: ```powershell [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidAssignmentToAutomaticVariable', 'IsWindows', Justification = 'IsWindows does not exist in PS5.1' )] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseDeclaredVarsMoreThanAssignments', 'IsWindows', Justification = 'IsWindows does not exist in PS5.1' )] ``` And the module post-header no longer includes: ```powershell if ($PSEdition -eq 'Desktop') { $IsWindows = $true } ``` Modules built with this version require PowerShell 7.x+ (LTS). If you need PS 5.1 support, pin Build-PSModule to v4. ## Technical Details - `Build-PSModuleRootModule.ps1`: Removed the `Add-Content` call that injected the two `SuppressMessageAttribute` entries and the empty here-string left after their removal. Removed the `if ($PSEdition -eq 'Desktop')` block from the module post-header template. - Companion PR in Test-PSModule removes the corresponding framework test for this shim.
1 parent 7a3ae1b commit 3457281

File tree

1 file changed

+0
-15
lines changed

1 file changed

+0
-15
lines changed

src/helpers/Build/Build-PSModuleRootModule.ps1

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,6 @@ $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
131131
#endregion - Analyze source files
132132

133133
#region - Module header
134-
Add-Content -Path $rootModuleFile -Force -Value @'
135-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
136-
'PSAvoidAssignmentToAutomaticVariable', 'IsWindows',
137-
Justification = 'IsWindows does not exist in PS5.1'
138-
)]
139-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
140-
'PSUseDeclaredVarsMoreThanAssignments', 'IsWindows',
141-
Justification = 'IsWindows does not exist in PS5.1'
142-
)]
143-
'@
144-
145134
$headerFilePath = Join-Path -Path $ModuleOutputFolder -ChildPath 'header.ps1'
146135
if (Test-Path -Path $headerFilePath) {
147136
Get-Content -Path $headerFilePath -Raw | Add-Content -Path $rootModuleFile -Force
@@ -162,10 +151,6 @@ $script:PSModuleInfo | Format-List | Out-String -Stream | ForEach-Object { Write
162151
$scriptName = $script:PSModuleInfo.Name
163152
Write-Debug "[$scriptName] - Importing module"
164153
165-
if ($PSEdition -eq 'Desktop') {
166-
$IsWindows = $true
167-
}
168-
169154
'@
170155
#endregion - Module post-header
171156

0 commit comments

Comments
 (0)