Skip to content

Commit 9d59941

Browse files
committed
Ignore config port
1 parent b55c80c commit 9d59941

28 files changed

+894
-19
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: 4 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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,13 @@
3838
"Project '{0}' is out of date because it has errors.": {
3939
"category": "Message",
4040
"code": 6423
41+
},
42+
"Ignore the tsconfig found and build with commandline options and files.": {
43+
"category": "Message",
44+
"code": 1547
45+
},
46+
"tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error.": {
47+
"category": "Error",
48+
"code": 5111
4149
}
42-
}
50+
}

internal/execute/tsc.go

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

169174
// !!! 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
@@ -919,6 +919,59 @@ func TestTscExtends(t *testing.T) {
919919
}
920920
}
921921

922+
func TestTscIgnoreConfig(t *testing.T) {
923+
t.Parallel()
924+
filesWithoutConfig := func() FileMap {
925+
return FileMap{
926+
"/home/src/workspaces/project/src/a.ts": "export const a = 10;",
927+
"/home/src/workspaces/project/src/b.ts": "export const b = 10;",
928+
"/home/src/workspaces/project/c.ts": "export const c = 10;",
929+
}
930+
}
931+
filesWithConfig := func() FileMap {
932+
files := filesWithoutConfig()
933+
files["/home/src/workspaces/project/tsconfig.json"] = stringtestutil.Dedent(`
934+
{
935+
"include": ["src"],
936+
}`)
937+
return files
938+
}
939+
getScenarios := func(subScenario string, commandLineArgs []string) []*tscInput {
940+
commandLineArgsIgnoreConfig := append(commandLineArgs, "--ignoreConfig")
941+
return []*tscInput{
942+
{
943+
subScenario: subScenario,
944+
files: filesWithConfig(),
945+
commandLineArgs: commandLineArgs,
946+
},
947+
{
948+
subScenario: subScenario + " with --ignoreConfig",
949+
files: filesWithConfig(),
950+
commandLineArgs: commandLineArgsIgnoreConfig,
951+
},
952+
{
953+
subScenario: subScenario + " when config file absent",
954+
files: filesWithoutConfig(),
955+
commandLineArgs: commandLineArgs,
956+
},
957+
{
958+
subScenario: subScenario + " when config file absent with --ignoreConfig",
959+
files: filesWithoutConfig(),
960+
commandLineArgs: commandLineArgsIgnoreConfig,
961+
},
962+
}
963+
}
964+
testCases := slices.Concat(
965+
getScenarios("without any options", nil),
966+
getScenarios("specifying files", []string{"src/a.ts"}),
967+
getScenarios("specifying project", []string{"-p", "."}),
968+
getScenarios("mixing project and files", []string{"-p", ".", "src/a.ts", "c.ts"}),
969+
)
970+
for _, test := range testCases {
971+
test.run(t, "ignoreConfig")
972+
}
973+
}
974+
922975
func TestTscIncremental(t *testing.T) {
923976
t.Parallel()
924977
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
@@ -290,6 +290,15 @@ var optionsForCompiler = []*CommandLineOption{
290290
Description: diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing,
291291
DefaultValueDescription: false,
292292
},
293+
{
294+
Name: "ignoreConfig",
295+
Kind: CommandLineOptionTypeBoolean,
296+
ShowInSimplifiedHelpView: true,
297+
Category: diagnostics.Command_line_Options,
298+
IsCommandLineOnly: true,
299+
Description: diagnostics.Ignore_the_tsconfig_found_and_build_with_commandline_options_and_files,
300+
DefaultValueDescription: false,
301+
},
293302

294303
// Basic
295304
// 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.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

testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.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

0 commit comments

Comments
 (0)