@@ -36,31 +36,28 @@ const DEFAULT_DISTRIBUTION_OWNER_NAME = "github";
3636const DEFAULT_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-binaries" ;
3737
3838/**
39- * Version constraint for the CLI.
39+ * Range of versions of the CLI that are compatible with the extension .
4040 *
4141 * This applies to both extension-managed and CLI distributions.
4242 */
43- export const DEFAULT_DISTRIBUTION_VERSION_CONSTRAINT : VersionConstraint = {
44- description : "2.*.*" ,
45- isVersionCompatible : ( v : semver . SemVer ) => semver . satisfies ( v , "2.x" )
46- } ;
43+ export const DEFAULT_DISTRIBUTION_VERSION_RANGE : semver . Range = new semver . Range ( "2.x" ) ;
4744
4845export interface DistributionProvider {
4946 getCodeQlPathWithoutVersionCheck ( ) : Promise < string | undefined > ;
5047 onDidChangeDistribution ?: Event < void > ;
5148}
5249
5350export class DistributionManager implements DistributionProvider {
54- constructor ( extensionContext : ExtensionContext , config : DistributionConfig , versionConstraint : VersionConstraint ) {
51+ constructor ( extensionContext : ExtensionContext , config : DistributionConfig , versionRange : semver . Range ) {
5552 this . _config = config ;
56- this . _extensionSpecificDistributionManager = new ExtensionSpecificDistributionManager ( extensionContext , config , versionConstraint ) ;
53+ this . _extensionSpecificDistributionManager = new ExtensionSpecificDistributionManager ( extensionContext , config , versionRange ) ;
5754 this . _onDidChangeDistribution = config . onDidChangeDistributionConfiguration ;
5855 this . _updateCheckRateLimiter = new InvocationRateLimiter (
5956 extensionContext ,
6057 "extensionSpecificDistributionUpdateCheck" ,
6158 ( ) => this . _extensionSpecificDistributionManager . checkForUpdatesToDistribution ( )
6259 ) ;
63- this . _versionConstraint = versionConstraint ;
60+ this . _versionRange = versionRange ;
6461 }
6562
6663 /**
@@ -74,17 +71,17 @@ export class DistributionManager implements DistributionProvider {
7471 } ;
7572 }
7673 const version = await getCodeQlCliVersion ( codeQlPath , logger ) ;
77- if ( version !== undefined && ! this . _versionConstraint . isVersionCompatible ( version ) ) {
74+ if ( version === undefined ) {
7875 return {
7976 codeQlPath,
80- kind : FindDistributionResultKind . IncompatibleDistribution ,
81- version,
77+ kind : FindDistributionResultKind . UnknownCompatibilityDistribution ,
8278 } ;
8379 }
84- if ( version === undefined ) {
80+ if ( ! semver . satisfies ( version , this . _versionRange ) ) {
8581 return {
8682 codeQlPath,
87- kind : FindDistributionResultKind . UnknownCompatibilityDistribution ,
83+ kind : FindDistributionResultKind . IncompatibleDistribution ,
84+ version,
8885 } ;
8986 }
9087 return {
@@ -197,14 +194,14 @@ export class DistributionManager implements DistributionProvider {
197194 private readonly _extensionSpecificDistributionManager : ExtensionSpecificDistributionManager ;
198195 private readonly _updateCheckRateLimiter : InvocationRateLimiter < DistributionUpdateCheckResult > ;
199196 private readonly _onDidChangeDistribution : Event < void > | undefined ;
200- private readonly _versionConstraint : VersionConstraint ;
197+ private readonly _versionRange : semver . Range ;
201198}
202199
203200class ExtensionSpecificDistributionManager {
204- constructor ( extensionContext : ExtensionContext , config : DistributionConfig , versionConstraint : VersionConstraint ) {
201+ constructor ( extensionContext : ExtensionContext , config : DistributionConfig , versionRange : semver . Range ) {
205202 this . _extensionContext = extensionContext ;
206203 this . _config = config ;
207- this . _versionConstraint = versionConstraint ;
204+ this . _versionRange = versionRange ;
208205 }
209206
210207 public async getCodeQlPathWithoutVersionCheck ( ) : Promise < string | undefined > {
@@ -325,7 +322,7 @@ class ExtensionSpecificDistributionManager {
325322 }
326323
327324 private async getLatestRelease ( ) : Promise < Release > {
328- const release = await this . createReleasesApiConsumer ( ) . getLatestRelease ( this . _versionConstraint , this . _config . includePrerelease ) ;
325+ const release = await this . createReleasesApiConsumer ( ) . getLatestRelease ( this . _versionRange , this . _config . includePrerelease ) ;
329326 // FIXME: Look for platform-specific codeql distribution if available
330327 release . assets = release . assets . filter ( asset => asset . name === 'codeql.zip' ) ;
331328 if ( release . assets . length === 0 ) {
@@ -373,7 +370,7 @@ class ExtensionSpecificDistributionManager {
373370
374371 private readonly _config : DistributionConfig ;
375372 private readonly _extensionContext : ExtensionContext ;
376- private readonly _versionConstraint : VersionConstraint ;
373+ private readonly _versionRange : semver . Range ;
377374
378375 private static readonly _currentDistributionFolderBaseName = "distribution" ;
379376 private static readonly _currentDistributionFolderIndexStateKey = "distributionFolderIndex" ;
@@ -394,7 +391,7 @@ export class ReleasesApiConsumer {
394391 this . _repoName = repoName ;
395392 }
396393
397- public async getLatestRelease ( versionConstraint : VersionConstraint , includePrerelease = false ) : Promise < Release > {
394+ public async getLatestRelease ( versionRange : semver . Range , includePrerelease = false ) : Promise < Release > {
398395 const apiPath = `/repos/${ this . _ownerName } /${ this . _repoName } /releases` ;
399396 const allReleases : GithubRelease [ ] = await ( await this . makeApiCall ( apiPath ) ) . json ( ) ;
400397 const compatibleReleases = allReleases . filter ( release => {
@@ -403,7 +400,7 @@ export class ReleasesApiConsumer {
403400 }
404401
405402 const version = semver . parse ( release . tag_name ) ;
406- return version !== null && versionConstraint . isVersionCompatible ( version ) ;
403+ return version !== null && semver . satisfies ( version , versionRange ) ;
407404 } ) ;
408405 // Tag names must all be parsable to semvers due to the previous filtering step.
409406 const latestRelease = compatibleReleases . sort ( ( a , b ) => {
@@ -739,11 +736,6 @@ export interface GithubReleaseAsset {
739736 size : number ;
740737}
741738
742- interface VersionConstraint {
743- description : string ;
744- isVersionCompatible ( version : semver . SemVer ) : boolean ;
745- }
746-
747739export class GithubApiError extends Error {
748740 constructor ( public status : number , public body : string ) {
749741 super ( `API call failed with status code ${ status } , body: ${ body } ` ) ;
0 commit comments