Skip to content

Commit

Permalink
Migrate from NAN to N-API
Browse files Browse the repository at this point in the history
  • Loading branch information
melikhov-dev authored and abbr committed Nov 11, 2018
1 parent 537bb6f commit 0901c8e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
11 changes: 10 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{
"targets": [{
"target_name": "deasync",
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"xcode_settings": { "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"CLANG_CXX_LIBRARY": "libc++",
"MACOSX_DEPLOYMENT_TARGET": "10.7",
},
"msvs_settings": {
"VCCLCompilerTool": { "ExceptionHandling": 1 },
},
"sources": [
"src/deasync.cc"
],
"include_dirs": [
"<!(node -e \"require('nan')\")"
"<!@(node -p \"require('node-addon-api').include\")",
]
}]
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"install": "node ./build.js"
},
"dependencies": {
"bindings": "~1.2.1",
"nan": "^2.0.7"
"node-addon-api": "^1.6.0",
"bindings": "~1.2.1"
},
"repository": {
"type": "git",
Expand Down
19 changes: 11 additions & 8 deletions src/deasync.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#include <uv.h>
#include <v8.h>
#include <nan.h>
#include <napi.h>
#include <uv.h>

using namespace v8;
using namespace Napi;

NAN_METHOD(Run) {
Nan::HandleScope scope;
Napi::Value Run(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
uv_run(uv_default_loop(), UV_RUN_ONCE);
info.GetReturnValue().Set(Nan::Undefined());
return env.Undefined();
}

static NAN_MODULE_INIT(init) {
Nan::Set(target, Nan::New("run").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(Run)).ToLocalChecked());
static Napi::Object init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "run"), Napi::Function::New(env, Run));
return exports;
}

NODE_MODULE(deasync, init)
NODE_API_MODULE(deasync, init)

0 comments on commit 0901c8e

Please sign in to comment.