fix: original-fs import replacement (#41209)

fix: original-fs import replacement
This commit is contained in:
Shelley Vohr 2024-02-05 09:51:04 +01:00 committed by GitHub
parent fb888a6989
commit 5dfa9e3317
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

View file

@ -2312,10 +2312,10 @@ index 0000000000000000000000000000000000000000..7848ddb1841b6d4f36e9376c73564eb4
+ f.write('\n') + f.write('\n')
diff --git a/tools/generate_original_fs.py b/tools/generate_original_fs.py diff --git a/tools/generate_original_fs.py b/tools/generate_original_fs.py
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..98d569e6ba6d85a29a215a8f9ce3c1f6a9bd655e index 0000000000000000000000000000000000000000..a6cdf33f2c0bcca4d7b4eacaa407f1ac5bdcb5cb
--- /dev/null --- /dev/null
+++ b/tools/generate_original_fs.py +++ b/tools/generate_original_fs.py
@@ -0,0 +1,18 @@ @@ -0,0 +1,19 @@
+import os +import os
+import sys +import sys
+ +
@ -2332,8 +2332,9 @@ index 0000000000000000000000000000000000000000..98d569e6ba6d85a29a215a8f9ce3c1f6
+ original_f.write(contents) + original_f.write(contents)
+ +
+ with open(os.path.join(out_dir, original_fs_file), 'w') as transformed_f: + 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) + transformed_f.write(transformed_contents)
+
diff --git a/tools/install.py b/tools/install.py diff --git a/tools/install.py b/tools/install.py
index 11616e1bcac5308020eb68fdb811bfb86cb14dd5..74b01f8352021f1105c080dbbf8bb29121a13501 100755 index 11616e1bcac5308020eb68fdb811bfb86cb14dd5..74b01f8352021f1105c080dbbf8bb29121a13501 100755
--- a/tools/install.py --- a/tools/install.py

View file

@ -1528,7 +1528,7 @@ describe('asar package', function () {
originalFs.createReadStream(path.join(asarDir, 'a.asar')); 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'); const deleteDir = path.join(asarDir, 'deleteme');
fs.mkdirSync(deleteDir); fs.mkdirSync(deleteDir);
@ -1538,6 +1538,16 @@ describe('asar package', function () {
expect(fs.existsSync(deleteDir)).to.be.false(); 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 () { 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'))).to.deep.equal(Object.keys(require('original-fs')));
expect(Object.keys(require('node:fs').promises)).to.deep.equal(Object.keys(require('original-fs').promises)); expect(Object.keys(require('node:fs').promises)).to.deep.equal(Object.keys(require('original-fs').promises));