How would I write nodejs
addon which would support all versions (atleast all stable versions > 0.10.6) of nodejs
. For example, one version would have String::Utf8Value name(args[0]);
where as another would have node::Utf8Value name(args[0]);
. This is just an example but I have many scenarios where there will be different code for different versions of nodejs
.
As far as I know this could be achieved in following ways.
- Defining pre-processor to check which version and compile code accordingly.
if defined()
//Not sure what exactly have to checked
include <nameser.h>
else
include <arpa/nameser.h>
endif
If this is the best option(which I don't think) even if multiple places pre-processor as to be added and code looks ugly, how would I achieve this. Meaning how would I check which version of NodeJS inside C/CPP addon.
- Having separate file for each version and defining conditions inside
binding.gyp
to compile specific file based onnodejs
version. If this is the best option, which variable I can refer to check thenodejs
version. - Having tags while publishing npm package so that user can install for his specific
nodejs
version. Tag a published version. Although user has to check for thenodejs
, non technical person won't be executing this, so shouldn't be a problem. The only problem I am seeing with this approach is versioning. Example, If there is a fix which has to applied for multiple tags, then, for every tag publish I have to specify different version (Not sure though).
Any other way I can achieve this which I am not aware of, if any the above options is not the good option to go with ?