mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Use fs.watch for all directory watchers and some bug fixes
This commit is contained in:
@@ -410,30 +410,19 @@ namespace ts {
|
||||
watchDirectory: (path, callback, recursive) => {
|
||||
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
|
||||
// (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.
|
||||
|
||||
// In watchDirectory we only care about adding and removing files (when event name is
|
||||
// "rename"); changes made within files are handled by corresponding fileWatchers (when
|
||||
// event name is "change")
|
||||
|
||||
if (isNode4OrLater()) {
|
||||
return _fs.watch(
|
||||
path,
|
||||
{ persisten: true, recursive: !!recursive },
|
||||
(eventName: string, relativeFileName: string) => {
|
||||
if (eventName == "rename") {
|
||||
// when deleting a file, the passed baseFileName is null
|
||||
callback(relativeFileName == null ? null : normalizePath(ts.combinePaths(path, relativeFileName)))
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// If Node version is older than 4.0, the "recursive" parameter will be ignored
|
||||
var watchedFile = watchedFileSet.addFile(path, callback);
|
||||
return {
|
||||
close: () => watchedFileSet.removeFile(watchedFile)
|
||||
}
|
||||
return _fs.watch(
|
||||
path,
|
||||
{ persisten: true, recursive: !!recursive },
|
||||
(eventName: string, relativeFileName: string) => {
|
||||
// In watchDirectory we only care about adding and removing files (when event name is
|
||||
// "rename"); changes made within files are handled by corresponding fileWatchers (when
|
||||
// event name is "change")
|
||||
if (eventName == "rename") {
|
||||
// When deleting a file, the passed baseFileName is null
|
||||
callback(relativeFileName == null ? null : normalizePath(ts.combinePaths(path, relativeFileName)))
|
||||
};
|
||||
}
|
||||
);
|
||||
},
|
||||
resolvePath: function (path: string): string {
|
||||
return _path.resolve(path);
|
||||
|
||||
@@ -927,7 +927,7 @@ namespace ts.server {
|
||||
var rootedProject = rootFile.defaultProject;
|
||||
var referencingProjects = this.findReferencingProjects(rootFile, rootedProject);
|
||||
|
||||
if (rootFile.defaultProject.isConfiguredProject()) {
|
||||
if (rootFile.defaultProject && rootFile.defaultProject.isConfiguredProject()) {
|
||||
// If the root file has already been added into a configured project,
|
||||
// meaning the original inferred project is gone already.
|
||||
if (!rootedProject.isConfiguredProject()) {
|
||||
|
||||
@@ -779,6 +779,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
private closeClientFile(fileName: string) {
|
||||
if (!fileName) { return; }
|
||||
var file = ts.normalizePath(fileName);
|
||||
this.projectService.closeClientFile(file);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user