aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-09-06 09:58:00 -0700
committerGravatar Ashcon Partovi <ashcon@partovi.net> 2023-09-06 09:58:00 -0700
commit5e074209c658687de0bfab209ae4990ab2208a81 (patch)
tree8e6d020231910bff6ade2ee310180c41b136a629
parent0c2675c8d306ee7f5da1fec37abad045da9b34f5 (diff)
downloadbun-5e074209c658687de0bfab209ae4990ab2208a81.tar.gz
bun-5e074209c658687de0bfab209ae4990ab2208a81.tar.zst
bun-5e074209c658687de0bfab209ae4990ab2208a81.zip
Add types for cp and cpSync
-rw-r--r--packages/bun-types/fs.d.ts90
-rw-r--r--packages/bun-types/fs/promises.d.ts16
2 files changed, 106 insertions, 0 deletions
diff --git a/packages/bun-types/fs.d.ts b/packages/bun-types/fs.d.ts
index 5fb552b7c..c2319e1c4 100644
--- a/packages/bun-types/fs.d.ts
+++ b/packages/bun-types/fs.d.ts
@@ -4067,6 +4067,96 @@ declare module "fs" {
filename: PathLike,
listener?: WatchListener<string>,
): FSWatcher;
+ interface CopyOptionsBase {
+ /**
+ * Dereference symlinks
+ * @default false
+ */
+ dereference?: boolean;
+ /**
+ * When `force` is `false`, and the destination
+ * exists, throw an error.
+ * @default false
+ */
+ errorOnExist?: boolean;
+ /**
+ * Overwrite existing file or directory. _The copy
+ * operation will ignore errors if you set this to false and the destination
+ * exists. Use the `errorOnExist` option to change this behavior.
+ * @default true
+ */
+ force?: boolean;
+ /**
+ * Modifiers for copy operation. See `mode` flag of {@link copyFileSync()}
+ */
+ mode?: number;
+ /**
+ * When `true` timestamps from `source` will
+ * be preserved.
+ * @default false
+ */
+ preserveTimestamps?: boolean;
+ /**
+ * Copy directories recursively.
+ * @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`,
+ * including subdirectories and files.
+ *
+ * When copying a directory to another directory, globs are not supported and
+ * behavior is similar to `cp dir1/ dir2/`.
+ *
+ * @param source source path to copy.
+ * @param destination destination path to copy to.
+ */
+ export function cp(
+ source: string | URL,
+ destination: string | URL,
+ callback: (error: ErrnoException | null) => void,
+ ): void;
+ export function cp(
+ source: string | URL,
+ destination: string | URL,
+ options: CopyOptions,
+ callback: (error: ErrnoException | null) => void,
+ ): void;
+ /**
+ * Synchronously copies the entire directory structure from `src` to `dest`,
+ * including subdirectories and files.
+ *
+ * When copying a directory to another directory, globs are not supported and
+ * behavior is similar to `cp dir1/ dir2/`.
+ *
+ * @param source source path to copy.
+ * @param destination destination path to copy to.
+ */
+ export function cpSync(
+ source: string | URL,
+ destination: string | URL,
+ options?: CopySyncOptions,
+ ): void;
}
declare module "node:fs" {
diff --git a/packages/bun-types/fs/promises.d.ts b/packages/bun-types/fs/promises.d.ts
index 953c59a42..21e8a2c09 100644
--- a/packages/bun-types/fs/promises.d.ts
+++ b/packages/bun-types/fs/promises.d.ts
@@ -780,6 +780,22 @@ declare module "fs/promises" {
):
| AsyncIterable<FileChangeInfo<string>>
| AsyncIterable<FileChangeInfo<Buffer>>;
+ /**
+ * Asynchronously copies the entire directory structure from `source` to `destination`,
+ * including subdirectories and files.
+ *
+ * When copying a directory to another directory, globs are not supported and
+ * behavior is similar to `cp dir1/ dir2/`.
+ *
+ * @param source source path to copy.
+ * @param destination destination path to copy to.
+ * @return Fulfills with `undefined` upon success.
+ */
+ function cp(
+ source: string | URL,
+ destination: string | URL,
+ options?: CopyOptions,
+ ): Promise<void>;
}
declare module "node:fs/promises" {