From 4544aa6032f66ee2175ea40ca207396af0d927c6 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 25 Sep 2018 15:57:27 -0700 Subject: [PATCH 1/5] Add showConfig tsc flag for debugging configs --- src/compiler/commandLineParser.ts | 7 +++ src/compiler/diagnosticMessages.json | 4 ++ src/compiler/types.ts | 1 + src/tsc/tsc.ts | 91 ++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 3ebb865a64c32..96f2e585b5806 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -164,6 +164,13 @@ namespace ts { category: Diagnostics.Command_line_Options, description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental }, + { + name: "showConfig", + type: "boolean", + category: Diagnostics.Command_line_Options, + isCommandLineOnly: true, + description: Diagnostics.Print_the_final_configuration_instead_of_building + }, // Basic { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ce1ccf1714548..8ab0e41edba1a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1007,6 +1007,10 @@ "category": "Error", "code": 1349 }, + "Print the final configuration instead of building.": { + "category": "Message", + "code": 1350 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 97ef69d41e58c..38118843e92ad 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4443,6 +4443,7 @@ namespace ts { /*@internal*/ version?: boolean; /*@internal*/ watch?: boolean; esModuleInterop?: boolean; + /* @internal */ showConfig?: boolean; [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; } diff --git a/src/tsc/tsc.ts b/src/tsc/tsc.ts index ec2d029e60a01..1ce5ec9bc4b5f 100644 --- a/src/tsc/tsc.ts +++ b/src/tsc/tsc.ts @@ -132,6 +132,50 @@ namespace ts { const commandLineOptions = commandLine.options; if (configFileName) { const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, sys, reportDiagnostic)!; // TODO: GH#18217 + if (commandLineOptions.showConfig) { + const getCanonicalFileName = createGetCanonicalFileName(sys.useCaseSensitiveFileNames); + const files = map( + filter( + configParseResult.fileNames, + !configParseResult.configFileSpecs ? _ => false : matchesSpecs( + configFileName, + configParseResult.configFileSpecs.validatedIncludeSpecs, + configParseResult.configFileSpecs.validatedExcludeSpecs + ) + ), + f => getRelativePathFromFile(getNormalizedAbsolutePath(configFileName!, sys.getCurrentDirectory()), f, getCanonicalFileName) + ); + const config = { + compilerOptions: { + ...Object.keys(configParseResult.options).map((key) => { + const value = configParseResult.options[key]; + const option = getOptionFromName(key); + if (!option) { + return [key, value] as [keyof CompilerOptions, {} | undefined]; + } + return [key, unencodeCompilerOption(value, option, getCanonicalFileName)] as [keyof CompilerOptions, {} | undefined]; + }).reduce((prev, cur) => ({ ...prev, [cur[0]]: cur[1] }), {}), + showConfig: undefined, + configFile: undefined, + configFilePath: undefined, + help: undefined, + init: undefined, + listFiles: undefined, + listEmittedFiles: undefined, + project: undefined, + }, + references: map(configParseResult.projectReferences, r => ({ ...r, path: 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 + }; + // tslint:disable-next-line:no-null-keyword + sys.write(JSON.stringify(config, null, 4) + sys.newLine); + return sys.exit(ExitStatus.Success); + } updateReportDiagnostic(configParseResult.options); if (isWatchSet(configParseResult.options)) { reportWatchModeWithoutSysSupport(); @@ -153,6 +197,53 @@ namespace ts { } } + function unencodeCompilerOption(value: any, option: CommandLineOption, getCanonicalFileName: ReturnType): {} | undefined { + switch (option.type) { + case "object": + case "number": + case "boolean": + return value; + case "string": + if (option.isFilePath) { + return getRelativePathFromFile(sys.getCurrentDirectory(), getNormalizedAbsolutePath(value as string, sys.getCurrentDirectory()), getCanonicalFileName); + } + return value; + case "list": + const elementType = (option as CommandLineOptionOfListType).element; + return isArray(value) ? value.map(v => unencodeCompilerOption(v, elementType, getCanonicalFileName)) : undefined; + default: + return forEachEntry(option.type, (optionEnumValue, optionStringValue) => { + if (optionEnumValue === value) { + return optionStringValue; + } + }); + } + } + + function filterSameAsDefaultInclude(specs: ReadonlyArray | undefined) { + if (!length(specs)) return undefined; + if (length(specs) !== 1) return specs; + if (specs![0] === "**/*") return undefined; + return specs; + } + + function matchesSpecs(path: string, includeSpecs: ReadonlyArray | undefined, excludeSpecs: ReadonlyArray | undefined): (path: string) => boolean { + if (!includeSpecs) return _ => false; + const patterns = getFileMatcherPatterns(path, excludeSpecs, includeSpecs, sys.useCaseSensitiveFileNames, sys.getCurrentDirectory()); + const excludeRe = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, sys.useCaseSensitiveFileNames); + const includeRe = patterns.includeFilePattern && getRegexFromPattern(patterns.includeFilePattern, sys.useCaseSensitiveFileNames); + if (includeRe) { + if (excludeRe) { + return path => includeRe.test(path) && !excludeRe.test(path); + } + return path => includeRe.test(path); + } + if (excludeRe) { + return path => !excludeRe.test(path); + } + return _ => false; + } + function reportWatchModeWithoutSysSupport() { if (!sys.watchFile || !sys.watchDirectory) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); From 4287349bb5a319a69433b1b1a7608dc63467bee2 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 27 Sep 2018 14:06:28 -0700 Subject: [PATCH 2/5] Merge showConfig implementation with init implementation, add basic unit tests --- src/compiler/commandLineParser.ts | 174 +++++++++++++----- src/testRunner/tsconfig.json | 1 + src/testRunner/unittests/showConfig.ts | 34 ++++ src/tsc/tsc.ts | 88 +-------- .../tsconfig.json | 3 + .../tsconfig.json | 8 + .../tsconfig.json | 5 + .../tsconfig.json | 6 + .../tsconfig.json | 3 + .../tsconfig.json | 8 + .../tsconfig.json | 3 + .../tsconfig.json | 8 + .../tsconfig.json | 8 + 13 files changed, 212 insertions(+), 137 deletions(-) create mode 100644 src/testRunner/unittests/showConfig.ts create mode 100644 tests/baselines/reference/showConfig/Default initialized TSConfig/tsconfig.json create mode 100644 tests/baselines/reference/showConfig/Show TSConfig with advanced options/tsconfig.json create mode 100644 tests/baselines/reference/showConfig/Show TSConfig with boolean value compiler options/tsconfig.json create mode 100644 tests/baselines/reference/showConfig/Show TSConfig with enum value compiler options/tsconfig.json create mode 100644 tests/baselines/reference/showConfig/Show TSConfig with files options/tsconfig.json create mode 100644 tests/baselines/reference/showConfig/Show TSConfig with incorrect compiler option value/tsconfig.json create mode 100644 tests/baselines/reference/showConfig/Show TSConfig with incorrect compiler option/tsconfig.json create mode 100644 tests/baselines/reference/showConfig/Show TSConfig with list compiler options with enum value/tsconfig.json create mode 100644 tests/baselines/reference/showConfig/Show TSConfig with list compiler options/tsconfig.json diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 24e6397e0ef2b..fde7ba08f8557 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1653,72 +1653,146 @@ namespace ts { } /** - * Generate tsconfig configuration when running command line "--init" - * @param options commandlineOptions to be generated into tsconfig.json - * @param fileNames array of filenames to be generated into tsconfig.json + * Generate an uncommented, complete tsconfig for use with "--showConfig" + * @param configParseResult options to be generated into tsconfig.json + * @param configFileName name of the parsed config file - output paths will be generated relative to this + * @param host provides current directory and case sensitivity services */ - /* @internal */ - export function generateTSConfig(options: CompilerOptions, fileNames: ReadonlyArray, newLine: string): string { - const compilerOptions = extend(options, defaultInitCompilerOptions); - const compilerOptionsMap = serializeCompilerOptions(compilerOptions); - return writeConfigurations(); + /** @internal */ + export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): object { + const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames); + const files = map( + filter( + configParseResult.fileNames, + !configParseResult.configFileSpecs ? _ => false : matchesSpecs( + configFileName, + configParseResult.configFileSpecs.validatedIncludeSpecs, + configParseResult.configFileSpecs.validatedExcludeSpecs + ) + ), + f => getRelativePathFromFile(getNormalizedAbsolutePath(configFileName!, host.getCurrentDirectory()), f, getCanonicalFileName) + ); + const optionMap = serializeCompilerOptions(configParseResult.options, { configFilePath: getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), useCaseSensitiveFileNames: host.useCaseSensitiveFileNames }); + const config = { + compilerOptions: { + ...arrayFrom(optionMap.entries()).reduce((prev, cur) => ({ ...prev, [cur[0]]: cur[1] }), {}), + showConfig: undefined, + configFile: undefined, + configFilePath: undefined, + help: undefined, + init: undefined, + listFiles: undefined, + listEmittedFiles: undefined, + project: undefined, + }, + references: map(configParseResult.projectReferences, r => ({ ...r, path: 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 + }; + return config; + } - function getCustomTypeMapOfCommandLineOption(optionDefinition: CommandLineOption): Map | undefined { - if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean") { - // this is of a type CommandLineOptionOfPrimitiveType - return undefined; - } - else if (optionDefinition.type === "list") { - return getCustomTypeMapOfCommandLineOption((optionDefinition).element); - } - else { - return (optionDefinition).type; + function filterSameAsDefaultInclude(specs: ReadonlyArray | undefined) { + if (!length(specs)) return undefined; + if (length(specs) !== 1) return specs; + if (specs![0] === "**/*") return undefined; + return specs; + } + + function matchesSpecs(path: string, includeSpecs: ReadonlyArray | undefined, excludeSpecs: ReadonlyArray | undefined): (path: string) => boolean { + if (!includeSpecs) return _ => false; + const patterns = getFileMatcherPatterns(path, excludeSpecs, includeSpecs, sys.useCaseSensitiveFileNames, sys.getCurrentDirectory()); + const excludeRe = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, sys.useCaseSensitiveFileNames); + const includeRe = patterns.includeFilePattern && getRegexFromPattern(patterns.includeFilePattern, sys.useCaseSensitiveFileNames); + if (includeRe) { + if (excludeRe) { + return path => includeRe.test(path) && !excludeRe.test(path); } + return path => includeRe.test(path); } + if (excludeRe) { + return path => !excludeRe.test(path); + } + return _ => false; + } - function getNameOfCompilerOptionValue(value: CompilerOptionsValue, customTypeMap: Map): string | undefined { - // There is a typeMap associated with this command-line option so use it to map value back to its name - return forEachEntry(customTypeMap, (mapValue, key) => { - if (mapValue === value) { - return key; - } - }); + function getCustomTypeMapOfCommandLineOption(optionDefinition: CommandLineOption): Map | undefined { + if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean") { + // this is of a type CommandLineOptionOfPrimitiveType + return undefined; + } + else if (optionDefinition.type === "list") { + return getCustomTypeMapOfCommandLineOption((optionDefinition).element); } + else { + return (optionDefinition).type; + } + } - function serializeCompilerOptions(options: CompilerOptions): Map { - const result = createMap(); - const optionsNameMap = getOptionNameMap().optionNameMap; + function getNameOfCompilerOptionValue(value: CompilerOptionsValue, customTypeMap: Map): string | undefined { + // There is a typeMap associated with this command-line option so use it to map value back to its name + return forEachEntry(customTypeMap, (mapValue, key) => { + if (mapValue === value) { + return key; + } + }); + } - for (const name in options) { - if (hasProperty(options, name)) { - // tsconfig only options cannot be specified via command line, - // so we can assume that only types that can appear here string | number | boolean - if (optionsNameMap.has(name) && optionsNameMap.get(name)!.category === Diagnostics.Command_line_Options) { - continue; - } - const value = options[name]; - const optionDefinition = optionsNameMap.get(name.toLowerCase()); - if (optionDefinition) { - const customTypeMap = getCustomTypeMapOfCommandLineOption(optionDefinition); - if (!customTypeMap) { - // There is no map associated with this compiler option then use the value as-is - // This is the case if the value is expect to be string, number, boolean or list of string + function serializeCompilerOptions(options: CompilerOptions, pathOptions?: { configFilePath: string, useCaseSensitiveFileNames: boolean }): Map { + const result = createMap(); + const optionsNameMap = getOptionNameMap().optionNameMap; + const getCanonicalFileName = pathOptions && createGetCanonicalFileName(pathOptions.useCaseSensitiveFileNames); + + for (const name in options) { + if (hasProperty(options, name)) { + // tsconfig only options cannot be specified via command line, + // so we can assume that only types that can appear here string | number | boolean + if (optionsNameMap.has(name) && optionsNameMap.get(name)!.category === Diagnostics.Command_line_Options) { + continue; + } + const value = options[name]; + const optionDefinition = optionsNameMap.get(name.toLowerCase()); + if (optionDefinition) { + const customTypeMap = getCustomTypeMapOfCommandLineOption(optionDefinition); + if (!customTypeMap) { + // There is no map associated with this compiler option then use the value as-is + // This is the case if the value is expect to be string, number, boolean or list of string + if (pathOptions && optionDefinition.isFilePath) { + result.set(name, getRelativePathFromFile(pathOptions.configFilePath, getNormalizedAbsolutePath(value as string, getDirectoryPath(pathOptions.configFilePath)), getCanonicalFileName!)); + } + else { result.set(name, value); } + } + else { + if (optionDefinition.type === "list") { + result.set(name, (value as ReadonlyArray).map(element => getNameOfCompilerOptionValue(element, customTypeMap)!)); // TODO: GH#18217 + } else { - if (optionDefinition.type === "list") { - result.set(name, (value as ReadonlyArray).map(element => getNameOfCompilerOptionValue(element, customTypeMap)!)); // TODO: GH#18217 - } - else { - // There is a typeMap associated with this command-line option so use it to map value back to its name - result.set(name, getNameOfCompilerOptionValue(value, customTypeMap)); - } + // There is a typeMap associated with this command-line option so use it to map value back to its name + result.set(name, getNameOfCompilerOptionValue(value, customTypeMap)); } } } } - return result; } + return result; + } + + /** + * Generate tsconfig configuration when running command line "--init" + * @param options commandlineOptions to be generated into tsconfig.json + * @param fileNames array of filenames to be generated into tsconfig.json + */ + /* @internal */ + export function generateTSConfig(options: CompilerOptions, fileNames: ReadonlyArray, newLine: string): string { + const compilerOptions = extend(options, defaultInitCompilerOptions); + const compilerOptionsMap = serializeCompilerOptions(compilerOptions); + return writeConfigurations(); function getDefaultValueForOption(option: CommandLineOption) { switch (option.type) { diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 42edf83996495..af25aba408dd1 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -75,6 +75,7 @@ "unittests/reuseProgramStructure.ts", "unittests/session.ts", "unittests/semver.ts", + "unittests/showConfig.ts", "unittests/symbolWalker.ts", "unittests/telemetry.ts", "unittests/textChanges.ts", diff --git a/src/testRunner/unittests/showConfig.ts b/src/testRunner/unittests/showConfig.ts new file mode 100644 index 0000000000000..3405c97494f0d --- /dev/null +++ b/src/testRunner/unittests/showConfig.ts @@ -0,0 +1,34 @@ +namespace ts { + describe("showTSConfig", () => { + function showTSConfigCorrectly(name: string, commandLinesArgs: string[]) { + describe(name, () => { + const commandLine = parseCommandLine(commandLinesArgs); + const initResult = convertToTSConfig(commandLine, `/${name}/tsconfig.json`, { getCurrentDirectory() { return `/${name}` }, useCaseSensitiveFileNames: true }); + const outputFileName = `showConfig/${name.replace(/[^a-z0-9\-. ]/ig, "")}/tsconfig.json`; + + it(`Correct output for ${outputFileName}`, () => { + // tslint:disable-next-line:no-null-keyword + Harness.Baseline.runBaseline(outputFileName, JSON.stringify(initResult, null, 4) + "\n"); + }); + }); + } + + showTSConfigCorrectly("Default initialized TSConfig", ["--showConfig"]); + + showTSConfigCorrectly("Show TSConfig with files options", ["--showConfig", "file0.st", "file1.ts", "file2.ts"]); + + showTSConfigCorrectly("Show TSConfig with boolean value compiler options", ["--showConfig", "--noUnusedLocals"]); + + showTSConfigCorrectly("Show TSConfig with enum value compiler options", ["--showConfig", "--target", "es5", "--jsx", "react"]); + + showTSConfigCorrectly("Show TSConfig with list compiler options", ["--showConfig", "--types", "jquery,mocha"]); + + showTSConfigCorrectly("Show TSConfig with list compiler options with enum value", ["--showConfig", "--lib", "es5,es2015.core"]); + + showTSConfigCorrectly("Show TSConfig with incorrect compiler option", ["--showConfig", "--someNonExistOption"]); + + showTSConfigCorrectly("Show TSConfig with incorrect compiler option value", ["--showConfig", "--lib", "nonExistLib,es5,es2015.promise"]); + + showTSConfigCorrectly("Show TSConfig with advanced options", ["--showConfig", "--declaration", "--declarationDir", "lib", "--skipLibCheck", "--noErrorTruncation"]); + }); +} \ No newline at end of file diff --git a/src/tsc/tsc.ts b/src/tsc/tsc.ts index 1ce5ec9bc4b5f..3e19d50e13a71 100644 --- a/src/tsc/tsc.ts +++ b/src/tsc/tsc.ts @@ -133,47 +133,8 @@ namespace ts { if (configFileName) { const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, sys, reportDiagnostic)!; // TODO: GH#18217 if (commandLineOptions.showConfig) { - const getCanonicalFileName = createGetCanonicalFileName(sys.useCaseSensitiveFileNames); - const files = map( - filter( - configParseResult.fileNames, - !configParseResult.configFileSpecs ? _ => false : matchesSpecs( - configFileName, - configParseResult.configFileSpecs.validatedIncludeSpecs, - configParseResult.configFileSpecs.validatedExcludeSpecs - ) - ), - f => getRelativePathFromFile(getNormalizedAbsolutePath(configFileName!, sys.getCurrentDirectory()), f, getCanonicalFileName) - ); - const config = { - compilerOptions: { - ...Object.keys(configParseResult.options).map((key) => { - const value = configParseResult.options[key]; - const option = getOptionFromName(key); - if (!option) { - return [key, value] as [keyof CompilerOptions, {} | undefined]; - } - return [key, unencodeCompilerOption(value, option, getCanonicalFileName)] as [keyof CompilerOptions, {} | undefined]; - }).reduce((prev, cur) => ({ ...prev, [cur[0]]: cur[1] }), {}), - showConfig: undefined, - configFile: undefined, - configFilePath: undefined, - help: undefined, - init: undefined, - listFiles: undefined, - listEmittedFiles: undefined, - project: undefined, - }, - references: map(configParseResult.projectReferences, r => ({ ...r, path: 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 - }; // tslint:disable-next-line:no-null-keyword - sys.write(JSON.stringify(config, null, 4) + sys.newLine); + sys.write(JSON.stringify(convertToTSConfig(configParseResult, configFileName, sys), null, 4) + sys.newLine); return sys.exit(ExitStatus.Success); } updateReportDiagnostic(configParseResult.options); @@ -197,53 +158,6 @@ namespace ts { } } - function unencodeCompilerOption(value: any, option: CommandLineOption, getCanonicalFileName: ReturnType): {} | undefined { - switch (option.type) { - case "object": - case "number": - case "boolean": - return value; - case "string": - if (option.isFilePath) { - return getRelativePathFromFile(sys.getCurrentDirectory(), getNormalizedAbsolutePath(value as string, sys.getCurrentDirectory()), getCanonicalFileName); - } - return value; - case "list": - const elementType = (option as CommandLineOptionOfListType).element; - return isArray(value) ? value.map(v => unencodeCompilerOption(v, elementType, getCanonicalFileName)) : undefined; - default: - return forEachEntry(option.type, (optionEnumValue, optionStringValue) => { - if (optionEnumValue === value) { - return optionStringValue; - } - }); - } - } - - function filterSameAsDefaultInclude(specs: ReadonlyArray | undefined) { - if (!length(specs)) return undefined; - if (length(specs) !== 1) return specs; - if (specs![0] === "**/*") return undefined; - return specs; - } - - function matchesSpecs(path: string, includeSpecs: ReadonlyArray | undefined, excludeSpecs: ReadonlyArray | undefined): (path: string) => boolean { - if (!includeSpecs) return _ => false; - const patterns = getFileMatcherPatterns(path, excludeSpecs, includeSpecs, sys.useCaseSensitiveFileNames, sys.getCurrentDirectory()); - const excludeRe = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, sys.useCaseSensitiveFileNames); - const includeRe = patterns.includeFilePattern && getRegexFromPattern(patterns.includeFilePattern, sys.useCaseSensitiveFileNames); - if (includeRe) { - if (excludeRe) { - return path => includeRe.test(path) && !excludeRe.test(path); - } - return path => includeRe.test(path); - } - if (excludeRe) { - return path => !excludeRe.test(path); - } - return _ => false; - } - function reportWatchModeWithoutSysSupport() { if (!sys.watchFile || !sys.watchDirectory) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); diff --git a/tests/baselines/reference/showConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/showConfig/Default initialized TSConfig/tsconfig.json new file mode 100644 index 0000000000000..cd727e8ccdc88 --- /dev/null +++ b/tests/baselines/reference/showConfig/Default initialized TSConfig/tsconfig.json @@ -0,0 +1,3 @@ +{ + "compilerOptions": {} +} diff --git a/tests/baselines/reference/showConfig/Show TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with advanced options/tsconfig.json new file mode 100644 index 0000000000000..6dbccf64bb9c4 --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with advanced options/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "declaration": true, + "declarationDir": "./lib", + "skipLibCheck": true, + "noErrorTruncation": true + } +} diff --git a/tests/baselines/reference/showConfig/Show TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with boolean value compiler options/tsconfig.json new file mode 100644 index 0000000000000..650a347f89585 --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with boolean value compiler options/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "noUnusedLocals": true + } +} diff --git a/tests/baselines/reference/showConfig/Show TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with enum value compiler options/tsconfig.json new file mode 100644 index 0000000000000..0052b1327f123 --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with enum value compiler options/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "target": "es5", + "jsx": "react" + } +} diff --git a/tests/baselines/reference/showConfig/Show TSConfig with files options/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with files options/tsconfig.json new file mode 100644 index 0000000000000..cd727e8ccdc88 --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with files options/tsconfig.json @@ -0,0 +1,3 @@ +{ + "compilerOptions": {} +} diff --git a/tests/baselines/reference/showConfig/Show TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with incorrect compiler option value/tsconfig.json new file mode 100644 index 0000000000000..c75e5d4ae1d96 --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with incorrect compiler option value/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "lib": [ + "es5", + "es2015.promise" + ] + } +} diff --git a/tests/baselines/reference/showConfig/Show TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with incorrect compiler option/tsconfig.json new file mode 100644 index 0000000000000..cd727e8ccdc88 --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with incorrect compiler option/tsconfig.json @@ -0,0 +1,3 @@ +{ + "compilerOptions": {} +} diff --git a/tests/baselines/reference/showConfig/Show TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with list compiler options with enum value/tsconfig.json new file mode 100644 index 0000000000000..6da42b43907bc --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with list compiler options with enum value/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "lib": [ + "es5", + "es2015.core" + ] + } +} diff --git a/tests/baselines/reference/showConfig/Show TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/showConfig/Show TSConfig with list compiler options/tsconfig.json new file mode 100644 index 0000000000000..7b5da8e7d3c71 --- /dev/null +++ b/tests/baselines/reference/showConfig/Show TSConfig with list compiler options/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "types": [ + "jquery", + "mocha" + ] + } +} From b3d2d68f7dc0c2ef46b855a5e0922ed492b44f28 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 28 Sep 2018 10:51:20 -0700 Subject: [PATCH 3/5] Fix lint --- src/compiler/commandLineParser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index fde7ba08f8557..82321f9884a50 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1670,7 +1670,7 @@ namespace ts { configParseResult.configFileSpecs.validatedExcludeSpecs ) ), - f => getRelativePathFromFile(getNormalizedAbsolutePath(configFileName!, host.getCurrentDirectory()), f, getCanonicalFileName) + f => getRelativePathFromFile(getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), f, getCanonicalFileName) ); const optionMap = serializeCompilerOptions(configParseResult.options, { configFilePath: getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), useCaseSensitiveFileNames: host.useCaseSensitiveFileNames }); const config = { From 169dc074311c7cdd1009fd7b3672f45f6f787f47 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 5 Oct 2018 14:44:16 -0700 Subject: [PATCH 4/5] Add missing semicolon --- src/testRunner/unittests/showConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testRunner/unittests/showConfig.ts b/src/testRunner/unittests/showConfig.ts index 3405c97494f0d..a2b5bb1025880 100644 --- a/src/testRunner/unittests/showConfig.ts +++ b/src/testRunner/unittests/showConfig.ts @@ -3,7 +3,7 @@ namespace ts { function showTSConfigCorrectly(name: string, commandLinesArgs: string[]) { describe(name, () => { const commandLine = parseCommandLine(commandLinesArgs); - const initResult = convertToTSConfig(commandLine, `/${name}/tsconfig.json`, { getCurrentDirectory() { return `/${name}` }, useCaseSensitiveFileNames: true }); + const initResult = convertToTSConfig(commandLine, `/${name}/tsconfig.json`, { getCurrentDirectory() { return `/${name}`; }, useCaseSensitiveFileNames: true }); const outputFileName = `showConfig/${name.replace(/[^a-z0-9\-. ]/ig, "")}/tsconfig.json`; it(`Correct output for ${outputFileName}`, () => { From 979cb3d4871721bddcbc7468cac2fc366115a2c0 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 31 Oct 2018 13:53:58 -0700 Subject: [PATCH 5/5] showConfig when theres no config file --- src/tsc/tsc.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tsc/tsc.ts b/src/tsc/tsc.ts index 3e19d50e13a71..549f79f9025a6 100644 --- a/src/tsc/tsc.ts +++ b/src/tsc/tsc.ts @@ -147,6 +147,11 @@ namespace ts { } } else { + if (commandLineOptions.showConfig) { + // tslint:disable-next-line:no-null-keyword + sys.write(JSON.stringify(convertToTSConfig(commandLine, combinePaths(sys.getCurrentDirectory(), "tsconfig.json"), sys), null, 4) + sys.newLine); + return sys.exit(ExitStatus.Success); + } updateReportDiagnostic(commandLineOptions); if (isWatchSet(commandLineOptions)) { reportWatchModeWithoutSysSupport();