Skip to content

Commit b41509d

Browse files
🩹 [Patch]: Default PowerShellVersion set to '5.1' (#29)
## Description - Default `PowerShellVersion` set to '5.1'. - Add checks for `CompatiblePSVersion` and `PowerShellVersion`. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 4eb8435 commit b41509d

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

scripts/helpers/Build/Build-PSModuleDocumentation.ps1

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@ function Build-PSModuleDocumentation {
2323
[System.IO.DirectoryInfo] $DocsOutputFolder
2424
)
2525

26-
Start-LogGroup 'Docs - Dependencies'
26+
Start-LogGroup 'Build docs - Dependencies'
2727
$moduleName = Split-Path -Path $ModuleOutputFolder -Leaf
2828

2929
Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent)
3030
Import-PSModule -Path $ModuleOutputFolder -ModuleName $moduleName
3131

32-
Start-LogGroup 'Build documentation'
32+
Start-LogGroup 'Build docs - Generate markdown help'
3333
$null = New-MarkdownHelp -Module $moduleName -OutputFolder $DocsOutputFolder -Force -Verbose
34-
Stop-LogGroup
35-
36-
Start-LogGroup 'Build documentation - Fix fence'
3734
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
3835
$content = Get-Content -Path $_.FullName
3936
$fixedOpening = $false
@@ -53,15 +50,6 @@ function Build-PSModuleDocumentation {
5350
}
5451
Stop-LogGroup
5552

56-
Start-LogGroup 'Build documentation - Result'
57-
Write-Verbose (Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
58-
@{
59-
Name = $_.FullName
60-
Hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash
61-
}
62-
} | Format-Table -AutoSize | Out-String)
63-
Stop-LogGroup
64-
6553
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
6654
$fileName = $_.Name
6755
$hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash

scripts/helpers/Build/Build-PSModuleManifest.ps1

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,38 @@ function Build-PSModuleManifest {
197197
Write-Verbose '[PowerShellVersion]'
198198
$capturedVersions = $capturedVersions | Sort-Object -Unique -Descending
199199
$capturedVersions | ForEach-Object { Write-Verbose "[PowerShellVersion] - [$_]" }
200-
$manifest.PowerShellVersion = $capturedVersions.count -eq 0 ? [version]'7.0' : [version]($capturedVersions | Select-Object -First 1)
200+
$manifest.PowerShellVersion = $capturedVersions.count -eq 0 ? [version]'5.1' : [version]($capturedVersions | Select-Object -First 1)
201201
Write-Verbose '[PowerShellVersion] - Selecting version'
202202
Write-Verbose "[PowerShellVersion] - [$($manifest.PowerShellVersion)]"
203203

204204
Write-Verbose '[CompatiblePSEditions]'
205205
$capturedPSEdition = $capturedPSEdition | Sort-Object -Unique
206206
if ($capturedPSEdition.count -eq 2) {
207-
throw 'The module is requires both Desktop and Core editions.'
207+
throw @"
208+
Conflict detected:
209+
The module requires both 'Desktop' and 'Core' editions.
210+
'Desktop' and 'Core' editions cannot be required at the same time.
211+
"@
208212
}
209213
$manifest.CompatiblePSEditions = $capturedPSEdition.count -eq 0 ? @('Core', 'Desktop') : @($capturedPSEdition)
210214
$manifest.CompatiblePSEditions | ForEach-Object { Write-Verbose "[CompatiblePSEditions] - [$_]" }
211215

216+
if ($manifest.PowerShellVersion -gt '5.1' -and $manifest.CompatiblePSEditions -contains 'Desktop') {
217+
throw @'
218+
Conflict detected:
219+
The module requires PowerShellVersion > 5.1 while CompatiblePSEditions = 'Desktop'
220+
'Desktop' edition is not supported for PowerShellVersion > 5.1
221+
'@
222+
}
223+
224+
if ($manifest.CompatiblePSEditions -contains 'Core' -and $manifest.PowerShellVersion -lt '6.0') {
225+
throw @'
226+
Conflict detected:
227+
The module requires CompatiblePSEditions = 'Core' while PowerShellVersion < 6.0
228+
'Core' edition is not supported for PowerShellVersion < 6.0
229+
'@
230+
}
231+
212232
Write-Verbose '[PrivateData]'
213233
$privateData = $manifest.Keys -contains 'PrivateData' ? $null -ne $manifest.PrivateData ? $manifest.PrivateData : @{} : @{}
214234
if ($manifest.Keys -contains 'PrivateData') {
@@ -318,17 +338,14 @@ function Build-PSModuleManifest {
318338
#endregion Build manifest file
319339

320340
#region Format manifest file
321-
Start-LogGroup 'Format manifest file - Before format'
341+
Start-LogGroup 'Build manifest file - Result - Before format'
322342
Show-FileContent -Path $outputManifestPath
323343
Stop-LogGroup
324344

325-
Start-LogGroup 'Format manifest file - After'
345+
Start-LogGroup 'Build manifest file - Result - After format'
326346
Set-ModuleManifest -Path $outputManifestPath
327347
Show-FileContent -Path $outputManifestPath
328348
Stop-LogGroup
329349

330-
Start-LogGroup 'Format manifest file - Result'
331-
Show-FileContent -Path $outputManifestPath
332-
Stop-LogGroup
333350
#endregion Format manifest file
334351
}

scripts/helpers/Build/Build-PSModuleRootModule.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,23 @@ Export-ModuleMember @exports
150150
#endregion Build root module
151151

152152
#region Format root module
153-
Start-LogGroup 'Build root module - Format root module - Before format'
153+
Start-LogGroup 'Build root module - Result - Before format'
154154
Show-FileContent -Path $rootModuleFile
155155
Stop-LogGroup
156156

157-
Start-LogGroup 'Build root module - Format root module - Format'
157+
Start-LogGroup 'Build root module - Format'
158158
$AllContent = Get-Content -Path $rootModuleFile -Raw
159159
$settings = (Join-Path -Path $PSScriptRoot 'PSScriptAnalyzer.Tests.psd1')
160160
Invoke-Formatter -ScriptDefinition $AllContent -Settings $settings |
161161
Out-File -FilePath $rootModuleFile -Encoding utf8BOM -Force
162162
Stop-LogGroup
163163

164-
Start-LogGroup 'Build root module - Format root module - Result'
164+
Start-LogGroup 'Build root module - Result - After format'
165165
Show-FileContent -Path $rootModuleFile
166166
Stop-LogGroup
167167
#endregion Format root module
168168

169-
Start-LogGroup 'Build root module - Result'
169+
Start-LogGroup 'Build module - Result - File list'
170170
(Get-ChildItem -Path $ModuleOutputFolder -Recurse -Force).FullName | Sort-Object
171171
Stop-LogGroup
172172
}

0 commit comments

Comments
 (0)