Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/core/compileroptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions internal/diagnostics/diagnostics_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion internal/diagnostics/extraDiagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
25 changes: 15 additions & 10 deletions internal/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down
53 changes: 53 additions & 0 deletions internal/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions internal/tsoptions/declscompiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions internal/tsoptions/parsinghelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions testdata/baselines/reference/tsc/commandLine/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
@@ -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*
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
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;


Original file line number Diff line number Diff line change
@@ -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*
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
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;


Loading
Loading