Skip to content

Commit b85eb37

Browse files
fix: better alz module validation (#522)
Due to the way OneDrive works, it is possible to have a newer version of the module installed, but not imported when using multiple machines. This PR adds a check for the imported version too and provides a command to update it. We also skip the check and warn if the dev version is detected to simplify the local dev lifecycle.
1 parent 5fb4021 commit b85eb37

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/ALZ/Private/Tools/Test-Tooling.ps1

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,22 @@ function Test-Tooling {
172172

173173
$currentScope = "CurrentUser"
174174

175-
if($skipAlzModuleVersionCheck.IsPresent) {
175+
$importedModule = Get-Module -Name ALZ
176+
$isDevelopmentModule = ($null -ne $importedModule -and $importedModule.Version -eq "0.1.0")
177+
if($skipAlzModuleVersionCheck.IsPresent -or $isDevelopmentModule) {
176178
Write-Verbose "Skipping ALZ module version check"
179+
180+
if($isDevelopmentModule) {
181+
$checkResults += @{
182+
message = "ALZ module version is 0.1.0. Skipping version check as this is a development module."
183+
result = "Warning"
184+
}
185+
} elseif ($skipAlzModuleVersionCheck.IsPresent) {
186+
$checkResults += @{
187+
message = "ALZ module version check was explicitly skipped using the -skipAlzModuleVersionRequirementsCheck parameter."
188+
result = "Warning"
189+
}
190+
}
177191
} else {
178192
# Check if latest ALZ module is installed
179193
Write-Verbose "Checking ALZ module version"
@@ -203,9 +217,19 @@ function Test-Tooling {
203217
}
204218
$hasFailure = $true
205219
} else {
206-
$checkResults += @{
207-
message = "ALZ module is the latest version ($($alzModuleCurrentVersion.Version))."
208-
result = "Success"
220+
if($importedModule.Version -lt $alzModuleLatestVersion.Version) {
221+
Write-Verbose "Imported ALZ module version ($($importedModule.Version)) is older than the latest installed version ($($alzModuleLatestVersion.Version)), re-importing module"
222+
223+
$checkResults += @{
224+
message = "ALZ module has the latest version installed, but not imported. Imported version: ($($importedModule.Version)). Please re-import the module using 'Remove-Module -Name ALZ; Import-Module -Name ALZ -Global' to use the latest version."
225+
result = "Failure"
226+
}
227+
$hasFailure = $true
228+
} else {
229+
$checkResults += @{
230+
message = "ALZ module is the latest version ($($alzModuleCurrentVersion.Version))."
231+
result = "Success"
232+
}
209233
}
210234
}
211235
}

0 commit comments

Comments
 (0)