Skip to content

Commit 417387a

Browse files
authored
Ignore config port (#1755)
1 parent bd7c18d commit 417387a

29 files changed

+900
-18
lines changed

internal/core/compileroptions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type CompilerOptions struct {
4747
ForceConsistentCasingInFileNames Tristate `json:"forceConsistentCasingInFileNames,omitzero"`
4848
IsolatedModules Tristate `json:"isolatedModules,omitzero"`
4949
IsolatedDeclarations Tristate `json:"isolatedDeclarations,omitzero"`
50+
IgnoreConfig Tristate `json:"ignoreConfig,omitzero"`
5051
IgnoreDeprecations string `json:"ignoreDeprecations,omitzero"`
5152
ImportHelpers Tristate `json:"importHelpers,omitzero"`
5253
InlineSourceMap Tristate `json:"inlineSourceMap,omitzero"`

internal/diagnostics/diagnostics_generated.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/diagnostics/extraDiagnosticMessages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,13 @@
4646
"Locale must be an IETF BCP 47 language tag. Examples: '{0}', '{1}'.": {
4747
"category": "Error",
4848
"code": 6048
49+
},
50+
"Ignore the tsconfig found and build with commandline options and files.": {
51+
"category": "Message",
52+
"code": 1549
53+
},
54+
"tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error.": {
55+
"category": "Error",
56+
"code": 5112
4957
}
5058
}

internal/execute/tsc.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,24 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
150150
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
151151
}
152152
}
153-
} else if len(commandLine.FileNames()) == 0 {
153+
} else if !commandLine.CompilerOptions().IgnoreConfig.IsTrue() || len(commandLine.FileNames()) == 0 {
154154
searchPath := tspath.NormalizePath(sys.GetCurrentDirectory())
155155
configFileName = findConfigFile(searchPath, sys.FS().FileExists, "tsconfig.json")
156-
}
157-
158-
if configFileName == "" && len(commandLine.FileNames()) == 0 {
159-
if commandLine.CompilerOptions().ShowConfig.IsTrue() {
160-
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory())))
161-
} else {
162-
tsc.PrintVersion(sys, locale)
163-
tsc.PrintHelp(sys, locale, commandLine)
156+
if len(commandLine.FileNames()) != 0 {
157+
if configFileName != "" {
158+
// Error to not specify config file
159+
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))
160+
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
161+
}
162+
} else if configFileName == "" {
163+
if commandLine.CompilerOptions().ShowConfig.IsTrue() {
164+
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory())))
165+
} else {
166+
tsc.PrintVersion(sys, locale)
167+
tsc.PrintHelp(sys, locale, commandLine)
168+
}
169+
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
164170
}
165-
return tsc.CommandLineResult{Status: tsc.ExitStatusDiagnosticsPresent_OutputsSkipped}
166171
}
167172

168173
// !!! convert to options with absolute paths is usually done here, but for ease of implementation, it's done in `tsoptions.ParseCommandLine()`

internal/execute/tsctests/tsc_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,59 @@ func TestTscExtends(t *testing.T) {
981981
}
982982
}
983983

984+
func TestTscIgnoreConfig(t *testing.T) {
985+
t.Parallel()
986+
filesWithoutConfig := func() FileMap {
987+
return FileMap{
988+
"/home/src/workspaces/project/src/a.ts": "export const a = 10;",
989+
"/home/src/workspaces/project/src/b.ts": "export const b = 10;",
990+
"/home/src/workspaces/project/c.ts": "export const c = 10;",
991+
}
992+
}
993+
filesWithConfig := func() FileMap {
994+
files := filesWithoutConfig()
995+
files["/home/src/workspaces/project/tsconfig.json"] = stringtestutil.Dedent(`
996+
{
997+
"include": ["src"],
998+
}`)
999+
return files
1000+
}
1001+
getScenarios := func(subScenario string, commandLineArgs []string) []*tscInput {
1002+
commandLineArgsIgnoreConfig := append(commandLineArgs, "--ignoreConfig")
1003+
return []*tscInput{
1004+
{
1005+
subScenario: subScenario,
1006+
files: filesWithConfig(),
1007+
commandLineArgs: commandLineArgs,
1008+
},
1009+
{
1010+
subScenario: subScenario + " with --ignoreConfig",
1011+
files: filesWithConfig(),
1012+
commandLineArgs: commandLineArgsIgnoreConfig,
1013+
},
1014+
{
1015+
subScenario: subScenario + " when config file absent",
1016+
files: filesWithoutConfig(),
1017+
commandLineArgs: commandLineArgs,
1018+
},
1019+
{
1020+
subScenario: subScenario + " when config file absent with --ignoreConfig",
1021+
files: filesWithoutConfig(),
1022+
commandLineArgs: commandLineArgsIgnoreConfig,
1023+
},
1024+
}
1025+
}
1026+
testCases := slices.Concat(
1027+
getScenarios("without any options", nil),
1028+
getScenarios("specifying files", []string{"src/a.ts"}),
1029+
getScenarios("specifying project", []string{"-p", "."}),
1030+
getScenarios("mixing project and files", []string{"-p", ".", "src/a.ts", "c.ts"}),
1031+
)
1032+
for _, test := range testCases {
1033+
test.run(t, "ignoreConfig")
1034+
}
1035+
}
1036+
9841037
func TestTscIncremental(t *testing.T) {
9851038
t.Parallel()
9861039
getConstEnumTest := func(bdsContents string, changeEnumFile string, testSuffix string) *tscInput {

internal/tsoptions/declscompiler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ var optionsForCompiler = []*CommandLineOption{
298298
Description: diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing,
299299
DefaultValueDescription: false,
300300
},
301+
{
302+
Name: "ignoreConfig",
303+
Kind: CommandLineOptionTypeBoolean,
304+
ShowInSimplifiedHelpView: true,
305+
Category: diagnostics.Command_line_Options,
306+
IsCommandLineOnly: true,
307+
Description: diagnostics.Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files,
308+
DefaultValueDescription: false,
309+
},
301310

302311
// Basic
303312
// targetOptionDeclaration,

internal/tsoptions/parsinghelpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ func parseCompilerOptions(key string, value any, allOptions *core.CompilerOption
259259
allOptions.GenerateTrace = ParseString(value)
260260
case "isolatedModules":
261261
allOptions.IsolatedModules = ParseTristate(value)
262+
case "ignoreConfig":
263+
allOptions.IgnoreConfig = ParseTristate(value)
262264
case "ignoreDeprecations":
263265
allOptions.IgnoreDeprecations = ParseString(value)
264266
case "importHelpers":

testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Compile the project given the path to its configuration file, or to a folder wit
5555
--showConfig
5656
Print the final configuration instead of building.
5757

58+
--ignoreConfig
59+
Ignore the tsconfig found and build with commandline options and files.
60+
5861
--build, -b
5962
Build one or more projects and their dependencies, if out of date
6063

testdata/baselines/reference/tsc/commandLine/help-all.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Print this message.
2626
--help, -?
2727

2828

29+
--ignoreConfig
30+
Ignore the tsconfig found and build with commandline options and files.
31+
2932
--init
3033
Initializes a TypeScript project and creates a tsconfig.json file.
3134

testdata/baselines/reference/tsc/commandLine/help.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Compile the project given the path to its configuration file, or to a folder wit
5454
--showConfig
5555
Print the final configuration instead of building.
5656

57+
--ignoreConfig
58+
Ignore the tsconfig found and build with commandline options and files.
59+
5760
--build, -b
5861
Build one or more projects and their dependencies, if out of date
5962

0 commit comments

Comments
 (0)