Skip to content

🩹 [Patch]: IsWindows PS 5.1 compatibility shim removed#132

Merged
Marius Storhaug (MariusStorhaug) merged 1 commit intomainfrom
remove/iswindows-shim
Apr 5, 2026
Merged

🩹 [Patch]: IsWindows PS 5.1 compatibility shim removed#132
Marius Storhaug (MariusStorhaug) merged 1 commit intomainfrom
remove/iswindows-shim

Conversation

@MariusStorhaug
Copy link
Copy Markdown
Member

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:

[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:

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.

PSModule targets PowerShell LTS (7.6+) where $IsWindows is a built-in
automatic variable. The Desktop edition shim and its PSScriptAnalyzer
suppressions are no longer needed.
@MariusStorhaug Marius Storhaug (MariusStorhaug) marked this pull request as ready for review April 5, 2026 15:59
Copilot AI review requested due to automatic review settings April 5, 2026 15:59
@MariusStorhaug Marius Storhaug (MariusStorhaug) merged commit 3457281 into main Apr 5, 2026
22 of 23 checks passed
@MariusStorhaug Marius Storhaug (MariusStorhaug) deleted the remove/iswindows-shim branch April 5, 2026 16:00
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in PSModule Framework Apr 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes the legacy PowerShell 5.1 $IsWindows compatibility shim and its PSScriptAnalyzer suppression attributes from generated root module (.psm1) output, aligning built modules with the PowerShell 7+ environment where $IsWindows is an automatic variable.

Changes:

  • Removed injection of SuppressMessageAttribute entries related to $IsWindows from the generated module header.
  • Removed the if ($PSEdition -eq 'Desktop') { $IsWindows = $true } block from the generated module post-header template.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Marius Storhaug (MariusStorhaug) added a commit to PSModule/Test-PSModule that referenced this pull request Apr 5, 2026
#113)

Module tests now validate framework-injected boilerplate — type
accelerator registration and OnRemove cleanup — so code coverage
reflects actual test gaps instead of penalizing module authors for
untested framework code.

## New: Type accelerator registration tests

When `Build-PSModule` injects a class exporter region, the module tests
now verify that every public class and enum listed in
`$ExportableClasses` / `$ExportableEnums` is registered as a type
accelerator after import.

```
Context Framework - Type accelerator registration
  [+] Should register public class [Book] as a type accelerator
  [+] Should register public class [BookList] as a type accelerator
```

Modules without a class exporter region skip these tests automatically.

## New: OnRemove cleanup tests

A new test verifies that when the module is removed, its type
accelerators are cleaned up via the `OnRemove` hook — preventing type
collisions when re-importing or importing a different version.

```
Context Framework - Module OnRemove cleanup
  [+] Should clean up type accelerators when the module is removed
```

## Changed: IsWindows compatibility shim removed

The `$IsWindows = $true` PS 5.1 Desktop edition shim has been removed
from `Build-PSModule` (see
[PSModule/Build-PSModule#132](PSModule/Build-PSModule#132)).
The corresponding test context and test fixture output have been removed
here as well. PSModule targets PowerShell LTS (7.6+) where `$IsWindows`
is a built-in automatic variable.

## Technical Details

- `PSModule.Tests.ps1`: Discovery-phase variables (`$hasClassExporter`,
`$expectedClassNames`, `$expectedEnumNames`) are computed at script
scope for Pester's `-Skip`/`-ForEach` evaluation, then recomputed in a
top-level `BeforeAll` for the Run phase. This dual-computation pattern
is required because Pester v5 Discovery and Run are separate executions
that don't share script-scope state.
- `PSModuleTest.psm1` (test fixture): Updated to remove the `$IsWindows`
shim and its suppression attributes, matching the new Build-PSModule
output format.
- PSScriptAnalyzer `PSUseDeclaredVarsMoreThanAssignments` suppressed at
file level because the analyzer cannot trace variable flow across
Pester's `BeforeAll` → `It` block boundaries.
Marius Storhaug (MariusStorhaug) added a commit to PSModule/Process-PSModule that referenced this pull request Apr 5, 2026
…le authors (#310)

Framework-generated boilerplate — type accelerator registration and
`OnRemove` cleanup — is now tested and covered by updated action
versions referenced in this workflow. The obsolete `$IsWindows` PS 5.1
shim is no longer injected into built modules. Coverage from the
framework test step and the module test step is already aggregated by
Get-CodeCoverage, so module authors' coverage percentages now reflect
only the code they wrote.

- Fixes #309

## Changed: Build-PSModule updated to v4.0.14

Built modules no longer include the `$IsWindows = $true` Desktop edition
shim or its PSScriptAnalyzer suppression attributes. PSModule targets
PowerShell LTS (7.6+), where `$IsWindows` is a built-in automatic
variable.

See
[PSModule/Build-PSModule#132](PSModule/Build-PSModule#132)
for details.

## Changed: Test-PSModule updated to v3.0.10

The framework module tests now validate that every public class and enum
is registered as a type accelerator after import, and that the
`OnRemove` hook cleans them up when the module is removed. These tests
produce coverage artifacts that are aggregated with module author test
coverage, so framework-generated boilerplate no longer counts against
the module author's coverage target.

See
[PSModule/Test-PSModule#113](PSModule/Test-PSModule#113)
for details.

## Changed: README documents the framework testing design

The README now explains:
- Why framework-generated code is tested by the framework itself
- How coverage from both the framework test step and the module test
step is aggregated
- That module authors do not need to test framework-generated code
themselves

## Technical Details

- `.github/workflows/Build-Module.yml`: Updated Build-PSModule from
v4.0.13 to v4.0.14 (`345728124d201f371a8b0f1aacb98f89000a06dc`)
- `.github/workflows/Test-Module.yml`: Updated Test-PSModule from v3.0.8
to v3.0.10 (`8c3337136dc7cf320da39eeb50e776d04bc9ac73`)
- `.github/workflows/Test-SourceCode.yml`: Updated Test-PSModule from
v3.0.8 to v3.0.10
- `README.md`: Added "Code coverage for framework-generated code"
paragraph under the Framework test section; added coverage aggregation
details under the Get code coverage section; removed reference to the
`$IsWindows` shim
- No workflow structure changes — code coverage was already enabled in
Test-Module.yml and Get-PesterCodeCoverage already aggregates all
`*-CodeCoverage` artifacts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants