@ts-bridge/cli
Version:
Bridge the gap between ES modules and CommonJS modules with an easy-to-use alternative to `tsc`.
73 lines • 3.02 kB
TypeScript
import type { CompilerHost, CompilerOptions, ResolvedProjectReference, System } from 'typescript';
import type { BuildType } from './build-type.js';
/**
* A dependency graph where each value has a list of dependencies.
*
* @template Value - The type of the values in the graph.
*/
export type DependencyGraph<Value> = Map<Value, Value[]>;
/**
* Create a dependency graph from the resolved project references.
*
* @param resolvedProjectReferences - The resolved project references of the
* package that is being built.
* @returns The dependency graph.
*/
export declare function createGraph(resolvedProjectReferences: readonly ResolvedProjectReference[]): DependencyGraph<ResolvedProjectReference>;
/**
* The result of a topological sort.
*
* @template Value - The type of the values in the graph.
*/
export type TopologicalSortResult<Value> = {
/**
* The sorted nodes.
*/
stack: Value[];
/**
* Whether there was a cycle in the graph.
*/
cycles: Value[][];
};
/**
* Topologically sort a dependency graph, i.e., sort the nodes in the graph such
* that all dependencies of a node come before the node itself.
*
* @param graph - The dependency graph to sort.
* @returns The topologically sorted nodes and an array of cycles (if any).
*/
export declare function topologicalSort<Value>(graph: DependencyGraph<Value>): TopologicalSortResult<Value>;
/**
* Get the error message for a dependency cycle.
*
* @param baseDirectory - The base directory path.
* @param cycles - The cycles in the dependency graph.
* @returns The error message.
*/
export declare function getCyclesError(baseDirectory: string, cycles: ResolvedProjectReference[][]): string;
/**
* Get the resolved project references from a TypeScript program.
*
* @param baseDirectory - The base directory path.
* @param resolvedProjectReferences - The resolved project references of the
* package that is being built.
* @returns The resolved project references.
*/
export declare function getResolvedProjectReferences(baseDirectory: string, resolvedProjectReferences: ResolvedProjectReference[]): ResolvedProjectReference[];
/**
* Create a compiler host that can be used to build projects using
* project references.
*
* This is almost the same as the default compiler host, but it modifies a few
* functions to redirect TypeScript to the `.[cm]ts` and `.[cm]js` files of the
* referenced projects, depending on the used format.
*
* @param format - The format of the output files.
* @param compilerOptions - The compiler options to use.
* @param resolvedProjectReferences - The resolved project references of the
* package that is being built.
* @param system - The TypeScript system to use.
* @returns The compiler host.
*/
export declare function createProjectReferencesCompilerHost(format: BuildType[], compilerOptions: CompilerOptions, resolvedProjectReferences: readonly ResolvedProjectReference[], system: System): CompilerHost;
//# sourceMappingURL=project-references.d.ts.map