The main compilation pipeline orchestrates TypeScript compilation with Angular-specific extensions, providing the primary entry point for the @angular/tsc-wrapped functionality.
The main compilation function that orchestrates the entire compilation process with Angular extensions.
/**
* Main compilation function that orchestrates TypeScript compilation with Angular extensions
* @param project - Path to tsconfig.json file or VinylFile object
* @param cliOptions - CLI options for compilation
* @param codegen - Optional code generation extension
* @param options - Optional TypeScript compiler options
* @returns Promise that resolves when compilation is complete
*/
function main(
project: string | VinylFile,
cliOptions: CliOptions,
codegen?: CodegenExtension,
options?: ts.CompilerOptions
): Promise<any>;Usage Example:
import { main, CliOptions } from "@angular/tsc-wrapped";
const cliOptions: CliOptions = {
basePath: "./src"
};
// Compile with basic options
await main("./tsconfig.json", cliOptions);
// Compile with custom TypeScript options
await main("./tsconfig.json", cliOptions, undefined, {
target: ts.ScriptTarget.ES2015,
module: ts.ModuleKind.CommonJS
});Interface for defining custom code generation extensions that can be plugged into the compilation pipeline.
/**
* Code generation extension interface
* @param ngOptions - Angular compiler options
* @param cliOptions - CLI options
* @param program - TypeScript program
* @param host - TypeScript compiler host
* @returns Promise resolving to array of generated file names
*/
interface CodegenExtension {
(ngOptions: NgOptions, cliOptions: CliOptions, program: ts.Program, host: ts.CompilerHost): Promise<string[]>;
}Usage Example:
import { main, CodegenExtension } from "@angular/tsc-wrapped";
const myCodegen: CodegenExtension = async (ngOptions, cliOptions, program, host) => {
// Custom code generation logic here
return ["generated-file1.ts", "generated-file2.ts"];
};
await main("./tsconfig.json", { basePath: "./src" }, myCodegen);Creates a specialized compiler host for generating flat module bundle indices.
/**
* Creates a bundle index host for flat module index generation
* @param ngOptions - Angular compiler options
* @param rootFiles - Array of root file paths
* @param host - Base TypeScript compiler host
* @returns Object containing host and optional index name or errors
*/
function createBundleIndexHost(
ngOptions: NgOptions,
rootFiles: string[],
host: ts.CompilerHost
): {host: ts.CompilerHost, indexName?: string, errors?: ts.Diagnostic[]};Usage Example:
import { createBundleIndexHost } from "@angular/tsc-wrapped";
import * as ts from "typescript";
const host = ts.createCompilerHost({});
const ngOptions = { flatModuleOutFile: "index.js" };
const rootFiles = ["./src/public_api.ts"];
const result = createBundleIndexHost(ngOptions, rootFiles, host);
if (result.errors) {
console.error("Bundle index creation failed:", result.errors);
} else {
console.log("Bundle index created:", result.indexName);
// Use result.host for compilation
}Specialized error class for user-facing compilation errors.
/**
* User error class for compilation errors that should be displayed to users
*/
class UserError extends Error {
constructor(message: string);
}Usage Example:
import { UserError } from "@angular/tsc-wrapped";
try {
// Some compilation operation
} catch (error) {
if (error instanceof UserError) {
console.error("User Error:", error.message);
} else {
console.error("Internal Error:", error);
}
}Type for vinyl file objects that can be passed to the main function instead of file paths.
interface VinylFile extends Object {
/** Absolute path to the virtual file */
path: string;
/** Content of the virtual file */
contents: Buffer;
}Angular-specific compiler options (alias for AngularCompilerOptions).
type NgOptions = AngularCompilerOptions;Type guard function for checking if an object is a VinylFile.
/**
* Type guard to check if an object is a VinylFile
* @param obj - Object to check
* @returns True if the object is a VinylFile
*/
function isVinylFile(obj: any): obj is VinylFile;