Skip to content

Commit

Permalink
Add Node-API support
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed Oct 29, 2024
1 parent dc7d380 commit da38617
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.25)

find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
find_package(cmake-napi REQUIRED PATHS node_modules/cmake-napi)
find_package(cmake-npm REQUIRED PATHS node_modules/cmake-npm)

project(bare_module_lexer C)

Expand All @@ -11,3 +13,19 @@ target_sources(
PRIVATE
binding.c
)

add_napi_module(bare_module_lexer_napi)

target_sources(
${bare_module_lexer_napi}
PRIVATE
binding.c
)

resolve_node_module(bare-compat-napi compat)

target_include_directories(
${bare_module_lexer_napi}
PRIVATE
"${compat}/include"
)
2 changes: 1 addition & 1 deletion binding.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require.addon()
module.exports = require('require-addon')('.', __filename)
2 changes: 1 addition & 1 deletion lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bare_module_lexer__lex (js_env_t *env, js_value_t *imports, js_value_t *exports,
uint32_t nl; // Names count

// Current character, unchecked
#define u(offset) (s[i + offset])
#define u(offset) ((uint8_t) s[i + offset])

// Current character, checked
#define c(offset) (i + offset < n ? u(offset) : -1)
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@
"url": "https://github.com/holepunchto/bare-module-lexer/issues"
},
"homepage": "https://github.com/holepunchto/bare-module-lexer#readme",
"dependencies": {
"require-addon": "^1.0.2"
},
"devDependencies": {
"bare-compat-napi": "^1.0.0",
"brittle": "^3.1.1",
"cmake-bare": "^1.1.7",
"cmake-napi": "^1.0.5",
"cmake-npm": "^1.0.2",
"standard": "^17.0.0"
}
}

0 comments on commit da38617

Please sign in to comment.