@@ -88,30 +88,23 @@ function ConvertTo-NormalizedModulePath {
8888 )
8989
9090 process {
91- # Split PSModulePath into individual paths and normalize them
92- $modulePaths = $env: PSModulePath -split [IO.Path ]::PathSeparator |
93- Where-Object { -not [string ]::IsNullOrWhiteSpace($_ ) } |
94- ForEach-Object { $_.TrimEnd (' \' , ' /' ) }
95-
96- # Try to match the start of the path with any module path
97- foreach ($modulePath in $modulePaths ) {
98- if ($Path -match [regex ]::Escape($modulePath )) {
99- $normalizedPath = $Path -replace [regex ]::Escape($modulePath ), ' '
100- # Remove any leading path separators
101- $normalizedPath = $normalizedPath.TrimStart (' \' , ' /' )
102-
103- # If path was successfully normalized, return it
104- if ($normalizedPath -ne $Path ) {
105- return " Modules/$normalizedPath "
106- }
107- } elseif ($Path -match ' (runner|runneradmin)[/\\].*[/\\]Modules[/\\]' ) {
108- # Handle common GitHub runner paths that might not be in PSModulePath
109- $normalizedPath = $Path -replace ' .*?(Modules[/\\])' , ' Modules/'
110- return $normalizedPath
111- }
91+ # Normalize backslashes to forward slashes for consistency
92+ $Path = $Path.Replace (' \' , ' /' )
93+
94+ # Get only the first module path and normalize it
95+ $modulePath = ($env: PSModulePath -split [IO.Path ]::PathSeparator | Where-Object { -not [string ]::IsNullOrWhiteSpace($_ ) } | Select-Object - First 1 ).TrimEnd(' \' , ' /' ).Replace(' \' , ' /' )
96+
97+ if ($modulePath -and $Path -match [regex ]::Escape($modulePath )) {
98+ # Remove the module path prefix
99+ $normalizedPath = $Path -replace [regex ]::Escape($modulePath ), ' '
100+ # Remove any leading path separators
101+ $normalizedPath = $normalizedPath.TrimStart (' /' )
102+
103+ # Return with the standard "Modules/" prefix
104+ return " Modules/$normalizedPath "
112105 }
113106
114- # If no module path matched, use the existing relative path function
115- return ConvertTo-RelativePath $Path
107+ # If no match found, just normalize slashes and return the original path
108+ return $Path
116109 }
117110}
0 commit comments