nodejs / node-gyp

Node.js native addon build tool
MIT License
9.88k stars 1.79k forks source link

Infer `nodedir` for headerfiles from execPath #3033

Open johnpyp opened 4 months ago

johnpyp commented 4 months ago

(Didn't follow for the format as this is a general capability request, for any version)


Following from https://github.com/nodejs/node-gyp/issues/812 and reading through some of the code in lib/configure.js and https://github.com/nodejs/node-gyp/blob/main/lib/find-node-directory.js, could the general strategy of inferring the nodedir through a traversal from process.execPath work to automatically find headers files even when using non-standard installation locations of node?

In other words, infer the npm_config_nodedir from the execPath, instead of requiring users set it explicitly:

export npm_config_nodedir="/my/node/install/path/18.x.x/"

node-gyp ...

My main hesitation is I don't know if this could accidentally end up with false-positive identification in a lot of the cases for some reason, or otherwise break some ecosystem usage. It could also be behind a flag or variable like --infer-nodedir / npm_config_infer_nodedir if that's a concern, though of course preferably it could be a default.