Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compensate for lazy-loaded circular deps #23956

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ index fabaea75686161f488a03349e07049a513b98fad..5a6b01dc12fb77d5f8c26a1153ead2a1

bool Exists(const char* id);
diff --git a/tools/js2c.py b/tools/js2c.py
index 752344d68c3f63b4c5e491b33d4576ed48f8b74f..a6f0805048e3c3f4dd81ce6e90b684c48e52b67c 100755
index 752344d68c3f63b4c5e491b33d4576ed48f8b74f..dc3946e3ac579134dd26e5855a1db0a7ed44e405 100755
--- a/tools/js2c.py
+++ b/tools/js2c.py
@@ -187,13 +187,15 @@ namespace native_module {{
Expand Down Expand Up @@ -100,14 +100,14 @@ index 752344d68c3f63b4c5e491b33d4576ed48f8b74f..a6f0805048e3c3f4dd81ce6e90b684c4
- definitions.append(config_def)
+ # Electron: Expose fs module without asar support.
+ if filename == 'lib/fs.js':
+ # Node's 'fs' and 'internal/fs/streams' have a lazy-loaded circular
+ # dependency. So to expose the unmodified Node 'fs' functionality here,
+ # we have to copy both 'fs' *and* 'internal/fs/streams' and modify the
+ # Node's 'fs' and 'internal/fs/<filename> have lazy-loaded circular
+ # dependencies. So to expose the unmodified Node 'fs' functionality here,
+ # we have to copy both 'fs' *and* 'internal/fs/<filename>' files and modify the
+ # copies to depend on each other instead of on our asarified 'fs' code.
+ # See https://github.com/electron/electron/pull/16028 for more.
+ AddModule('lib/original-fs.js', consts, macros, definitions, initializers, lambda _: ReadFile(filename).replace("require('internal/fs/streams')", "require('internal/original-fs/streams')"))
+ elif filename == 'lib/internal/fs/streams.js':
+ AddModule('lib/internal/original-fs/streams.js', consts, macros, definitions, initializers, lambda _: ReadFile(filename).replace("require('fs')", "require('original-fs')"))
+ AddModule('lib/original-fs.js', consts, macros, definitions, initializers, lambda _: ReadFile(filename).replace("require('internal/fs/", "require('internal/original-fs/"))
+ elif filename.startswith('lib/internal/fs/'):
+ original_fs_filename = filename.replace('internal/fs/', 'internal/original-fs/')
+ AddModule(original_fs_filename, consts, macros, definitions, initializers, lambda _: ReadFile(filename).replace("require('fs')", "require('original-fs')"))
+
+ config_size = 0
+ if not only_js:
Expand Down
8 changes: 8 additions & 0 deletions spec/asar-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,14 @@ describe('asar package', function () {
originalFs.createReadStream(path.join(asarDir, 'a.asar'));
});

it('can recursively delete a directory with an asar file in it', () => {
const deleteDir = path.join(asarDir, 'deleteme');

originalFs.rmdirSync(deleteDir, { recursive: true });

expect(fs.existsSync(deleteDir)).to.be.false();
});

it('has the same APIs as fs', function () {
expect(Object.keys(require('fs'))).to.deep.equal(Object.keys(require('original-fs')));
expect(Object.keys(require('fs').promises)).to.deep.equal(Object.keys(require('original-fs').promises));
Expand Down
Binary file added spec/fixtures/test.asar/deleteme/a.asar
Binary file not shown.