@@ -4,6 +4,22 @@ import * as os from 'node:os';
44import * as path from 'node:path' ;
55import { s as semverExports } from './semver.mjs' ;
66
7+ var NugetServiceType = /* @__PURE__ */ ( ( NugetServiceType2 ) => {
8+ NugetServiceType2 [ "Catalog" ] = "Catalog" ;
9+ NugetServiceType2 [ "PackageBaseAddress" ] = "PackageBaseAddress" ;
10+ NugetServiceType2 [ "PackageDetailsUriTemplate" ] = "PackageDetailsUriTemplate" ;
11+ NugetServiceType2 [ "PackagePublish" ] = "PackagePublish" ;
12+ NugetServiceType2 [ "ReadmeUriTemplate" ] = "ReadmeUriTemplate" ;
13+ NugetServiceType2 [ "RegistrationsBaseUrl" ] = "RegistrationsBaseUrl" ;
14+ NugetServiceType2 [ "ReportAbuseUriTemplate" ] = "ReportAbuseUriTemplate" ;
15+ NugetServiceType2 [ "RepositorySignatures" ] = "RepositorySignatures" ;
16+ NugetServiceType2 [ "SearchAutocompleteService" ] = "SearchAutocompleteService" ;
17+ NugetServiceType2 [ "SearchQueryService" ] = "SearchQueryService" ;
18+ NugetServiceType2 [ "SymbolPackagePublish" ] = "SymbolPackagePublish" ;
19+ NugetServiceType2 [ "VulnerabilityInfo" ] = "VulnerabilityInfo" ;
20+ return NugetServiceType2 ;
21+ } ) ( NugetServiceType || { } ) ;
22+
723class ArgumentsBuilder {
824 args = [ ] ;
925 isWindows = os . platform ( ) === "win32" ;
@@ -167,7 +183,6 @@ class DotnetTool {
167183 constructor ( buildAgent ) {
168184 this . buildAgent = buildAgent ;
169185 }
170- static nugetRoot = "https://azuresearch-usnc.nuget.org/query" ;
171186 disableTelemetry ( ) {
172187 this . buildAgent . info ( "Disable Telemetry" ) ;
173188 this . buildAgent . setVariable ( "DOTNET_CLI_TELEMETRY_OPTOUT" , "true" ) ;
@@ -318,13 +333,40 @@ class DotnetTool {
318333 }
319334 return path . normalize ( workDir ) ;
320335 }
336+ async getQueryService ( ) {
337+ const result = await this . execute (
338+ "dotnet" ,
339+ new ArgumentsBuilder ( ) . addArgument ( "nuget" ) . addArgument ( "list" ) . addArgument ( "source" ) . addKeyValue ( "format" , "short" ) . build ( )
340+ ) ;
341+ const defaultNugetSource = / E (?< index > .+ ) / . exec ( result . stdout ?? "" ) ?. groups ?. index ;
342+ if ( ! defaultNugetSource ) {
343+ this . buildAgent . error ( "Failed to fetch an enabled package source for dotnet." ) ;
344+ return null ;
345+ }
346+ var nugetIndex = await fetch ( defaultNugetSource ) ;
347+ if ( ! nugetIndex ?. ok ) {
348+ this . buildAgent . error ( `Failed to fetch data from NuGet source ${ defaultNugetSource } .` ) ;
349+ return null ;
350+ }
351+ const resources = ( await nugetIndex . json ( ) ) ?. resources ;
352+ var service = resources ?. find ( ( s ) => s [ "@type" ] . startsWith ( "SearchQueryService" ) ) ?. [ "@id" ] ;
353+ if ( ! service ) {
354+ this . buildAgent . error ( `Could not find a ${ NugetServiceType . SearchQueryService } in NuGet source ${ defaultNugetSource } ` ) ;
355+ return null ;
356+ }
357+ return service ;
358+ }
321359 async queryLatestMatch ( toolName , versionSpec , includePrerelease ) {
322360 this . buildAgent . info (
323361 `Querying tool versions for ${ toolName } ${ versionSpec ? `@${ versionSpec } ` : "" } ${ includePrerelease ? "including pre-releases" : "" } `
324362 ) ;
363+ const queryService = await this . getQueryService ( ) ;
364+ if ( ! queryService ) {
365+ return null ;
366+ }
325367 const toolNameParam = encodeURIComponent ( toolName . toLowerCase ( ) ) ;
326368 const prereleaseParam = includePrerelease ? "true" : "false" ;
327- const downloadPath = `${ DotnetTool . nugetRoot } ?q=${ toolNameParam } &prerelease=${ prereleaseParam } &semVerLevel=2.0.0&take=1` ;
369+ const downloadPath = `${ queryService } ?q=${ toolNameParam } &prerelease=${ prereleaseParam } &semVerLevel=2.0.0&take=1` ;
328370 const response = await fetch ( downloadPath ) ;
329371 if ( ! response || ! response . ok ) {
330372 this . buildAgent . info ( `failed to query latest version for ${ toolName } from ${ downloadPath } . Status code: ${ response ? response . status : "unknown" } ` ) ;
0 commit comments