From dbfe862dbd87e491728fdd83c82c26572c63af7b Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Thu, 14 Jan 2016 00:34:43 -0800 Subject: [PATCH] not casting relative filenames in 'tsc watch' to Path --- src/compiler/core.ts | 7 +++++++ src/compiler/sys.ts | 6 +++--- src/compiler/tsc.ts | 6 ++++-- src/server/editorServices.ts | 4 ++-- src/services/services.ts | 7 ------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index aba2e48e4a..639660a2a4 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -872,4 +872,11 @@ namespace ts { } return copiedList; } + + export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string { + return useCaseSensitivefileNames + ? ((fileName) => fileName) + : ((fileName) => fileName.toLowerCase()); + } + } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 073a662ce1..e6f908d250 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -11,7 +11,7 @@ namespace ts { write(s: string): void; readFile(path: string, encoding?: string): string; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; - watchFile?(path: string, callback: FileWatcherCallback): FileWatcher; + watchFile?(path: Path, callback: FileWatcherCallback): FileWatcher; watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; resolvePath(path: string): string; fileExists(path: string): boolean; @@ -500,13 +500,13 @@ namespace ts { }, readFile, writeFile, - watchFile: (fileName, callback) => { + watchFile: (filePath, callback) => { // Node 4.0 stablized the `fs.watch` function on Windows which avoids polling // and is more efficient than `fs.watchFile` (ref: https://github.com/nodejs/node/pull/2649 // and https://github.com/Microsoft/TypeScript/issues/4643), therefore // if the current node.js version is newer than 4, use `fs.watch` instead. const watchSet = isNode4OrLater() ? watchedFileSet : pollingWatchedFileSet; - const watchedFile = watchSet.addFile(fileName, callback); + const watchedFile = watchSet.addFile(filePath, callback); return { close: () => watchSet.removeFile(watchedFile) }; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index d064ec54c9..808ee6da80 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -334,7 +334,8 @@ namespace ts { return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } if (configFileName) { - configFileWatcher = sys.watchFile(configFileName, configFileChanged); + const configFilePath = toPath(configFileName, sys.getCurrentDirectory(), createGetCanonicalFileName(sys.useCaseSensitiveFileNames)); + configFileWatcher = sys.watchFile(configFilePath, configFileChanged); } if (sys.watchDirectory && configFileName) { const directory = ts.getDirectoryPath(configFileName); @@ -442,7 +443,8 @@ namespace ts { const sourceFile = hostGetSourceFile(fileName, languageVersion, onError); if (sourceFile && compilerOptions.watch) { // Attach a file watcher - sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, (fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed)); + const filePath = toPath(sourceFile.fileName, sys.getCurrentDirectory(), createGetCanonicalFileName(sys.useCaseSensitiveFileNames)); + sourceFile.fileWatcher = sys.watchFile(filePath, (fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed)); } return sourceFile; } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 5a1c85fc13..0442575ade 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1000,7 +1000,7 @@ namespace ts.server { info.setFormatOptions(this.getFormatCodeOptions()); this.filenameToScriptInfo[fileName] = info; if (!info.isOpen) { - info.fileWatcher = this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); }); + info.fileWatcher = this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); }); } } } @@ -1213,7 +1213,7 @@ namespace ts.server { } } project.finishGraph(); - project.projectFileWatcher = this.host.watchFile(configFilename, _ => this.watchedProjectConfigFileChanged(project)); + project.projectFileWatcher = this.host.watchFile(configFilename, _ => this.watchedProjectConfigFileChanged(project)); this.log("Add recursive watcher for: " + ts.getDirectoryPath(configFilename)); project.directoryWatcher = this.host.watchDirectory( ts.getDirectoryPath(configFilename), diff --git a/src/services/services.ts b/src/services/services.ts index 0ffd1138cb..0f3c18f7a8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2008,13 +2008,6 @@ namespace ts { return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents*/ true); } - export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string { - return useCaseSensitivefileNames - ? ((fileName) => fileName) - : ((fileName) => fileName.toLowerCase()); - } - - export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory = ""): DocumentRegistry { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings.