Skip to content

Commit

Permalink
Show implied options in --showConfig (microsoft#56701)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch authored and c0sta committed Dec 20, 2023
1 parent cfbb206 commit 530fc3c
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 158 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"playwright": "^1.38.0",
"source-map-support": "^0.5.21",
"tslib": "^2.5.0",
"typescript": "^5.3.2",
"typescript": "5.4.0-dev.20231206",
"which": "^2.0.2"
},
"overrides": {
Expand Down
20 changes: 18 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
CommandLineOptionOfListType,
CompilerOptions,
CompilerOptionsValue,
computedOptions,
ConfigFileSpecs,
containsPath,
convertToRelativePath,
Expand Down Expand Up @@ -103,6 +104,7 @@ import {
removeTrailingDirectorySeparator,
returnTrue,
ScriptTarget,
some,
startsWith,
StringLiteral,
SyntaxKind,
Expand Down Expand Up @@ -2475,9 +2477,10 @@ export function convertToTSConfig(configParseResult: ParsedCommandLine, configFi
),
f => getRelativePathFromFile(getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), getNormalizedAbsolutePath(f, host.getCurrentDirectory()), getCanonicalFileName),
);
const optionMap = serializeCompilerOptions(configParseResult.options, { configFilePath: getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), useCaseSensitiveFileNames: host.useCaseSensitiveFileNames });
const pathOptions = { configFilePath: getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), useCaseSensitiveFileNames: host.useCaseSensitiveFileNames };
const optionMap = serializeCompilerOptions(configParseResult.options, pathOptions);
const watchOptionMap = configParseResult.watchOptions && serializeWatchOptions(configParseResult.watchOptions);
const config = {
const config: TSConfig & { watchOptions?: object; } = {
compilerOptions: {
...optionMapToObject(optionMap),
showConfig: undefined,
Expand All @@ -2500,6 +2503,19 @@ export function convertToTSConfig(configParseResult: ParsedCommandLine, configFi
} : {}),
compileOnSave: !!configParseResult.compileOnSave ? true : undefined,
};

const providedKeys = new Set(optionMap.keys());
const impliedCompilerOptions: Record<string, CompilerOptionsValue> = {};
for (const option in computedOptions) {
if (!providedKeys.has(option) && some(computedOptions[option as keyof typeof computedOptions].dependencies, dep => providedKeys.has(dep))) {
const implied = computedOptions[option as keyof typeof computedOptions].computeValue(configParseResult.options);
const defaultValue = computedOptions[option as keyof typeof computedOptions].computeValue({});
if (implied !== defaultValue) {
impliedCompilerOptions[option] = computedOptions[option as keyof typeof computedOptions].computeValue(configParseResult.options);
}
}
}
assign(config.compilerOptions, optionMapToObject(serializeCompilerOptions(impliedCompilerOptions, pathOptions)));
return config;
}

Expand Down
Loading

0 comments on commit 530fc3c

Please sign in to comment.