diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5b70c70ae4b83..780f95d7f8cc3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1622,7 +1622,7 @@ }, "Cannot assign an abstract constructor type to a non-abstract constructor type.": { "category": "Error", - "code":2517 + "code": 2517 }, "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": { "category": "Error", @@ -2068,6 +2068,14 @@ "category": "Error", "code": 5056 }, + "Cannot find a tsconfig.json file at the specified directory: '{0}'": { + "category": "Error", + "code": 5057 + }, + "The specified path does not exist: '{0}'": { + "category": "Error", + "code": 5058 + }, "Concatenate and emit output to single file.": { "category": "Message", diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index c288e11eb2438..d064ec54c9ce6 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -295,11 +295,26 @@ namespace ts { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"), /* compilerHost */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } - configFileName = normalizePath(combinePaths(commandLine.options.project, "tsconfig.json")); if (commandLine.fileNames.length !== 0) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line), /* compilerHost */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } + + const fileOrDirectory = normalizePath(commandLine.options.project); + if (!fileOrDirectory /* current directory "." */ || sys.directoryExists(fileOrDirectory)) { + configFileName = combinePaths(fileOrDirectory, "tsconfig.json"); + if (!sys.fileExists(configFileName)) { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0, commandLine.options.project), /* compilerHost */ undefined); + return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); + } + } + else { + configFileName = fileOrDirectory; + if (!sys.fileExists(configFileName)) { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_specified_path_does_not_exist_Colon_0, commandLine.options.project), /* compilerHost */ undefined); + return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); + } + } } else if (commandLine.fileNames.length === 0 && isJSONSupported()) { const searchPath = normalizePath(sys.getCurrentDirectory());