Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental adoption #871

Closed
kidneysolo opened this issue Dec 31, 2020 · 8 comments
Closed

Incremental adoption #871

kidneysolo opened this issue Dec 31, 2020 · 8 comments

Comments

@kidneysolo
Copy link
Contributor

Hello Everyone,

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.

@mhdawson
Copy link
Member

mhdawson commented 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
Copy link
Contributor Author

kidneysolo commented Jan 6, 2021

Thank you @mhdawson I see it is not at all straightforward. Seems like splitting the module would be much easier.

@NickNaso
Copy link
Member

NickNaso commented 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
Copy link
Member

mhdawson commented 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
Copy link
Member

NickNaso commented 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
Copy link
Member

mhdawson commented Jan 8, 2021

@NickNaso sounds good.

kidneysolo added a commit to kidneysolo/node-addon-api that referenced this issue Jan 18, 2021
@kidneysolo
Copy link
Contributor Author

@NickNaso @mhdawson I prepared a PR with the link in case you want to add it
#880

@NickNaso
Copy link
Member

@kidneysolo thanks for your contribution.

mhdawson pushed a commit that referenced this issue Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants