Skip to content

Commit 7741ec0

Browse files
author
zhengbli
committed
Use fs.watch for all directory watchers and some bug fixes
1 parent 9db53f2 commit 7741ec0

3 files changed

Lines changed: 15 additions & 25 deletions

File tree

src/compiler/sys.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -410,30 +410,19 @@ namespace ts {
410410
watchDirectory: (path, callback, recursive) => {
411411
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
412412
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
413-
// therefore if the current node.js version is newer than 4, use `fs.watch` instead.
414-
415-
// In watchDirectory we only care about adding and removing files (when event name is
416-
// "rename"); changes made within files are handled by corresponding fileWatchers (when
417-
// event name is "change")
418-
419-
if (isNode4OrLater()) {
420-
return _fs.watch(
421-
path,
422-
{ persisten: true, recursive: !!recursive },
423-
(eventName: string, relativeFileName: string) => {
424-
if (eventName == "rename") {
425-
// when deleting a file, the passed baseFileName is null
426-
callback(relativeFileName == null ? null : normalizePath(ts.combinePaths(path, relativeFileName)))
427-
};
428-
}
429-
);
430-
}
431-
432-
// If Node version is older than 4.0, the "recursive" parameter will be ignored
433-
var watchedFile = watchedFileSet.addFile(path, callback);
434-
return {
435-
close: () => watchedFileSet.removeFile(watchedFile)
436-
}
413+
return _fs.watch(
414+
path,
415+
{ persisten: true, recursive: !!recursive },
416+
(eventName: string, relativeFileName: string) => {
417+
// In watchDirectory we only care about adding and removing files (when event name is
418+
// "rename"); changes made within files are handled by corresponding fileWatchers (when
419+
// event name is "change")
420+
if (eventName == "rename") {
421+
// When deleting a file, the passed baseFileName is null
422+
callback(relativeFileName == null ? null : normalizePath(ts.combinePaths(path, relativeFileName)))
423+
};
424+
}
425+
);
437426
},
438427
resolvePath: function (path: string): string {
439428
return _path.resolve(path);

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ namespace ts.server {
927927
var rootedProject = rootFile.defaultProject;
928928
var referencingProjects = this.findReferencingProjects(rootFile, rootedProject);
929929

930-
if (rootFile.defaultProject.isConfiguredProject()) {
930+
if (rootFile.defaultProject && rootFile.defaultProject.isConfiguredProject()) {
931931
// If the root file has already been added into a configured project,
932932
// meaning the original inferred project is gone already.
933933
if (!rootedProject.isConfiguredProject()) {

src/server/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ namespace ts.server {
779779
}
780780

781781
private closeClientFile(fileName: string) {
782+
if (!fileName) { return; }
782783
var file = ts.normalizePath(fileName);
783784
this.projectService.closeClientFile(file);
784785
}

0 commit comments

Comments
 (0)