Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: separate error emit args from regular emit args #1397

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export type FSWInstanceOptions = BasicOpts & {
};

export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
export type EmitArgs = [Path | Error, Stats?];
export type EmitArgsWithName = [EventName, ...EmitArgs];
export type EmitArgs = [path: Path, stats?: Stats];
export type EmitErrorArgs = [error: Error, stats?: Stats];
export type EmitArgsWithName = [event: EventName, ...EmitArgs];
export type MatchFunction = (val: string, stats?: Stats) => boolean;
export interface MatcherObject {
path: string;
Expand Down Expand Up @@ -302,7 +303,7 @@ export interface FSWatcherKnownEventMap {
[EV.READY]: [];
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
[EV.ALL]: [EventName, ...EmitArgs];
[EV.ALL]: [event: EventName, ...EmitArgs];
}

export type FSWatcherEventMap = FSWatcherKnownEventMap & {
Expand Down Expand Up @@ -602,7 +603,7 @@ export class FSWatcher extends EventEmitter<FSWatcherEventMap> {
const opts = this.options;
if (isWindows) path = sysPath.normalize(path);
if (opts.cwd) path = sysPath.relative(opts.cwd, path);
const args: EmitArgs = [path];
const args: EmitArgs | EmitErrorArgs = [path];
if (stats != null) args.push(stats);

const awf = opts.awaitWriteFinish;
Expand Down Expand Up @@ -637,7 +638,7 @@ export class FSWatcher extends EventEmitter<FSWatcherEventMap> {
const awfEmit = (err?: Error, stats?: Stats) => {
if (err) {
event = EV.ERROR;
args[0] = err;
(args as unknown as EmitErrorArgs)[0] = err;
this.emitWithAll(event, args);
} else if (stats) {
// if stats doesn't exist the file must have been deleted
Expand Down
Loading