CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rushstack--rush-sdk

A lightweight proxy API for accessing @microsoft/rush-lib with smart loading and version resolution

Pending
Overview
Eval results
Files

build-operations.mddocs/

Build Operations

Build operation management, incremental builds, and change detection for efficient CI/CD workflows.

Note: All APIs in this document are re-exported from @microsoft/rush-lib through @rushstack/rush-sdk.

Capabilities

Operation Management

Core operation execution and dependency management for Rush build workflows.

/**
 * Represents a single build operation in the Rush workflow
 */
class Operation {
  /** Operation name */
  readonly name: string;
  
  /** Current operation status */
  readonly status: OperationStatus;
  
  /** Operations that this operation depends on */
  readonly dependencies: ReadonlySet<Operation>;
  
  /** Operations that depend on this operation */
  readonly consumers: ReadonlySet<Operation>;
  
  /** Associated Rush project */
  readonly associatedProject?: RushConfigurationProject;
  
  /** Execute this operation */
  executeAsync(): Promise<OperationStatus>;
  
  /** Get weight for scheduling priority */
  readonly weight: number;
}

/**
 * Status values for operations
 */
enum OperationStatus {
  /** Ready to execute */
  Ready = "ready",
  
  /** Currently executing */
  Executing = "executing", 
  
  /** Completed successfully */
  Success = "success",
  
  /** Failed during execution */
  Failure = "failure",
  
  /** Blocked by failed dependency */
  Blocked = "blocked",
  
  /** Skipped (not needed) */
  Skipped = "skipped"
}

Usage Examples:

import { Operation, OperationStatus } from "@rushstack/rush-sdk";

// Execute operations (typically done by Rush internally)
async function executeOperation(operation: Operation): Promise<void> {
  console.log(`Starting ${operation.name}`);
  
  const result = await operation.executeAsync();
  
  switch (result) {
    case OperationStatus.Success:
      console.log(`✅ ${operation.name} completed successfully`);
      break;
    case OperationStatus.Failure:
      console.log(`❌ ${operation.name} failed`);
      break;
    default:
      console.log(`⚠️ ${operation.name} finished with status: ${result}`);
  }
}

// Check operation dependencies
function analyzeOperation(operation: Operation): void {
  console.log(`Operation: ${operation.name}`);
  console.log(`Status: ${operation.status}`);
  console.log(`Dependencies: ${operation.dependencies.size}`);
  console.log(`Consumers: ${operation.consumers.size}`);
  
  if (operation.associatedProject) {
    console.log(`Project: ${operation.associatedProject.packageName}`);
  }
}

Change Detection

Change detection system for incremental builds and selective testing.

/**
 * Manages change detection for incremental builds
 */
class ChangeManager {
  /** Build all projects with change detection */
  static buildAsync(terminal: ITerminal): Promise<void>;
  
  /** Check if project has changes since last build */
  static hasChanges(project: RushConfigurationProject): boolean;
  
  /** Get list of changed projects */
  static getChangedProjects(
    rushConfiguration: RushConfiguration,
    terminal: ITerminal
  ): ReadonlyArray<RushConfigurationProject>;
  
  /** Clear change tracking state */
  static clearChangeState(rushConfiguration: RushConfiguration): void;
}

/**
 * Analyzes changes between project versions
 */
class ProjectChangeAnalyzer {
  constructor(project: RushConfigurationProject);
  
  /** Get files that have changed */
  getChangedFiles(): ReadonlyArray<string>;
  
  /** Check if specific file has changed */
  hasFileChanged(relativePath: string): boolean;
  
  /** Get change summary */
  getChangeSummary(): IChangeSummary;
}

interface IChangeSummary {
  /** Number of files changed */
  filesChanged: number;
  
  /** Number of files added */
  filesAdded: number;
  
  /** Number of files deleted */
  filesDeleted: number;
  
  /** Whether dependencies changed */
  dependenciesChanged: boolean;
}

Usage Examples:

import { ChangeManager, ProjectChangeAnalyzer, RushConfiguration } from "@rushstack/rush-sdk";

const config = RushConfiguration.loadFromDefaultLocation();

// Check for changes across workspace
const changedProjects = ChangeManager.getChangedProjects(config, terminal);
console.log(`${changedProjects.length} projects have changes`);

for (const project of changedProjects) {
  console.log(`Changed: ${project.packageName}`);
  
  // Analyze specific project changes
  const analyzer = new ProjectChangeAnalyzer(project);
  const summary = analyzer.getChangeSummary();
  
  console.log(`  Files changed: ${summary.filesChanged}`);
  console.log(`  Dependencies changed: ${summary.dependenciesChanged}`);
  
  // Get specific changed files
  const changedFiles = analyzer.getChangedFiles();
  changedFiles.slice(0, 5).forEach(file => {
    console.log(`    ${file}`);
  });
}

// Check individual project
const myProject = config.projectsByName.get("@mycompany/my-package");
if (myProject && ChangeManager.hasChanges(myProject)) {
  console.log("My package has changes");
}

Build Cache

Build cache configuration and management for faster builds.

/**
 * Build cache configuration and settings
 */
class BuildCacheConfiguration {
  /** Whether build cache is disabled */
  readonly disabled: boolean;
  
  /** Cache entry name pattern */
  readonly cacheEntryNamePattern?: string;
  
  /** Build cache provider */
  readonly buildCacheProvider?: IBuildCacheProvider;
  
  /** Load configuration from rush.json */
  static loadFromConfiguration(
    rushConfiguration: RushConfiguration
  ): BuildCacheConfiguration | undefined;
}

/**
 * File system build cache provider
 */
class FileSystemBuildCacheProvider implements IBuildCacheProvider {
  /** Cache folder path */
  readonly cacheFolder: string;
  
  /** Get cache entry for operation */
  tryGetCacheEntryAsync(
    terminal: ITerminal,
    cacheId: string
  ): Promise<ICacheEntry | undefined>;
  
  /** Store cache entry */
  trySetCacheEntryAsync(
    terminal: ITerminal,
    cacheId: string,
    cacheEntry: ICacheEntry
  ): Promise<boolean>;
}

interface IBuildCacheProvider {
  /** Try to get cached build result */
  tryGetCacheEntryAsync(
    terminal: ITerminal,
    cacheId: string
  ): Promise<ICacheEntry | undefined>;
  
  /** Try to store build result in cache */
  trySetCacheEntryAsync(
    terminal: ITerminal,
    cacheId: string,
    cacheEntry: ICacheEntry
  ): Promise<boolean>;
}

interface ICacheEntry {
  /** Cached file contents */
  readonly files: ReadonlyMap<string, Buffer>;
  
  /** Metadata about the cache entry */
  readonly metadata?: Record<string, string>;
}

Usage Examples:

import { BuildCacheConfiguration, RushConfiguration } from "@rushstack/rush-sdk";

const config = RushConfiguration.loadFromDefaultLocation();
const buildCache = BuildCacheConfiguration.loadFromConfiguration(config);

if (buildCache && !buildCache.disabled) {
  console.log("Build cache is enabled");
  console.log(`Cache pattern: ${buildCache.cacheEntryNamePattern}`);
  
  if (buildCache.buildCacheProvider) {
    console.log("Build cache provider configured");
    
    // Check for cached result (typically done by Rush internally)
    const cacheEntry = await buildCache.buildCacheProvider.tryGetCacheEntryAsync(
      terminal,
      "my-cache-key"
    );
    
    if (cacheEntry) {
      console.log(`Found cached entry with ${cacheEntry.files.size} files`);
    }
  }
} else {
  console.log("Build cache is disabled");
}

Cobuild Configuration

Distributed build configuration for scaling across multiple machines.

/**
 * Configuration for distributed (cobuild) builds
 */
class CobuildConfiguration {
  /** Whether cobuild is disabled */  
  readonly disabled: boolean;
  
  /** Cobuild context ID */
  readonly cobuildContextId?: string;
  
  /** Redis configuration for coordination */
  readonly redisConfiguration?: IRedisConfiguration;
  
  /** Load from rush.json configuration */
  static loadFromConfiguration(
    rushConfiguration: RushConfiguration  
  ): CobuildConfiguration | undefined;
}

interface IRedisConfiguration {
  /** Redis host */
  readonly host: string;
  
  /** Redis port */
  readonly port: number;
  
  /** Redis password */
  readonly password?: string;
  
  /** Redis database number */
  readonly db?: number;
}

Operation Metadata

Internal operation tracking and state management.

/**
 * Manages operation metadata and state
 */
class _OperationMetadataManager {
  /** Get metadata for operation */
  tryGetOperationMetadata(operationName: string): IOperationMetadata | undefined;
  
  /** Save operation metadata */
  saveOperationMetadata(operationName: string, metadata: IOperationMetadata): void;
}

/**
 * Operation state file management
 */
class _OperationStateFile {
  /** Load state from file */
  static tryLoad(filePath: string): _OperationStateFile | undefined;
  
  /** Operation status */
  readonly status: OperationStatus;
  
  /** Last modified time */
  readonly lastModifiedTime: Date;
  
  /** Save state to file */
  save(): void;
}

interface IOperationMetadata {
  /** Last execution status */
  readonly lastStatus?: OperationStatus;
  
  /** Last execution time */
  readonly lastExecutionTime?: Date;
  
  /** Execution duration in milliseconds */
  readonly executionDurationMs?: number;
  
  /** Cache hit/miss information */
  readonly cacheHit?: boolean;
}

Install with Tessl CLI

npx tessl i tessl/npm-rushstack--rush-sdk

docs

build-operations.md

configuration-files.md

configuration.md

index.md

manual-loading.md

package-management.md

version-management.md

tile.json