@rushstack/heft
Version:
Build all your JavaScript projects the same way: A way that works.
147 lines • 4.9 kB
TypeScript
import * as fs from 'fs';
/**
* Options for `fs.readdir`
* @public
*/
export interface IReaddirOptions {
/**
* If true, readdir will return `fs.Dirent` objects instead of strings.
*/
withFileTypes: true;
}
/**
* Callback for `fs.stat` and `fs.lstat`
* @public
*/
export type StatCallback = (error: NodeJS.ErrnoException | null, stats: fs.Stats) => void;
/**
* Callback for `fs.readdir` when `withFileTypes` is not specified or false
* @public
*/
export type ReaddirStringCallback = (error: NodeJS.ErrnoException | null, files: string[]) => void;
/**
* Callback for `fs.readdir` when `withFileTypes` is true
* @public
*/
export type ReaddirDirentCallback = (error: NodeJS.ErrnoException | null, files: fs.Dirent[]) => void;
/**
* Information about the state of a watched file.
* @public
*/
export interface IWatchedFileState {
/**
* If the file has changed since the last invocation.
*/
changed: boolean;
}
/**
* Interface contract for heft plugins to use the `WatchFileSystemAdapter`
* @public
*/
export interface IWatchFileSystem {
/**
* Synchronous readdir. Watches the directory for changes.
*
* @see fs.readdirSync
*/
readdirSync(filePath: string): string[];
readdirSync(filePath: string, options: IReaddirOptions): fs.Dirent[];
/**
* Asynchronous readdir. Watches the directory for changes.
*
* @see fs.readdir
*/
readdir(filePath: string, callback: ReaddirStringCallback): void;
readdir(filePath: string, options: IReaddirOptions, callback: ReaddirDirentCallback): void;
/**
* Asynchronous lstat. Watches the file for changes, or if it does not exist, watches to see if it is created.
* @see fs.lstat
*/
lstat(filePath: string, callback: StatCallback): void;
/**
* Synchronous lstat. Watches the file for changes, or if it does not exist, watches to see if it is created.
* @see fs.lstatSync
*/
lstatSync(filePath: string): fs.Stats;
/**
* Asynchronous stat. Watches the file for changes, or if it does not exist, watches to see if it is created.
* @see fs.stat
*/
stat(filePath: string, callback: StatCallback): void;
/**
* Synchronous stat. Watches the file for changes, or if it does not exist, watches to see if it is created.
* @see fs.statSync
*/
statSync(filePath: string): fs.Stats;
/**
* Tells the adapter to track the specified file (or folder) as used.
* Returns an object containing data about the state of said file (or folder).
* Uses promise-based API.
*/
getStateAndTrackAsync(filePath: string): Promise<IWatchedFileState>;
/**
* Tells the adapter to track the specified file (or folder) as used.
* Returns an object containing data about the state of said file (or folder).
* Uses synchronous API.
*/
getStateAndTrack(filePath: string): IWatchedFileState;
}
/**
* Interface contract for `WatchFileSystemAdapter` for cross-version compatibility
*/
export interface IWatchFileSystemAdapter extends IWatchFileSystem {
/**
* Prepares for incoming glob requests. Any file changed after this method is called
* will trigger the watch callback in the next invocation.
* File mtimes will be recorded at this time for any files that do not receive explicit
* stat() or lstat() calls.
*/
setBaseline(): void;
/**
* Watches all files that have been accessed since `prepare()` was called.
* Clears the tracked file lists.
*/
watch(onChange: () => void): void;
}
/**
* A filesystem adapter for use with the "fast-glob" package. This adapter tracks file system accesses
* to initialize `watchpack`.
*/
export declare class WatchFileSystemAdapter implements IWatchFileSystemAdapter {
private _files;
private _contexts;
private _missing;
private _watcher;
private _lastFiles;
private _lastQueryTime;
private _times;
/** { @inheritdoc fs.readdirSync } */
readdirSync: IWatchFileSystemAdapter['readdirSync'];
/** { @inheritdoc fs.readdir } */
readdir: IWatchFileSystemAdapter['readdir'];
/** { @inheritdoc fs.lstat } */
lstat: IWatchFileSystemAdapter['lstat'];
/** { @inheritdoc fs.lstatSync } */
lstatSync: IWatchFileSystemAdapter['lstatSync'];
/** { @inheritdoc fs.stat } */
stat: IWatchFileSystemAdapter['stat'];
/** { @inheritdoc fs.statSync } */
statSync: IWatchFileSystemAdapter['statSync'];
/**
* @inheritdoc
*/
setBaseline(): void;
/**
* @inheritdoc
*/
watch(onChange: () => void): void;
/**
* @inheritdoc
*/
getStateAndTrackAsync(filePath: string): Promise<IWatchedFileState>;
/**
* @inheritdoc
*/
getStateAndTrack(filePath: string): IWatchedFileState;
}
//# sourceMappingURL=WatchFileSystemAdapter.d.ts.map