Skip to content

Commit 580e3f5

Browse files
authored
Merge pull request #34527 from microsoft/rootDir
Use getNormalizedAbsolutePath to combine basePath and config value for file names
2 parents 454a3a0 + b3df23c commit 580e3f5

File tree

7 files changed

+72
-9
lines changed

7 files changed

+72
-9
lines changed

src/compiler/commandLineParser.ts

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

25342534
function normalizeNonListOptionValue(option: CommandLineOption, basePath: string, value: any): CompilerOptionsValue {
25352535
if (option.isFilePath) {
2536-
value = normalizePath(combinePaths(basePath, value));
2536+
value = getNormalizedAbsolutePath(value, basePath);
25372537
if (value === "") {
25382538
value = ".";
25392539
}

src/testRunner/unittests/tsc/incremental.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,23 @@ namespace ts {
5454
}
5555
]
5656
});
57+
58+
verifyTscIncrementalEdits({
59+
scenario: "incremental",
60+
subScenario: "when passing rootDir is in the tsconfig",
61+
fs: () => loadProjectFromFiles({
62+
"/src/project/src/main.ts": "export const x = 10;",
63+
"/src/project/tsconfig.json": utils.dedent`
64+
{
65+
"compilerOptions": {
66+
"incremental": true,
67+
"outDir": "./built",
68+
"rootDir": "./"
69+
},
70+
}`,
71+
}),
72+
commandLineArgs: ["--p", "src/project"],
73+
incrementalScenarios: [noChangeRun]
74+
});
5775
});
5876
}

src/tsc/executeCommandLine.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,9 @@ namespace ts {
241241
}
242242

243243
const currentDirectory = sys.getCurrentDirectory();
244-
const getCanonicalFileName = createGetCanonicalFileName(sys.useCaseSensitiveFileNames);
245244
const commandLineOptions = convertToOptionsWithAbsolutePaths(
246245
commandLine.options,
247-
fileName => toPath(fileName, currentDirectory, getCanonicalFileName)
246+
fileName => getNormalizedAbsolutePath(fileName, currentDirectory)
248247
);
249248
if (configFileName) {
250249
const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, sys, reportDiagnostic)!; // TODO: GH#18217

tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"======== Module name './project/file2' was successfully resolved to 'c:/root/generated/src/project/file2.ts'. ========",
1313
"======== Resolving module 'module3' from 'c:/root/src/file1.ts'. ========",
1414
"Module resolution kind is not specified, using 'Classic'.",
15-
"'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'module3'.",
15+
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'module3'.",
1616
"'paths' option is specified, looking for a pattern to match module name 'module3'.",
1717
"Module name 'module3', matched pattern '*'.",
1818
"Trying substitution '*', candidate module location: 'module3'.",
@@ -35,7 +35,7 @@
3535
"======== Module name 'module3' was successfully resolved to 'c:/module3.d.ts'. ========",
3636
"======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========",
3737
"Module resolution kind is not specified, using 'Classic'.",
38-
"'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'module1'.",
38+
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'module1'.",
3939
"'paths' option is specified, looking for a pattern to match module name 'module1'.",
4040
"Module name 'module1', matched pattern '*'.",
4141
"Trying substitution '*', candidate module location: 'module1'.",
@@ -49,7 +49,7 @@
4949
"======== Module name 'module1' was successfully resolved to 'c:/shared/module1.d.ts'. ========",
5050
"======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========",
5151
"Module resolution kind is not specified, using 'Classic'.",
52-
"'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'templates/module2'.",
52+
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'templates/module2'.",
5353
"'paths' option is specified, looking for a pattern to match module name 'templates/module2'.",
5454
"Module name 'templates/module2', matched pattern 'templates/*'.",
5555
"Trying substitution 'generated/src/templates/*', candidate module location: 'generated/src/templates/module2'.",

tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"======== Module name './project/file2' was successfully resolved to 'c:/root/generated/src/project/file2.ts'. ========",
1616
"======== Resolving module 'module3' from 'c:/root/src/file1.ts'. ========",
1717
"Module resolution kind is not specified, using 'NodeJs'.",
18-
"'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'module3'.",
18+
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'module3'.",
1919
"'paths' option is specified, looking for a pattern to match module name 'module3'.",
2020
"Module name 'module3', matched pattern '*'.",
2121
"Trying substitution '*', candidate module location: 'module3'.",
@@ -40,7 +40,7 @@
4040
"======== Module name 'module3' was successfully resolved to 'c:/node_modules/module3.d.ts'. ========",
4141
"======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========",
4242
"Module resolution kind is not specified, using 'NodeJs'.",
43-
"'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'module1'.",
43+
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'module1'.",
4444
"'paths' option is specified, looking for a pattern to match module name 'module1'.",
4545
"Module name 'module1', matched pattern '*'.",
4646
"Trying substitution '*', candidate module location: 'module1'.",
@@ -61,7 +61,7 @@
6161
"======== Module name 'module1' was successfully resolved to 'c:/shared/module1/index.d.ts'. ========",
6262
"======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========",
6363
"Module resolution kind is not specified, using 'NodeJs'.",
64-
"'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'templates/module2'.",
64+
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'templates/module2'.",
6565
"'paths' option is specified, looking for a pattern to match module name 'templates/module2'.",
6666
"Module name 'templates/module2', matched pattern 'templates/*'.",
6767
"Trying substitution 'generated/src/templates/*', candidate module location: 'generated/src/templates/module2'.",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc --p src/project
3+
exitCode:: ExitStatus.Success
4+
5+
6+
//// [/src/project/built/src/main.js]
7+
"use strict";
8+
exports.__esModule = true;
9+
exports.x = 10;
10+
11+
12+
//// [/src/project/built/tsconfig.tsbuildinfo]
13+
{
14+
"program": {
15+
"fileInfos": {
16+
"../../../lib/lib.d.ts": {
17+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
18+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
19+
},
20+
"../src/main.ts": {
21+
"version": "-10726455937-export const x = 10;",
22+
"signature": "-6057683066-export declare const x = 10;\r\n"
23+
}
24+
},
25+
"options": {
26+
"incremental": true,
27+
"outDir": "./",
28+
"rootDir": "..",
29+
"project": "..",
30+
"configFilePath": "../tsconfig.json"
31+
},
32+
"referencedMap": {},
33+
"exportedModulesMap": {},
34+
"semanticDiagnosticsPerFile": [
35+
"../../../lib/lib.d.ts",
36+
"../src/main.ts"
37+
]
38+
},
39+
"version": "FakeTSVersion"
40+
}
41+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//// [/lib/no-change-runOutput.txt]
2+
/lib/tsc --p src/project
3+
exitCode:: ExitStatus.Success
4+
5+

0 commit comments

Comments
 (0)