import { HttpOperationResponse } from '@azure/ms-rest-js' ; import * as semver from 'semver' ; import { IActionContext } from 'vscode-azureextensionui' ; import { FuncVersion , getMajorVersion } from '../FuncVersion' ; import { localize } from '../localize' ; import { requestUtils } from '../utils/requestUtils' ; const npmRegistryUri = 'https://aka.ms/AA2qmnu' ; export interface INpmDistTag { tag : string ; value : string ; } interface IPackageMetadata { versions : { [ version ] : { } ; } ; } export async function getNpmDistTag ( context , version ) { const response = await requestUtils . sendRequestWithExtTimeout ( context , { method : 'GET' , url : npmRegistryUri } ) ; const packageMetadata = < IPackageMetadata > response . parsedBody ; const majorVersion = getMajorVersion ( version ) ; const validVersions = Object . keys ( packageMetadata . versions ) . filter ( ( v ) => ! ! semver . valid ( v ) ) ; const maxVersion = semver . maxSatisfying ( validVersions , majorVersion ) ; if ( ! maxVersion ) { throw new Error ( localize ( 'noDistTag' , 'Failed to retrieve NPM tag for version "{0}".' , version ) ) ; } return { tag : majorVersion , value : maxVersion } ; }