Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

using electron-compile and a forked child node process, passing parameters to compiled js #304

Open
ddombrowsky opened this issue Jul 17, 2018 · 2 comments

Comments

@ddombrowsky
Copy link

I have a system that works perfectly with "compiled" javascript code, as done by electron-forge. It does exactly what I need.

Then I needed to fork a new process. This means I can't just point it to the javascript file that I want to run, because that's compiled and in the .cache directory. I can't just re-launch es6-shim.js, because that is hardcoded to launch the application in package.json. I've resorted to copying in the raw js files, which kinda defeats the purpose of pre-compiling

How can I accomplish this? I've launching the child process with script:

const electronCompile = require('electron-compile');
const c = electronCompile.init(__dirname, 'child.js');

but c is undefined and I can't use it as I would a require-d object. I can't figure out how to pass parameters into the newly minted process and call a js file that has been pre-compiled.

Any ideas?

@ddombrowsky
Copy link
Author

Seems to me like it's as easy as changing

  require.main.require(mainModule);

to

return   require.main.require(mainModule);

in init()

@ddombrowsky
Copy link
Author

Also, for the sake of the internet, you can work around this by putting a pointer into the main module from within child.js:

require.main.server = exports;

Then in the script which calls electronCompile.init(), just use require.main.server to pass in parameters to the compiled object.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant