You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to incrementally adopt node-addon-api in a module which is written with node.h/nan ?
The Init function is exposed through the node.h NODE_MODULE(modname, regfunc) . This legacy module is quite large, cross-platform and spawning several threads (in different ways) so I am not very confident proceeding with a one step rewrite.
But if you mean shipping a module that uses both then its not setup for that as marking the modules a an N-API module removes the version safety checks that you need with a Nan/pure native module.
Activity
mhdawson commentedon Jan 4, 2021
If you mean being able to use both as part of incremental development, that might be possible by copying some of the wrapping/unwrapping that is done in: src/js_native_api_v8.cc, for example https://github.com/nodejs/node/blob/2da36112d177efc19201f1610dcf51647378131c/src/js_native_api_v8.cc#L144
But if you mean shipping a module that uses both then its not setup for that as marking the modules a an N-API module removes the version safety checks that you need with a Nan/pure native module.
kidneysolo commentedon Jan 6, 2021
Thank you @mhdawson I see it is not at all straightforward. Seems like splitting the module would be much easier.
NickNaso commentedon Jan 6, 2021
Hi @kidneysolo,
maybe you could use the approach proposed in this article https://developer.mongodb.com/article/realm-javascript-nan-to-n-api
I hope that this help.
mhdawson commentedon Jan 7, 2021
@NickNaso that article is a good resource I wonder if there is somewhere in our docs we could add a reference?
NickNaso commentedon Jan 8, 2021
Yes I can insert it on this section of the doc: https://github.com/nodejs/node-addon-api#more-resource-and-info-about-native-addons
mhdawson commentedon Jan 8, 2021
@NickNaso sounds good.
kidneysolo commentedon Jan 18, 2021
@NickNaso @mhdawson I prepared a PR with the link in case you want to add it
#880
NickNaso commentedon Jan 18, 2021
@kidneysolo thanks for your contribution.
docs: add NAN to N-API resource link (#880)