Improve Node.js compatibility

This commit is contained in:
Wilson Lin 2020-07-24 16:29:25 +10:00
parent afdc4998e7
commit c1e7c64cdd
2 changed files with 12 additions and 6 deletions

View File

@ -246,13 +246,16 @@ rollback:
return undefined; 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_value node_module_init(napi_env env, napi_value exports) {
napi_property_descriptor props[] = { define_method(env, exports, "createConfiguration", node_method_create_configuration);
{"createConfiguration", NULL, node_method_create_configuration, NULL, NULL, NULL, napi_default, NULL}, define_method(env, exports, "minify", node_method_minify);
{"minify", NULL, node_method_minify, NULL, NULL, NULL, napi_default, NULL}, define_method(env, exports, "minifyInPlace", node_method_minify_in_place);
{"minifyInPlace", NULL, node_method_minify_in_place, NULL, NULL, NULL, napi_default, NULL},
};
assert_ok(napi_define_properties(env, exports, 3, props));
return exports; return exports;
} }

View File

@ -23,6 +23,9 @@
"bugs": { "bugs": {
"url": "https://github.com/wilsonzlin/minify-html/issues" "url": "https://github.com/wilsonzlin/minify-html/issues"
}, },
"engines": {
"node": "^8.6.0"
},
"homepage": "https://github.com/wilsonzlin/minify-html#readme", "homepage": "https://github.com/wilsonzlin/minify-html#readme",
"devDependencies": { "devDependencies": {
"node-gyp": "^7.0.0" "node-gyp": "^7.0.0"