rclnodejs icon indicating copy to clipboard operation
rclnodejs copied to clipboard

Migrate project from NAN to Node-API for improved compatibility

Open SanjayUG opened this issue 9 months ago • 3 comments

Hello there, This pr is the contribution to issue #1036,

Here's a summary of the changes made to migrate the project from nan to Node-API: src/addon.cpp Replaced #include <nan.h> with #include <node_api.h>. Updated the IsRunningInElectronRenderer function to use Node-API functions instead of nan functions. Modified the InitModule function to use Node-API for module initialization.

src/shadow_node.hpp Replaced #include <nan.h> with #include <node_api.h>. Changed the class inheritance from Nan::ObjectWrap to Napi::ObjectWrap<ShadowNode>. Updated method signatures to use Napi::CallbackInfo instead of Nan::FunctionCallbackInfov8::Value. Replaced Nan::Persistentv8::Function with Napi::FunctionReference.

src/rcl_handle.cpp Replaced #include <nan.h> with #include <node_api.h>. Changed the class inheritance from Nan::ObjectWrap to Napi::ObjectWrap<RclHandle>. Updated method signatures to use Napi::CallbackInfo instead of Nan::FunctionCallbackInfov8::Value. Replaced Nan functions with their Node-API equivalents in the Init, New, SyncProperties, PropertiesGetter, Release, Dismiss, and NewInstance methods.

src/rcl_bindings.cpp Replaced #include <nan.h> with #include <node_api.h>. Updated the Init and CreateNode methods to use Node-API functions instead of Nan functions. src/rcl_action_bindings.cpp Updated the ActionCreateServer method to use Node-API instead of nan.

If any feedback feel free to mention.

SanjayUG avatar Mar 13 '25 14:03 SanjayUG

Just wondering if we could leverage AI agent to convert most of the code from NAPI to Node-API :smile:

minggangw avatar Mar 14 '25 09:03 minggangw

Just wondering if we could leverage AI agent to convert most of the code from NAPI to Node-API 😄

Glad for your reply, I believe using AI in efficient way will help in the problem solving faster.

SanjayUG avatar Mar 14 '25 13:03 SanjayUG

Can you just check it now,

I just modified the following things,

  • Header File: Included node_api.h in both files.
  • Initialization Function: Updated the initialization function to use Node-API conventions.
  • Module Registration: Used NAPI_MODULE macro for module registration.

i welcome you with some feedback to it.

SanjayUG avatar Mar 14 '25 13:03 SanjayUG