File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -163,7 +163,24 @@ function ProcessCratesIoLink([System.Uri]$linkUri, $path) {
163163function ProcessNpmLink ([System.Uri ]$linkUri ) {
164164 # npmjs.com started using Cloudflare which returns 403 and we need to instead check the registry api for existence checks
165165 # https://github.com/orgs/community/discussions/174098#discussioncomment-14461226
166- $apiUrl = $linkUri.ToString () -replace ' ^https?://(?:www\.)?npmjs\.com/package/(.*)/v' , ' https://registry.npmjs.org/$1'
166+
167+ # Handle versioned URLs: https://www.npmjs.com/package/@azure/ai-agents/v/1.1.0 -> https://registry.npmjs.org/@azure/ai-agents/1.1.0
168+ # Handle non-versioned URLs: https://www.npmjs.com/package/@azure/ai-agents -> https://registry.npmjs.org/@azure/ai-agents
169+ # The regex captures the package name (which may contain a slash for scoped packages) and optionally the version.
170+ # Query parameters and URL fragments are excluded from the transformation.
171+ $urlString = $linkUri.ToString ()
172+ if ($urlString -match ' ^https?://(?:www\.)?npmjs\.com/package/([^?#]+)/v/([^?#]+)' ) {
173+ # Versioned URL: remove the /v/ segment but keep the version
174+ $apiUrl = " https://registry.npmjs.org/$ ( $matches [1 ]) /$ ( $matches [2 ]) "
175+ }
176+ elseif ($urlString -match ' ^https?://(?:www\.)?npmjs\.com/package/([^?#]+)' ) {
177+ # Non-versioned URL: just replace the domain
178+ $apiUrl = " https://registry.npmjs.org/$ ( $matches [1 ]) "
179+ }
180+ else {
181+ # Fallback: use the original URL if it doesn't match expected patterns
182+ $apiUrl = $urlString
183+ }
167184
168185 return ProcessStandardLink ([System.Uri ]$apiUrl )
169186}
You can’t perform that action at this time.
0 commit comments