diff --git a/src/compiler/executeCommandLine.ts b/src/compiler/executeCommandLine.ts index edeb0eb277c57..3d07bfe9e241e 100644 --- a/src/compiler/executeCommandLine.ts +++ b/src/compiler/executeCommandLine.ts @@ -639,6 +639,8 @@ function executeCommandLineWorker( const extendedConfigCache = new Map(); const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, extendedConfigCache, commandLine.watchOptions, sys, reportDiagnostic)!; // TODO: GH#18217 if (commandLineOptions.showConfig) { + // eslint-disable-next-line no-restricted-syntax + sys.write(JSON.stringify(convertToTSConfig(configParseResult, configFileName, sys), null, 4) + sys.newLine); if (configParseResult.errors.length !== 0) { reportDiagnostic = updateReportDiagnostic( sys, @@ -648,8 +650,6 @@ function executeCommandLineWorker( configParseResult.errors.forEach(reportDiagnostic); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } - // eslint-disable-next-line no-restricted-syntax - sys.write(JSON.stringify(convertToTSConfig(configParseResult, configFileName, sys), null, 4) + sys.newLine); return sys.exit(ExitStatus.Success); } reportDiagnostic = updateReportDiagnostic( diff --git a/src/testRunner/unittests/config/showConfig.ts b/src/testRunner/unittests/config/showConfig.ts index 9000ce035cb62..aad7192101865 100644 --- a/src/testRunner/unittests/config/showConfig.ts +++ b/src/testRunner/unittests/config/showConfig.ts @@ -132,6 +132,11 @@ describe("unittests:: config:: showConfig", () => { files: ["${configDir}/main.ts"], // eslint-disable-line no-template-curly-in-string }); + // Test that --showConfig works even when no input files are found + showTSConfigCorrectly("Show TSConfig with no input files", ["-p", "tsconfig.json"], { + include: ["./*"], + }); + // Bulk validation of all option declarations for (const option of ts.optionDeclarations) { baselineOption(option, /*isCompilerOptions*/ true); diff --git a/tests/baselines/reference/config/showConfig/Show TSConfig with no input files/tsconfig.json b/tests/baselines/reference/config/showConfig/Show TSConfig with no input files/tsconfig.json new file mode 100644 index 0000000000000..33428857131df --- /dev/null +++ b/tests/baselines/reference/config/showConfig/Show TSConfig with no input files/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": {}, + "include": [ + "./*" + ] +}