Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always look for tsconfig, allow command line to override tsconfig file list #49817

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 4 additions & 6 deletions src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,6 @@ namespace ts {
}

if (commandLine.options.project) {
if (commandLine.fileNames.length !== 0) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}

const fileOrDirectory = normalizePath(commandLine.options.project);
if (!fileOrDirectory /* current directory "." */ || sys.directoryExists(fileOrDirectory)) {
configFileName = combinePaths(fileOrDirectory, "tsconfig.json");
Expand All @@ -528,7 +523,7 @@ namespace ts {
}
}
}
else if (commandLine.fileNames.length === 0) {
else if (!hasProperty(commandLine.options, "project")) {
const searchPath = normalizePath(sys.getCurrentDirectory());
configFileName = findConfigFile(searchPath, fileName => sys.fileExists(fileName));
}
Expand All @@ -552,6 +547,9 @@ namespace ts {
if (configFileName) {
const extendedConfigCache = new Map<string, ExtendedConfigCacheEntry>();
const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, extendedConfigCache, commandLine.watchOptions, sys, reportDiagnostic)!; // TODO: GH#18217
if (length(commandLine.fileNames)) {
configParseResult.fileNames = commandLine.fileNames;
}
if (commandLineOptions.showConfig) {
if (configParseResult.errors.length !== 0) {
reportDiagnostic = updateReportDiagnostic(
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"unittests/tsbuildWatch/reexport.ts",
"unittests/tsbuildWatch/watchEnvironment.ts",
"unittests/tsc/cancellationToken.ts",
"unittests/tsc/commandLineOverridesConfig.ts",
"unittests/tsc/composite.ts",
"unittests/tsc/declarationEmit.ts",
"unittests/tsc/incremental.ts",
Expand Down
5 changes: 3 additions & 2 deletions src/testRunner/unittests/tsbuild/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ interface Symbol {
*/
export function loadProjectFromFiles(
files: vfs.FileSet,
libContentToAppend?: string
libContentToAppend?: string,
cwd = "/"
): vfs.FileSystem {
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
files,
cwd: "/",
cwd,
meta: { defaultLibLocation: "/lib" },
});
addLibAndMakeReadonly(fs, libContentToAppend);
Expand Down
103 changes: 103 additions & 0 deletions src/testRunner/unittests/tsc/commandLineOverridesConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
namespace ts {
describe("unittests:: tsc:: commandLineOverridesConfig::", () => {
verifyTsc({
scenario: "commandLineOverridesConfig",
subScenario: "files passed on commandline override default tsconfig",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "export const x = 10;",
"/src/project/src/file.ts": "export const y: string = undefined;",
"/src/project/tsconfig.json": Utils.dedent`
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}`,
}, /*libContent*/ undefined, "/src/project/"),
commandLineArgs: ["src/main.ts"],
environmentVariables: {},
});

verifyTsc({
scenario: "commandLineOverridesConfig",
subScenario: "compiler options passed on commandline override default tsconfig",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "export const x = 10;",
"/src/project/src/file.ts": "export const y: string = undefined;",
"/src/project/tsconfig.json": Utils.dedent`
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}`,
}, /*libContent*/ undefined, "/src/project/"),
commandLineArgs: ["--strict", "false"],
environmentVariables: {},
});

verifyTsc({
scenario: "commandLineOverridesConfig",
subScenario: "files passed on commandline override passed tsconfig",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "export const x = 10;",
"/src/project/src/file.ts": "export const y: string = undefined;",
"/src/project/tsconfig.new.json": Utils.dedent`
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}`,
}, /*libContent*/ undefined, "/src/project/"),
commandLineArgs: ["-p", "tsconfig.new.json", "src/main.ts"],
environmentVariables: {},
});

verifyTsc({
scenario: "commandLineOverridesConfig",
subScenario: "compiler options passed on commandline override passed tsconfig",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "export const x = 10;",
"/src/project/src/file.ts": "export const y: string = undefined;",
"/src/project/tsconfig.new.json": Utils.dedent`
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}`,
}, /*libContent*/ undefined, "/src/project/"),
commandLineArgs: ["-p", "tsconfig.new.json", "--strict", "false"],
environmentVariables: {},
});

verifyTsc({
scenario: "commandLineOverridesConfig",
subScenario: "-p null disables config",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "export const x = 10;",
"/src/project/src/file.ts": "export const y: string = undefined;",
"/src/project/tsconfig.json": Utils.dedent`
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}`,
}, /*libContent*/ undefined, "/src/project/"),
commandLineArgs: ["-p", "null", "src/file.ts"],
environmentVariables: {},
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Input::
//// [/lib/lib.d.ts]
/// <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> {}
declare const console: { log(msg: any): void; };

//// [/src/project/src/file.ts]
export const y: string = undefined;

//// [/src/project/src/main.ts]
export const x = 10;

//// [/src/project/tsconfig.json]
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}



Output::
/lib/tsc -p null src/file.ts
exitCode:: ExitStatus.Success


//// [/src/project/src/file.js]
"use strict";
exports.__esModule = true;
exports.y = void 0;
exports.y = undefined;


Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Input::
//// [/lib/lib.d.ts]
/// <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> {}
declare const console: { log(msg: any): void; };

//// [/src/project/src/file.ts]
export const y: string = undefined;

//// [/src/project/src/main.ts]
export const x = 10;

//// [/src/project/tsconfig.json]
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}



Output::
/lib/tsc --strict false
exitCode:: ExitStatus.Success


//// [/src/project/src/file.js]
"use strict";
exports.__esModule = true;
exports.y = void 0;
exports.y = undefined;


//// [/src/project/src/main.js]
"use strict";
exports.__esModule = true;
exports.x = void 0;
exports.x = 10;


Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Input::
//// [/lib/lib.d.ts]
/// <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> {}
declare const console: { log(msg: any): void; };

//// [/src/project/src/file.ts]
export const y: string = undefined;

//// [/src/project/src/main.ts]
export const x = 10;

//// [/src/project/tsconfig.new.json]
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}



Output::
/lib/tsc -p tsconfig.new.json --strict false
exitCode:: ExitStatus.Success


//// [/src/project/src/file.js]
"use strict";
exports.__esModule = true;
exports.y = void 0;
exports.y = undefined;


//// [/src/project/src/main.js]
"use strict";
exports.__esModule = true;
exports.x = void 0;
exports.x = 10;


Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Input::
//// [/lib/lib.d.ts]
/// <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> {}
declare const console: { log(msg: any): void; };

//// [/src/project/src/file.ts]
export const y: string = undefined;

//// [/src/project/src/main.ts]
export const x = 10;

//// [/src/project/tsconfig.json]
{
"compilerOptions": {
"strict": true,
},
"include": [
"src/**/*.ts"
]
}



Output::
/lib/tsc src/main.ts
exitCode:: ExitStatus.Success


//// [/src/project/src/main.js]
"use strict";
exports.__esModule = true;
exports.x = void 0;
exports.x = 10;


Loading