Skip to content
Merged
Show file tree
Hide file tree
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
36 changes: 28 additions & 8 deletions types/node/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ declare module "fs" {
* Asynchronously close the directory's underlying resource handle.
* Subsequent reads will result in errors.
*
* A promise is returned that will be resolved after the resource has been
* A promise is returned that will be fulfilled after the resource has been
* closed.
* @since v12.12.0
*/
Expand All @@ -296,7 +296,7 @@ declare module "fs" {
/**
* Asynchronously read the next directory entry via [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) as an `fs.Dirent`.
*
* A promise is returned that will be resolved with an `fs.Dirent`, or `null`if there are no more directory entries to read.
* A promise is returned that will be fulfilled with an `fs.Dirent`, or `null`if there are no more directory entries to read.
*
* Directory entries returned by this function are in no particular order as
* provided by the operating system's underlying directory mechanisms.
Expand Down Expand Up @@ -354,31 +354,51 @@ declare module "fs" {
* @since v0.5.8
*/
close(): void;
/**
* When called, requests that the Node.js event loop _not_ exit so long as the `fs.FSWatcher` is active. Calling `watcher.ref()` multiple times will have
* no effect.
*
* By default, all `fs.FSWatcher` objects are "ref'ed", making it normally
* unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
* called previously.
* @since v14.3.0, v12.20.0
*/
ref(): this;
/**
* When called, the active `fs.FSWatcher` object will not require the Node.js
* event loop to remain active. If there is no other activity keeping the
* event loop running, the process may exit before the `fs.FSWatcher` object's
* callback is invoked. Calling `watcher.unref()` multiple times will have
* no effect.
* @since v14.3.0, v12.20.0
*/
unref(): this;
/**
* events.EventEmitter
* 1. change
* 2. error
* 2. close
* 3. error
*/
addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
addListener(event: "error", listener: (error: Error) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "error", listener: (error: Error) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
on(event: "error", listener: (error: Error) => void): this;
on(event: "close", listener: () => void): this;
on(event: "error", listener: (error: Error) => void): this;
once(event: string, listener: (...args: any[]) => void): this;
once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
once(event: "error", listener: (error: Error) => void): this;
once(event: "close", listener: () => void): this;
once(event: "error", listener: (error: Error) => void): this;
prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependListener(event: "error", listener: (error: Error) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "error", listener: (error: Error) => void): this;
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependOnceListener(event: "error", listener: (error: Error) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "error", listener: (error: Error) => void): this;
}
/**
* Instances of `fs.ReadStream` are created and returned using the {@link createReadStream} function.
Expand Down
4 changes: 3 additions & 1 deletion types/node/test/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,16 @@ async function testPromisify() {
console.log(event, filename);
});

fs.watch("/tmp/foo-", {
const fsWatcher = fs.watch("/tmp/foo-", {
recursive: true,
persistent: true,
encoding: "utf8",
signal: new AbortSignal(),
}, (event, filename) => {
console.log(event, filename);
});

fsWatcher.unref().ref().close();
}

{
Expand Down
36 changes: 28 additions & 8 deletions types/node/ts4.8/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ declare module "fs" {
* Asynchronously close the directory's underlying resource handle.
* Subsequent reads will result in errors.
*
* A promise is returned that will be resolved after the resource has been
* A promise is returned that will be fulfilled after the resource has been
* closed.
* @since v12.12.0
*/
Expand All @@ -296,7 +296,7 @@ declare module "fs" {
/**
* Asynchronously read the next directory entry via [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) as an `fs.Dirent`.
*
* A promise is returned that will be resolved with an `fs.Dirent`, or `null`if there are no more directory entries to read.
* A promise is returned that will be fulfilled with an `fs.Dirent`, or `null`if there are no more directory entries to read.
*
* Directory entries returned by this function are in no particular order as
* provided by the operating system's underlying directory mechanisms.
Expand Down Expand Up @@ -354,31 +354,51 @@ declare module "fs" {
* @since v0.5.8
*/
close(): void;
/**
* When called, requests that the Node.js event loop _not_ exit so long as the `fs.FSWatcher` is active. Calling `watcher.ref()` multiple times will have
* no effect.
*
* By default, all `fs.FSWatcher` objects are "ref'ed", making it normally
* unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
* called previously.
* @since v14.3.0, v12.20.0
*/
ref(): this;
/**
* When called, the active `fs.FSWatcher` object will not require the Node.js
* event loop to remain active. If there is no other activity keeping the
* event loop running, the process may exit before the `fs.FSWatcher` object's
* callback is invoked. Calling `watcher.unref()` multiple times will have
* no effect.
* @since v14.3.0, v12.20.0
*/
unref(): this;
/**
* events.EventEmitter
* 1. change
* 2. error
* 2. close
* 3. error
*/
addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
addListener(event: "error", listener: (error: Error) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "error", listener: (error: Error) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
on(event: "error", listener: (error: Error) => void): this;
on(event: "close", listener: () => void): this;
on(event: "error", listener: (error: Error) => void): this;
once(event: string, listener: (...args: any[]) => void): this;
once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
once(event: "error", listener: (error: Error) => void): this;
once(event: "close", listener: () => void): this;
once(event: "error", listener: (error: Error) => void): this;
prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependListener(event: "error", listener: (error: Error) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "error", listener: (error: Error) => void): this;
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependOnceListener(event: "error", listener: (error: Error) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "error", listener: (error: Error) => void): this;
}
/**
* Instances of `fs.ReadStream` are created and returned using the {@link createReadStream} function.
Expand Down
6 changes: 5 additions & 1 deletion types/node/ts4.8/test/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,16 @@ async function testPromisify() {
console.log(event, filename);
});

fs.watch("/tmp/foo-", {
const fsWatcher = fs.watch("/tmp/foo-", {
recursive: true,
persistent: true,
encoding: "utf8",
signal: new AbortSignal(),
}, (event, filename) => {
console.log(event, filename);
});

fsWatcher.unref().ref().close();
}

{
Expand Down Expand Up @@ -557,6 +559,7 @@ async function testPromisify() {
fs.createWriteStream("./index.d.ts", { encoding: "utf8" });
// @ts-expect-error
fs.createWriteStream("./index.d.ts", { encoding: "invalid encoding" });
fs.createWriteStream("./index.d.ts", { fs: { write: fs.write }, signal: new AbortSignal() });

fs.createReadStream("./index.d.ts");
fs.createReadStream("./index.d.ts", "utf8");
Expand All @@ -565,6 +568,7 @@ async function testPromisify() {
fs.createReadStream("./index.d.ts", { encoding: "utf8" });
// @ts-expect-error
fs.createReadStream("./index.d.ts", { encoding: "invalid encoding" });
fs.createReadStream("./index.d.ts", { fs: { read: fs.read }, signal: new AbortSignal() });
}

(async () => {
Expand Down
32 changes: 26 additions & 6 deletions types/node/v16/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,31 +289,51 @@ declare module "fs" {
* @since v0.5.8
*/
close(): void;
/**
* When called, requests that the Node.js event loop _not_ exit so long as the `fs.FSWatcher` is active. Calling `watcher.ref()` multiple times will have
* no effect.
*
* By default, all `fs.FSWatcher` objects are "ref'ed", making it normally
* unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
* called previously.
* @since v14.3.0, v12.20.0
*/
ref(): this;
/**
* When called, the active `fs.FSWatcher` object will not require the Node.js
* event loop to remain active. If there is no other activity keeping the
* event loop running, the process may exit before the `fs.FSWatcher` object's
* callback is invoked. Calling `watcher.unref()` multiple times will have
* no effect.
* @since v14.3.0, v12.20.0
*/
unref(): this;
/**
* events.EventEmitter
* 1. change
* 2. error
* 2. close
* 3. error
*/
addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
addListener(event: "error", listener: (error: Error) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "error", listener: (error: Error) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
on(event: "error", listener: (error: Error) => void): this;
on(event: "close", listener: () => void): this;
on(event: "error", listener: (error: Error) => void): this;
once(event: string, listener: (...args: any[]) => void): this;
once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
once(event: "error", listener: (error: Error) => void): this;
once(event: "close", listener: () => void): this;
once(event: "error", listener: (error: Error) => void): this;
prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependListener(event: "error", listener: (error: Error) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "error", listener: (error: Error) => void): this;
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependOnceListener(event: "error", listener: (error: Error) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "error", listener: (error: Error) => void): this;
}
/**
* Instances of `fs.ReadStream` are created and returned using the {@link createReadStream} function.
Expand Down
32 changes: 26 additions & 6 deletions types/node/v16/ts4.8/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,31 +289,51 @@ declare module "fs" {
* @since v0.5.8
*/
close(): void;
/**
* When called, requests that the Node.js event loop _not_ exit so long as the `fs.FSWatcher` is active. Calling `watcher.ref()` multiple times will have
* no effect.
*
* By default, all `fs.FSWatcher` objects are "ref'ed", making it normally
* unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
* called previously.
* @since v14.3.0, v12.20.0
*/
ref(): this;
/**
* When called, the active `fs.FSWatcher` object will not require the Node.js
* event loop to remain active. If there is no other activity keeping the
* event loop running, the process may exit before the `fs.FSWatcher` object's
* callback is invoked. Calling `watcher.unref()` multiple times will have
* no effect.
* @since v14.3.0, v12.20.0
*/
unref(): this;
/**
* events.EventEmitter
* 1. change
* 2. error
* 2. close
* 3. error
*/
addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
addListener(event: "error", listener: (error: Error) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "error", listener: (error: Error) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
on(event: "error", listener: (error: Error) => void): this;
on(event: "close", listener: () => void): this;
on(event: "error", listener: (error: Error) => void): this;
once(event: string, listener: (...args: any[]) => void): this;
once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
once(event: "error", listener: (error: Error) => void): this;
once(event: "close", listener: () => void): this;
once(event: "error", listener: (error: Error) => void): this;
prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependListener(event: "error", listener: (error: Error) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "error", listener: (error: Error) => void): this;
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependOnceListener(event: "error", listener: (error: Error) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "error", listener: (error: Error) => void): this;
}
/**
* Instances of `fs.ReadStream` are created and returned using the {@link createReadStream} function.
Expand Down
Loading