Skip to content

Commit a01a711

Browse files
Replace null-coalescing operators with PS5.1-compatible syntax (#443)
Plaster v2.0.0-alpha uses the null-coalescing operator (`??`) introduced in PowerShell 7.0, breaking compatibility with PowerShell 5.1 as specified in the module manifest. ## Changes **Write-PlasterLog.ps1** - Replaced `??` operators with conditional expressions compatible with PS5.1+ ```powershell # Before $currentLogLevel = $script:LogLevel ?? 'Information' $currentLevelValue = $logLevels[$currentLogLevel] ?? 2 # After $currentLogLevel = if ($null -ne $script:LogLevel) { $script:LogLevel } else { 'Information' } $currentLevelValue = if ($null -ne $logLevels[$currentLogLevel]) { $logLevels[$currentLogLevel] } else { 2 } ``` **Plaster.psm1** - Added dot-sourcing for Private and Public function files - Implemented selective export of public functions only > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `www.powershellgallery.com` > - Triggering command: `/usr/bin/pwsh pwsh -NoProfile -File ./build.ps1 -Bootstrap` (dns block) > - Triggering command: `/usr/bin/pwsh pwsh -NoProfile -Command Register-PSRepository -Default -ErrorAction SilentlyContinue Get-PSRepository` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/PowerShellOrg/Plaster/settings/copilot/coding_agent) (admins only) > > </details> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Plaster v2.0.0-alpha broken on Windows</issue_title> > <issue_description>Hiya, > > [Sampler]() uses Plaster and we've noticed on our pipelines that the prerelease version breaks on windows because `Write-PlasterLog` uses the Null-coalescing operator. > > https://github.com/PowerShellOrg/Plaster/blob/v2/Plaster/Private/Write-PlasterLog.ps1#L52-L54 > > Could you please fix soonish, or would you recommend we pin an old version?</issue_description> > > <agent_instructions>Search for any use of null coalescing and remove it. This module must be able to run PS5.1</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #442 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: HeyItsGilbert <615265+HeyItsGilbert@users.noreply.github.com> Co-authored-by: Gilbert Sanchez <me@gilbertsanchez.com>
1 parent 00a42e0 commit a01a711

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
## [2.0.0] 2025-06-18
8+
## [2.0.0-alpha.1] 2026-02-12
9+
10+
### Fixed
11+
12+
- Null-coalescing operators replaced with PS5.1-compatible syntax in
13+
Write-PlasterLog to fix PowerShell 5.1 compatibility
14+
([#442](https://github.com/PowerShellOrg/Plaster/issues/442))
15+
16+
## [2.0.0-alpha] 2025-06-18
917

1018
### Added
1119

Plaster/Plaster.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# PSData hashtable with additional module metadata used by PowerShell.
1616
PrivateData = @{
1717
PSData = @{
18-
Prerelease = 'alpha'
18+
Prerelease = 'alpha.1'
1919

2020
# Tags applied to this module. These help with module discovery in online galleries.
2121
Tags = @('Plaster', 'CodeGenerator', 'Scaffold', 'Template', 'JSON', 'PowerShell7')

Plaster/Private/Write-PlasterLog.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ function Write-PlasterLog {
4949
'Debug' = 4
5050
}
5151

52-
$currentLogLevel = $script:LogLevel ?? 'Information'
53-
$currentLevelValue = $logLevels[$currentLogLevel] ?? 2
54-
$messageLevelValue = $logLevels[$Level] ?? 2
52+
$currentLogLevel = if ($null -ne $script:LogLevel) { $script:LogLevel } else { 'Information' }
53+
$currentLevelValue = if ($null -ne $logLevels[$currentLogLevel]) { $logLevels[$currentLogLevel] } else { 2 }
54+
$messageLevelValue = if ($null -ne $logLevels[$Level]) { $logLevels[$Level] } else { 2 }
5555

5656
if ($messageLevelValue -gt $currentLevelValue) {
5757
return

tests/Manifest.tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ BeforeAll {
44
. $path -Task Build
55
}
66
# NEW: Pre-Specify RegEx Matching Patterns
7-
$gitTagMatchRegEx = 'tag:\s?.(\d+(\.\d+)*)' # NOTE - was 'tag:\s*(\d+(?:\.\d+)*)' previously
8-
$changelogTagMatchRegEx = "^##\s\[(?<Version>(\d+\.){1,3}\d+)\]"
7+
# Matches semantic versioning with optional pre-release and build metadata
8+
# Examples: 1.0.0, 2.0.0-alpha, 2.0.0-alpha.1, 2.0.0+build.123
9+
$gitTagMatchRegEx = 'tag:\s?.(\d+(?:\.\d+)*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?'
10+
$changelogTagMatchRegEx = "^##\s\[(?<Version>(\d+\.){2}\d+)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?\]"
911

1012
$moduleName = $env:BHProjectName
1113
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest

0 commit comments

Comments
 (0)