From a297fc363aeb6f0aa96847d228fb4f918a29407f Mon Sep 17 00:00:00 2001 From: Niklas Gollenstede Date: Fri, 13 Oct 2017 02:17:19 +0200 Subject: [PATCH] fix build, publish --- connect.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/connect.js b/connect.js index a6ab8f2..89c322a 100644 --- a/connect.js +++ b/connect.js @@ -33,6 +33,10 @@ const Port = require('./node_modules/multiport/index.js'), port = new Port( Object.defineProperty(process, 'stdout', { value: stdout, }); Object.defineProperty(process, 'stderr', { value: stderr, }); + if (process.argv[1].startsWith(Path.resolve('/snapshot/'))) { // for some weird reason, in pkg packed apps, the console writes directly to fd 1 and 2 + Object.defineProperty(global, 'console', { value: new (require('console').Console)(stdout, stderr), }); + } + process.on('uncaughtException', async error => !(await port.request('error', error)) && process.exit(1)); process.on('unhandledRejection', async error => !(await port.request('reject', error)) && process.exit(1)); } @@ -75,7 +79,7 @@ const modules = { __proto__: null, }; let originalRequireResolve; { // extend re function makeLazyLoader(name, precond) { return () => { precond && precond(); - if (!bindingsModule) { require(bindingsPath); bindingsModule = require.cache[bindingsPath]; } + if (!bindingsModule) { module.require(bindingsPath); bindingsModule = require.cache[bindingsPath]; } const bindingsExports = bindingsModule.exports; const nodePath = Path.join(cwd, `res/${name}.node`); bindingsModule.exports = () => module.require(nodePath); @@ -92,7 +96,7 @@ const modules = { __proto__: null, }; let originalRequireResolve; { // extend re let exports, currentCwd; try { currentCwd = process.cwd(); process.chdir(cwd); const fullPath = originalRequireResolve(id, module); - exports = require(fullPath); + exports = module.require(fullPath); (function clear(module) { delete require.cache[module.filename] && module.children.forEach(clear); })(require.cache[fullPath]);