fix: make fs proxy return undefined for keys which do not exist on the file system instance

This commit is contained in:
Ben Heidemann 2021-04-18 15:42:47 +01:00 committed by David Humphrey
parent fb100b165a
commit 11e05e131b
1 changed files with 12 additions and 0 deletions

View File

@ -26,8 +26,16 @@ var fsInstance = new FileSystem({ provider }, (err) => {
}
});
function proxyHasProp(target, prop) {
return prop in target;
}
const fsPromises = new Proxy(fsInstance.promises, {
get(target, prop) {
if (!proxyHasProp(target, prop)) {
return;
}
return async (...args) => {
await fsReady;
return await target[prop](...args);
@ -37,6 +45,10 @@ const fsPromises = new Proxy(fsInstance.promises, {
const fs = new Proxy(fsInstance, {
get(target, prop) {
if (!proxyHasProp(target, prop)) {
return;
}
if (prop === 'promises') {
return fsPromises;
}