diff --git a/internal/core/compileroptions.go b/internal/core/compileroptions.go index 35e0600f57..844465642b 100644 --- a/internal/core/compileroptions.go +++ b/internal/core/compileroptions.go @@ -47,6 +47,7 @@ type CompilerOptions struct { ForceConsistentCasingInFileNames Tristate `json:"forceConsistentCasingInFileNames,omitzero"` IsolatedModules Tristate `json:"isolatedModules,omitzero"` IsolatedDeclarations Tristate `json:"isolatedDeclarations,omitzero"` + IgnoreConfig Tristate `json:"ignoreConfig,omitzero"` IgnoreDeprecations string `json:"ignoreDeprecations,omitzero"` ImportHelpers Tristate `json:"importHelpers,omitzero"` InlineSourceMap Tristate `json:"inlineSourceMap,omitzero"` diff --git a/internal/diagnostics/diagnostics_generated.go b/internal/diagnostics/diagnostics_generated.go index 1c9410eeac..4625c8d4a6 100644 --- a/internal/diagnostics/diagnostics_generated.go +++ b/internal/diagnostics/diagnostics_generated.go @@ -920,6 +920,8 @@ var Importing_a_JSON_file_into_an_ECMAScript_module_requires_a_type_Colon_json_i var Named_imports_from_a_JSON_file_into_an_ECMAScript_module_are_not_allowed_when_module_is_set_to_0 = &Message{code: 1544, category: CategoryError, key: "Named_imports_from_a_JSON_file_into_an_ECMAScript_module_are_not_allowed_when_module_is_set_to_0_1544", text: "Named imports from a JSON file into an ECMAScript module are not allowed when 'module' is set to '{0}'."} +var Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files = &Message{code: 1547, category: CategoryMessage, key: "Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files_1547", text: "Ignore the tsconfig found and build with commandline options and files."} + var The_types_of_0_are_incompatible_between_these_types = &Message{code: 2200, category: CategoryError, key: "The_types_of_0_are_incompatible_between_these_types_2200", text: "The types of '{0}' are incompatible between these types."} var The_types_returned_by_0_are_incompatible_between_these_types = &Message{code: 2201, category: CategoryError, key: "The_types_returned_by_0_are_incompatible_between_these_types_2201", text: "The types returned by '{0}' are incompatible between these types."} @@ -2344,6 +2346,8 @@ var Option_moduleResolution_must_be_set_to_0_or_left_unspecified_when_option_mod var Option_module_must_be_set_to_0_when_option_moduleResolution_is_set_to_1 = &Message{code: 5110, category: CategoryError, key: "Option_module_must_be_set_to_0_when_option_moduleResolution_is_set_to_1_5110", text: "Option 'module' must be set to '{0}' when option 'moduleResolution' is set to '{1}'."} +var X_tsconfig_json_is_present_but_will_not_be_loaded_if_files_are_specified_on_commandline_Use_ignoreConfig_to_skip_this_error = &Message{code: 5111, category: CategoryError, key: "tsconfig_json_is_present_but_will_not_be_loaded_if_files_are_specified_on_commandline_Use_ignoreConf_5111", text: "tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error."} + var Generates_a_sourcemap_for_each_corresponding_d_ts_file = &Message{code: 6000, category: CategoryMessage, key: "Generates_a_sourcemap_for_each_corresponding_d_ts_file_6000", text: "Generates a sourcemap for each corresponding '.d.ts' file."} var Concatenate_and_emit_output_to_single_file = &Message{code: 6001, category: CategoryMessage, key: "Concatenate_and_emit_output_to_single_file_6001", text: "Concatenate and emit output to single file."} diff --git a/internal/diagnostics/extraDiagnosticMessages.json b/internal/diagnostics/extraDiagnosticMessages.json index b735a67695..b9a2e1160f 100644 --- a/internal/diagnostics/extraDiagnosticMessages.json +++ b/internal/diagnostics/extraDiagnosticMessages.json @@ -38,5 +38,13 @@ "Project '{0}' is out of date because it has errors.": { "category": "Message", "code": 6423 + }, + "Ignore the tsconfig found and build with commandline options and files.": { + "category": "Message", + "code": 1547 + }, + "tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error.": { + "category": "Error", + "code": 5111 } } diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index 65bf8d43bb..11405fff1e 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -151,19 +151,24 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped} } } - } else if len(commandLine.FileNames()) == 0 { + } else if !commandLine.CompilerOptions().IgnoreConfig.IsTrue() || len(commandLine.FileNames()) == 0 { searchPath := tspath.NormalizePath(sys.GetCurrentDirectory()) configFileName = findConfigFile(searchPath, sys.FS().FileExists, "tsconfig.json") - } - - if configFileName == "" && len(commandLine.FileNames()) == 0 { - if commandLine.CompilerOptions().ShowConfig.IsTrue() { - reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory()))) - } else { - tsc.PrintVersion(sys) - tsc.PrintHelp(sys, commandLine) + if len(commandLine.FileNames()) != 0 { + if configFileName != "" { + // Error to not specify config file + reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.X_tsconfig_json_is_present_but_will_not_be_loaded_if_files_are_specified_on_commandline_Use_ignoreConfig_to_skip_this_error)) + return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped} + } + } else if configFileName == "" { + if commandLine.CompilerOptions().ShowConfig.IsTrue() { + reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory()))) + } else { + tsc.PrintVersion(sys) + tsc.PrintHelp(sys, commandLine) + } + return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped} } - return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped} } // !!! convert to options with absolute paths is usually done here, but for ease of implementation, it's done in `tsoptions.ParseCommandLine()` diff --git a/internal/execute/tsctests/tsc_test.go b/internal/execute/tsctests/tsc_test.go index 31f0f94911..9b8eac6680 100644 --- a/internal/execute/tsctests/tsc_test.go +++ b/internal/execute/tsctests/tsc_test.go @@ -919,6 +919,59 @@ func TestTscExtends(t *testing.T) { } } +func TestTscIgnoreConfig(t *testing.T) { + t.Parallel() + filesWithoutConfig := func() FileMap { + return FileMap{ + "/home/src/workspaces/project/src/a.ts": "export const a = 10;", + "/home/src/workspaces/project/src/b.ts": "export const b = 10;", + "/home/src/workspaces/project/c.ts": "export const c = 10;", + } + } + filesWithConfig := func() FileMap { + files := filesWithoutConfig() + files["/home/src/workspaces/project/tsconfig.json"] = stringtestutil.Dedent(` + { + "include": ["src"], + }`) + return files + } + getScenarios := func(subScenario string, commandLineArgs []string) []*tscInput { + commandLineArgsIgnoreConfig := append(commandLineArgs, "--ignoreConfig") + return []*tscInput{ + { + subScenario: subScenario, + files: filesWithConfig(), + commandLineArgs: commandLineArgs, + }, + { + subScenario: subScenario + " with --ignoreConfig", + files: filesWithConfig(), + commandLineArgs: commandLineArgsIgnoreConfig, + }, + { + subScenario: subScenario + " when config file absent", + files: filesWithoutConfig(), + commandLineArgs: commandLineArgs, + }, + { + subScenario: subScenario + " when config file absent with --ignoreConfig", + files: filesWithoutConfig(), + commandLineArgs: commandLineArgsIgnoreConfig, + }, + } + } + testCases := slices.Concat( + getScenarios("without any options", nil), + getScenarios("specifying files", []string{"src/a.ts"}), + getScenarios("specifying project", []string{"-p", "."}), + getScenarios("mixing project and files", []string{"-p", ".", "src/a.ts", "c.ts"}), + ) + for _, test := range testCases { + test.run(t, "ignoreConfig") + } +} + func TestTscIncremental(t *testing.T) { t.Parallel() getConstEnumTest := func(bdsContents string, changeEnumFile string, testSuffix string) *tscInput { diff --git a/internal/tsoptions/declscompiler.go b/internal/tsoptions/declscompiler.go index 1223b52df5..4288cba0c8 100644 --- a/internal/tsoptions/declscompiler.go +++ b/internal/tsoptions/declscompiler.go @@ -290,6 +290,15 @@ var optionsForCompiler = []*CommandLineOption{ Description: diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing, DefaultValueDescription: false, }, + { + Name: "ignoreConfig", + Kind: CommandLineOptionTypeBoolean, + ShowInSimplifiedHelpView: true, + Category: diagnostics.Command_line_Options, + IsCommandLineOnly: true, + Description: diagnostics.Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files, + DefaultValueDescription: false, + }, // Basic // targetOptionDeclaration, diff --git a/internal/tsoptions/parsinghelpers.go b/internal/tsoptions/parsinghelpers.go index bf16518be2..56880ce3fb 100644 --- a/internal/tsoptions/parsinghelpers.go +++ b/internal/tsoptions/parsinghelpers.go @@ -259,6 +259,8 @@ func parseCompilerOptions(key string, value any, allOptions *core.CompilerOption allOptions.GenerateTrace = parseString(value) case "isolatedModules": allOptions.IsolatedModules = parseTristate(value) + case "ignoreConfig": + allOptions.IgnoreConfig = parseTristate(value) case "ignoreDeprecations": allOptions.IgnoreDeprecations = parseString(value) case "importHelpers": diff --git a/testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js b/testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js index b874e0df4d..2aeb59abba 100644 --- a/testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js +++ b/testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js @@ -55,6 +55,9 @@ Compile the project given the path to its configuration file, or to a folder wit --showConfig Print the final configuration instead of building. +--ignoreConfig +Ignore the tsconfig found and build with commandline options and files. + --build, -b Build one or more projects and their dependencies, if out of date diff --git a/testdata/baselines/reference/tsc/commandLine/help.js b/testdata/baselines/reference/tsc/commandLine/help.js index 74d5bff71e..2d049cb512 100644 --- a/testdata/baselines/reference/tsc/commandLine/help.js +++ b/testdata/baselines/reference/tsc/commandLine/help.js @@ -54,6 +54,9 @@ Compile the project given the path to its configuration file, or to a folder wit --showConfig Print the final configuration instead of building. +--ignoreConfig +Ignore the tsconfig found and build with commandline options and files. + --build, -b Build one or more projects and their dependencies, if out of date diff --git a/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js b/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js index 755231ecf2..b72b404539 100644 --- a/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js +++ b/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js @@ -55,6 +55,9 @@ Compile the project given the path to its configuration file, or to a folder wit --showConfig Print the final configuration instead of building. +--ignoreConfig +Ignore the tsconfig found and build with commandline options and files. + --build, -b Build one or more projects and their dependencies, if out of date diff --git a/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js b/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js index a53b791e93..070c2a2be0 100644 --- a/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js +++ b/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js @@ -34,28 +34,31 @@ tsc: The TypeScript Compiler - Version FakeTSVersion COMMAND LINE FLAGS - --help, -h Print this message. + --help, -h Print this message. - --watch, -w Watch input files. + --watch, -w Watch input files. - --all Show all compiler options. + --all Show all compiler options. - --version, -v Print the compiler's version. + --version, -v Print the compiler's version. - --init Initializes a TypeScript project and creates a tsconfig.json file. + --init Initializes a TypeScript project and creates a tsconfig.json file. - --project, -p Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'. + --project, -p Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'. - --showConfig Print the final configuration instead of building. + --showConfig Print the final configuration instead of building. - --build, -b Build one or more projects and their dependencies, if out of date + --ignoreConfig Ignore the tsconfig found and build with commandline options and files. + + + --build, -b Build one or more projects and their dependencies, if out of date COMMON COMPILER OPTIONS diff --git a/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-when-config-file-absent-with---ignoreConfig.js b/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-when-config-file-absent-with---ignoreConfig.js new file mode 100644 index 0000000000..74d6e07863 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-when-config-file-absent-with---ignoreConfig.js @@ -0,0 +1,15 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; + +tsgo -p . src/a.ts c.ts --ignoreConfig +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +error TS5042: Option 'project' cannot be mixed with source files on a command line. + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-when-config-file-absent.js b/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-when-config-file-absent.js new file mode 100644 index 0000000000..c557a4537a --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-when-config-file-absent.js @@ -0,0 +1,15 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; + +tsgo -p . src/a.ts c.ts +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +error TS5042: Option 'project' cannot be mixed with source files on a command line. + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-with---ignoreConfig.js b/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-with---ignoreConfig.js new file mode 100644 index 0000000000..f325237920 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files-with---ignoreConfig.js @@ -0,0 +1,19 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "include": ["src"], +} + +tsgo -p . src/a.ts c.ts --ignoreConfig +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +error TS5042: Option 'project' cannot be mixed with source files on a command line. + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files.js b/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files.js new file mode 100644 index 0000000000..35141cbcc6 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/mixing-project-and-files.js @@ -0,0 +1,19 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "include": ["src"], +} + +tsgo -p . src/a.ts c.ts +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +error TS5042: Option 'project' cannot be mixed with source files on a command line. + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-when-config-file-absent-with---ignoreConfig.js b/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-when-config-file-absent-with---ignoreConfig.js new file mode 100644 index 0000000000..47a583d164 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-when-config-file-absent-with---ignoreConfig.js @@ -0,0 +1,43 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; + +tsgo src/a.ts --ignoreConfig +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; +//// [/home/src/workspaces/project/src/a.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = 10; + + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-when-config-file-absent.js b/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-when-config-file-absent.js new file mode 100644 index 0000000000..c6a8afd92d --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-when-config-file-absent.js @@ -0,0 +1,43 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; + +tsgo src/a.ts +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; +//// [/home/src/workspaces/project/src/a.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = 10; + + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-with---ignoreConfig.js b/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-with---ignoreConfig.js new file mode 100644 index 0000000000..5803cbdefd --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/specifying-files-with---ignoreConfig.js @@ -0,0 +1,47 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "include": ["src"], +} + +tsgo src/a.ts --ignoreConfig +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; +//// [/home/src/workspaces/project/src/a.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = 10; + + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/specifying-files.js b/testdata/baselines/reference/tsc/ignoreConfig/specifying-files.js new file mode 100644 index 0000000000..ad781717a1 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/specifying-files.js @@ -0,0 +1,19 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "include": ["src"], +} + +tsgo src/a.ts +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +error TS5111: tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error. + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-when-config-file-absent-with---ignoreConfig.js b/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-when-config-file-absent-with---ignoreConfig.js new file mode 100644 index 0000000000..ed09be7914 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-when-config-file-absent-with---ignoreConfig.js @@ -0,0 +1,15 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; + +tsgo -p . --ignoreConfig +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +error TS5081: Cannot find a tsconfig.json file at the current directory: /home/src/workspaces/project/tsconfig.json. + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-when-config-file-absent.js b/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-when-config-file-absent.js new file mode 100644 index 0000000000..c8d7560ae5 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-when-config-file-absent.js @@ -0,0 +1,15 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; + +tsgo -p . +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +error TS5081: Cannot find a tsconfig.json file at the current directory: /home/src/workspaces/project/tsconfig.json. + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-with---ignoreConfig.js b/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-with---ignoreConfig.js new file mode 100644 index 0000000000..ba70a4cca3 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/specifying-project-with---ignoreConfig.js @@ -0,0 +1,53 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "include": ["src"], +} + +tsgo -p . --ignoreConfig +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; +//// [/home/src/workspaces/project/src/a.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = 10; + +//// [/home/src/workspaces/project/src/b.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = void 0; +exports.b = 10; + + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/specifying-project.js b/testdata/baselines/reference/tsc/ignoreConfig/specifying-project.js new file mode 100644 index 0000000000..da6ef69692 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/specifying-project.js @@ -0,0 +1,53 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "include": ["src"], +} + +tsgo -p . +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; +//// [/home/src/workspaces/project/src/a.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = 10; + +//// [/home/src/workspaces/project/src/b.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = void 0; +exports.b = 10; + + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-when-config-file-absent-with---ignoreConfig.js b/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-when-config-file-absent-with---ignoreConfig.js new file mode 100644 index 0000000000..2906935439 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-when-config-file-absent-with---ignoreConfig.js @@ -0,0 +1,158 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; + +tsgo --ignoreConfig +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +Version FakeTSVersion +tsc: The TypeScript Compiler - Version FakeTSVersion + +COMMON COMMANDS + + tsc + Compiles the current project (tsconfig.json in the working directory.) + + tsc app.ts util.ts + Ignoring tsconfig.json, compiles the specified files with default compiler options. + + tsc -b + Build a composite project in the working directory. + + tsc --init + Creates a tsconfig.json with the recommended settings in the working directory. + + tsc -p ./path/to/tsconfig.json + Compiles the TypeScript project located at the specified path. + + tsc --help --all + An expanded version of this information, showing all possible compiler options + + tsc --noEmit + tsc --target esnext + Compiles the current project, with additional settings. + +COMMAND LINE FLAGS + +--help, -h +Print this message. + +--watch, -w +Watch input files. + +--all +Show all compiler options. + +--version, -v +Print the compiler's version. + +--init +Initializes a TypeScript project and creates a tsconfig.json file. + +--project, -p +Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'. + +--showConfig +Print the final configuration instead of building. + +--ignoreConfig +Ignore the tsconfig found and build with commandline options and files. + +--build, -b +Build one or more projects and their dependencies, if out of date + +COMMON COMPILER OPTIONS + +--pretty +Enable color and formatting in TypeScript's output to make compiler errors easier to read. +type: boolean +default: true + +--declaration, -d +Generate .d.ts files from TypeScript and JavaScript files in your project. +type: boolean +default: `false`, unless `composite` is set + +--declarationMap +Create sourcemaps for d.ts files. +type: boolean +default: false + +--emitDeclarationOnly +Only output d.ts files and not JavaScript files. +type: boolean +default: false + +--sourceMap +Create source map files for emitted JavaScript files. +type: boolean +default: false + +--noEmit +Disable emitting files from a compilation. +type: boolean +default: false + +--target, -t +Set the JavaScript language version for emitted JavaScript and include compatible library declarations. +one of: es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext +default: es5 + +--module, -m +Specify what module code is generated. +one of: none, commonjs, amd, system, umd, es6/es2015, es2020, es2022, esnext, node16, node18, nodenext, preserve +default: undefined + +--lib +Specify a set of bundled library declaration files that describe the target runtime environment. +one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext, dom, dom.iterable, dom.asynciterable, webworker, webworker.importscripts, webworker.iterable, webworker.asynciterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2016.intl, es2017.arraybuffer, es2017.date, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.string, es2022.regexp, es2023.array, es2023.collection, es2023.intl, es2024.arraybuffer, es2024.collection, es2024.object/esnext.object, es2024.promise, es2024.regexp/esnext.regexp, es2024.sharedmemory, es2024.string/esnext.string, esnext.array, esnext.collection, esnext.intl, esnext.disposable, esnext.promise, esnext.decorators, esnext.iterator, esnext.float16, decorators, decorators.legacy +default: undefined + +--allowJs +Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. +type: boolean +default: false + +--checkJs +Enable error reporting in type-checked JavaScript files. +type: boolean +default: false + +--jsx +Specify what JSX code is generated. +one of: preserve, react-native, react, react-jsx, react-jsxdev +default: undefined + +--outFile +Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. + +--outDir +Specify an output folder for all emitted files. + +--removeComments +Disable emitting comments. +type: boolean +default: false + +--strict +Enable all strict type-checking options. +type: boolean +default: false + +--types +Specify type package names to be included without being referenced in a source file. + +--esModuleInterop +Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. +type: boolean +default: false + +You can learn about all of the compiler options at https://aka.ms/tsc + + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-when-config-file-absent.js b/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-when-config-file-absent.js new file mode 100644 index 0000000000..34a4ddaecf --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-when-config-file-absent.js @@ -0,0 +1,158 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; + +tsgo +ExitStatus:: DiagnosticsPresent_OutputsSkipped +Output:: +Version FakeTSVersion +tsc: The TypeScript Compiler - Version FakeTSVersion + +COMMON COMMANDS + + tsc + Compiles the current project (tsconfig.json in the working directory.) + + tsc app.ts util.ts + Ignoring tsconfig.json, compiles the specified files with default compiler options. + + tsc -b + Build a composite project in the working directory. + + tsc --init + Creates a tsconfig.json with the recommended settings in the working directory. + + tsc -p ./path/to/tsconfig.json + Compiles the TypeScript project located at the specified path. + + tsc --help --all + An expanded version of this information, showing all possible compiler options + + tsc --noEmit + tsc --target esnext + Compiles the current project, with additional settings. + +COMMAND LINE FLAGS + +--help, -h +Print this message. + +--watch, -w +Watch input files. + +--all +Show all compiler options. + +--version, -v +Print the compiler's version. + +--init +Initializes a TypeScript project and creates a tsconfig.json file. + +--project, -p +Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'. + +--showConfig +Print the final configuration instead of building. + +--ignoreConfig +Ignore the tsconfig found and build with commandline options and files. + +--build, -b +Build one or more projects and their dependencies, if out of date + +COMMON COMPILER OPTIONS + +--pretty +Enable color and formatting in TypeScript's output to make compiler errors easier to read. +type: boolean +default: true + +--declaration, -d +Generate .d.ts files from TypeScript and JavaScript files in your project. +type: boolean +default: `false`, unless `composite` is set + +--declarationMap +Create sourcemaps for d.ts files. +type: boolean +default: false + +--emitDeclarationOnly +Only output d.ts files and not JavaScript files. +type: boolean +default: false + +--sourceMap +Create source map files for emitted JavaScript files. +type: boolean +default: false + +--noEmit +Disable emitting files from a compilation. +type: boolean +default: false + +--target, -t +Set the JavaScript language version for emitted JavaScript and include compatible library declarations. +one of: es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext +default: es5 + +--module, -m +Specify what module code is generated. +one of: none, commonjs, amd, system, umd, es6/es2015, es2020, es2022, esnext, node16, node18, nodenext, preserve +default: undefined + +--lib +Specify a set of bundled library declaration files that describe the target runtime environment. +one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext, dom, dom.iterable, dom.asynciterable, webworker, webworker.importscripts, webworker.iterable, webworker.asynciterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2016.intl, es2017.arraybuffer, es2017.date, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.string, es2022.regexp, es2023.array, es2023.collection, es2023.intl, es2024.arraybuffer, es2024.collection, es2024.object/esnext.object, es2024.promise, es2024.regexp/esnext.regexp, es2024.sharedmemory, es2024.string/esnext.string, esnext.array, esnext.collection, esnext.intl, esnext.disposable, esnext.promise, esnext.decorators, esnext.iterator, esnext.float16, decorators, decorators.legacy +default: undefined + +--allowJs +Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. +type: boolean +default: false + +--checkJs +Enable error reporting in type-checked JavaScript files. +type: boolean +default: false + +--jsx +Specify what JSX code is generated. +one of: preserve, react-native, react, react-jsx, react-jsxdev +default: undefined + +--outFile +Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. + +--outDir +Specify an output folder for all emitted files. + +--removeComments +Disable emitting comments. +type: boolean +default: false + +--strict +Enable all strict type-checking options. +type: boolean +default: false + +--types +Specify type package names to be included without being referenced in a source file. + +--esModuleInterop +Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. +type: boolean +default: false + +You can learn about all of the compiler options at https://aka.ms/tsc + + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-with---ignoreConfig.js b/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-with---ignoreConfig.js new file mode 100644 index 0000000000..34690eb99a --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/without-any-options-with---ignoreConfig.js @@ -0,0 +1,53 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "include": ["src"], +} + +tsgo --ignoreConfig +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; +//// [/home/src/workspaces/project/src/a.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = 10; + +//// [/home/src/workspaces/project/src/b.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = void 0; +exports.b = 10; + + diff --git a/testdata/baselines/reference/tsc/ignoreConfig/without-any-options.js b/testdata/baselines/reference/tsc/ignoreConfig/without-any-options.js new file mode 100644 index 0000000000..c131036837 --- /dev/null +++ b/testdata/baselines/reference/tsc/ignoreConfig/without-any-options.js @@ -0,0 +1,53 @@ +currentDirectory::/home/src/workspaces/project +useCaseSensitiveFileNames::true +Input:: +//// [/home/src/workspaces/project/c.ts] *new* +export const c = 10; +//// [/home/src/workspaces/project/src/a.ts] *new* +export const a = 10; +//// [/home/src/workspaces/project/src/b.ts] *new* +export const b = 10; +//// [/home/src/workspaces/project/tsconfig.json] *new* +{ + "include": ["src"], +} + +tsgo +ExitStatus:: Success +Output:: +//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +interface SymbolConstructor { + (desc?: string | number): symbol; + for(name: string): symbol; + readonly toStringTag: symbol; +} +declare var Symbol: SymbolConstructor; +interface Symbol { + readonly [Symbol.toStringTag]: string; +} +declare const console: { log(msg: any): void; }; +//// [/home/src/workspaces/project/src/a.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = 10; + +//// [/home/src/workspaces/project/src/b.js] *new* +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = void 0; +exports.b = 10; + + diff --git a/testdata/baselines/reference/tscWatch/commandLine/Parse-watch-interval-option-without-tsconfig.json.js b/testdata/baselines/reference/tscWatch/commandLine/Parse-watch-interval-option-without-tsconfig.json.js index 164937402c..ddf4e53d3d 100644 --- a/testdata/baselines/reference/tscWatch/commandLine/Parse-watch-interval-option-without-tsconfig.json.js +++ b/testdata/baselines/reference/tscWatch/commandLine/Parse-watch-interval-option-without-tsconfig.json.js @@ -55,6 +55,9 @@ Compile the project given the path to its configuration file, or to a folder wit --showConfig Print the final configuration instead of building. +--ignoreConfig +Ignore the tsconfig found and build with commandline options and files. + --build, -b Build one or more projects and their dependencies, if out of date