diff --git a/internal/core/compileroptions.go b/internal/core/compileroptions.go index 057d034ec2..ad6a4ceeca 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 50df22ce10..d59fa2ec20 100644 --- a/internal/diagnostics/diagnostics_generated.go +++ b/internal/diagnostics/diagnostics_generated.go @@ -926,6 +926,8 @@ var X_using_declarations_are_not_allowed_in_ambient_contexts = &Message{code: 15 var X_await_using_declarations_are_not_allowed_in_ambient_contexts = &Message{code: 1546, category: CategoryError, key: "await_using_declarations_are_not_allowed_in_ambient_contexts_1546", text: "'await using' declarations are not allowed in ambient contexts."} +var Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files = &Message{code: 1549, category: CategoryMessage, key: "Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files_1549", 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."} @@ -2356,6 +2358,8 @@ var Option_module_must_be_set_to_0_when_option_moduleResolution_is_set_to_1 = &M var Visit_https_Colon_Slash_Slashaka_ms_Slashts6_for_migration_information = &Message{code: 5111, category: CategoryMessage, key: "Visit_https_Colon_Slash_Slashaka_ms_Slashts6_for_migration_information_5111", text: "Visit https://aka.ms/ts6 for migration information."} +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: 5112, category: CategoryError, key: "tsconfig_json_is_present_but_will_not_be_loaded_if_files_are_specified_on_commandline_Use_ignoreConf_5112", 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."} @@ -5184,6 +5188,8 @@ func keyToMessage(key Key) *Message { return X_using_declarations_are_not_allowed_in_ambient_contexts case "await_using_declarations_are_not_allowed_in_ambient_contexts_1546": return X_await_using_declarations_are_not_allowed_in_ambient_contexts + case "Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files_1549": + return Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files case "The_types_of_0_are_incompatible_between_these_types_2200": return The_types_of_0_are_incompatible_between_these_types case "The_types_returned_by_0_are_incompatible_between_these_types_2201": @@ -6614,6 +6620,8 @@ func keyToMessage(key Key) *Message { return Option_module_must_be_set_to_0_when_option_moduleResolution_is_set_to_1 case "Visit_https_Colon_Slash_Slashaka_ms_Slashts6_for_migration_information_5111": return Visit_https_Colon_Slash_Slashaka_ms_Slashts6_for_migration_information + case "tsconfig_json_is_present_but_will_not_be_loaded_if_files_are_specified_on_commandline_Use_ignoreConf_5112": + return X_tsconfig_json_is_present_but_will_not_be_loaded_if_files_are_specified_on_commandline_Use_ignoreConfig_to_skip_this_error case "Generates_a_sourcemap_for_each_corresponding_d_ts_file_6000": return Generates_a_sourcemap_for_each_corresponding_d_ts_file case "Concatenate_and_emit_output_to_single_file_6001": diff --git a/internal/diagnostics/extraDiagnosticMessages.json b/internal/diagnostics/extraDiagnosticMessages.json index aefd5c7426..47d3e93a11 100644 --- a/internal/diagnostics/extraDiagnosticMessages.json +++ b/internal/diagnostics/extraDiagnosticMessages.json @@ -46,5 +46,13 @@ "Locale must be an IETF BCP 47 language tag. Examples: '{0}', '{1}'.": { "category": "Error", "code": 6048 + }, + "Ignore the tsconfig found and build with commandline options and files.": { + "category": "Message", + "code": 1549 + }, + "tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error.": { + "category": "Error", + "code": 5112 } } diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index d68a31e3a3..f70b053ea5 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -150,19 +150,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, locale) - tsc.PrintHelp(sys, locale, 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, locale) + tsc.PrintHelp(sys, locale, 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 5efa3262de..e618ce7829 100644 --- a/internal/execute/tsctests/tsc_test.go +++ b/internal/execute/tsctests/tsc_test.go @@ -981,6 +981,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 f2584810aa..65c54a2718 100644 --- a/internal/tsoptions/declscompiler.go +++ b/internal/tsoptions/declscompiler.go @@ -298,6 +298,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 2583ed4147..279f40f4ea 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 b349e1df0e..a77e5c9b7a 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-all.js b/testdata/baselines/reference/tsc/commandLine/help-all.js index a2b8184ea2..340e017541 100644 --- a/testdata/baselines/reference/tsc/commandLine/help-all.js +++ b/testdata/baselines/reference/tsc/commandLine/help-all.js @@ -26,6 +26,9 @@ Print this message. --help, -? +--ignoreConfig +Ignore the tsconfig found and build with commandline options and files. + --init Initializes a TypeScript project and creates a tsconfig.json file. diff --git a/testdata/baselines/reference/tsc/commandLine/help.js b/testdata/baselines/reference/tsc/commandLine/help.js index 1eb6ad1811..4c0e76cd30 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 244169b3bb..ec9433c01f 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 86cc398b85..97992a3c39 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..fab3875627 --- /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 TS5112: 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..662b11e11c --- /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, node20, 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, esnext.error, esnext.sharedmemory, 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-jsx, react-jsxdev, react +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..329fd14871 --- /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, node20, 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, esnext.error, esnext.sharedmemory, 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-jsx, react-jsxdev, react +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 6a59db07d6..d93d565d85 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