Browse Source

fix: fix an original-fs regression introduced in 4.0 betas (backport: 4-0-x) (#16038)

* fix: fix an original-fs regression introduced in 4.0 betas

* chore: remove cruft from earlier draft
trop[bot] 6 years ago
parent
commit
6ba053434c
1 changed files with 7 additions and 1 deletions
  1. 7 1
      lib/common/asar_init.js

+ 7 - 1
lib/common/asar_init.js

@@ -5,7 +5,13 @@
     const source = process.binding('natives')
 
     // Expose fs module without asar support.
-    source['original-fs'] = source.fs
+
+    // NB: 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
+    // copies to depend on each other instead of on our asarified 'fs' code.
+    source['original-fs'] = source.fs.replace("require('internal/fs/streams')", "require('original-fs/streams')")
+    source['original-fs/streams'] = source['internal/fs/streams'].replace("require('fs')", "require('original-fs')")
 
     // Make asar.js accessible via "require".
     source.ELECTRON_ASAR = asarSource