Skip to content

Commit dbfe862

Browse files
committed
not casting relative filenames in 'tsc watch' to Path
1 parent 067573b commit dbfe862

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

src/compiler/core.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,4 +872,11 @@ namespace ts {
872872
}
873873
return copiedList;
874874
}
875+
876+
export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string {
877+
return useCaseSensitivefileNames
878+
? ((fileName) => fileName)
879+
: ((fileName) => fileName.toLowerCase());
880+
}
881+
875882
}

src/compiler/sys.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ts {
1111
write(s: string): void;
1212
readFile(path: string, encoding?: string): string;
1313
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
14-
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
14+
watchFile?(path: Path, callback: FileWatcherCallback): FileWatcher;
1515
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
1616
resolvePath(path: string): string;
1717
fileExists(path: string): boolean;
@@ -500,13 +500,13 @@ namespace ts {
500500
},
501501
readFile,
502502
writeFile,
503-
watchFile: (fileName, callback) => {
503+
watchFile: (filePath, callback) => {
504504
// Node 4.0 stablized the `fs.watch` function on Windows which avoids polling
505505
// and is more efficient than `fs.watchFile` (ref: https://github.com/nodejs/node/pull/2649
506506
// and https://github.com/Microsoft/TypeScript/issues/4643), therefore
507507
// if the current node.js version is newer than 4, use `fs.watch` instead.
508508
const watchSet = isNode4OrLater() ? watchedFileSet : pollingWatchedFileSet;
509-
const watchedFile = watchSet.addFile(<Path>fileName, callback);
509+
const watchedFile = watchSet.addFile(filePath, callback);
510510
return {
511511
close: () => watchSet.removeFile(watchedFile)
512512
};

src/compiler/tsc.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ namespace ts {
334334
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
335335
}
336336
if (configFileName) {
337-
configFileWatcher = sys.watchFile(configFileName, configFileChanged);
337+
const configFilePath = toPath(configFileName, sys.getCurrentDirectory(), createGetCanonicalFileName(sys.useCaseSensitiveFileNames));
338+
configFileWatcher = sys.watchFile(configFilePath, configFileChanged);
338339
}
339340
if (sys.watchDirectory && configFileName) {
340341
const directory = ts.getDirectoryPath(configFileName);
@@ -442,7 +443,8 @@ namespace ts {
442443
const sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
443444
if (sourceFile && compilerOptions.watch) {
444445
// Attach a file watcher
445-
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, (fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed));
446+
const filePath = toPath(sourceFile.fileName, sys.getCurrentDirectory(), createGetCanonicalFileName(sys.useCaseSensitiveFileNames));
447+
sourceFile.fileWatcher = sys.watchFile(filePath, (fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed));
446448
}
447449
return sourceFile;
448450
}

src/server/editorServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ namespace ts.server {
10001000
info.setFormatOptions(this.getFormatCodeOptions());
10011001
this.filenameToScriptInfo[fileName] = info;
10021002
if (!info.isOpen) {
1003-
info.fileWatcher = this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); });
1003+
info.fileWatcher = this.host.watchFile(<Path>fileName, _ => { this.watchedFileChanged(fileName); });
10041004
}
10051005
}
10061006
}
@@ -1213,7 +1213,7 @@ namespace ts.server {
12131213
}
12141214
}
12151215
project.finishGraph();
1216-
project.projectFileWatcher = this.host.watchFile(configFilename, _ => this.watchedProjectConfigFileChanged(project));
1216+
project.projectFileWatcher = this.host.watchFile(<Path>configFilename, _ => this.watchedProjectConfigFileChanged(project));
12171217
this.log("Add recursive watcher for: " + ts.getDirectoryPath(configFilename));
12181218
project.directoryWatcher = this.host.watchDirectory(
12191219
ts.getDirectoryPath(configFilename),

src/services/services.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,13 +2008,6 @@ namespace ts {
20082008
return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents*/ true);
20092009
}
20102010

2011-
export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string {
2012-
return useCaseSensitivefileNames
2013-
? ((fileName) => fileName)
2014-
: ((fileName) => fileName.toLowerCase());
2015-
}
2016-
2017-
20182011
export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory = ""): DocumentRegistry {
20192012
// Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have
20202013
// for those settings.

0 commit comments

Comments
 (0)