Skip to content

Commit

Permalink
Show implied options in --showConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Dec 6, 2023
1 parent 7e1c297 commit 1032991
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 150 deletions.
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
305 changes: 164 additions & 141 deletions src/compiler/utilities.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"esModuleInterop": true,
"target": "es5",
"module": "commonjs",
"strict": true
"strict": true,
"allowSyntheticDefaultImports": true
},
"references": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
},
"include": [
"./src/**/*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"checkJs": true
"checkJs": true,
"allowJs": true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"composite": true
"composite": true,
"declaration": true,
"incremental": true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"isolatedModules": true
"isolatedModules": true,
"preserveConstEnums": true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"module": "none"
"module": "none",
"moduleResolution": "classic"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"verbatimModuleSyntax": true
"verbatimModuleSyntax": true,
"isolatedModules": true,
"preserveConstEnums": true
}
}

0 comments on commit 1032991

Please sign in to comment.