Skip to content

Commit 81fedfa

Browse files
azure-sdkCopilotweshaggard
authored
Sync eng/common directory with azure-sdk-tools for PR 13307 (#44397)
* Fix npm URL replacement logic to handle versioned and non-versioned URLs Co-authored-by: weshaggard <[email protected]> * Simplify regex pattern as suggested by weshaggard Co-authored-by: weshaggard <[email protected]> * Fix regex to handle query params and fragments, add edge case tests Co-authored-by: weshaggard <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: weshaggard <[email protected]> Co-authored-by: Wes Haggard <[email protected]>
1 parent c9f47f9 commit 81fedfa

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

eng/common/scripts/Verify-Links.ps1

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,24 @@ function ProcessCratesIoLink([System.Uri]$linkUri, $path) {
163163
function 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
}

0 commit comments

Comments
 (0)