Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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 @@ -672,6 +672,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
30 changes: 9 additions & 21 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,6 @@
"category": "Error",
"code": 1464
},

"The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.": {
"category": "Error",
"code": 1470
Expand Down Expand Up @@ -1849,7 +1848,10 @@
"category": "Error",
"code": 1546
},

"Ignore the tsconfig found and build with commandline options and files.": {
"category": "Message",
"code": 1547
},
"The types of '{0}' are incompatible between these types.": {
"category": "Error",
"code": 2200
Expand Down Expand Up @@ -1890,7 +1892,6 @@
"category": "Error",
"code": 2208
},

"The project root is ambiguous, but is required to resolve export map entry '{0}' in file '{1}'. Supply the `rootDir` compiler option to disambiguate.": {
"category": "Error",
"code": 2209
Expand All @@ -1907,7 +1908,6 @@
"category": "Message",
"code": 2212
},

"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
Expand Down Expand Up @@ -2888,7 +2888,6 @@
"category": "Error",
"code": 2568
},

"Could not find name '{0}'. Did you mean '{1}'?": {
"category": "Error",
"code": 2570
Expand Down Expand Up @@ -3129,7 +3128,6 @@
"category": "Error",
"code": 2639
},

"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
"category": "Error",
"code": 2649
Expand Down Expand Up @@ -4011,7 +4009,6 @@
"category": "Error",
"code": 2882
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
Expand Down Expand Up @@ -4456,7 +4453,6 @@
"category": "Error",
"code": 4128
},

"The current host does not support the '{0}' option.": {
"category": "Error",
"code": 5001
Expand Down Expand Up @@ -4725,7 +4721,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",
"code": 6000
Expand Down Expand Up @@ -5669,7 +5668,6 @@
"category": "Error",
"code": 6266
},

"Directory '{0}' has no containing package.json scope. Imports will not resolve.": {
"category": "Message",
"code": 6270
Expand Down Expand Up @@ -5762,7 +5760,6 @@
"category": "Message",
"code": 6294
},

"Enable project compilation": {
"category": "Message",
"code": 6302
Expand Down Expand Up @@ -6045,7 +6042,6 @@
"category": "Message",
"code": 6421
},

"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",
"code": 6500
Expand Down Expand Up @@ -6570,7 +6566,6 @@
"category": "Message",
"code": 6808
},

"one of:": {
"category": "Message",
"code": 6900
Expand Down Expand Up @@ -6699,7 +6694,6 @@
"category": "Error",
"code": 6931
},

"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
Expand Down Expand Up @@ -6922,7 +6916,6 @@
"category": "Error",
"code": 7061
},

"You cannot rename this element.": {
"category": "Error",
"code": 8000
Expand Down Expand Up @@ -7067,7 +7060,6 @@
"category": "Error",
"code": 8039
},

"Declaration emit for this file requires using private name '{0}'. An explicit type annotation may unblock declaration emit.": {
"category": "Error",
"code": 9005
Expand Down Expand Up @@ -7300,7 +7292,6 @@
"category": "Error",
"code": 18003
},

"File is a CommonJS module; it may be converted to an ES module.": {
"category": "Suggestion",
"code": 80001
Expand Down Expand Up @@ -7341,7 +7332,6 @@
"category": "Suggestion",
"code": 80010
},

"Add missing 'super()' call": {
"category": "Message",
"code": 90001
Expand Down Expand Up @@ -7562,7 +7552,6 @@
"category": "Message",
"code": 90071
},

"Convert function to an ES2015 class": {
"category": "Message",
"code": 95001
Expand Down Expand Up @@ -8331,7 +8320,6 @@
"category": "Message",
"code": 95197
},

"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",
"code": 18004
Expand Down Expand Up @@ -8528,4 +8516,4 @@
"category": "Error",
"code": 18061
}
}
}
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) {
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) {
if (commandLine.fileNames.length !== 0) {
if (configFileName) {
// Error to not specify config file
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 @@ -7550,6 +7550,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
Loading
Loading