Skip to content

Incremental adoption #871

Closed
Closed

Description

@kidneysolo

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.

Activity

  1. mhdawson commented on Jan 4, 2021

    @mhdawson
    Member

    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.

  2. kidneysolo commented on Jan 6, 2021

    @kidneysolo
    ContributorAuthor

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

  3. NickNaso commented on Jan 6, 2021

    @NickNaso
    Member

    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.

  4. mhdawson commented on Jan 7, 2021

    @mhdawson
    Member

    @NickNaso that article is a good resource I wonder if there is somewhere in our docs we could add a reference?

  5. NickNaso commented on Jan 8, 2021

    @NickNaso
    Member
  6. mhdawson commented on Jan 8, 2021

    @mhdawson
    Member

    @NickNaso sounds good.

  7. kidneysolo commented on Jan 18, 2021

    @kidneysolo
    ContributorAuthor

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

  8. NickNaso commented on Jan 18, 2021

    @NickNaso
    Member

    @kidneysolo thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions