@@ -1130,30 +1130,44 @@ function Find-LocalModule {
11301130
11311131 # NOTE: We are intentionally using return instead of continue here, as soon as we find a match we are done.
11321132 foreach ($modulePath in $modulePaths ) {
1133+ # Linux/Mac support requires a case insensitive search on a user supplied variable.
1134+ $moduleDir = [Directory ]::GetDirectories($modulePath , $moduleSpec.Name , [EnumerationOptions ]@ {MatchCasing = ' CaseInsensitive' })
1135+ if ($moduleDir.count -gt 1 ) { throw " $ ( $moduleSpec.Name ) folder is ambiguous, please delete one of these folders: $moduleDir " }
1136+ if (-not $moduleDir ) {
1137+ Write-Debug " $modulePath does not have a $ ( $moduleSpec.Name ) folder. Skipping..."
1138+ continue
1139+ }
1140+
11331141 if ($moduleSpec.Required ) {
11341142 # We can speed up the search for explicit requiredVersion matches
11351143 $moduleVersion = $ModuleSpec.Version # We want to search using a nuget translated path
1136- $manifestPath = Join-Path $modulePath $ModuleSpec.Name $moduleVersion " $ ( $ModuleSpec.Name ) .psd1"
1137- if ([File ]::Exists($manifestPath )) { return $manifestPath }
1144+ $moduleFolder = Join-Path $modulePath $ModuleSpec.Name $moduleVersion
1145+
1146+ $manifestPath = Join-Path $moduleFolder " $ ( $ModuleSpec.Name ) .psd1"
1147+
1148+ if (Test-Path $ModuleFolder ) {
1149+ # Linux/Mac support requires a case insensitive search on a user supplied variable.
1150+ $manifestPath = [Directory ]::GetFiles($moduleFolder , " $ ( $ModuleSpec.Name ) .psd1" , [EnumerationOptions ]@ {MatchCasing = ' CaseInsensitive' })
1151+
1152+ if ($manifestPath.count -gt 1 ) { throw " $moduleFolder manifest is ambiguous, please delete one of these: $manifestPath " }
1153+ if ($manifestPath.count -eq 1 ) { return $manifestPath }
1154+ }
11381155 } else {
1139- # Get all the version folders for the moduleName
1140- $moduleNamePath = Join-Path $modulePath $ModuleSpec.Name
1141- if (-not ([Directory ]::Exists($moduleNamePath ))) { continue }
1142- $folders = [System.IO.Directory ]::GetDirectories($moduleNamePath ) | Split-Path - Leaf
1156+ $folders = [System.IO.Directory ]::GetDirectories($moduleDir ) | Split-Path - Leaf
11431157 [Version []]$candidateVersions = foreach ($folder in $folders ) {
11441158 [Version ]$version = $null
11451159 if ([Version ]::TryParse($folder , [ref ]$version )) { $version } else {
1146- Write-Warning " Could not parse $folder in $moduleNamePath as a valid version. This is probably a bad module directory and should be removed."
1160+ Write-Warning " Could not parse $folder in $moduleDir as a valid version. This is probably a bad module directory and should be removed."
11471161 }
11481162 }
11491163
11501164 if (-not $candidateVersions ) {
1151- Write-Verbose " $moduleSpec `: module folder exists at $moduleNamePath but no modules found that match the version spec."
1165+ Write-Verbose " $moduleSpec `: module folder exists at $moduleDir but no modules found that match the version spec."
11521166 continue
11531167 }
11541168 $versionMatch = Limit-ModuleFastSpecVersions - ModuleSpec $ModuleSpec - Versions $candidateVersions - Highest
11551169 if ($versionMatch ) {
1156- $manifestPath = Join-Path $moduleNamePath $ ([Version ]$versionMatch ) " $ ( $ModuleSpec.Name ) .psd1"
1170+ $manifestPath = Join-Path $moduleDir $ ([Version ]$versionMatch ) " $ ( $ModuleSpec.Name ) .psd1"
11571171 if (-not [File ]::Exists($manifestPath )) {
11581172 # Our matching method doesn't make it easy to match on "next highest" version, so we have to do this.
11591173 throw " A matching module folder was found for $ModuleSpec but the manifest is not present at $manifestPath . This indicates a corrupt module and should be removed before proceeding."
0 commit comments