@@ -77,3 +77,41 @@ function Normalize-IndentationExceptFirst {
7777 # Reconstruct the final code: first line + adjusted subsequent lines
7878 return ($firstLine + $newLine + ($subsequentLines -join $newLine ))
7979}
80+
81+
82+ # Improve path normalization by using PSModulePath
83+ function ConvertTo-NormalizedModulePath {
84+ [CmdletBinding ()]
85+ param (
86+ [Parameter (Mandatory , ValueFromPipeline )]
87+ [string ] $Path
88+ )
89+
90+ 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+ }
112+ }
113+
114+ # If no module path matched, use the existing relative path function
115+ return ConvertTo-RelativePath $Path
116+ }
117+ }
0 commit comments