import { changeHostToUseReactNativeResolver } from "@rnx-kit/typescript-react-native-resolver" ; import fs from "fs" ; import os from "os" ; import ts from "typescript" ; import { changeModuleResolutionHostToUseReadCache } from "./cache" ; import type { CommandLine } from "./command-line" ; function configureCompilerHost ( compilerHost , cmdLine ) { const { platform , platformExtensions , disableReactNativePackageSubstitution , traceReactNativeModuleResolutionErrors , traceResolutionLog , } = cmdLine . rnts ; changeModuleResolutionHostToUseReadCache ( compilerHost ) ; if ( platform ) { changeHostToUseReactNativeResolver ( { host : compilerHost , options : cmdLine . ts . options , platform , platformExtensionNames : platformExtensions , disableReactNativePackageSubstitution : ! ! disableReactNativePackageSubstitution , traceReactNativeModuleResolutionErrors : ! ! traceReactNativeModuleResolutionErrors , traceResolutionLog } ) ; } else { if ( traceResolutionLog ) { compilerHost . trace = ( message ) : void => { fs . writeFileSync ( traceResolutionLog , message + os . EOL , { encoding : "utf-8" , flag : "a" } ) ; } ; } else { compilerHost . trace = ts . sys . write ; } } } function getProgramOptions ( cmdLine , host ) { return { rootNames : cmdLine . ts . fileNames , options : cmdLine . ts . options , projectReferences : cmdLine . ts . projectReferences , host , configFileParsingDiagnostics : ts . getConfigFileParsingDiagnostics ( cmdLine . ts ) } ; } param cmdLine returns export function createProgram ( cmdLine ) { const host = ts . createCompilerHost ( cmdLine . ts . options ) ; configureCompilerHost ( host , cmdLine ) ; const program = ts . createProgram ( getProgramOptions ( cmdLine , host ) ) ; return program ; } param cmdLine returns export function createIncrementalProgram ( cmdLine ) { const host = ts . createIncrementalCompilerHost ( cmdLine . ts . options ) ; configureCompilerHost ( host , cmdLine ) ; const program = ts . createIncrementalProgram ( getProgramOptions ( cmdLine , host ) ) ; return program ; }