Skip to content

Commit 02531af

Browse files
committed
Update the watchedFileSet to use Path instead of string for file names
1 parent d22626f commit 02531af

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/compiler/sys.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace ts {
2525
}
2626

2727
interface WatchedFile {
28-
fileName: string;
28+
filePath: Path;
2929
callback: FileWatcherCallback;
3030
mtime?: Date;
3131
}
@@ -244,13 +244,13 @@ namespace ts {
244244
return;
245245
}
246246

247-
_fs.stat(watchedFile.fileName, (err: any, stats: any) => {
247+
_fs.stat(watchedFile.filePath, (err: any, stats: any) => {
248248
if (err) {
249-
watchedFile.callback(watchedFile.fileName);
249+
watchedFile.callback(watchedFile.filePath);
250250
}
251251
else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
252-
watchedFile.mtime = getModifiedTime(watchedFile.fileName);
253-
watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0);
252+
watchedFile.mtime = getModifiedTime(watchedFile.filePath);
253+
watchedFile.callback(watchedFile.filePath, watchedFile.mtime.getTime() === 0);
254254
}
255255
});
256256
}
@@ -278,11 +278,11 @@ namespace ts {
278278
}, interval);
279279
}
280280

281-
function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile {
281+
function addFile(filePath: Path, callback: FileWatcherCallback): WatchedFile {
282282
const file: WatchedFile = {
283-
fileName,
283+
filePath,
284284
callback,
285-
mtime: getModifiedTime(fileName)
285+
mtime: getModifiedTime(filePath)
286286
};
287287

288288
watchedFiles.push(file);
@@ -309,7 +309,6 @@ namespace ts {
309309
const dirWatchers = createFileMap<DirectoryWatcher>();
310310
// One file can have multiple watchers
311311
const fileWatcherCallbacks = createFileMap<FileWatcherCallback[]>();
312-
const currentDirectory = process.cwd();
313312
return { addFile, removeFile };
314313

315314
function reduceDirWatcherRefCount(dirPath: Path) {
@@ -355,16 +354,15 @@ namespace ts {
355354
return undefined;
356355
}
357356

358-
function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile {
359-
const filePath = toPath(fileName, currentDirectory, getCanonicalPath);
357+
function addFile(filePath: Path, callback: FileWatcherCallback): WatchedFile {
360358
addFileWatcherCallback(filePath, callback);
361359
addDirWatcher(getDirectoryPath(filePath));
362360

363-
return { fileName, callback };
361+
return { filePath, callback };
364362
}
365363

366364
function removeFile(watchedFile: WatchedFile) {
367-
const filePath = toPath(watchedFile.fileName, currentDirectory, getCanonicalPath);
365+
const filePath = watchedFile.filePath;
368366
if (fileWatcherCallbacks.contains(filePath)) {
369367
const newCallbacks = copyListRemovingItem(watchedFile.callback, fileWatcherCallbacks.get(filePath));
370368
if (newCallbacks.length === 0) {
@@ -513,7 +511,7 @@ namespace ts {
513511
// and https://github.com/Microsoft/TypeScript/issues/4643), therefore
514512
// if the current node.js version is newer than 4, use `fs.watch` instead.
515513
const watchSet = isNode4OrLater() ? watchedFileSet : pollingWatchedFileSet;
516-
const watchedFile = watchSet.addFile(fileName, callback);
514+
const watchedFile = watchSet.addFile(<Path>fileName, callback);
517515
return {
518516
close: () => watchSet.removeFile(watchedFile)
519517
};

0 commit comments

Comments
 (0)