Skip to content

🐛 Modules with Trailing Zeroes do not install correctly #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions ModuleFast.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,47 @@ function Install-ModuleFastHelper {
$zip = [IO.Compression.ZipArchive]::new($stream, 'Read')
[IO.Compression.ZipFileExtensions]::ExtractToDirectory($zip, $installPath)

$manifestPath = Join-Path $installPath "$($context.Module.Name).psd1"

# Try to read the manifest with a streamreader just to ModuleVersion.
# This makes a glaring but reasonable assumption that the moduleVersion is not dynamic and has no newlines.
# Much more performant than a full parse, as it will stop as soon as it hits moduleversion, perhaps at the
# expense of more iops due to the readline vs reading the entire file at once
$reader = [IO.StreamReader]::new($manifestPath)
[Version]$moduleManifestVersion = $null
try {
while ($null -ne ($line = $reader.ReadLine())) {
if ($line -match '\s*ModuleVersion\s*=\s*[''"](?<version>.+?)[''"]') {
$moduleManifestVersion = $matches['version']
break
}
}
} finally {
$reader.Close()
}

# Resolves an edge case where nuget packages are normalized in some package manages from 3.2.1.0 to 3.2.1
if (-not $moduleManifestVersion) {
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"
} else {
$installPathRoot = Split-Path $installPath
$originalModuleVersion = Split-Path $installPath -Leaf
if ($originalModuleVersion -ne $moduleManifestVersion)
{
Write-Debug "$($context.Module): Module Manifest Version $moduleManifestVersion differs from package version $originalModuleVersion, moving..."

$newInstallPath = Join-Path $installPathRoot $moduleManifestVersion
[System.IO.Directory]::Move($installPath, $newInstallPath)

$installPath = $newInstallPath
$context.InstallPath = $installPath
$originalModuleVersion > (Join-Path $installPath '.originalModuleVersion')
$installIndicatorPath = Join-Path $installPath '.incomplete'
} else {
Write-Debug "$($context.Module): Module Manifest version matches the expected version"
}
}

if ($context.Module.Guid -and $context.Module.Guid -ne [Guid]::Empty) {
Write-Debug "$($context.Module): GUID was specified in Module. Verifying manifest"
$manifestPath = Join-Path $installPath "$($context.Module.Name).psd1"
Expand Down
3 changes: 2 additions & 1 deletion ModuleFast.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ Describe 'Install-ModuleFast' -Tag 'E2E' {
}
It '4 section version numbers with single trailing zero' {
$actual = Install-ModuleFast @imfParams 'ConnectWiseManageApi=0.4.15.0' -PassThru
$resolvedPath = Resolve-Path $actual.Location.LocalPath
# Path should exist in the new location
$resolvedPath = $actual.Location.LocalPath
Split-Path $resolvedPath -Leaf | Should -Be '0.4.15.0'
}
It 'lots of dependencies (Az)' {
Expand Down