From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cheng Zhao <zcbenz@gmail.com>
Date: Thu, 11 Apr 2019 17:16:13 +0900
Subject: feat: add original-fs module


diff --git a/tools/js2c.py b/tools/js2c.py
index 68152c499ce610d759b5abd659340957efb864d6..3e6ad7d5e12888e26a2b4eaa2eff7e2421b630f7 100755
--- a/tools/js2c.py
+++ b/tools/js2c.py
@@ -283,6 +283,16 @@ def JS2C(source_files, target):
 
   for filename in source_files['.js']:
     AddModule(filename, consts, macros, definitions, initializers)
+    # Electron: Expose fs module without asar support.
+    if name == '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
+      # copies to depend on each other instead of on our asarified 'fs' code.
+      # See https://github.com/electron/electron/pull/16028 for more.
+      AddModule('original-fs', lines.replace("require('internal/fs/streams')", "require('original-fs/streams')"))
+    elif name == 'internal/fs/streams.js':
+      AddModule('original-fs/streams', lines.replace("require('fs')", "require('original-fs')"))
 
   config_def, config_size = handle_config_gypi(source_files['config.gypi'])
   definitions.append(config_def)
