Avoid re-evaluating internal modules
authorCheng Zhao <zcbenz@gmail.com>
Sun, 27 Mar 2016 10:13:15 +0000 (19:13 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 27 Mar 2016 10:16:26 +0000 (19:16 +0900)
lib/common/asar_init.js

index 49b5790..85bb828 100644 (file)
@@ -9,6 +9,12 @@
     // Make graceful-fs work with asar.
     var source = process.binding('natives');
     source['original-fs'] = source.fs;
-    return source['fs'] = "var src = '(function (exports, require, module, __filename, __dirname) { ' +\n          process.binding('natives')['original-fs'] +\n          ' });';\nvar vm = require('vm');\nvar fn = vm.runInThisContext(src, { filename: 'fs.js' });\nfn(exports, require, module);\nvar asar = require('ATOM_SHELL_ASAR');\nasar.wrapFsWithAsar(exports);";
+    return source['fs'] = `
+var nativeModule = new process.NativeModule('original-fs');
+nativeModule.cache();
+nativeModule.compile();
+var asar = require('ATOM_SHELL_ASAR');
+asar.wrapFsWithAsar(nativeModule.exports);
+module.exports = nativeModule.exports`;
   };
 })();