Detecting node-webkit during npm installation

I am working on a library for node.js, which is created mainly as a native module. Thus, when people try to include it in node-webkit projects, they must recompile it using nw-gypinstead node-gyp. I know that we can detect node -webkit specifically when our inline code works using something like this:

try { isNodeWebkit = (typeof require('nw.gui') !== "undefined"); } catch(e) { isNodeWebkit = false; }

However, I would like to find this inside our installation script (executed npm install). Alternatively, we look at our own package.json, but can there be a way to look at the root project package.json? So we could at least take a look at some property, maybe, engineor something else?

+4
source share
3 answers

I ended up writing a module for this: https://github.com/maxkorp/which-native-nodish (also supports atomic shell and renamed nw.js)

The bottom line is that you start with the parent directory in the module and continue to grow as long as you are a child of the node_modules folder, which is a child of the package folder. json At the root level, check the engine property in package.json for the atom-shell, node -webkit, or nwjs property. Operation is not guaranteed (the project of the farthest ancestor should indicate if it uses the node -ish mechanism in this way), but this is better than nothing and the only one from the box that I saw.

0
source

package.json, -

gui = require(nw.gui); 
myPackageJSONFile = gui.App.manifest; // this will get the package.json file

, .

0

:

isNodeWebkit = (typeof process == "object");
0
source

All Articles