fix: compensate for lazy-loaded circular deps (#23890)
This commit is contained in:
parent
83247c48c3
commit
ac81a39e09
3 changed files with 16 additions and 8 deletions
|
@ -38,7 +38,7 @@ index fabaea75686161f488a03349e07049a513b98fad..5a6b01dc12fb77d5f8c26a1153ead2a1
|
|||
|
||||
bool Exists(const char* id);
|
||||
diff --git a/tools/js2c.py b/tools/js2c.py
|
||||
index 9e9883129bed62c591d23f71d139514c5034ac8d..dd7a49c2a13e58be8af343bdded6d885c5598e03 100755
|
||||
index 9e9883129bed62c591d23f71d139514c5034ac8d..ad073bd7f023c8436985f177011a7d29829098b4 100755
|
||||
--- a/tools/js2c.py
|
||||
+++ b/tools/js2c.py
|
||||
@@ -56,13 +56,15 @@ namespace native_module {{
|
||||
|
@ -96,14 +96,14 @@ index 9e9883129bed62c591d23f71d139514c5034ac8d..dd7a49c2a13e58be8af343bdded6d885
|
|||
- 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', 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', definitions, initializers, lambda _: ReadFile(filename).replace("require('fs')", "require('original-fs')"))
|
||||
+ AddModule('lib/original-fs.js', 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, definitions, initializers, lambda _: ReadFile(filename).replace("require('fs')", "require('original-fs')"))
|
||||
+
|
||||
+ config_size = 0
|
||||
+ if not only_js:
|
||||
|
|
|
@ -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));
|
||||
|
|
BIN
spec/fixtures/test.asar/deleteme/a.asar
vendored
Normal file
BIN
spec/fixtures/test.asar/deleteme/a.asar
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue