diff --git a/nodejs/binding.c b/nodejs/binding.c index 02d5231..5f7a624 100644 --- a/nodejs/binding.c +++ b/nodejs/binding.c @@ -246,13 +246,16 @@ rollback: return undefined; } +static inline void define_method(napi_env env, napi_value exports, char const* name, napi_callback cb) { + napi_value js_fn; + assert_ok(napi_create_function(env, name, NAPI_AUTO_LENGTH, cb, NULL, &js_fn)); + assert_ok(napi_set_named_property(env, exports, name, js_fn)); +} + napi_value node_module_init(napi_env env, napi_value exports) { - napi_property_descriptor props[] = { - {"createConfiguration", NULL, node_method_create_configuration, NULL, NULL, NULL, napi_default, NULL}, - {"minify", NULL, node_method_minify, NULL, NULL, NULL, napi_default, NULL}, - {"minifyInPlace", NULL, node_method_minify_in_place, NULL, NULL, NULL, napi_default, NULL}, - }; - assert_ok(napi_define_properties(env, exports, 3, props)); + define_method(env, exports, "createConfiguration", node_method_create_configuration); + define_method(env, exports, "minify", node_method_minify); + define_method(env, exports, "minifyInPlace", node_method_minify_in_place); return exports; } diff --git a/nodejs/package.json b/nodejs/package.json index 5f6b962..99de5b6 100644 --- a/nodejs/package.json +++ b/nodejs/package.json @@ -23,6 +23,9 @@ "bugs": { "url": "https://github.com/wilsonzlin/minify-html/issues" }, + "engines": { + "node": "^8.6.0" + }, "homepage": "https://github.com/wilsonzlin/minify-html#readme", "devDependencies": { "node-gyp": "^7.0.0"