feat: add typings for watchpack

This commit is contained in:
e-cloud
2016-12-02 15:21:04 +08:00
parent 822f53a17b
commit f2731469da
6 changed files with 160 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
/// <reference types="node" />
/// <reference types="chokidar" />
import { EventEmitter } from 'events';
import fs = require('graceful-fs');
import Watcher = require('./Watcher');
import Watchpack = require('watchpack');
declare class DirectoryWatcher extends EventEmitter {
options: Watchpack.WatcherOptions;
directories: {
[path: string]: Watcher | true;
};
files: {
[path: string]: [number, number];
};
initialScan: boolean;
initialScanRemoved: string[];
nestedWatching: boolean;
path: string;
refs: number;
watcher: fs.FSWatcher;
watchers: {
[path: string]: Watcher[];
};
constructor(directoryPath: string, options: Watchpack.WatcherOptions);
setFileTime(filePath: string, mtime: number, initial: boolean, type?: string | boolean): void;
setDirectory(directoryPath: string, exist: boolean, initial: boolean): void;
createNestedWatcher(directoryPath: string): void;
setNestedWatching(flag: boolean): void;
watch(filePath: string, startTime: number): Watcher;
onFileAdded(filePath: string, stat: fs.Stats): void;
onDirectoryAdded(directoryPath: string): void;
onChange(filePath: string, stat: fs.Stats): void;
onFileUnlinked(filePath: string): void;
onDirectoryUnlinked(directoryPath: string): void;
onWatcherError(): void;
doInitialScan(): void;
getTimes(): {
[path: string]: number;
};
close(): void;
}
export = DirectoryWatcher;
+18
View File
@@ -0,0 +1,18 @@
/// <reference types="node" />
import { EventEmitter } from 'events';
import DirectoryWatcher = require('./DirectoryWatcher');
declare class Watcher extends EventEmitter {
data: number;
directoryWatcher: DirectoryWatcher;
path: string;
startTime: number;
constructor(directoryWatcher: DirectoryWatcher, filePath: string, startTime: number);
checkStartTime(mtime: number, initial: boolean): boolean;
close(): void;
}
export = Watcher;
+54
View File
@@ -0,0 +1,54 @@
// Type definitions for watchpack 1.1
// Project: https://github.com/webpack/watchpack
// Definitions by: e-cloud <https://github.com/e-cloud>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { EventEmitter } from 'events';
import Watcher = require('./Watcher');
declare class Watchpack extends EventEmitter {
aggregatedChanges: string[];
aggregateTimeout: NodeJS.Timer;
dirWatchers: Watcher[];
fileWatchers: Watcher[];
mtimes: {
[path: string]: number;
};
options: Watchpack.WatchOptions;
paused: boolean;
watcherOptions: Watchpack.WatcherOptions;
constructor(options: Watchpack.WatchOptions);
watch(files: string[], directories: string[], startTime: number): void;
close(): void;
pause(): void;
getTimes(): {
[path: string]: number;
};
_fileWatcher(file: string, watcher: Watcher): Watcher;
_dirWatcher(item: string, watcher: Watcher): Watcher;
_onChange(item: string, mtime: number, file?: string): void;
_onTimeout(): void;
}
declare namespace Watchpack {
interface WatcherOptions {
ignored?: string[] | string | RegExp | ((path: string) => boolean);
poll?: boolean | number;
}
interface WatchOptions extends WatcherOptions {
aggregateTimeout?: number;
}
}
export = Watchpack;
+21
View File
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"DirectoryWatcher.d.ts",
"Watcher.d.ts",
"watchpack-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }
+7
View File
@@ -0,0 +1,7 @@
import Watchpack = require('watchpack');
const watch = new Watchpack({});
watch.watch(['test.js'], ['lib/'], 1000);
let time: number
time = watch.getTimes()['test.js']