Add OfflineFeatures class

This commit is contained in:
Michael B. Gale
2026-02-12 17:42:40 +00:00
parent 5283c3ba5a
commit 368f322a09
8 changed files with 577 additions and 168 deletions
+68 -19
View File
@@ -104027,27 +104027,24 @@ var featureConfig = {
}
};
var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json";
var Features = class {
constructor(gitHubVersion, repositoryNwo, tempDir, logger) {
var OfflineFeatures = class {
constructor(logger) {
this.logger = logger;
this.gitHubFeatureFlags = new GitHubFeatureFlags(
gitHubVersion,
repositoryNwo,
path4.join(tempDir, FEATURE_FLAGS_FILE_NAME),
logger
);
}
gitHubFeatureFlags;
async getDefaultCliVersion(variant) {
if (supportsFeatureFlags(variant)) {
return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags();
}
async getDefaultCliVersion(_variant) {
return {
cliVersion,
tagName: bundleVersion
};
}
/**
* Gets the `FeatureConfig` for `feature`.
*/
getFeatureConfig(feature) {
return featureConfig[feature];
}
/**
* Determines whether `feature` is enabled without consulting the GitHub API.
*
* @param feature The feature to check.
* @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the
@@ -104060,7 +104057,17 @@ var Features = class {
* @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided.
*/
async getValue(feature, codeql) {
const config = featureConfig[feature];
const offlineValue = await this.getOfflineValue(feature, codeql);
if (offlineValue !== void 0) {
return offlineValue;
}
return this.getDefaultValue(feature);
}
/**
* Determines whether `feature` is enabled using the CLI and environment variables.
*/
async getOfflineValue(feature, codeql) {
const config = this.getFeatureConfig(feature);
if (!codeql && config.minimumVersion) {
throw new Error(
`Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.`
@@ -104110,6 +104117,52 @@ var Features = class {
);
return true;
}
return void 0;
}
/** Gets the default value of `feature`. */
async getDefaultValue(feature) {
const config = this.getFeatureConfig(feature);
const defaultValue = config.defaultValue;
this.logger.debug(
`Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.`
);
return defaultValue;
}
};
var Features = class extends OfflineFeatures {
gitHubFeatureFlags;
constructor(gitHubVersion, repositoryNwo, tempDir, logger) {
super(logger);
this.gitHubFeatureFlags = new GitHubFeatureFlags(
gitHubVersion,
repositoryNwo,
path4.join(tempDir, FEATURE_FLAGS_FILE_NAME),
logger
);
}
async getDefaultCliVersion(variant) {
if (supportsFeatureFlags(variant)) {
return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags();
}
return super.getDefaultCliVersion(variant);
}
/**
*
* @param feature The feature to check.
* @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the
* feature, the version of the CodeQL CLI will be checked against the minimum version.
* If the version is less than the minimum version, the feature will be considered
* disabled. If not provided, and a `minimumVersion` is specified for the feature, the
* this function will throw.
* @returns true if the feature is enabled, false otherwise.
*
* @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided.
*/
async getValue(feature, codeql) {
const offlineValue = await this.getOfflineValue(feature, codeql);
if (offlineValue !== void 0) {
return offlineValue;
}
const apiValue = await this.gitHubFeatureFlags.getValue(feature);
if (apiValue !== void 0) {
this.logger.debug(
@@ -104117,11 +104170,7 @@ var Features = class {
);
return apiValue;
}
const defaultValue = config.defaultValue;
this.logger.debug(
`Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.`
);
return defaultValue;
return this.getDefaultValue(feature);
}
};
var GitHubFeatureFlags = class {