From 0991f0811f78238e1a88be578b41213ef41d9f88 Mon Sep 17 00:00:00 2001 From: Hal <22532613+HalRiveria@users.noreply.github.com> Date: Tue, 1 Dec 2026 23:04:22 -0500 Subject: [PATCH 1/2] The module's version has three parts Windows PowerShell's built-in PowerShellGet (1.0.0.1) installed the 4.0 module into a 4.0.0 folder, since Compress-PSResource gives the package a three-part version, while the manifest said 4.0. PowerShell doesn't find a module whose version folder isn't its manifest's version, so after Install-Module, Import-Module ParallelKit failed. PowerShell 7's installers use the manifest's version and weren't affected. The generator now writes the manifest's version with three parts: the kit's 4.0 is the module's 4.0.0, and an X.Y.Z version stays as it is. The kit itself still reports 4.0. The README says so. The harness builds its module into a folder named the way Install-Module names it, and section BM checks the manifest's version for a two- and a three-part kit version. Co-Authored-By: Claude Opus 5.5 --- Build/New-ParallelKitModule.ps1 | 16 ++++++++++--- ParallelKit.Harness.ps1 | 42 +++++++++++++++++++++++++++++---- README.md | 2 ++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Build/New-ParallelKitModule.ps1 b/Build/New-ParallelKitModule.ps1 index a8ab87d..3e4b15b 100644 --- a/Build/New-ParallelKitModule.ps1 +++ b/Build/New-ParallelKitModule.ps1 @@ -4,7 +4,10 @@ # .\Build\New-ParallelKitModule.ps1 -OutputDirectory C:\Modules\ParallelKit # # The folder has to be called ParallelKit, or be a version folder inside one -# (ParallelKit\4.0), for Import-Module to find it by name. +# (ParallelKit\4.0.0), for Import-Module to find it by name. +# +# The manifest's version always has three parts: the kit's 4.0 is the module's +# 4.0.0, and 3.4.1 stays 3.4.1. # # The .psm1 is the .ps1 without the wrapper that loads it as an in-memory # module: the Get-Module | Remove-Module line, and the New-Module wrapper's first @@ -128,6 +131,13 @@ try { if ($header.Count -ne 1 -or $inCode.Count -ne 1) { Stop-PkBuild ("expected one '# Version X.Y' line and one `$version = [version]'X.Y' line, found " + $header.Count + " and " + $inCode.Count + ".") } $version = $header[0].Groups[1].Value if ($version -cne $inCode[0].Groups[1].Value) { Stop-PkBuild ("the header says version " + $version + " and Initialize-ParallelKit " + $inCode[0].Groups[1].Value + ".") } + # Three parts in the manifest. The package gets three whatever the manifest + # says, Windows PowerShell's built-in PowerShellGet installs into a folder + # named after the package's version, and PowerShell doesn't find a module + # whose version folder isn't its manifest's version. The harness works the + # same version out for its module folder (Get-HarnessModuleVersion). + $moduleVersion = $version + if ($moduleVersion -notmatch '^\d+\.\d+\.\d+$') { $moduleVersion += '.0' } # Written out rather than made by New-ModuleManifest, which puts the date # and the user's name in the file. @@ -157,13 +167,13 @@ __FUNCTIONS__ } } '@ - $manifest = $manifest.Replace("`r`n", "`n").Replace('__VERSION__', $version).Replace('__MODULEGUID__', $moduleGuid).Replace('__FUNCTIONS__', $fnLines) + "`n" + $manifest = $manifest.Replace("`r`n", "`n").Replace('__VERSION__', $moduleVersion).Replace('__MODULEGUID__', $moduleGuid).Replace('__FUNCTIONS__', $fnLines) + "`n" $null = Get-PkBuildAst -Text $manifest -What 'the manifest made from it' $null = New-Item -ItemType Directory -Force -Path $OutputDirectory [System.IO.File]::WriteAllBytes((Join-Path $OutputDirectory 'ParallelKit.psm1'), [System.Text.Encoding]::ASCII.GetBytes($module.Replace("`n", "`r`n"))) [System.IO.File]::WriteAllBytes((Join-Path $OutputDirectory 'ParallelKit.psd1'), [System.Text.Encoding]::ASCII.GetBytes($manifest.Replace("`n", "`r`n"))) - Write-Output ("Wrote ParallelKit " + $version + " (" + @($moduleFns).Count + " functions, " + $public.Count + " public) to " + $OutputDirectory) + Write-Output ("Wrote ParallelKit " + $moduleVersion + " (" + @($moduleFns).Count + " functions, " + $public.Count + " public) to " + $OutputDirectory) } catch { [Console]::Error.WriteLine($_.Exception.Message) exit 1 diff --git a/ParallelKit.Harness.ps1 b/ParallelKit.Harness.ps1 index 01f309c..fbbc931 100644 --- a/ParallelKit.Harness.ps1 +++ b/ParallelKit.Harness.ps1 @@ -27,8 +27,16 @@ $kitPs1 = Join-Path $PSScriptRoot "ParallelKit.ps1" $kitPath = $kitPs1 $kitSource = $kitPs1 $moduleDir = $null +function Get-HarnessModuleVersion { + # The module's version for a kit's: three parts, as the generator writes it + # in the manifest (4.0 is 4.0.0, 3.4.1 stays). Worked out here on its own, + # not read from a built manifest, so a build that gets it wrong fails. + param([string]$KitVersion) + if ($KitVersion -match '^\d+\.\d+$') { return $KitVersion + '.0' } + return $KitVersion +} if ($AsModule) { - $moduleVersion = [regex]::Match([System.IO.File]::ReadAllText($kitPs1), '(?m)^# Version (\d+\.\d+(?:\.\d+)?)\b').Groups[1].Value + $moduleVersion = Get-HarnessModuleVersion ([regex]::Match([System.IO.File]::ReadAllText($kitPs1), '(?m)^# Version (\d+\.\d+(?:\.\d+)?)\b').Groups[1].Value) $moduleDir = Join-Path $env:TEMP ("pk-harness-module-" + $PID) $moduleBuilt = Join-Path $moduleDir ('mods\ParallelKit\' + $moduleVersion) $global:LASTEXITCODE = 0 @@ -5862,6 +5870,9 @@ $bmDir = Join-Path $env:TEMP ("pk-harness-bm-" + $PID) $null = New-Item -ItemType Directory -Force -Path $bmDir $bmText = [System.IO.File]::ReadAllText($kitPs1) $bmVersion = [regex]::Match($bmText, '(?m)^# Version (\d+\.\d+(?:\.\d+)?)\b').Groups[1].Value +# A version folder named after the manifest's version, as Install-Module makes: +# Import-Module by name doesn't find the module in one that isn't. +$bmModuleVersion = Get-HarnessModuleVersion $bmVersion function Get-BmBuildCommand([string]$Source, [string]$Out) { return @{ FilePath = $selfExe; Arguments = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $bmGenerator, '-SourcePath', $Source, '-OutputDirectory', $Out); Out = $Out } @@ -5876,7 +5887,7 @@ try { # The same bytes every time, with LF or CRLF, and only the wrapper gone. $bmMods = Join-Path $bmDir 'mods' -$bmBuilt = Join-Path $bmMods ('ParallelKit\' + $bmVersion) +$bmBuilt = Join-Path $bmMods ('ParallelKit\' + $bmModuleVersion) $bmLf = New-BmFile 'lf.ps1' $bmText.Replace("`r`n", "`n") $bmCrlf = New-BmFile 'crlf.ps1' $bmText.Replace("`r`n", "`n").Replace("`n", "`r`n") $bmBuilds = Invoke-PkProcessBatch -MaxConcurrent 4 -Commands @((Get-BmBuildCommand $kitPs1 $bmBuilt), (Get-BmBuildCommand $kitPs1 (Join-Path $bmDir 'again')), (Get-BmBuildCommand $bmLf (Join-Path $bmDir 'lf')), (Get-BmBuildCommand $bmCrlf (Join-Path $bmDir 'crlf'))) @@ -5931,11 +5942,34 @@ foreach ($r in (Invoke-PkProcessBatch -MaxConcurrent 4 -Commands $bmCommands).Re Test-Assert ($bmMissed.Count -eq 0) ("a .ps1 that doesn't look as expected is refused with a message, writing nothing (" + $bmCases.Count + " cases; not: " + ($bmMissed -join '; ') + ")") # The manifest. -$bmManifest = Test-ModuleManifest -Path (Join-Path $bmBuilt 'ParallelKit.psd1') +# Test-ModuleManifest also checks the version folder is named after the +# manifest's version, and throws if it isn't. +$bmManifestError = '' +try { + $bmManifest = Test-ModuleManifest -Path (Join-Path $bmBuilt 'ParallelKit.psd1') -ErrorAction Stop +} catch { + $bmManifestError = [string]$_ + $bmManifest = [pscustomobject]@{ Version = $null; ExportedFunctions = @{}; PowerShellVersion = $null; Tags = @(); Author = ''; Guid = [guid]::Empty } +} $bmExported = @($bmManifest.ExportedFunctions.Keys) $bmDiffer = @($publicFunctions | Where-Object { $bmExported -notcontains $_ }) + @($bmExported | Where-Object { $publicFunctions -notcontains $_ }) -Test-Assert ($bmManifest.Version -eq [version]$bmVersion -and $bmDiffer.Count -eq 0 -and $bmManifest.PowerShellVersion -eq [version]'5.1') ("its manifest is valid, with the kit's version and public functions (" + $bmManifest.Version + "; differ: " + ($bmDiffer -join ', ') + ")") +Test-Assert ($bmManifest.Version -eq [version]$bmModuleVersion -and $bmDiffer.Count -eq 0 -and $bmManifest.PowerShellVersion -eq [version]'5.1') ("its manifest is valid, with the kit's version and public functions, in a folder named after its version (" + $bmManifest.Version + "; differ: " + ($bmDiffer -join ', ') + $bmManifestError + ")") Test-Assert (@('PSEdition_Desktop', 'PSEdition_Core', 'Windows' | Where-Object { $bmManifest.Tags -notcontains $_ }).Count -eq 0 -and $bmManifest.Author -eq 'HalRiveria' -and $bmManifest.Guid -eq [guid]'1a05c60a-cafb-4e52-98e8-dd52affd2d61') ("and its identity: GUID, author and tags (" + ($bmManifest.Tags -join ', ') + ")") +# Three parts in the manifest's version, whatever the kit's has: a folder +# named after a two-part one isn't where 5.1's Install-Module puts it. +$bmVersionCases = [ordered]@{ '9.8' = '9.8.0'; '9.8.7' = '9.8.7' } +$bmVersionCommands = @(foreach ($v in $bmVersionCases.Keys) { + $text = $bmText.Replace('# Version ' + $bmVersion + ' ', '# Version ' + $v + ' ').Replace("`$version = [version]'" + $bmVersion + "'", "`$version = [version]'" + $v + "'") + $command = Get-BmBuildCommand (New-BmFile ('version-' + $v + '.ps1') $text) (Join-Path $bmDir ('version-' + $v)) + $command['Kit'] = $v + $command +}) +$bmVersionsWrong = @(foreach ($r in (Invoke-PkProcessBatch -MaxConcurrent 2 -Commands $bmVersionCommands).Results) { + $got = 'exit ' + $r.ExitCode + if ($r.ExitCode -eq 0) { $got = [regex]::Match([System.IO.File]::ReadAllText((Join-Path $r.Command['Out'] 'ParallelKit.psd1')), "ModuleVersion\s*=\s*'([^']*)'").Groups[1].Value } + if ($got -cne $bmVersionCases[$r.Command['Kit']]) { $r.Command['Kit'] + ' gave ' + $got } +}) +Test-Assert ($bmVersionCommands.Count -eq 2 -and $bmVersionsWrong.Count -eq 0) ("the manifest's version has three parts: 9.8 is 9.8.0, 9.8.7 stays (not: " + ($bmVersionsWrong -join '; ') + ")") # Loaded in fresh processes, by name and by path: what a caller does with it. # -OnComplete and -ResultHandler are closures that call the kit's functions. diff --git a/README.md b/README.md index 1ea8951..cfc41b8 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,8 @@ Import-Module C:\Modules\ParallelKit Installed, or built into a `ParallelKit` folder somewhere on `$env:PSModulePath`, `Import-Module ParallelKit` finds it by name, and so does a call to any of its functions without importing it first. The rest of this README applies either way. +The module's version has three parts: for the kit's 4.0 (what `Initialize-ParallelKit` reports), `Get-Module ParallelKit` shows 4.0.0, and that's the version `Import-Module -RequiredVersion` takes. +
If the import is refused From f21a5d7a2262a446d60956a1c72e9bfe6aec4757 Mon Sep 17 00:00:00 2001 From: Hal <22532613+HalRiveria@users.noreply.github.com> Date: Tue, 1 Dec 2026 23:28:22 -0500 Subject: [PATCH 2/2] Harness: a clearer message when the manifest can't be read; README: the version rule in general Co-Authored-By: Claude Opus 5.5 --- ParallelKit.Harness.ps1 | 3 ++- README.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ParallelKit.Harness.ps1 b/ParallelKit.Harness.ps1 index fbbc931..8bf8573 100644 --- a/ParallelKit.Harness.ps1 +++ b/ParallelKit.Harness.ps1 @@ -5953,7 +5953,8 @@ try { } $bmExported = @($bmManifest.ExportedFunctions.Keys) $bmDiffer = @($publicFunctions | Where-Object { $bmExported -notcontains $_ }) + @($bmExported | Where-Object { $publicFunctions -notcontains $_ }) -Test-Assert ($bmManifest.Version -eq [version]$bmModuleVersion -and $bmDiffer.Count -eq 0 -and $bmManifest.PowerShellVersion -eq [version]'5.1') ("its manifest is valid, with the kit's version and public functions, in a folder named after its version (" + $bmManifest.Version + "; differ: " + ($bmDiffer -join ', ') + $bmManifestError + ")") +if ($bmManifestError) { $bmDiffer = @('none read: ' + $bmManifestError) } +Test-Assert ($bmManifestError -eq '' -and $bmManifest.Version -eq [version]$bmModuleVersion -and $bmDiffer.Count -eq 0 -and $bmManifest.PowerShellVersion -eq [version]'5.1') ("its manifest is valid, with the kit's version and public functions, in a folder named after its version (" + $bmManifest.Version + "; differ: " + ($bmDiffer -join ', ') + ")") Test-Assert (@('PSEdition_Desktop', 'PSEdition_Core', 'Windows' | Where-Object { $bmManifest.Tags -notcontains $_ }).Count -eq 0 -and $bmManifest.Author -eq 'HalRiveria' -and $bmManifest.Guid -eq [guid]'1a05c60a-cafb-4e52-98e8-dd52affd2d61') ("and its identity: GUID, author and tags (" + ($bmManifest.Tags -join ', ') + ")") # Three parts in the manifest's version, whatever the kit's has: a folder # named after a two-part one isn't where 5.1's Install-Module puts it. diff --git a/README.md b/README.md index cfc41b8..f48dca0 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ Import-Module C:\Modules\ParallelKit Installed, or built into a `ParallelKit` folder somewhere on `$env:PSModulePath`, `Import-Module ParallelKit` finds it by name, and so does a call to any of its functions without importing it first. The rest of this README applies either way. -The module's version has three parts: for the kit's 4.0 (what `Initialize-ParallelKit` reports), `Get-Module ParallelKit` shows 4.0.0, and that's the version `Import-Module -RequiredVersion` takes. +The module's version always has three parts: the kit's X.Y (what `Initialize-ParallelKit` reports) is the module's X.Y.0, and an X.Y.Z version stays as it is. So for 4.0, `Get-Module ParallelKit` shows 4.0.0, and that's the version `Import-Module -RequiredVersion` takes.
If the import is refused