diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 2c4c867fb67..9ba03842cec 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1743,6 +1743,16 @@ namespace ts { return false; } + /** @internal */ + export interface TSConfig { + compilerOptions: CompilerOptions; + compileOnSave: boolean | undefined; + exclude?: ReadonlyArray; + files: ReadonlyArray | undefined; + include?: ReadonlyArray; + references: ReadonlyArray | undefined; + } + /** * Generate an uncommented, complete tsconfig for use with "--showConfig" * @param configParseResult options to be generated into tsconfig.json @@ -1750,7 +1760,7 @@ namespace ts { * @param host provides current directory and case sensitivity services */ /** @internal */ - export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): object { + export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): TSConfig { const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames); const files = map( filter( @@ -1778,13 +1788,13 @@ namespace ts { build: undefined, version: undefined, }, - references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath, originalPath: undefined })), + references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath ? r.originalPath : "", originalPath: undefined })), files: length(files) ? files : undefined, ...(configParseResult.configFileSpecs ? { include: filterSameAsDefaultInclude(configParseResult.configFileSpecs.validatedIncludeSpecs), exclude: configParseResult.configFileSpecs.validatedExcludeSpecs } : {}), - compilerOnSave: !!configParseResult.compileOnSave ? true : undefined + compileOnSave: !!configParseResult.compileOnSave ? true : undefined }; return config; } diff --git a/src/testRunner/unittests/config/showConfig.ts b/src/testRunner/unittests/config/showConfig.ts index 043e8382d23..0a4acece37e 100644 --- a/src/testRunner/unittests/config/showConfig.ts +++ b/src/testRunner/unittests/config/showConfig.ts @@ -53,6 +53,26 @@ namespace ts { showTSConfigCorrectly("Show TSConfig with advanced options", ["--showConfig", "--declaration", "--declarationDir", "lib", "--skipLibCheck", "--noErrorTruncation"]); + showTSConfigCorrectly("Show TSConfig with compileOnSave and more", ["-p", "tsconfig.json"], { + compilerOptions: { + esModuleInterop: true, + target: "es5", + module: "commonjs", + strict: true, + }, + compileOnSave: true, + exclude: [ + "dist" + ], + files: [], + include: [ + "src/*" + ], + references: [ + { path: "./test" } + ], + }); + // Regression test for https://github.com/Microsoft/TypeScript/issues/28836 showTSConfigCorrectly("Show TSConfig with paths and more", ["-p", "tsconfig.json"], { compilerOptions: { diff --git a/tests/baselines/reference/showConfig/Show TSConfig with compileOnSave and more/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with compileOnSave and more/tsconfig.json new file mode 100644 index 00000000000..373e81d1f75 --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with compileOnSave and more/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "target": "es5", + "module": "commonjs", + "strict": true + }, + "references": [ + { + "path": "./test" + } + ], + "include": [ + "src/*" + ], + "exclude": [ + "dist" + ], + "compileOnSave": true +}