A lightweight proxy API for accessing @microsoft/rush-lib with smart loading and version resolution
—
Management of Rush configuration files including common-versions.json, approved packages, and workspace settings.
Note: All APIs in this document are re-exported from @microsoft/rush-lib through @rushstack/rush-sdk.
Management of the common-versions.json file for enforcing consistent dependency versions across the workspace.
/**
* Manages the common-versions.json configuration file
*/
class CommonVersionsConfiguration {
/** Path to the common-versions.json file */
readonly filePath: string;
/** Preferred versions map from common-versions.json */
readonly preferredVersions: ReadonlyMap<string, string>;
/** Allowed alternative versions */
readonly allowedAlternativeVersions: ReadonlyMap<string, ReadonlyArray<string>>;
/** Load configuration from file */
static loadFromFile(jsonFilename: string): CommonVersionsConfiguration;
/** Get preferred version for package */
getPreferredVersion(packageName: string): string | undefined;
/** Set preferred version for package */
setPreferredVersion(packageName: string, version: string): void;
/** Remove preferred version for package */
removePreferredVersion(packageName: string): boolean;
/** Check if version is allowed */
isVersionAllowed(packageName: string, version: string): boolean;
/** Add allowed alternative version */
addAllowedAlternativeVersion(packageName: string, version: string): void;
/** Save changes to file */
save(): void;
}Usage Examples:
import { CommonVersionsConfiguration, RushConfiguration } from "@rushstack/rush-sdk";
const config = RushConfiguration.loadFromDefaultLocation();
const commonVersions = CommonVersionsConfiguration.loadFromFile(
path.join(config.commonRushConfigFolder, "common-versions.json")
);
// Check preferred versions
console.log("Preferred versions:");
for (const [packageName, version] of commonVersions.preferredVersions) {
console.log(` ${packageName}: ${version}`);
}
// Set a preferred version
commonVersions.setPreferredVersion("lodash", "^4.17.21");
// Check if version is allowed
const isAllowed = commonVersions.isVersionAllowed("react", "17.0.2");
console.log(`React 17.0.2 allowed: ${isAllowed}`);
// Add alternative version
commonVersions.addAllowedAlternativeVersion("typescript", "~4.4.0");
// Save changes
commonVersions.save();Management of approved packages lists and review categories for security and compliance.
/**
* Manages the approved packages configuration
*/
class ApprovedPackagesConfiguration {
/** Array of approved packages */
readonly approvedPackages: ReadonlyArray<ApprovedPackagesItem>;
/** Load configuration from file */
static loadFromFile(jsonFilename: string): ApprovedPackagesConfiguration;
/** Add or update an approved package */
addOrUpdatePackage(packageName: string, reviewCategory: string): ApprovedPackagesItem;
/** Try to get approved package by name */
tryGetItemByPackageName(packageName: string): ApprovedPackagesItem | undefined;
/** Check if package is approved */
isPackageApproved(packageName: string): boolean;
/** Remove approved package */
removePackage(packageName: string): boolean;
/** Save changes to file */
save(): void;
}
/**
* Represents an individual approved package entry
*/
class ApprovedPackagesItem {
/** Package name */
readonly packageName: string;
/** Review category */
readonly reviewCategory: string;
/** Whether package is allowed */
readonly allowedCategories: ReadonlySet<string>;
}
/**
* Policy for approved packages enforcement
*/
class ApprovedPackagesPolicy {
/** Whether policy is enabled */
readonly enabled: boolean;
/** Review categories that are allowed */
readonly reviewCategories: ReadonlySet<string>;
/** Default review category for new packages */
readonly defaultReviewCategory: string;
/** Check if package meets policy requirements */
checkPackage(packageName: string, projectReviewCategory: string): boolean;
}Usage Examples:
import { ApprovedPackagesConfiguration, ApprovedPackagesPolicy } from "@rushstack/rush-sdk";
// Load approved packages configuration
const approvedPackages = ApprovedPackagesConfiguration.loadFromFile(
path.join(config.commonRushConfigFolder, "approved-packages.json")
);
// Check if package is approved
const isApproved = approvedPackages.isPackageApproved("lodash");
console.log(`Lodash approved: ${isApproved}`);
// List all approved packages
console.log("Approved packages:");
for (const item of approvedPackages.approvedPackages) {
console.log(` ${item.packageName} (${item.reviewCategory})`);
}
// Add new approved package
const newItem = approvedPackages.addOrUpdatePackage("react", "standard");
console.log(`Added: ${newItem.packageName}`);
// Get specific package info
const packageInfo = approvedPackages.tryGetItemByPackageName("typescript");
if (packageInfo) {
console.log(`TypeScript category: ${packageInfo.reviewCategory}`);
}
// Save changes
approvedPackages.save();Management of experimental feature flags and Rush behavior modifications.
/**
* Manages experimental features configuration
*/
class ExperimentsConfiguration {
/** Map of experiment names to enabled status */
readonly configuration: ReadonlyMap<string, boolean>;
/** Load configuration from file */
static loadFromFile(jsonFilename: string): ExperimentsConfiguration;
/** Check if experiment is enabled */
isFeatureEnabled(experimentName: string): boolean;
/** Enable or disable an experiment */
setFeatureEnabled(experimentName: string, enabled: boolean): void;
/** Get all enabled experiments */
getEnabledExperiments(): ReadonlyArray<string>;
/** Save changes to file */
save(): void;
}Usage Examples:
import { ExperimentsConfiguration } from "@rushstack/rush-sdk";
const experiments = ExperimentsConfiguration.loadFromFile(
path.join(config.commonRushConfigFolder, "experiments.json")
);
// Check specific experiment
const buildCacheEnabled = experiments.isFeatureEnabled("buildCache");
console.log(`Build cache experiment: ${buildCacheEnabled}`);
// List enabled experiments
const enabled = experiments.getEnabledExperiments();
console.log(`Enabled experiments: ${enabled.join(", ")}`);
// Enable new experiment
experiments.setFeatureEnabled("newFeature", true);
// Save changes
experiments.save();Configuration for custom tip messages and notifications displayed by Rush.
/**
* Manages custom tips configuration
*/
class CustomTipsConfiguration {
/** Array of configured tips */
readonly tips: ReadonlyArray<ICustomTip>;
/** Load configuration from file */
static loadFromFile(jsonFilename: string): CustomTipsConfiguration;
/** Get tips by severity */
getTipsBySeverity(severity: CustomTipSeverity): ReadonlyArray<ICustomTip>;
/** Get tips by ID */
getTipById(tipId: CustomTipId): ICustomTip | undefined;
}
/**
* Individual custom tip configuration
*/
interface ICustomTip {
/** Unique tip identifier */
readonly tipId: CustomTipId;
/** Tip message text */
readonly message: string;
/** Tip severity level */
readonly severity: CustomTipSeverity;
/** Tip type */
readonly tipType: CustomTipType;
/** Optional URL for more information */
readonly url?: string;
}
/**
* Custom tip identifiers
*/
enum CustomTipId {
TIP_RUSH_CONSISTENT_VERSIONS = "TIP_RUSH_CONSISTENT_VERSIONS",
TIP_RUSH_GENERATE_CHANGELOG = "TIP_RUSH_GENERATE_CHANGELOG"
}
/**
* Tip severity levels
*/
enum CustomTipSeverity {
warning = "warning",
suggestion = "suggestion"
}
/**
* Tip types
*/
enum CustomTipType {
machineReadable = "machineReadable",
humanReadable = "humanReadable"
}Management of environment variables and Rush runtime environment settings.
/**
* Manages environment variables for Rush operations
*/
class EnvironmentConfiguration {
/** Environment variables map */
readonly environmentVariables: ReadonlyMap<string, string>;
/** Load configuration from file */
static loadFromFile(jsonFilename: string): EnvironmentConfiguration;
/** Get environment variable value */
getEnvironmentVariable(name: string): string | undefined;
/** Set environment variable */
setEnvironmentVariable(name: string, value: string): void;
/** Apply environment variables to process */
applyToProcess(): void;
}
/**
* Standard Rush environment variable names
*/
enum EnvironmentVariableNames {
RUSH_INVOKED_FOLDER = "RUSH_INVOKED_FOLDER",
RUSH_TEMP_FOLDER = "RUSH_TEMP_FOLDER",
_RUSH_LIB_PATH = "_RUSH_LIB_PATH"
}Usage Examples:
import { EnvironmentConfiguration, EnvironmentVariableNames } from "@rushstack/rush-sdk";
const envConfig = EnvironmentConfiguration.loadFromFile(
path.join(config.commonRushConfigFolder, "environment.json")
);
// Check specific environment variables
const rushPath = envConfig.getEnvironmentVariable(EnvironmentVariableNames._RUSH_LIB_PATH);
if (rushPath) {
console.log(`Rush lib path: ${rushPath}`);
}
// Set new environment variable
envConfig.setEnvironmentVariable("MY_CUSTOM_VAR", "custom-value");
// Apply to current process
envConfig.applyToProcess();
// List all configured variables
for (const [name, value] of envConfig.environmentVariables) {
console.log(`${name}=${value}`);
}Management of repository state files and persistent workspace information.
/**
* Manages repository state information
*/
class RepoStateFile {
/** Path to repo state file */
readonly filePath: string;
/** Last update time */
readonly lastUpdateTime: Date;
/** Pnpm shrinkwrap hash */
readonly pnpmShrinkwrapHash?: string;
/** Load from file */
static loadFromFile(filePath: string): RepoStateFile;
/** Check if file exists */
static exists(filePath: string): boolean;
/** Update pnpm shrinkwrap hash */
updatePnpmShrinkwrapHash(hash: string): void;
/** Save state to file */
save(): void;
/** Delete state file */
delete(): void;
}Install with Tessl CLI
npx tessl i tessl/npm-rushstack--rush-sdk