UNPKG

ttsc

Version:

General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.

125 lines (124 loc) 6.68 kB
import { type ProjectInputPathIdentityContext } from "../../internal/projectInputPathIdentity"; import type { ITtscCompilerDiagnostic } from "../../structures/ITtscCompilerDiagnostic"; import type { ITtscLoadedNativePlugin } from "../../structures/internal/ITtscLoadedNativePlugin"; import type { ITtscParsedProjectConfig } from "../../structures/internal/ITtscParsedProjectConfig"; import type { ITtscProjectInputSnapshot } from "../../structures/internal/ITtscProjectInputSnapshot"; import type { TtscBuildOptions } from "../../structures/internal/TtscBuildOptions"; import type { TtscBuildResult } from "../../structures/internal/TtscBuildResult"; import { type ResidentCheckRequest } from "./residentCheckProcess"; export type RunBuildOptions = TtscBuildOptions & { skipDiagnosticsCheck?: boolean; forceListEmittedFiles?: boolean; /** Keep every compiler-owned side product inside this private directory. */ isolateOutputsTo?: string; /** * Receives selected native-plugin source roots after the project resolves. * The watch launcher uses these roots to invalidate a sidecar when its Go * implementation changes between rebuilds. */ onWatchInputs?: (inputs: readonly string[]) => void; /** * Receives the reconciled project-rule filesystem dependency snapshot. Called * only by watch launchers; ordinary builds do not probe the optional sidecar * command. */ onProjectInputs?: (inputs: ITtscProjectInputSnapshot) => void; /** * Emit an external source map from the direct tsgo build lane even when the * project configures none. Set by the ttsx runtime builds so a served emit * carries a map to inline under the source URL (issue #353). Applied only to * the plain tsgo emit — never forwarded to a native plugin host, whose own * emit honours the project's `sourceMap` setting. */ forceRuntimeSourceMap?: boolean; /** Retain an already selected project's lexical identity across API lanes. */ resolvedProject?: ITtscParsedProjectConfig; }; /** * Run `ttsc` against a tsconfig. Returns once the binary exits so the CLI can * decide how to surface diagnostics. Does not throw on non-zero exit. */ export declare function runBuild(options?: RunBuildOptions): TtscBuildResult; export type ResidentCheckWatchChange = { /** Re-resolve project, plugin, contributor, and Program topology. */ reload?: boolean; /** Retain the sidecar and execution selection but cold-load its Program. */ invalidate?: boolean; /** Local compiler or data paths changed since the prior cycle. */ changed?: readonly string[]; /** Subset of changed paths declared by ProjectRules as external inputs. */ external?: readonly string[]; }; /** * Analysis-only watch coordinator. * * The selected project and compatible check-stage processes stay resident * across ordinary source/data edits. A config, root-set, contributor, or plugin * topology transition calls for a full reset before the next cycle. Emit and * transform lanes can pass through the coordinator, but compatibility checks * keep them on the established one-shot path without starting sidecars. */ export declare class ResidentCheckWatchSession { private execution; private readonly pendingChanges; private projectInputs; private readonly processes; run(options: RunBuildOptions, change?: ResidentCheckWatchChange): Promise<TtscBuildResult>; /** Terminate every sidecar and discard the cached selection context. */ dispose(): void; private reset; private captureProjectInputs; private refreshProjectInputTopology; private runCheckPlugins; } export type ResidentCheckEntryPlan = { args: string[]; entryIndex: number; key: string | undefined; plugin: ITtscLoadedNativePlugin; }; /** * Plan every configured check entry while sharing resident processes only by * binary/name/argument identity. */ export declare function planResidentCheckEntries(plugins: readonly ITtscLoadedNativePlugin[], createArgs: (plugin: ITtscLoadedNativePlugin) => string[]): ResidentCheckEntryPlan[]; /** Retain one complete change stream per configured resident check entry. */ export declare function bufferResidentCheckEntryRequests(pending: Map<number, ResidentCheckRequest>, checks: readonly ResidentCheckEntryPlan[], request: ResidentCheckRequest): void; /** Consume exactly one configured entry's buffered request. */ export declare function takeResidentCheckEntryRequest(pending: Map<number, ResidentCheckRequest>, entryIndex: number): ResidentCheckRequest; export declare function residentCheckRequest(change: ResidentCheckWatchChange, cwd: string): ResidentCheckRequest; export declare function mergeProjectInputSnapshots(fallbackRoot: string, snapshots: readonly ITtscProjectInputSnapshot[], identities?: ProjectInputPathIdentityContext): ITtscProjectInputSnapshot; export declare function parseProjectInputSnapshot(text: string, plugin: ITtscLoadedNativePlugin): ITtscProjectInputSnapshot; export declare function isAbsoluteLocalProjectInputPath(location: string, platform?: NodeJS.Platform): boolean; /** * Merge two `TtscBuildResult` values into one. * * - `status`: the right status wins unless it is 0 (failure propagates). * - `diagnostics`: concatenated left then right. * - `emittedFiles`: right wins when present, otherwise left is kept. * - `stdout`/`stderr`: concatenated left then right. */ export declare function appendBuildOutput(left: TtscBuildResult, right: TtscBuildResult): TtscBuildResult; /** * Synthesize one structured diagnostic from a non-zero process result that * produced no parsable diagnostics, carrying the captured stderr/stdout as the * message. Shared by the public API result mapping and the plugin-failure * recovery pass so the failure text is never dropped from structured output. */ export declare function createProcessDiagnostic(result: TtscBuildResult): ITtscCompilerDiagnostic; /** * `TtscBuildResult` with `diagnostics` made optional. Used internally when * diagnostics are parsed lazily from stdout/stderr by `normalizeBuildOutput`. */ type PartialBuildResult = Omit<TtscBuildResult, "diagnostics"> & { diagnostics?: ITtscCompilerDiagnostic[]; }; /** * Normalise a raw spawn result into a `TtscBuildResult`. * * When `diagnostics` is absent they are parsed from the text output. When the * process exited non-zero but stderr is empty and stdout is non-empty, stdout * is moved to stderr so the error is visible to callers who only check stderr. */ export declare function normalizeBuildOutput(result: PartialBuildResult, cwd?: string): TtscBuildResult; export {};