From f8d624c5838231fbda0e19dbbd74ffae6981be3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Isager=20Dalsgar=C3=B0?= Date: Tue, 16 Jul 2024 08:44:29 +0200 Subject: [PATCH] Add Node.js compatibility --- CMakeLists.txt | 23 +++++++++++++++++++++++ binding.js | 2 +- package.json | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7ef0f8..ef49b0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ project(sqlite3_native C) set(CMAKE_POSITION_INDEPENDENT_CODE ON) include(bare) +include(napi) if(NOT TARGET sqlite3) add_subdirectory(vendor/sqlite3 EXCLUDE_FROM_ALL) @@ -23,3 +24,25 @@ target_link_libraries( PRIVATE sqlite3 ) + +add_napi_module(sqlite3_native_node) + +bare_include_directories(compat NAPI) + +target_include_directories( + ${sqlite3_native_node} + PRIVATE + ${compat} +) + +target_sources( + ${sqlite3_native_node} + PRIVATE + binding.c +) + +target_link_libraries( + ${sqlite3_native_node} + PUBLIC + sqlite3 +) diff --git a/binding.js b/binding.js index cea4630..8a3aade 100644 --- a/binding.js +++ b/binding.js @@ -1 +1 @@ -module.exports = require.addon() +module.exports = require('load-addon')(__dirname) diff --git a/package.json b/package.json index 328c348..e010939 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "bare": ">=1.4.0" }, "dependencies": { + "load-addon": "^1.0.0", "ready-resource": "^1.0.3" }, "devDependencies": {