From 93fed60943fef354e0cefde58b72fa48eb8ff23e Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Wed, 13 Nov 2024 12:11:53 +0100 Subject: [PATCH] fix: missing `fs/promises` patches to resolve `Not found` error (#124) --- prelude/bootstrap.js | 8 ++++++-- prelude/diagnostic.js | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/prelude/bootstrap.js b/prelude/bootstrap.js index 2f85f902a..93ab1e794 100644 --- a/prelude/bootstrap.js +++ b/prelude/bootstrap.js @@ -1722,12 +1722,16 @@ function payloadFileSync(pointer) { fs.promises.stat = util.promisify(fs.stat); fs.promises.lstat = util.promisify(fs.lstat); - /* fs.promises.read = util.promisify(fs.read); fs.promises.realpath = util.promisify(fs.realpath); fs.promises.fstat = util.promisify(fs.fstat); + fs.promises.statfs = util.promisify(fs.fstat); fs.promises.access = util.promisify(fs.access); - */ + + // TODO: all promises methods that try to edit files in snapshot should throw + // TODO implement missing methods + // fs.promises.readlink ? + // fs.promises.opendir ? } // /////////////////////////////////////////////////////////////// diff --git a/prelude/diagnostic.js b/prelude/diagnostic.js index 64acac204..22201a589 100644 --- a/prelude/diagnostic.js +++ b/prelude/diagnostic.js @@ -80,7 +80,7 @@ function humanSize(bytes) { return totalSize; } function wrap(obj, name) { - const f = fs[name]; + const f = obj[name]; obj[name] = (...args) => { const args1 = Object.values(args); console.log( @@ -111,6 +111,7 @@ function humanSize(bytes) { wrap(fs, 'open'); wrap(fs, 'readSync'); wrap(fs, 'read'); + wrap(fs, 'readFile'); wrap(fs, 'writeSync'); wrap(fs, 'write'); wrap(fs, 'closeSync'); @@ -131,6 +132,18 @@ function humanSize(bytes) { wrap(fs, 'exists'); wrap(fs, 'accessSync'); wrap(fs, 'access'); + + wrap(fs.promises, 'open'); + wrap(fs.promises, 'read'); + wrap(fs.promises, 'readFile'); + wrap(fs.promises, 'write'); + wrap(fs.promises, 'readdir'); + wrap(fs.promises, 'realpath'); + wrap(fs.promises, 'stat'); + wrap(fs.promises, 'lstat'); + wrap(fs.promises, 'fstat'); + wrap(fs.promises, 'access'); + wrap(fs.promises, 'copyFile'); } } })();