Merge branch 'master' of https://github.com/ShyykoSerhiy/TypeScript into ShyykoSerhiy-master
Conflicts: src/compiler/sys.ts src/compiler/tsc.ts
This commit is contained in:
commit
2b6d2a9f71
|
@ -8,7 +8,7 @@ namespace ts {
|
||||||
write(s: string): void;
|
write(s: string): void;
|
||||||
readFile(path: string, encoding?: string): string;
|
readFile(path: string, encoding?: string): string;
|
||||||
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
|
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
|
||||||
watchFile?(path: string, callback: (path: string) => void): FileWatcher;
|
watchFile?(path: string, callback: (path: string, removed: boolean) => void): FileWatcher;
|
||||||
resolvePath(path: string): string;
|
resolvePath(path: string): string;
|
||||||
fileExists(path: string): boolean;
|
fileExists(path: string): boolean;
|
||||||
directoryExists(path: string): boolean;
|
directoryExists(path: string): boolean;
|
||||||
|
@ -292,11 +292,16 @@ namespace ts {
|
||||||
};
|
};
|
||||||
|
|
||||||
function fileChanged(curr: any, prev: any) {
|
function fileChanged(curr: any, prev: any) {
|
||||||
|
// mtime.getTime() equals 0 if file was removed
|
||||||
|
if (curr.mtime.getTime() === 0) {
|
||||||
|
callback(fileName, /* removed */ true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (+curr.mtime <= +prev.mtime) {
|
if (+curr.mtime <= +prev.mtime) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(fileName);
|
callback(fileName, /* removed */ false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolvePath: function (path: string): string {
|
resolvePath: function (path: string): string {
|
||||||
|
|
|
@ -275,7 +275,7 @@ namespace ts {
|
||||||
let sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
|
let sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
|
||||||
if (sourceFile && compilerOptions.watch) {
|
if (sourceFile && compilerOptions.watch) {
|
||||||
// Attach a file watcher
|
// Attach a file watcher
|
||||||
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, () => sourceFileChanged(sourceFile));
|
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, (fileName, removed) => sourceFileChanged(sourceFile, removed));
|
||||||
}
|
}
|
||||||
return sourceFile;
|
return sourceFile;
|
||||||
}
|
}
|
||||||
|
@ -297,9 +297,15 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a source file changes, mark it as unwatched and start the recompilation timer
|
// If a source file changes, mark it as unwatched and start the recompilation timer
|
||||||
function sourceFileChanged(sourceFile: SourceFile) {
|
function sourceFileChanged(sourceFile: SourceFile, removed: boolean) {
|
||||||
sourceFile.fileWatcher.close();
|
sourceFile.fileWatcher.close();
|
||||||
sourceFile.fileWatcher = undefined;
|
sourceFile.fileWatcher = undefined;
|
||||||
|
if (removed) {
|
||||||
|
var index = rootFileNames.indexOf(sourceFile.fileName);
|
||||||
|
if (index >= 0) {
|
||||||
|
rootFileNames.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
startTimer();
|
startTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace ts.server {
|
||||||
|
|
||||||
interface WatchedFile {
|
interface WatchedFile {
|
||||||
fileName: string;
|
fileName: string;
|
||||||
callback: (fileName: string) => void;
|
callback: (fileName: string, removed: boolean) => void;
|
||||||
mtime: Date;
|
mtime: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,11 +121,11 @@ namespace ts.server {
|
||||||
|
|
||||||
fs.stat(watchedFile.fileName,(err, stats) => {
|
fs.stat(watchedFile.fileName,(err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
watchedFile.callback(watchedFile.fileName);
|
watchedFile.callback(watchedFile.fileName, /* removed */ false);
|
||||||
}
|
}
|
||||||
else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
|
else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
|
||||||
watchedFile.mtime = WatchedFileSet.getModifiedTime(watchedFile.fileName);
|
watchedFile.mtime = WatchedFileSet.getModifiedTime(watchedFile.fileName);
|
||||||
watchedFile.callback(watchedFile.fileName);
|
watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ namespace ts.server {
|
||||||
}, this.interval);
|
}, this.interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
addFile(fileName: string, callback: (fileName: string) => void ): WatchedFile {
|
addFile(fileName: string, callback: (fileName: string, removed: boolean) => void ): WatchedFile {
|
||||||
var file: WatchedFile = {
|
var file: WatchedFile = {
|
||||||
fileName,
|
fileName,
|
||||||
callback,
|
callback,
|
||||||
|
|
Loading…
Reference in a new issue