import { type PackageInfos } from "workspace-tools"; import type { Priority } from "./types/Priority.js"; import type { Target } from "./types/Target.js"; import type { TargetConfig } from "./types/TargetConfig.js"; import type { TargetGraph } from "./types/TargetGraph.js"; /** * TargetGraphBuilder class provides a builder API for registering target configs. It exposes a method called `generateTargetGraph` to * generate a topological graph of targets (package + task) and their dependencies. * * Usage: * * ```typescript * const rootDir = process.cwd(); * const packageInfos = getPackageInfos(rootDir); * const builder = new WorkspaceTargetGraphBuilder(rootDir, packageInfos); * const targetGraph = builder.buildTargetGraph([...packages], [...tasks]); * ``` */ export declare class WorkspaceTargetGraphBuilder { private options; /** A cache of the dependencyMap for packages, used inside dependency expansion */ private dependencyMap; private graphBuilder; private targetFactory; /** Whether at least one global/root target has been added */ private hasRootTarget; /** Whether at least one relevant staged target has been added */ private hasAnyStagedTarget; private targetConfigMap; /** * Initializes the builder with package infos */ constructor(options: { /** Root directory of the monorepo */ root: string; /** Package infos for the monorepo */ packageInfos: PackageInfos; enableTargetConfigMerging: boolean; enablePhantomTargetOptimization: boolean; }); /** * Generates new `Target`, indexed by the id based on a new target configuration. */ addTargetConfig(id: string, config?: TargetConfig, changedFiles?: string[]): void; private deepCloneTargetConfig; /** * If `enableTargetConfigMerging`, merges `config` with any existing config for target `targetId`. * @param targetId The Id of the target to merge * @param config The TargetConfig settings that will be merged if this target has already been seen before * @returns The merged TargetConfig object. */ private determineFinalTargetConfig; /** * If `parentTarget` has a `stagedTarget` field and the number of `changedFiles` is below the * threshold, adds a staged version of this target with the same dependencies as `parentTarget`, * and makes `parentTarget` a no-op that depends on the staged target. This allows us to have a s * ingle task that runs over a list of changed files when running with `--since` flag, while still * preserving the original target for cases when we want to run it over all files. */ private processStagedConfig; shouldRun(config: TargetConfig, target: Target): boolean | Promise; /** * Builds a scoped target graph for given tasks and packages * * Steps: * 1. expands the dependency specs from the target definitions * 2. sub-graph filtered from the full dependency graph * 3. filtering all targets to just only the ones listed in the sub-graph * 4. returns the sub-graph * * @param tasks Tasks for the graph * @param scope If provided, scope to these packages. Otherwise includes all packages. * @param priorities the set of global priorities for the workspace. */ build(tasks: string[], scope?: string[], priorities?: Priority[]): Promise; }