diff --git a/.gitignore b/.gitignore index 3e2e84b0..cacbcae0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,11 @@ build/ node_modules/ +Debug/ +Release/ +*.lock +*.log +npm-debug.log* + +.idea/ +.vscode/ +.DS_Store diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..10a51272 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: node_js +node_js: + - "8" + - "10" +# - "12" enable this when fix issue on Node.js 12 +cache: + npm +before_script: + - npx envinfo +script: + - npm install + - npm test diff --git a/6_object_wrap/nan/myobject.cc b/6_object_wrap/nan/myobject.cc index 1a478d99..e4ababcb 100644 --- a/6_object_wrap/nan/myobject.cc +++ b/6_object_wrap/nan/myobject.cc @@ -37,7 +37,9 @@ void MyObject::New(const Nan::FunctionCallbackInfo& info) { const int argc = 1; v8::Local argv[argc] = { info[0] }; v8::Local cons = Nan::New(constructor); - info.GetReturnValue().Set(cons->NewInstance(argc, argv)); + v8::Local context = info.GetIsolate()->GetCurrentContext(); + info.GetReturnValue().Set( + cons->NewInstance(context, argc, argv).ToLocalChecked()); } } @@ -61,5 +63,7 @@ void MyObject::Multiply(const Nan::FunctionCallbackInfo& info) { const int argc = 1; v8::Local argv[argc] = { Nan::New(obj->value_ * multiple) }; - info.GetReturnValue().Set(cons->NewInstance(argc, argv)); + v8::Local context = info.GetIsolate()->GetCurrentContext(); + info.GetReturnValue().Set( + cons->NewInstance(context, argc, argv).ToLocalChecked()); } diff --git a/6_object_wrap/nan/package.json b/6_object_wrap/nan/package.json index 210555ef..d485e9b4 100644 --- a/6_object_wrap/nan/package.json +++ b/6_object_wrap/nan/package.json @@ -6,7 +6,7 @@ "private": true, "gypfile": true, "dependencies": { - "bindings": "~1.2.1", - "nan": "^2.0.0" + "bindings": "~1.5.0", + "nan": "^2.14.0" } } diff --git a/7_factory_wrap/nan/myobject.cc b/7_factory_wrap/nan/myobject.cc index 749cfbf7..5d040f3b 100644 --- a/7_factory_wrap/nan/myobject.cc +++ b/7_factory_wrap/nan/myobject.cc @@ -37,7 +37,10 @@ v8::Local MyObject::NewInstance(v8::Local arg) { const unsigned argc = 1; v8::Local argv[argc] = { arg }; v8::Local cons = Nan::New(constructor); - v8::Local instance = cons->NewInstance(argc, argv); + v8::Local context = + v8::Isolate::GetCurrent()->GetCurrentContext(); + v8::Local instance = + cons->NewInstance(context, argc, argv).ToLocalChecked(); return scope.Escape(instance); } diff --git a/8_passing_wrapped/nan/myobject.cc b/8_passing_wrapped/nan/myobject.cc index 94e56853..52d16234 100644 --- a/8_passing_wrapped/nan/myobject.cc +++ b/8_passing_wrapped/nan/myobject.cc @@ -31,7 +31,10 @@ v8::Local MyObject::NewInstance(v8::Local arg) { const unsigned argc = 1; v8::Local argv[argc] = { arg }; v8::Local cons = Nan::New(constructor); - v8::Local instance = cons->NewInstance(argc, argv); + v8::Local context = + v8::Isolate::GetCurrent()->GetCurrentContext(); + v8::Local instance = + cons->NewInstance(context, argc, argv).ToLocalChecked(); return scope.Escape(instance); } diff --git a/README.md b/README.md index d7563c86..754f3b5a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ Node.js Addon Examples ========================================= +[![Build Status](https://travis-ci.org/nodejs/node-addon-examples.svg?branch=master)](https://travis-ci.org/nodejs/node-addon-examples) + **A repository of [Node.js Addons](https://nodejs.org/api/addons.html#addons_c_addons) examples.** Implementations of examples are named either after Node.js versions (`node_0.10`, diff --git a/async_work_thread_safe_function/node-api/package.json b/async_work_thread_safe_function/node-api/package.json index b4c4662c..4a02fb21 100644 --- a/async_work_thread_safe_function/node-api/package.json +++ b/async_work_thread_safe_function/node-api/package.json @@ -7,6 +7,9 @@ "dependencies": { "bindings": "~1.2.1" }, + "engines": { + "node": ">= 10.6.0" + }, "scripts": { "test": "node index.js" }, diff --git a/package.json b/package.json new file mode 100644 index 00000000..cdf1d737 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "node-addon-examples", + "version": "1.0.0", + "description": "Node.js Addon Examples", + "main": "test_all.js", + "scripts": { + "test": "node test_all.js" + }, + "dependencies": { + "chalk": "^2.4.2", + "semver": "^6.3.0" + } +} diff --git a/test_all.js b/test_all.js new file mode 100644 index 00000000..bf9506ca --- /dev/null +++ b/test_all.js @@ -0,0 +1,49 @@ +const fs = require('fs') +const path = require('path') +const { execSync } = require('child_process') +const chalk = require('chalk') +const semver = require('semver') + +const excludeFolder = ['node_modules'] + +function getAllTests() { + return fs + .readdirSync('./') + .filter(i => { + return ( + !i.startsWith('.') && + fs.statSync(i).isDirectory() && + !excludeFolder.includes(i) + ) + }) + .map(i => { + const p = path.join(__dirname, i) + const tests = fs + .readdirSync(p) + .filter(j => fs.statSync(path.join(p, j)).isDirectory()) + .map(j => path.join(p, j)) + return tests + }) +} + +getAllTests().map(tests => { + tests.map(i => { + console.log(chalk.green(`testing: ${i}`)) + const p = require(path.join(i, 'package.json')) + if (p.engines && p.engines.node) { + const currentNodeVersion = process.versions.node + const range = p.engines.node + const engineOk = semver.satisfies(currentNodeVersion, range) + if (!engineOk) { + console.warn( + chalk.yellow(`${i} require Node.js ${range}, current is ${currentNodeVersion}, skipping`) + ) + return + } + } + const stdout = execSync('npm install', { + cwd: i + }) + console.log(stdout.toString()) + }) +}) diff --git a/thread_safe_function_round_trip/node-api/package.json b/thread_safe_function_round_trip/node-api/package.json index 23f73e92..b00cf6e5 100644 --- a/thread_safe_function_round_trip/node-api/package.json +++ b/thread_safe_function_round_trip/node-api/package.json @@ -7,6 +7,9 @@ "dependencies": { "bindings": "~1.2.1" }, + "engines": { + "node": ">= 10.6.0" + }, "scripts": { "test": "node index.js" },