Skip to content

Commit

Permalink
feat: add node n-api bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jul 10, 2021
1 parent dee9aab commit f03e0cf
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
10 changes: 10 additions & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ configuration "executable" {
}

configuration "library" {
mainSourceFile "./src/native/lib.d"
excludedSourceFiles "./src/native/cli.d"
targetType "library"
targetName "minijson"
}

configuration "node" {
mainSourceFile "./src/node/node.d"
excludedSourceFiles "./src/native/cli.d" "./src/native/libc.d"
dependency "node_dlang" version="0.4.11"
targetType "dynamicLibrary"
targetName "minijson.node"
}

# -------- Build Options and configurations --------

// enables all disp except =nosharedaccess
Expand Down
1 change: 1 addition & 0 deletions dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"fileVersion": 1,
"versions": {
"automem": "0.6.6",
"node_dlang": "0.4.11",
"test_allocator": "0.3.3",
"unit-threaded": "2.0.0"
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"zip": "zip -9 -j ./dist/minijson-windows-x64.zip ./dist/win32-x64/minijson.exe && zip -9 -j ./dist/minijson-macos-x64.zip ./dist/darwin-x64/minijson && zip -9 -j ./dist/minijson-linux-x64.zip ./dist/linux-x64/minijson",
"prepublishOnly": "shx rm -rf ./dist/tsconfig.tsbuildinfo ./dist/build.*"
},
"dependencies": {
"node-addon-api": "^4.0.0"
},
"devDependencies": {
"@types/jasmine": "^3.7.7",
"@types/node": "16.0.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/native/lib.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const spaceOrBreakRegex = ctRegex!(`\s`);
Return:
the minified json string
*/
string minifyString(in string jsonString, in bool hasComment = false) @trusted
extern (C) string minifyString(string jsonString, bool hasComment = false) @trusted
{
auto in_string = false;
auto in_multiline_comment = false;
Expand Down Expand Up @@ -133,7 +133,7 @@ private bool notSlashAndNoSpaceOrBreak(in string matchFrontHit) @safe
files = the paths to the files.
hasComment = a boolean to support comments in json. Default: `false`.
*/
void minifyFiles(in string[] files, in bool hasComment = false)
extern (C) void minifyFiles(string[] files, bool hasComment = false)
{
import std.parallelism : parallel;
import std.file : readText, write;
Expand Down
4 changes: 1 addition & 3 deletions src/native/libc.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module minijson.libc;

import minijson.lib : minifyString;

extern (C):

/**
Minify the given JSON string using C ABI.
Expand All @@ -14,7 +12,7 @@ extern (C):
Return:
the minified json string
*/
auto minifyString(in char* jsonCString, in bool hasComment = false)
extern (C) auto c_minifyString(in char* jsonCString, in bool hasComment = false)
{
import std : fromStringz, toStringz;

Expand Down
7 changes: 7 additions & 0 deletions src/node/node.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module minijson.node;

import node_dlang;

import minijson.lib: minifyString;

mixin exportToJs! (minifyString);

0 comments on commit f03e0cf

Please sign in to comment.