From 5dfa9e33172d994c2f2a98a00312134cbc703d6b Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 5 Feb 2024 09:51:04 +0100 Subject: [PATCH] fix: `original-fs` import replacement (#41209) fix: original-fs import replacement --- patches/node/build_add_gn_build_files.patch | 7 ++++--- spec/asar-spec.ts | 12 +++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/patches/node/build_add_gn_build_files.patch b/patches/node/build_add_gn_build_files.patch index 0b92e06f86c8..59a813f35469 100644 --- a/patches/node/build_add_gn_build_files.patch +++ b/patches/node/build_add_gn_build_files.patch @@ -2312,10 +2312,10 @@ index 0000000000000000000000000000000000000000..7848ddb1841b6d4f36e9376c73564eb4 + f.write('\n') diff --git a/tools/generate_original_fs.py b/tools/generate_original_fs.py new file mode 100644 -index 0000000000000000000000000000000000000000..98d569e6ba6d85a29a215a8f9ce3c1f6a9bd655e +index 0000000000000000000000000000000000000000..a6cdf33f2c0bcca4d7b4eacaa407f1ac5bdcb5cb --- /dev/null +++ b/tools/generate_original_fs.py -@@ -0,0 +1,18 @@ +@@ -0,0 +1,19 @@ +import os +import sys + @@ -2332,8 +2332,9 @@ index 0000000000000000000000000000000000000000..98d569e6ba6d85a29a215a8f9ce3c1f6 + original_f.write(contents) + + with open(os.path.join(out_dir, original_fs_file), 'w') as transformed_f: -+ transformed_contents = contents.replace('internal/fs/', 'internal/original-fs/') ++ transformed_contents = contents.replace('internal/fs/', 'internal/original-fs/').replace('require(\'fs', 'require(\'original-fs') + transformed_f.write(transformed_contents) ++ diff --git a/tools/install.py b/tools/install.py index 11616e1bcac5308020eb68fdb811bfb86cb14dd5..74b01f8352021f1105c080dbbf8bb29121a13501 100755 --- a/tools/install.py diff --git a/spec/asar-spec.ts b/spec/asar-spec.ts index 6caa556cdae2..48fea506f9fa 100644 --- a/spec/asar-spec.ts +++ b/spec/asar-spec.ts @@ -1528,7 +1528,7 @@ describe('asar package', function () { originalFs.createReadStream(path.join(asarDir, 'a.asar')); }); - itremote('can recursively delete a directory with an asar file in itremote', () => { + itremote('can recursively delete a directory with an asar file in itremote using rmdirSync', () => { const deleteDir = path.join(asarDir, 'deleteme'); fs.mkdirSync(deleteDir); @@ -1538,6 +1538,16 @@ describe('asar package', function () { expect(fs.existsSync(deleteDir)).to.be.false(); }); + itremote('can recursively delete a directory with an asar file in itremote using promises.rmdir', async () => { + const deleteDir = path.join(asarDir, 'deleteme'); + fs.mkdirSync(deleteDir); + + const originalFs = require('original-fs'); + await originalFs.promises.rmdir(deleteDir, { recursive: true }); + + expect(fs.existsSync(deleteDir)).to.be.false(); + }); + itremote('has the same APIs as fs', function () { expect(Object.keys(require('node:fs'))).to.deep.equal(Object.keys(require('original-fs'))); expect(Object.keys(require('node:fs').promises)).to.deep.equal(Object.keys(require('original-fs').promises));