Skip to content

Commit

Permalink
fix build, publish
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasGollenstede committed Oct 13, 2017
1 parent 4ebb8ff commit a297fc3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand All @@ -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]);
Expand Down

0 comments on commit a297fc3

Please sign in to comment.