| 6 | import { ParsedCommandLine, updateParsedConfigFile } from "./parse"; |
| 7 | |
| 8 | export function locateConfigFile(commandLine: ParsedCommandLine): ts.Diagnostic | string | undefined { |
| 9 | const { project } = commandLine.options; |
| 10 | if (!project) { |
| 11 | if (commandLine.fileNames.length > 0) { |
| 12 | return undefined; |
| 13 | } |
| 14 | |
| 15 | const searchPath = normalizeSlashes(process.cwd()); |
| 16 | return ts.findConfigFile(searchPath, ts.sys.fileExists); |
| 17 | } |
| 18 | |
| 19 | if (commandLine.fileNames.length !== 0) { |
| 20 | return cliDiagnostics.optionProjectCannotBeMixedWithSourceFilesOnACommandLine(); |
| 21 | } |
| 22 | |
| 23 | // TODO: Unlike tsc, this resolves `.` to absolute path |
| 24 | const fileOrDirectory = normalizeSlashes(path.resolve(process.cwd(), project)); |
| 25 | if (ts.sys.directoryExists(fileOrDirectory)) { |
| 26 | const configFileName = path.posix.join(fileOrDirectory, "tsconfig.json"); |
| 27 | if (ts.sys.fileExists(configFileName)) { |
| 28 | return configFileName; |
| 29 | } else { |
| 30 | return cliDiagnostics.cannotFindATsconfigJsonAtTheSpecifiedDirectory(project); |
| 31 | } |
| 32 | } else if (ts.sys.fileExists(fileOrDirectory)) { |
| 33 | return fileOrDirectory; |
| 34 | } else { |
| 35 | return cliDiagnostics.theSpecifiedPathDoesNotExist(project); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | export function parseConfigFileWithSystem( |
| 40 | configFileName: string, |