Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
description: Diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing,
defaultValueDescription: false,
},
{
name: "ignoreConfig",
type: "boolean",
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
8 changes: 8 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,10 @@
"category": "Error",
"code": 1548
},
"Ignore the tsconfig found and build with commandline options and files.": {
"category": "Message",
"code": 1549
},

"The types of '{0}' are incompatible between these types.": {
"category": "Error",
Expand Down Expand Up @@ -4733,6 +4737,10 @@
"category": "Message",
"code": 5111
},
"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
},

"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
Expand Down
27 changes: 17 additions & 10 deletions src/compiler/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,20 +614,27 @@ function executeCommandLineWorker(
}
}
}
else if (commandLine.fileNames.length === 0) {
else if (!commandLine.options.ignoreConfig || commandLine.fileNames.length === 0) {
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The logic here is hard to follow. When ignoreConfig is true AND fileNames.length > 0, this condition is false and configFileName remains undefined (desired). When ignoreConfig is false OR no files specified, we search for config. Consider extracting this condition to a named boolean variable like shouldSearchForConfig to improve readability.

Copilot uses AI. Check for mistakes.
const searchPath = normalizePath(sys.getCurrentDirectory());
configFileName = findConfigFile(searchPath, fileName => sys.fileExists(fileName));
}

if (commandLine.fileNames.length === 0 && !configFileName) {
if (commandLine.options.showConfig) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, normalizePath(sys.getCurrentDirectory())));
// if (!commandLine.options.ignoreConfig) {
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out code. This leftover comment should be deleted as it doesn't serve any purpose and clutters the implementation.

Suggested change
// if (!commandLine.options.ignoreConfig) {

Copilot uses AI. Check for mistakes.
if (commandLine.fileNames.length !== 0) {
if (configFileName) {
// Error to not specify config file
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is unclear and grammatically incorrect. It should be "Error when files are specified on command line but tsconfig.json is present" to accurately describe what's happening.

Suggested change
// Error to not specify config file
// Error when files are specified on command line but tsconfig.json is present

Copilot uses AI. Check for mistakes.
reportDiagnostic(createCompilerDiagnostic(Diagnostics.tsconfig_json_is_present_but_will_not_be_loaded_if_files_are_specified_on_commandline_Use_ignoreConfig_to_skip_this_error));
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
}
else {
printVersion(sys);
printHelp(sys, commandLine);
else if (!configFileName) {
if (commandLine.options.showConfig) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, normalizePath(sys.getCurrentDirectory())));
}
else {
printVersion(sys);
printHelp(sys, commandLine);
}
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}

const currentDirectory = sys.getCurrentDirectory();
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7552,6 +7552,7 @@ export interface CompilerOptions {
/** @internal */ watch?: boolean;
esModuleInterop?: boolean;
/** @internal */ showConfig?: boolean;
/** @internal */ ignoreConfig?: boolean;
useDefineForClassFields?: boolean;
/** @internal */ tscBuild?: boolean;

Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export * from "./unittests/tsc/composite.js";
export * from "./unittests/tsc/declarationEmit.js";
export * from "./unittests/tsc/extends.js";
export * from "./unittests/tsc/forceConsistentCasingInFileNames.js";
export * from "./unittests/tsc/ignoreConfig.js";
export * from "./unittests/tsc/incremental.js";
export * from "./unittests/tsc/libraryResolution.js";
export * from "./unittests/tsc/listFilesOnly.js";
Expand Down
58 changes: 58 additions & 0 deletions src/testRunner/unittests/tsc/ignoreConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as ts from "../../_namespaces/ts.js";
import { jsonToReadableText } from "../helpers.js";
import { verifyTsc } from "../helpers/tsc.js";
import { TestServerHost } from "../helpers/virtualFileSystemWithWatch.js";

describe("unittests:: tsc:: ignoreConfig::", () => {
function sysWithoutConfig() {
return TestServerHost.createWatchedSystem({
"/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;",
});
}
function sysWithConfig() {
const sys = sysWithoutConfig();
sys.writeFile(
"/home/src/workspaces/project/tsconfig.json",
jsonToReadableText({
include: ["src"],
}),
);
return sys;
}
function runScenario(subScenario: string, commandLineArgs: readonly string[]) {
verifyTsc({
scenario: "ignoreConfig",
subScenario,
sys: sysWithConfig,
commandLineArgs,
});

verifyTsc({
scenario: "ignoreConfig",
subScenario: subScenario + " with --ignoreConfig",
sys: sysWithConfig,
commandLineArgs: commandLineArgs.concat("--ignoreConfig"),
});

verifyTsc({
scenario: "ignoreConfig",
subScenario: subScenario + " when config file absent",
sys: sysWithoutConfig,
commandLineArgs,
});

verifyTsc({
scenario: "ignoreConfig",
subScenario: subScenario + " when config file absent with --ignoreConfig",
sys: sysWithoutConfig,
commandLineArgs: commandLineArgs.concat("--ignoreConfig"),
});
}

runScenario("without any options", ts.emptyArray);
runScenario("specifying files", ["src/a.ts"]);
runScenario("specifying project", ["-p", "."]);
runScenario("mixing project and files", ["-p", ".", "src/a.ts", "c.ts"]);
});
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tscWatch/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ declare module "fs" {
],
});
}
verifyIgnore("watch without configFile", ["--w", `/user/username/projects/myproject/test.ts`]);
verifyIgnore("watch without configFile", ["--w", "--ignoreConfig", `/user/username/projects/myproject/test.ts`]);
verifyIgnore("watch with configFile", ["--w", "-p", `/user/username/projects/myproject/tsconfig.json`]);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"ignoreConfig": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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 tests/baselines/reference/tsc/commandLine/help-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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.

Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/tsc/commandLine/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 @@ -67,6 +67,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 @@ -67,6 +67,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
@@ -0,0 +1,33 @@
currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false
Input::
//// [/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;

//// [/home/src/tslibs/TS/Lib/lib.d.ts]
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> {}
declare const console: { log(msg: any): void; };


/home/src/tslibs/TS/Lib/tsc.js -p . src/a.ts c.ts --ignoreConfig
Output::
error TS5042: Option 'project' cannot be mixed with source files on a command line.



exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false
Input::
//// [/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;

//// [/home/src/tslibs/TS/Lib/lib.d.ts]
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> {}
declare const console: { log(msg: any): void; };


/home/src/tslibs/TS/Lib/tsc.js -p . src/a.ts c.ts
Output::
error TS5042: Option 'project' cannot be mixed with source files on a command line.



exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false
Input::
//// [/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;

//// [/home/src/tslibs/TS/Lib/lib.d.ts]
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> {}
declare const console: { log(msg: any): void; };

//// [/home/src/workspaces/project/tsconfig.json]
{
"include": [
"src"
]
}


/home/src/tslibs/TS/Lib/tsc.js -p . src/a.ts c.ts --ignoreConfig
Output::
error TS5042: Option 'project' cannot be mixed with source files on a command line.



exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false
Input::
//// [/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;

//// [/home/src/tslibs/TS/Lib/lib.d.ts]
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> {}
declare const console: { log(msg: any): void; };

//// [/home/src/workspaces/project/tsconfig.json]
{
"include": [
"src"
]
}


/home/src/tslibs/TS/Lib/tsc.js -p . src/a.ts c.ts
Output::
error TS5042: Option 'project' cannot be mixed with source files on a command line.



exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
Loading
Loading