Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(endomoat): support native modules in policy gen
- Loading branch information
Showing
12 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# needed to build native module | ||
ignore-scripts=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import addon from 'napi' | ||
export const hello = addon.hello() |
5 changes: 5 additions & 0 deletions
5
packages/endomoat/test/fixture/native/node-modules/napi/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This is an example of a module using Node-API (a.k.a. N-API) to provide a native module. | ||
|
||
It was modified from the [nodejs/node-addon-examples](https://github.com/nodejs/node-addon-examples/tree/f8561c0233c3a75a99fab5ec20e729ae1fd0a1f6/src/1-getting-started/1_hello_world/napi) repo. | ||
|
||
The original uses the [bindings](https://npm.im/bindings) package, but it was removed here since that package uses dynamic requires. |
8 changes: 8 additions & 0 deletions
8
packages/endomoat/test/fixture/native/node-modules/napi/binding.gyp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "hello", | ||
"sources": [ "hello.c" ] | ||
} | ||
] | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/endomoat/test/fixture/native/node-modules/napi/hello.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <assert.h> | ||
#include <node_api.h> | ||
|
||
static napi_value Method(napi_env env, napi_callback_info info) { | ||
napi_status status; | ||
napi_value world; | ||
status = napi_create_string_utf8(env, "world", 5, &world); | ||
assert(status == napi_ok); | ||
return world; | ||
} | ||
|
||
#define DECLARE_NAPI_METHOD(name, func) \ | ||
{ name, 0, func, 0, 0, 0, napi_default, 0 } | ||
|
||
static napi_value Init(napi_env env, napi_value exports) { | ||
napi_status status; | ||
napi_property_descriptor desc = DECLARE_NAPI_METHOD("hello", Method); | ||
status = napi_define_properties(env, exports, 1, &desc); | ||
assert(status == napi_ok); | ||
return exports; | ||
} | ||
|
||
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) |
5 changes: 5 additions & 0 deletions
5
packages/endomoat/test/fixture/native/node-modules/napi/hello.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var addon = require('./build/Release/hello') | ||
|
||
console.log(addon.hello()) // 'world' | ||
|
||
module.exports = addon |
14 changes: 14 additions & 0 deletions
14
packages/endomoat/test/fixture/native/node-modules/napi/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "napi", | ||
"version": "0.0.0", | ||
"description": "Node.js Addons Example #1", | ||
"private": true, | ||
"main": "hello.js", | ||
"scripts": { | ||
"test": "node hello.js" | ||
}, | ||
"gypfile": true, | ||
"parsers": { | ||
"node": "bytes" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "no-deps", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"license": "ISC", | ||
"private": true, | ||
"main": "app.js", | ||
"dependencies": { | ||
"napi": "file://./node-modules/napi" | ||
} | ||
} |