import { isDirectory , isFile } from "@rnx-kit/tools-node" ; import { findConfigFile , readConfigFile } from "@rnx-kit/typescript-service" ; import path from "path" ; import ts from "typescript" ; import type { CommandLine } from "./command-line" ; param project returns export function resolveConfigFile ( project ) { const fileOrDirectory = path . normalize ( project ) ; if ( ! fileOrDirectory || isDirectory ( fileOrDirectory ) ) { const projectFile = path . join ( fileOrDirectory , "tsconfig.json" ) ; if ( ! isFile ( projectFile ) ) { throw new Error ( `Cannot find a tsconfig.json file at the specified directory: ${ project }` ) ; } return projectFile ; } if ( ! isFile ( fileOrDirectory ) ) { throw new Error ( `The specified path does not exist: ${ project }` ) ; } return fileOrDirectory ; } param cmdLineTs returns export function ensureConfigFileOrSourceFiles ( cmdLineTs ) { let configFileName = undefined ; if ( cmdLineTs . options . project ) { if ( cmdLineTs . fileNames . length !== 0 ) { throw new Error ( "Cannot use a TypeScript configuration file and individually named source files together on the command-line" ) ; } configFileName = resolveConfigFile ( cmdLineTs . options . project ) ; } else if ( cmdLineTs . fileNames . length === 0 ) { configFileName = findConfigFile ( process . cwd ( ) ) ; } if ( cmdLineTs . fileNames . length === 0 && ! configFileName ) { throw new Error ( "The command-line must include either a TypeScript configuration file or individually named source files" ) ; } return configFileName ; } param cmdLine returns export function tryReadTsConfigFile ( cmdLine ) { const configFileName = ensureConfigFileOrSourceFiles ( cmdLine . ts ) ; if ( configFileName ) { const parsedConfig = readConfigFile ( configFileName , cmdLine . ts . options , cmdLine . ts . watchOptions ) ; return parsedConfig ; } return undefined ; }