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
28 changes: 21 additions & 7 deletions types/node/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3791,7 +3791,7 @@ declare module 'fs' {
export interface StatSyncOptions extends StatOptions {
throwIfNoEntry?: boolean | undefined;
}
export interface CopyOptions {
interface CopyOptionsBase {
/**
* Dereference symlinks
* @default false
Expand All @@ -3803,11 +3803,6 @@ declare module 'fs' {
* @default false
*/
errorOnExist?: boolean;
/**
* Function to filter copied files/directories. Return
* `true` to copy the item, `false` to ignore it.
*/
filter?(source: string, destination: string): boolean;
/**
* Overwrite existing file or directory. _The copy
* operation will ignore errors if you set this to false and the destination
Expand All @@ -3826,6 +3821,25 @@ declare module 'fs' {
* @default false
*/
recursive?: boolean;
/**
* When true, path resolution for symlinks will be skipped
* @default false
*/
verbatimSymlinks?: boolean;
}
export interface CopyOptions extends CopyOptionsBase {
/**
* Function to filter copied files/directories. Return
* `true` to copy the item, `false` to ignore it.
*/
filter?(source: string, destination: string): boolean | Promise<boolean>;
}
export interface CopySyncOptions extends CopyOptionsBase {
/**
* Function to filter copied files/directories. Return
* `true` to copy the item, `false` to ignore it.
*/
filter?(source: string, destination: string): boolean;
}
/**
* Asynchronously copies the entire directory structure from `src` to `dest`,
Expand All @@ -3851,7 +3865,7 @@ declare module 'fs' {
* @param src source path to copy.
* @param dest destination path to copy to.
*/
export function cpSync(source: string | URL, destination: string | URL, opts?: CopyOptions): void;
export function cpSync(source: string | URL, destination: string | URL, opts?: CopySyncOptions): void;
Comment thread
peterblazejewicz marked this conversation as resolved.
Resolved
}
declare module 'node:fs' {
export * from 'fs';
Expand Down
13 changes: 10 additions & 3 deletions types/node/test/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'node:fs';
import * as util from 'node:util';
import { URL } from 'node:url';
import assert = require('node:assert');
import { CopyOptions, cpSync, cp } from 'fs';
import { CopyOptions, CopySyncOptions, cpSync, cp } from 'fs';

{
fs.writeFile("thebible.txt",
Expand Down Expand Up @@ -695,17 +695,24 @@ const anyStats: fs.Stats | fs.BigIntStats = fs.statSync('.', { bigint: Math.rand
dereference: false,
errorOnExist: true,
filter(src, dst) {
return src !== 'node_modules' && dst !== 'something';
return Promise.resolve(src !== 'node_modules' && dst !== 'something');
},
force: true,
preserveTimestamps: true,
recursive: false,
verbatimSymlinks: false,
};
const optsSync: CopySyncOptions = {
...opts,
filter(src, dst) {
return src !== 'node_modules' && dst !== 'something';
}
};
cp('src', 'dest', (err: Error | null) => {});
cp('src', 'dest', opts, (err: Error | null) => {});
cp(new URL(`file://${__dirname}`), new URL(`file://${__dirname}`), (err: Error | null) => {});
cpSync('src', 'dest');
cpSync('src', 'dest', opts);
cpSync('src', 'dest', optsSync);
cpSync(new URL(`file://${__dirname}`), new URL(`file://${__dirname}`));
cpAsync('src', 'dest'); // $ExpectType Promise<void>
cpAsync('src', 'dest', opts); // $ExpectType Promise<void>
Expand Down
23 changes: 16 additions & 7 deletions types/node/v16/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3723,7 +3723,7 @@ declare module 'fs' {
export interface StatSyncOptions extends StatOptions {
throwIfNoEntry?: boolean | undefined;
}
export interface CopyOptions {
interface CopyOptionsBase {
/**
* Dereference symlinks
* @default false
Expand All @@ -3735,11 +3735,6 @@ declare module 'fs' {
* @default false
*/
errorOnExist?: boolean;
/**
* Function to filter copied files/directories. Return
* `true` to copy the item, `false` to ignore it.
*/
filter?(source: string, destination: string): boolean;
/**
* Overwrite existing file or directory. _The copy
* operation will ignore errors if you set this to false and the destination
Expand All @@ -3759,6 +3754,20 @@ declare module 'fs' {
*/
recursive?: boolean;
}
export interface CopyOptions extends CopyOptionsBase {
/**
* Function to filter copied files/directories. Return
* `true` to copy the item, `false` to ignore it.
*/
filter?(source: string, destination: string): boolean | Promise<boolean>;
}
export interface CopySyncOptions extends CopyOptionsBase {
/**
* Function to filter copied files/directories. Return
* `true` to copy the item, `false` to ignore it.
*/
filter?(source: string, destination: string): boolean;
}
/**
* Asynchronously copies the entire directory structure from `src` to `dest`,
* including subdirectories and files.
Expand All @@ -3783,7 +3792,7 @@ declare module 'fs' {
* @param src source path to copy.
* @param dest destination path to copy to.
*/
export function cpSync(source: string | URL, destination: string | URL, opts?: CopyOptions): void;
export function cpSync(source: string | URL, destination: string | URL, opts?: CopySyncOptions): void;
}
declare module 'node:fs' {
export * from 'fs';
Expand Down
11 changes: 9 additions & 2 deletions types/node/v16/test/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'node:fs';
import * as util from 'node:util';
import { URL } from 'node:url';
import assert = require('node:assert');
import { CopyOptions, cpSync, cp } from 'fs';
import { CopyOptions, CopySyncOptions, cpSync, cp } from 'fs';

{
fs.writeFile("thebible.txt",
Expand Down Expand Up @@ -686,10 +686,17 @@ const anyStats: fs.Stats | fs.BigIntStats = fs.statSync('.', { bigint: Math.rand
preserveTimestamps: true,
recursive: false,
};
const optsSync: CopySyncOptions = {
...opts,
filter(src, dst) {
return src !== 'node_modules' && dst !== 'something';
}
};

cp('src', 'dest', (err: Error | null) => {});
cp('src', 'dest', opts, (err: Error | null) => {});
cpSync('src', 'dest');
cpSync('src', 'dest', opts);
cpSync('src', 'dest', optsSync);
cpAsync('src', 'dest'); // $ExpectType Promise<void>
cpAsync('src', 'dest', opts); // $ExpectType Promise<void>
}
Expand Down