mapbox / node-pre-gyp

Node.js tool for easy binary deployment of C++ addons
BSD 3-Clause "New" or "Revised" License
1.11k stars 261 forks source link

Proposal/feature request: add API for adding custom versioning variables #286

Open murgatroid99 opened 7 years ago

murgatroid99 commented 7 years ago

I would like to be able to choose which binary package to download based on a criteria that is not currently represented in the versioning strings. In my particular case, I would like to be able to determine whether the version of OpenSSL that the Node executable is using is recent enough to support ALPN.

To accomplish this, I suggest the following API:

The node-pre-gyp would add an argument --plugin that takes the name of a JavaScript file. This file would be loaded as a module. That module's checkVersion function would be called, and a callback would be passed. The function should then call that callback with a plain JavaScript object mapping custom keys to detected values. For example, myplugin might call the callback with {tls: 'alpn'} or {tls: 'npn'}.

murgatroid99 commented 7 years ago

An example implementation of one of these plugins is here: https://gist.github.com/murgatroid99/a6f4b3f85c5a8d1acdbdceedc3263df7

springmeyer commented 7 years ago

You can use the --toolset option. It accepts an arbitrary string. You can then use the {toolset} variable in your versioning inside the package.json. By default toolset is an empty string.

So you could do node-pre-gyp build package publish --toolset=alpn. Then those binaries could be installed with npm install --toolset=alpn. More details of usage can be see in the commit that added this option: https://github.com/mapbox/node-pre-gyp/commit/c37a051a625c9b912f656e5ec80f7fbe368c3a57