Skip to content

Commit 00cd8ad

Browse files
committed
Add --outFile and revert change make --out relative in tsconfig.json
1 parent cfc164b commit 00cd8ad

21 files changed

Lines changed: 379 additions & 15 deletions

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ namespace ts {
388388
return node1.pos <= node2.pos;
389389
}
390390

391-
if (!compilerOptions.out) {
391+
if (!compilerOptions.outFile && !compilerOptions.out) {
392392
return true;
393393
}
394394

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ namespace ts {
120120
{
121121
name: "out",
122122
type: "string",
123+
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
124+
// for correct behaviour, please use outFile
125+
paramType: Diagnostics.FILE,
126+
},
127+
{
128+
name: "outFile",
129+
type: "string",
123130
isFilePath: true,
124131
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
125132
paramType: Diagnostics.FILE,

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ namespace ts {
15741574
? referencedFile.fileName // Declaration file, use declaration file name
15751575
: shouldEmitToOwnFile(referencedFile, compilerOptions)
15761576
? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file
1577-
: removeFileExtension(compilerOptions.out) + ".d.ts"; // Global out file
1577+
: removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts"; // Global out file
15781578

15791579
declFileName = getRelativePathToDirectoryOrUrl(
15801580
getDirectoryPath(normalizeSlashes(jsFilePath)),

src/compiler/emitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
7878
}
7979
});
8080

81-
if (compilerOptions.out) {
82-
emitFile(compilerOptions.out);
81+
if (compilerOptions.outFile || compilerOptions.out) {
82+
emitFile(compilerOptions.outFile || compilerOptions.out);
8383
}
8484
}
8585
else {
@@ -88,8 +88,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
8888
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, forEach(host.getSourceFiles(), shouldEmitJsx) ? ".jsx" : ".js");
8989
emitFile(jsFilePath, targetSourceFile);
9090
}
91-
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
92-
emitFile(compilerOptions.out);
91+
else if (!isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) {
92+
emitFile(compilerOptions.outFile || compilerOptions.out);
9393
}
9494
}
9595

src/compiler/program.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ namespace ts {
413413
// This is because in the -out scenario all files need to be emitted, and therefore all
414414
// files need to be type checked. And the way to specify that all files need to be type
415415
// checked is to not pass the file to getEmitResolver.
416-
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
416+
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out)? undefined : sourceFile);
417417

418418
let start = new Date().getTime();
419419

@@ -804,6 +804,10 @@ namespace ts {
804804
if (options.out) {
805805
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules"));
806806
}
807+
808+
if (options.outFile) {
809+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules"));
810+
}
807811
}
808812

809813
if (options.inlineSourceMap) {
@@ -825,6 +829,10 @@ namespace ts {
825829
}
826830
}
827831

832+
if (options.out && options.outFile) {
833+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile"));
834+
}
835+
828836
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
829837
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
830838
if (options.mapRoot) {
@@ -837,6 +845,7 @@ namespace ts {
837845
}
838846

839847
let languageVersion = options.target || ScriptTarget.ES3;
848+
let outFile = options.outFile || options.out;
840849

841850
let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
842851
if (options.isolatedModules) {
@@ -866,7 +875,7 @@ namespace ts {
866875
if (options.outDir || // there is --outDir specified
867876
options.sourceRoot || // there is --sourceRoot specified
868877
(options.mapRoot && // there is --mapRoot specified and there would be multiple js files generated
869-
(!options.out || firstExternalModuleSourceFile !== undefined))) {
878+
(!outFile || firstExternalModuleSourceFile !== undefined))) {
870879

871880
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
872881
// If a rootDir is specified and is valid use it as the commonSourceDirectory
@@ -890,6 +899,10 @@ namespace ts {
890899
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out"));
891900
}
892901

902+
if (options.outFile) {
903+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile"));
904+
}
905+
893906
if (options.outDir) {
894907
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir"));
895908
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,7 @@ namespace ts {
20322032
noLib?: boolean;
20332033
noResolve?: boolean;
20342034
out?: string;
2035+
outFile?: string;
20352036
outDir?: string;
20362037
preserveConstEnums?: boolean;
20372038
project?: string;

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ namespace ts {
17661766

17671767
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
17681768
if (!isDeclarationFile(sourceFile)) {
1769-
if ((isExternalModule(sourceFile) || !compilerOptions.out)) {
1769+
if ((isExternalModule(sourceFile) || !(compilerOptions.outFile || compilerOptions.out))) {
17701770
// 1. in-browser single file compilation scenario
17711771
// 2. non .js file
17721772
return compilerOptions.isolatedModules || !fileExtensionIs(sourceFile.fileName, ".js");

src/harness/fourslash.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ module FourSlash {
123123
mapRoot: "mapRoot",
124124
module: "module",
125125
out: "out",
126+
outFile: "outFile",
126127
outDir: "outDir",
127128
sourceMap: "sourceMap",
128129
sourceRoot: "sourceRoot",
@@ -133,7 +134,7 @@ module FourSlash {
133134
// List of allowed metadata names
134135
let fileMetadataNames = [metadataOptionNames.fileName, metadataOptionNames.emitThisFile, metadataOptionNames.resolveReference];
135136
let globalMetadataNames = [metadataOptionNames.allowNonTsExtensions, metadataOptionNames.baselineFile, metadataOptionNames.declaration,
136-
metadataOptionNames.mapRoot, metadataOptionNames.module, metadataOptionNames.out,
137+
metadataOptionNames.mapRoot, metadataOptionNames.module, metadataOptionNames.out, metadataOptionNames.outFile,
137138
metadataOptionNames.outDir, metadataOptionNames.sourceMap, metadataOptionNames.sourceRoot];
138139

139140
function convertGlobalOptionsToCompilerOptions(globalOptions: { [idx: string]: string }): ts.CompilerOptions {
@@ -169,6 +170,9 @@ module FourSlash {
169170
case metadataOptionNames.out:
170171
settings.out = globalOptions[prop];
171172
break;
173+
case metadataOptionNames.outFile:
174+
settings.outFile = globalOptions[prop];
175+
break;
172176
case metadataOptionNames.outDir:
173177
settings.outDir = globalOptions[prop];
174178
break;
@@ -2407,7 +2411,7 @@ module FourSlash {
24072411
ts.ScriptTarget.Latest,
24082412
ts.sys.useCaseSensitiveFileNames);
24092413

2410-
let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
2414+
let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { outFile: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
24112415

24122416
let sourceFile = host.getSourceFile(fileName, ts.ScriptTarget.ES3);
24132417

src/harness/harness.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,10 @@ module Harness {
10911091
options.out = setting.value;
10921092
break;
10931093

1094+
case "outfile":
1095+
options.outFile = setting.value;
1096+
break;
1097+
10941098
case "outdiroption":
10951099
case "outdir":
10961100
options.outDir = setting.value;
@@ -1229,7 +1233,8 @@ module Harness {
12291233
assert(sourceFile, "Program has no source file with name '" + fileName + "'");
12301234
// Is this file going to be emitted separately
12311235
let sourceFileName: string;
1232-
if (ts.isExternalModule(sourceFile) || !options.out) {
1236+
let outFile = options.outFile || options.out;
1237+
if (ts.isExternalModule(sourceFile) || !outFile) {
12331238
if (options.outDir) {
12341239
let sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, result.currentDirectoryForProgram);
12351240
sourceFilePath = sourceFilePath.replace(result.program.getCommonSourceDirectory(), "");
@@ -1241,7 +1246,7 @@ module Harness {
12411246
}
12421247
else {
12431248
// Goes to single --out file
1244-
sourceFileName = options.out;
1249+
sourceFileName = outFile;
12451250
}
12461251

12471252
let dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts";

src/harness/projectsRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class ProjectRunner extends RunnerBase {
158158
return {
159159
declaration: !!testCase.declaration,
160160
sourceMap: !!testCase.sourceMap,
161-
out: testCase.out,
161+
outFile: testCase.out,
162162
outDir: testCase.outDir,
163163
mapRoot: testCase.resolveMapRoot && testCase.mapRoot ? ts.sys.resolvePath(testCase.mapRoot) : testCase.mapRoot,
164164
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot ? ts.sys.resolvePath(testCase.sourceRoot) : testCase.sourceRoot,
@@ -299,7 +299,7 @@ class ProjectRunner extends RunnerBase {
299299
allInputFiles.unshift(findOutpuDtsFile(outputDtsFileName));
300300
}
301301
else {
302-
let outputDtsFileName = ts.removeFileExtension(compilerOptions.out) + ".d.ts";
302+
let outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile|| compilerOptions.out) + ".d.ts";
303303
let outputDtsFile = findOutpuDtsFile(outputDtsFileName);
304304
if (!ts.contains(allInputFiles, outputDtsFile)) {
305305
allInputFiles.unshift(outputDtsFile);

0 commit comments

Comments
 (0)