Skip to content

Commit eddf6f4

Browse files
🐛 Modules with Trailing Zeroes do not install correctly (#100)
Fixes #98 Co-authored-by: Justin Grote <[email protected]> Co-authored-by: Raimund Andree <[email protected]>
1 parent 8457844 commit eddf6f4

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

ModuleFast.psm1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,47 @@ function Install-ModuleFastHelper {
10111011
$zip = [IO.Compression.ZipArchive]::new($stream, 'Read')
10121012
[IO.Compression.ZipFileExtensions]::ExtractToDirectory($zip, $installPath)
10131013

1014+
$manifestPath = Join-Path $installPath "$($context.Module.Name).psd1"
1015+
1016+
# Try to read the manifest with a streamreader just to ModuleVersion.
1017+
# This makes a glaring but reasonable assumption that the moduleVersion is not dynamic and has no newlines.
1018+
# Much more performant than a full parse, as it will stop as soon as it hits moduleversion, perhaps at the
1019+
# expense of more iops due to the readline vs reading the entire file at once
1020+
$reader = [IO.StreamReader]::new($manifestPath)
1021+
[Version]$moduleManifestVersion = $null
1022+
try {
1023+
while ($null -ne ($line = $reader.ReadLine())) {
1024+
if ($line -match '\s*ModuleVersion\s*=\s*[''"](?<version>.+?)[''"]') {
1025+
$moduleManifestVersion = $matches['version']
1026+
break
1027+
}
1028+
}
1029+
} finally {
1030+
$reader.Close()
1031+
}
1032+
1033+
# Resolves an edge case where nuget packages are normalized in some package manages from 3.2.1.0 to 3.2.1
1034+
if (-not $moduleManifestVersion) {
1035+
Write-Warning "$($context.Module): Could not detect the module manifest version. This module may not install properly if it has trailing zeros in the version"
1036+
} else {
1037+
$installPathRoot = Split-Path $installPath
1038+
$originalModuleVersion = Split-Path $installPath -Leaf
1039+
if ($originalModuleVersion -ne $moduleManifestVersion)
1040+
{
1041+
Write-Debug "$($context.Module): Module Manifest Version $moduleManifestVersion differs from package version $originalModuleVersion, moving..."
1042+
1043+
$newInstallPath = Join-Path $installPathRoot $moduleManifestVersion
1044+
[System.IO.Directory]::Move($installPath, $newInstallPath)
1045+
1046+
$installPath = $newInstallPath
1047+
$context.InstallPath = $installPath
1048+
$originalModuleVersion > (Join-Path $installPath '.originalModuleVersion')
1049+
$installIndicatorPath = Join-Path $installPath '.incomplete'
1050+
} else {
1051+
Write-Debug "$($context.Module): Module Manifest version matches the expected version"
1052+
}
1053+
}
1054+
10141055
if ($context.Module.Guid -and $context.Module.Guid -ne [Guid]::Empty) {
10151056
Write-Debug "$($context.Module): GUID was specified in Module. Verifying manifest"
10161057
$manifestPath = Join-Path $installPath "$($context.Module.Name).psd1"

ModuleFast.tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ Describe 'Install-ModuleFast' -Tag 'E2E' {
461461
| Limit-ModulePath $installTempPath
462462
| Should -HaveCount 1
463463
}
464+
It '4 section version numbers with single trailing zero' {
465+
$actual = Install-ModuleFast @imfParams 'ConnectWiseManageApi=0.4.15.0' -PassThru
466+
# Path should exist in the new location
467+
$resolvedPath = $actual.Location.LocalPath
468+
Split-Path $resolvedPath -Leaf | Should -Be '0.4.15.0'
469+
}
464470
It 'lots of dependencies (Az)' {
465471
Install-ModuleFast @imfParams 'Az'
466472
(Get-Module Az* -ListAvailable).count | Should -BeGreaterThan 10

0 commit comments

Comments
 (0)