Skip to content

Commit 9446fc0

Browse files
committed
Convert options to relative paths
1 parent d760cbb commit 9446fc0

File tree

17 files changed

+144
-40
lines changed

17 files changed

+144
-40
lines changed

src/compiler/builder.ts

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,10 @@ namespace ts {
619619
fileInfos[relativeToBuildInfo(key)] = signature === undefined ? value : { version: value.version, signature };
620620
});
621621

622-
const result: ProgramBuildInfo = { fileInfos, options: state.compilerOptions };
622+
const result: ProgramBuildInfo = {
623+
fileInfos,
624+
options: convertToReusableCompilerOptions(state.compilerOptions, relativeToBuildInfo)
625+
};
623626
if (state.referencedMap) {
624627
const referencedMap: MapLike<string[]> = {};
625628
state.referencedMap.forEach((value, key) => {
@@ -663,6 +666,40 @@ namespace ts {
663666
}
664667
}
665668

669+
function convertToReusableCompilerOptions(options: CompilerOptions, relativeToBuildInfo: (path: string) => string) {
670+
const result: CompilerOptions = {};
671+
const optionsNameMap = getOptionNameMap().optionNameMap;
672+
673+
for (const name in options) {
674+
if (hasProperty(options, name)) {
675+
result[name] = convertToReusableCompilerOptionValue(
676+
optionsNameMap.get(name.toLowerCase()),
677+
options[name] as CompilerOptionsValue,
678+
relativeToBuildInfo
679+
);
680+
}
681+
}
682+
if (result.configFilePath) {
683+
result.configFilePath = relativeToBuildInfo(result.configFilePath);
684+
}
685+
return result;
686+
}
687+
688+
function convertToReusableCompilerOptionValue(option: CommandLineOption | undefined, value: CompilerOptionsValue, relativeToBuildInfo: (path: string) => string) {
689+
if (option) {
690+
if (option.type === "list") {
691+
const values = value as ReadonlyArray<string | number>;
692+
if (option.element.isFilePath && values.length) {
693+
return values.map(relativeToBuildInfo);
694+
}
695+
}
696+
else if (option.isFilePath) {
697+
return relativeToBuildInfo(value as string);
698+
}
699+
}
700+
return value;
701+
}
702+
666703
function convertToReusableDiagnostics(diagnostics: ReadonlyArray<Diagnostic>, relativeToBuildInfo: (path: string) => string): ReadonlyArray<ReusableDiagnostic> {
667704
Debug.assert(!!diagnostics.length);
668705
return diagnostics.map(diagnostic => {
@@ -991,7 +1028,7 @@ namespace ts {
9911028

9921029
const state: ReusableBuilderProgramState = {
9931030
fileInfos,
994-
compilerOptions: program.options,
1031+
compilerOptions: convertFromReusableCompilerOptions(program.options, toAbsolutePath),
9951032
referencedMap: getMapOfReferencedSet(program.referencedMap, toPath),
9961033
exportedModulesMap: getMapOfReferencedSet(program.exportedModulesMap, toPath),
9971034
semanticDiagnosticsPerFile: program.semanticDiagnosticsPerFile && arrayToMap(program.semanticDiagnosticsPerFile, value => isString(value) ? value : value[0], value => isString(value) ? emptyArray : value[1]),
@@ -1023,6 +1060,44 @@ namespace ts {
10231060
function toPath(path: string) {
10241061
return ts.toPath(path, buildInfoDirectory, getCanonicalFileName);
10251062
}
1063+
1064+
function toAbsolutePath(path: string) {
1065+
return getNormalizedAbsolutePath(path, buildInfoDirectory);
1066+
}
1067+
}
1068+
1069+
function convertFromReusableCompilerOptions(options: CompilerOptions, toAbsolutePath: (path: string) => string) {
1070+
const result: CompilerOptions = {};
1071+
const optionsNameMap = getOptionNameMap().optionNameMap;
1072+
1073+
for (const name in options) {
1074+
if (hasProperty(options, name)) {
1075+
result[name] = convertFromReusableCompilerOptionValue(
1076+
optionsNameMap.get(name.toLowerCase()),
1077+
options[name] as CompilerOptionsValue,
1078+
toAbsolutePath
1079+
);
1080+
}
1081+
}
1082+
if (result.configFilePath) {
1083+
result.configFilePath = toAbsolutePath(result.configFilePath);
1084+
}
1085+
return result;
1086+
}
1087+
1088+
function convertFromReusableCompilerOptionValue(option: CommandLineOption | undefined, value: CompilerOptionsValue, toAbsolutePath: (path: string) => string) {
1089+
if (option) {
1090+
if (option.type === "list") {
1091+
const values = value as ReadonlyArray<string | number>;
1092+
if (option.element.isFilePath && values.length) {
1093+
return values.map(toAbsolutePath);
1094+
}
1095+
}
1096+
else if (option.isFilePath) {
1097+
return toAbsolutePath(value as string);
1098+
}
1099+
}
1100+
return value;
10261101
}
10271102

10281103
export function createRedirectedBuilderProgram(state: { program: Program | undefined; compilerOptions: CompilerOptions; }, configFileParsingDiagnostics: ReadonlyArray<Diagnostic>): BuilderProgram {

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,8 @@ namespace ts {
969969
return typeAcquisition;
970970
}
971971

972-
function getOptionNameMap(): OptionNameMap {
972+
/* @internal */
973+
export function getOptionNameMap(): OptionNameMap {
973974
return optionNameMapCache || (optionNameMapCache = createOptionNameMap(optionDeclarations));
974975
}
975976

src/testRunner/unittests/tscWatch/incremental.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ namespace ts.tscWatch {
174174
[file1Path]: getFileInfo(file1.content),
175175
[file2Path]: getFileInfo(file2.content)
176176
},
177-
options: { incremental: true, configFilePath: configFile.path },
177+
options: {
178+
incremental: true,
179+
configFilePath: "./tsconfig.json"
180+
},
178181
referencedMap: {},
179182
exportedModulesMap: {},
180183
semanticDiagnosticsPerFile: [libFilePath, file1Path, file2Path]
@@ -197,7 +200,10 @@ namespace ts.tscWatch {
197200
[file1Path]: getFileInfo(file1.content),
198201
[file2Path]: getFileInfo(modifiedFile2Content)
199202
},
200-
options: { incremental: true, configFilePath: configFile.path },
203+
options: {
204+
incremental: true,
205+
configFilePath: "./tsconfig.json"
206+
},
201207
referencedMap: {},
202208
exportedModulesMap: {},
203209
semanticDiagnosticsPerFile: [libFilePath, file1Path, file2Path]
@@ -249,7 +255,10 @@ namespace ts.tscWatch {
249255
[file1Path]: getFileInfo(file1.content),
250256
[file2Path]: file2FileInfo
251257
},
252-
options: { incremental: true, configFilePath: configFile.path },
258+
options: {
259+
incremental: true,
260+
configFilePath: "./tsconfig.json"
261+
},
253262
referencedMap: {},
254263
exportedModulesMap: {},
255264
semanticDiagnosticsPerFile: [
@@ -276,7 +285,10 @@ namespace ts.tscWatch {
276285
[file1Path]: getFileInfo(modifiedFile1Content),
277286
[file2Path]: file2FileInfo
278287
},
279-
options: { incremental: true, configFilePath: configFile.path },
288+
options: {
289+
incremental: true,
290+
configFilePath: "./tsconfig.json"
291+
},
280292
referencedMap: {},
281293
exportedModulesMap: {},
282294
semanticDiagnosticsPerFile: [
@@ -380,7 +392,11 @@ namespace ts.tscWatch {
380392
[file1Path]: getFileInfo(file1.content),
381393
[file2Path]: getFileInfo(file2.content)
382394
},
383-
options: { incremental: true, module: ModuleKind.AMD, configFilePath: configFile.path },
395+
options: {
396+
incremental: true,
397+
module: ModuleKind.AMD,
398+
configFilePath: "./tsconfig.json"
399+
},
384400
referencedMap: {},
385401
exportedModulesMap: {},
386402
semanticDiagnosticsPerFile: [libFilePath, file1Path, file2Path]
@@ -402,7 +418,11 @@ namespace ts.tscWatch {
402418
[file1Path]: getFileInfo(file1.content),
403419
[file2Path]: getFileInfo(modifiedFile2Content)
404420
},
405-
options: { incremental: true, module: ModuleKind.AMD, configFilePath: configFile.path },
421+
options: {
422+
incremental: true,
423+
module: ModuleKind.AMD,
424+
configFilePath: "./tsconfig.json"
425+
},
406426
referencedMap: {},
407427
exportedModulesMap: {},
408428
semanticDiagnosticsPerFile: [libFilePath, file1Path, file2Path]
@@ -454,7 +474,11 @@ namespace ts.tscWatch {
454474
[file1Path]: getFileInfo(file1.content),
455475
[file2Path]: file2FileInfo
456476
},
457-
options: { incremental: true, module: ModuleKind.AMD, configFilePath: configFile.path },
477+
options: {
478+
incremental: true,
479+
module: ModuleKind.AMD,
480+
configFilePath: "./tsconfig.json"
481+
},
458482
referencedMap: {},
459483
exportedModulesMap: {},
460484
semanticDiagnosticsPerFile: [
@@ -480,7 +504,11 @@ namespace ts.tscWatch {
480504
[file1Path]: getFileInfo(modifiedFile1Content),
481505
[file2Path]: file2FileInfo
482506
},
483-
options: { incremental: true, module: ModuleKind.AMD, configFilePath: configFile.path },
507+
options: {
508+
incremental: true,
509+
module: ModuleKind.AMD,
510+
configFilePath: "./tsconfig.json"
511+
},
484512
referencedMap: {},
485513
exportedModulesMap: {},
486514
semanticDiagnosticsPerFile: [

tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/incremental-declaration-changes/inferred-type-from-transitive-module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ export declare const lazyBar: LazyAction<() => void, typeof import("./lazyIndex"
5858
"options": {
5959
"target": 1,
6060
"declaration": true,
61-
"outDir": "/src/obj",
61+
"outDir": "./",
6262
"incremental": true,
63-
"configFilePath": "/src/tsconfig.json"
63+
"configFilePath": "../tsconfig.json"
6464
},
6565
"referencedMap": {
6666
"../index.ts": [

tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/initial-Build/inferred-type-from-transitive-module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ exports.bar = bar_1.default;
9696
"options": {
9797
"target": 1,
9898
"declaration": true,
99-
"outDir": "/src/obj",
99+
"outDir": "./",
100100
"incremental": true,
101-
"configFilePath": "/src/tsconfig.json"
101+
"configFilePath": "../tsconfig.json"
102102
},
103103
"referencedMap": {
104104
"../index.ts": [

tests/baselines/reference/tsbuild/lateBoundSymbol/incremental-declaration-doesnt-change/interface-is-merged-and-contains-late-bound-member.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ type A = HKT<number>[typeof sym];
3939
}
4040
},
4141
"options": {
42-
"rootDir": "/src/src",
42+
"rootDir": "./src",
4343
"incremental": true,
44-
"configFilePath": "/src/tsconfig.json"
44+
"configFilePath": "./tsconfig.json"
4545
},
4646
"referencedMap": {
4747
"./src/main.ts": [

tests/baselines/reference/tsbuild/lateBoundSymbol/initial-Build/interface-is-merged-and-contains-late-bound-member.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ var x = 10;
3232
}
3333
},
3434
"options": {
35-
"rootDir": "/src/src",
35+
"rootDir": "./src",
3636
"incremental": true,
37-
"configFilePath": "/src/tsconfig.json"
37+
"configFilePath": "./tsconfig.json"
3838
},
3939
"referencedMap": {
4040
"./src/main.ts": [

tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/sample.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class someClass { }
193193
"declaration": true,
194194
"declarationMap": true,
195195
"skipDefaultLibCheck": true,
196-
"configFilePath": "/src/core/tsconfig.json"
196+
"configFilePath": "./tsconfig.json"
197197
},
198198
"referencedMap": {},
199199
"exportedModulesMap": {},
@@ -234,7 +234,7 @@ export class someClass { }
234234
"sourceMap": true,
235235
"forceConsistentCasingInFileNames": true,
236236
"skipDefaultLibCheck": true,
237-
"configFilePath": "/src/logic/tsconfig.json"
237+
"configFilePath": "./tsconfig.json"
238238
},
239239
"referencedMap": {
240240
"./index.ts": [
@@ -287,7 +287,7 @@ export class someClass { }
287287
"declaration": true,
288288
"forceConsistentCasingInFileNames": true,
289289
"skipDefaultLibCheck": true,
290-
"configFilePath": "/src/tests/tsconfig.json"
290+
"configFilePath": "./tsconfig.json"
291291
},
292292
"referencedMap": {
293293
"../logic/index.ts": [

tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-declaration-option-changes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export declare function multiply(a: number, b: number): number;
4141
"incremental": true,
4242
"declaration": true,
4343
"skipDefaultLibCheck": true,
44-
"configFilePath": "/src/core/tsconfig.json"
44+
"configFilePath": "./tsconfig.json"
4545
},
4646
"referencedMap": {},
4747
"exportedModulesMap": {},

tests/baselines/reference/tsbuild/sample1/incremental-declaration-changes/when-logic-config-changes-declaration-dir.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ export declare const m: typeof mod;
4444
"options": {
4545
"composite": true,
4646
"declaration": true,
47-
"declarationDir": "/src/logic/decls",
47+
"declarationDir": "./decls",
4848
"sourceMap": true,
4949
"forceConsistentCasingInFileNames": true,
5050
"skipDefaultLibCheck": true,
51-
"configFilePath": "/src/logic/tsconfig.json"
51+
"configFilePath": "./tsconfig.json"
5252
},
5353
"referencedMap": {
5454
"./index.ts": [
@@ -101,7 +101,7 @@ export declare const m: typeof mod;
101101
"declaration": true,
102102
"forceConsistentCasingInFileNames": true,
103103
"skipDefaultLibCheck": true,
104-
"configFilePath": "/src/tests/tsconfig.json"
104+
"configFilePath": "./tsconfig.json"
105105
},
106106
"referencedMap": {
107107
"../logic/index.ts": [

0 commit comments

Comments
 (0)