Skip to content

Fix --showConfig to work when no input files are found #62047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/compiler/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,19 +638,24 @@ function executeCommandLineWorker(
if (configFileName) {
const extendedConfigCache = new Map<string, ExtendedConfigCacheEntry>();
const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, extendedConfigCache, commandLine.watchOptions, sys, reportDiagnostic)!; // TODO: GH#18217
if (commandLineOptions.showConfig) {
if (configParseResult.errors.length !== 0) {
reportDiagnostic = updateReportDiagnostic(
sys,
reportDiagnostic,
configParseResult.options,
);
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);
if (commandLineOptions.showConfig) {
// For --showConfig, filter out "no inputs found" errors since the purpose is to show configuration, not compile
const errorsExcludingNoInputs = configParseResult.errors.filter(error =>
error.code !== Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2.code
);

if (errorsExcludingNoInputs.length !== 0) {
reportDiagnostic = updateReportDiagnostic(
sys,
reportDiagnostic,
configParseResult.options,
);
errorsExcludingNoInputs.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(
sys,
Expand Down
11 changes: 8 additions & 3 deletions src/testRunner/unittests/config/showConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@ describe("unittests:: config:: showConfig", () => {
include: [
"${configDir}/src/**/*", // eslint-disable-line no-template-curly-in-string
],
files: ["${configDir}/main.ts"], // eslint-disable-line no-template-curly-in-string
});

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);
Expand Down