aboutsummaryrefslogtreecommitdiff
path: root/src/js/node/fs.promises.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/node/fs.promises.ts')
-rw-r--r--src/js/node/fs.promises.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/js/node/fs.promises.ts b/src/js/node/fs.promises.ts
index 406858f7f..dfc24cae7 100644
--- a/src/js/node/fs.promises.ts
+++ b/src/js/node/fs.promises.ts
@@ -89,11 +89,28 @@ function watch(
};
}
+let lazy_cp: any = null;
+// attempt to use the native code version if possible
+// and on MacOS, simple cases of recursive directory trees can be done in a single `clonefile()`
+// using filter and other options uses a lazily loaded js fallback ported from node.js
+function cp(src, dest, options) {
+ if (!options) return fs.cp(src, dest);
+ if (typeof options !== "object") {
+ throw new TypeError("options must be an object");
+ }
+ if (options.dereference || options.filter || options.preserveTimestamps || options.verbatimSymlinks) {
+ if (!lazy_cp) lazy_cp = require("../internal/fs/cp-sync");
+ return lazy_cp!(src, dest, options);
+ }
+ return fs.cp(src, dest, options.recursive, options.errorOnExist, options.force ?? true, options.mode);
+}
+
export default {
access: promisify(fs.accessSync),
appendFile: promisify(fs.appendFileSync),
close: promisify(fs.closeSync),
- copyFile: promisify(fs.copyFileSync),
+ copyFile: fs.copyFile.bind(fs),
+ cp,
exists: promisify(fs.existsSync),
chown: promisify(fs.chownSync),
chmod: promisify(fs.chmodSync),