Skip to content

Commit f03e0cf

Browse files
committed
feat: add node n-api bindings
1 parent dee9aab commit f03e0cf

7 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎dub.sdl‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ configuration "executable" {
1717
}
1818

1919
configuration "library" {
20+
mainSourceFile "./src/native/lib.d"
21+
excludedSourceFiles "./src/native/cli.d"
2022
targetType "library"
2123
targetName "minijson"
2224
}
2325

26+
configuration "node" {
27+
mainSourceFile "./src/node/node.d"
28+
excludedSourceFiles "./src/native/cli.d" "./src/native/libc.d"
29+
dependency "node_dlang" version="0.4.11"
30+
targetType "dynamicLibrary"
31+
targetName "minijson.node"
32+
}
33+
2434
# -------- Build Options and configurations --------
2535

2636
// enables all disp except =nosharedaccess

‎dub.selections.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"fileVersion": 1,
33
"versions": {
44
"automem": "0.6.6",
5+
"node_dlang": "0.4.11",
56
"test_allocator": "0.3.3",
67
"unit-threaded": "2.0.0"
78
}

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"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",
3333
"prepublishOnly": "shx rm -rf ./dist/tsconfig.tsbuildinfo ./dist/build.*"
3434
},
35+
"dependencies": {
36+
"node-addon-api": "^4.0.0"
37+
},
3538
"devDependencies": {
3639
"@types/jasmine": "^3.7.7",
3740
"@types/node": "16.0.0",

‎pnpm-lock.yaml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/native/lib.d‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const spaceOrBreakRegex = ctRegex!(`\s`);
1717
Return:
1818
the minified json string
1919
*/
20-
string minifyString(in string jsonString, in bool hasComment = false) @trusted
20+
extern (C) string minifyString(string jsonString, bool hasComment = false) @trusted
2121
{
2222
auto in_string = false;
2323
auto in_multiline_comment = false;
@@ -133,7 +133,7 @@ private bool notSlashAndNoSpaceOrBreak(in string matchFrontHit) @safe
133133
files = the paths to the files.
134134
hasComment = a boolean to support comments in json. Default: `false`.
135135
*/
136-
void minifyFiles(in string[] files, in bool hasComment = false)
136+
extern (C) void minifyFiles(string[] files, bool hasComment = false)
137137
{
138138
import std.parallelism : parallel;
139139
import std.file : readText, write;

‎src/native/libc.d‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module minijson.libc;
22

33
import minijson.lib : minifyString;
44

5-
extern (C):
6-
75
/**
86
Minify the given JSON string using C ABI.
97
@@ -14,7 +12,7 @@ extern (C):
1412
Return:
1513
the minified json string
1614
*/
17-
auto minifyString(in char* jsonCString, in bool hasComment = false)
15+
extern (C) auto c_minifyString(in char* jsonCString, in bool hasComment = false)
1816
{
1917
import std : fromStringz, toStringz;
2018

‎src/node/node.d‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module minijson.node;
2+
3+
import node_dlang;
4+
5+
import minijson.lib: minifyString;
6+
7+
mixin exportToJs! (minifyString);

0 commit comments

Comments
 (0)