@@ -1120,7 +1120,10 @@ function Find-LocalModule {
11201120
11211121 # NOTE: We are intentionally using return instead of continue here, as soon as we find a match we are done.
11221122 foreach ($modulePath in $modulePaths ) {
1123- if (-not [Directory ]::Exists($modulePath )) { continue }
1123+ if (-not [Directory ]::Exists($modulePath )) {
1124+ Write-Debug " PSModulePath $modulePath is configured but does not exist, skipping..."
1125+ continue
1126+ }
11241127
11251128 # Linux/Mac support requires a case insensitive search on a user supplied variable.
11261129 $moduleDir = [Directory ]::GetDirectories($modulePath , $moduleSpec.Name , [EnumerationOptions ]@ {MatchCasing = ' CaseInsensitive' })
@@ -1138,7 +1141,7 @@ function Find-LocalModule {
11381141 $manifestPath = Join-Path $moduleFolder " $ ( $ModuleSpec.Name ) .psd1"
11391142
11401143 if (Test-Path $ModuleFolder ) {
1141- # Linux/Mac support requires a case insensitive search on a user supplied variable .
1144+ # Linux/Mac support requires a case insensitive search on a user supplied argument .
11421145 $manifestPath = [Directory ]::GetFiles($moduleFolder , " $ ( $ModuleSpec.Name ) .psd1" , [EnumerationOptions ]@ {MatchCasing = ' CaseInsensitive' })
11431146
11441147 if ($manifestPath.count -gt 1 ) { throw " $moduleFolder manifest is ambiguous, please delete one of these: $manifestPath " }
@@ -1148,7 +1151,19 @@ function Find-LocalModule {
11481151 $folders = [System.IO.Directory ]::GetDirectories($moduleDir ) | Split-Path - Leaf
11491152 [Version []]$candidateVersions = foreach ($folder in $folders ) {
11501153 [Version ]$version = $null
1151- if ([Version ]::TryParse($folder , [ref ]$version )) { $version } else {
1154+ if ([Version ]::TryParse($folder , [ref ]$version )) {
1155+ $version
1156+ } else {
1157+ # Check for a "classic" non-versioned module folder and get the version from the manifest
1158+ $manifestPath = [Directory ]::GetFiles((Join-Path $modulePath $moduleSpec.Name ), " $ ( $ModuleSpec.Name ) .psd1" , [EnumerationOptions ]@ {MatchCasing = ' CaseInsensitive' })
1159+ if ($manifestPath.count -gt 1 ) { throw " $moduleFolder manifest is ambiguous, please delete one of these: $manifestPath " }
1160+
1161+ if ($manifestPath ) {
1162+ $manifestData = Import-PowerShellDataFile $manifestPath
1163+ # Return the version in the manifest
1164+ $manifestData.ModuleVersion
1165+ }
1166+
11521167 Write-Warning " Could not parse $folder in $moduleDir as a valid version. This is probably a bad module directory and should be removed."
11531168 }
11541169 }
0 commit comments