UNPKG

@ts-bridge/cli

Version:

Bridge the gap between ES modules and CommonJS modules with an easy-to-use alternative to `tsc`.

154 lines 6.87 kB
import type { CompilerHost, CompilerOptions, ParsedCommandLine, Program, ProjectReference, System } from 'typescript'; import typescript from 'typescript'; import type { BuildType } from './build-type.js'; import type { TransformerOptions } from './transformers.js'; type GetProgramOptions = { compilerOptions: CompilerOptions; projectReferences?: readonly ProjectReference[]; files: string[]; oldProgram?: Program; host?: CompilerHost; }; /** * Get the TypeScript program for the project. This function will create a new * program using the provided options and files, and perform a pre-emit * diagnostics check to ensure the project is valid. * * @param options - The options. * @param options.compilerOptions - The compiler options to use. * @param options.projectReferences - The project references to use. * @param options.files - The files to include in the program. * @param options.oldProgram - The old program to reuse. * @param options.host - The compiler host to use. * @returns The TypeScript program for the project. */ export declare function getProgram({ compilerOptions, projectReferences, files, oldProgram, host, }: GetProgramOptions): Program; export type InitialProgramOptions = { project: string; format: BuildType[]; system: System; tsConfig: ParsedCommandLine; }; /** * Get the initial program for the project. This function will create the * initial program using the provided options. * * @param options - The options. * @param options.project - The path to the project's `tsconfig.json` file. * @param options.format - The formats to build. * @param options.system - The system to use. * @param options.tsConfig - The TypeScript configuration. * @returns The initial program for the project. */ export declare function getInitialProgram({ project, format, system, tsConfig, }: InitialProgramOptions): Program; /** * Clean the output directory before building the project. * * @param project - The path to the project's `tsconfig.json` file. * @param options - The compiler options to use. * @param clean - Whether to clean the output directory before building. * @param verbose - Whether to enable verbose logging. */ export declare function cleanOutputDirectory(project: string, options: CompilerOptions, clean?: boolean, verbose?: boolean): void; export type BuilderOptions = { name: string; program: Program; projectReferences?: readonly ProjectReference[]; compilerOptions: CompilerOptions; format: BuildType[]; system: System; host?: CompilerHost; baseDirectory: string; tsConfig: ParsedCommandLine; verbose?: boolean; shims: boolean; clean?: boolean; }; /** * Build the project using the Node.js 10 module resolution strategy. This * function will build the project using the specified formats. Note that this * function is slower than {@link buildNode16} because it creates a new program * for each format. * * @param options - The build options. * @param options.name - The name of the project to build. * @param options.program - The TypeScript program to build. * @param options.projectReferences - The project references to use. * @param options.compilerOptions - The compiler options to use. * @param options.format - The formats to build. * @param options.system - The file system to use. * @param options.host - The compiler host to use. * @param options.verbose - Whether to enable verbose logging. * @param options.shims - Whether to generate shims for environment-specific * APIs. * @param options.tsConfig - The TypeScript configuration. * @param options.baseDirectory - The base directory of the project. */ export declare function buildNode10({ name, program, projectReferences, compilerOptions, format, system, host, verbose, shims, tsConfig, baseDirectory, }: BuilderOptions): void; /** * Build the project using the Node.js 16 module resolution strategy. * * @param options - The build options. * @param options.name - The name of the project to build. * @param options.program - The TypeScript program to build. * @param options.format - The formats to build. * @param options.system - The file system to use. * @param options.verbose - Whether to enable verbose logging. * @param options.shims - Whether to generate shims for environment-specific * APIs. * @param options.baseDirectory - The base directory of the project. */ export declare function buildNode16({ name, program, format, system, verbose, shims, baseDirectory, }: BuilderOptions): void; /** * Build the project references. This function will build the project references * using the specified formats. * * @param options - The build options. */ export declare function buildProjectReferences(options: BuilderOptions): Promise<void>; /** * Get the build function to use based on the TypeScript configuration. This * function will return the appropriate build function based on whether project * references are used and the module resolution strategy. * * @param tsConfig - The TypeScript configuration. * @param useReferences - Whether to include project references in the build. * @returns The build function to use. */ export declare function getBuildFunction(tsConfig: ParsedCommandLine, useReferences?: boolean): (options: BuilderOptions) => void | Promise<void>; /** * Get the transformers to use for the build. This function will return the * transformers to use based on the build type and whether shims are enabled. * If shims are enabled, the shims transformers will be included in the list. * * @param type - The build type to use. * @param options - The transformer options. * @param useShims - Whether to generate shims for environment-specific APIs. * @returns The transformers to use for the build. */ export declare function getTransformers(type: BuildType, options: TransformerOptions, useShims: boolean): typescript.TransformerFactory<typescript.SourceFile>[]; type BuildOptions = { program: Program; type: BuildType; system: System; verbose?: boolean; shims: boolean; baseDirectory: string; }; /** * Build the project. This function will compile the project using the * TypeScript compiler. * * @param options - The build options. * @param options.program - The TypeScript program to build. * @param options.type - The build type to use. * @param options.system - The file system to use. * @param options.verbose - Whether to enable verbose logging. * @param options.shims - Whether to generate shims for environment-specific * APIs. * @param options.baseDirectory - The base directory of the project. * @returns A promise that resolves when the build is complete. */ export declare function build({ program, type, system, verbose, shims, baseDirectory, }: BuildOptions): Program; export {}; //# sourceMappingURL=build-utils.d.ts.map