aboutsummaryrefslogtreecommitdiff
path: root/src/js/node/fs.js
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-09-27 18:40:45 +0800
committerGravatar GitHub <noreply@github.com> 2023-09-27 03:40:45 -0700
commita0081f9e29e72ae800373b536e03fe1d729c68ae (patch)
tree12b785e83f661d3c93d21db8e9b2204d00395348 /src/js/node/fs.js
parent4d2b442a33f2f0538c4655152d1798f40f84d03d (diff)
downloadbun-a0081f9e29e72ae800373b536e03fe1d729c68ae.tar.gz
bun-a0081f9e29e72ae800373b536e03fe1d729c68ae.tar.zst
bun-a0081f9e29e72ae800373b536e03fe1d729c68ae.zip
fix(node:fs): fix `fs.exists` callback parameters (#6097)
Close: #6073
Diffstat (limited to 'src/js/node/fs.js')
-rw-r--r--src/js/node/fs.js21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/js/node/fs.js b/src/js/node/fs.js
index 8340c7375..df500342e 100644
--- a/src/js/node/fs.js
+++ b/src/js/node/fs.js
@@ -126,14 +126,27 @@ var access = function access(...args) {
copyFile = function copyFile(...args) {
const callback = args[args.length - 1];
if (typeof callback !== "function") {
- // TODO: set code
- throw new TypeError("Callback must be a function");
+ const err = new TypeError("Callback must be a function");
+ err.code = "ERR_INVALID_ARG_TYPE";
+ throw err;
}
fs.copyFile(...args).then(result => callback(null, result), callback);
},
- exists = function exists(...args) {
- callbackify(fs.exists, args);
+ exists = function exists(path, callback) {
+ if (typeof callback !== "function") {
+ const err = new TypeError("Callback must be a function");
+ err.code = "ERR_INVALID_ARG_TYPE";
+ throw err;
+ }
+ try {
+ fs.exists.apply(fs, [path]).then(
+ existed => callback(existed),
+ _ => callback(false),
+ );
+ } catch (e) {
+ callback(false);
+ }
},
chown = function chown(...args) {
callbackify(fs.chown, args);