Skip to content

Commit

Permalink
Added FSWatcher and StatWatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed May 23, 2024
1 parent 16f55c3 commit 53e5680
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@types/node": "^20.12.5",
"@types/readable-stream": "^4.0.10",
"buffer": "^6.0.3",
"eventemitter3": "^5.0.1",
"minimatch": "^9.0.3",
"readable-stream": "^4.5.2",
"utilium": "^0.4.0"
Expand Down
57 changes: 57 additions & 0 deletions src/emulation/watchers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { EventEmitter } from 'eventemitter3';
import type { EventEmitter as NodeEventEmitter } from 'node:events';
import type * as fs from 'node:fs';
import { ErrnoError } from '../error.js';

class Watcher<TEvents extends Record<string, unknown[]> = Record<string, unknown[]>> extends EventEmitter<TEvents> implements NodeEventEmitter {
/* eslint-disable @typescript-eslint/no-explicit-any */
public off<T extends EventEmitter.EventNames<TEvents>>(event: T, fn?: ((...args: any[]) => void) | undefined, context?: any, once?: boolean | undefined): this {
return super.off<T>(event, fn as EventEmitter.EventListener<TEvents, T>, context, once);
}

public removeListener<T extends EventEmitter.EventNames<TEvents>>(event: T, fn?: ((...args: any[]) => void) | undefined, context?: any, once?: boolean | undefined): this {
return super.removeListener<T>(event, fn as EventEmitter.EventListener<TEvents, T>, context, once);
}
/* eslint-enable @typescript-eslint/no-explicit-any */

public setMaxListeners(): never {
throw ErrnoError.With('ENOTSUP');
}

public getMaxListeners(): never {
throw ErrnoError.With('ENOTSUP');
}

public prependListener(): never {
throw ErrnoError.With('ENOTSUP');
}

public prependOnceListener(): never {
throw ErrnoError.With('ENOTSUP');
}

public rawListeners(): never {
throw ErrnoError.With('ENOTSUP');
}

public ref(): this {
return this;
}

public unref(): this {
return this;
}
}

export class FSWatcher
extends Watcher<{
change: [eventType: string, filename: string | Buffer];
close: [];
error: [error: Error];
}>
implements fs.FSWatcher
{
public close(): void {}
}

export class StatWatcher extends Watcher implements fs.StatWatcher {}

0 comments on commit 53e5680

Please sign in to comment.