From 7a0883ec3641b1d11f85470ae6999ac6b7aba356 Mon Sep 17 00:00:00 2001 From: Bong Nguyen Date: Tue, 15 Nov 2022 11:49:42 +1100 Subject: [PATCH] fix: make the native addon to be context-aware Since Electron 14, all native addons must be context-aware. Therefore, in order to make node-tree-sitter run with Electron >= 14, it has to be context-aware. Ref: https://github.com/electron/electron/issues/18397 In this commit, NAN_MODULE_WORKER_ENABLED is used to make the native addon context-aware. It will allow context as the third param but will ignore it. This change doesn't mean that the addon will be safe to be initialised multiple times so can be run on worker threads though. Perhaps, someone with better understanding of the library need to implement AddEnvironmentCleanupHook to clean up resources. Ref: https://nodejs.org/api/addons.html#context-aware-addons --- binding.gyp | 4 +--- package.json | 2 +- src/binding.cc | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/binding.gyp b/binding.gyp index 8f93e64f..82684b0e 100644 --- a/binding.gyp +++ b/binding.gyp @@ -24,15 +24,13 @@ ['OS == "mac"', { 'xcode_settings': { 'MACOSX_DEPLOYMENT_TARGET': '10.9', + 'CLANG_CXX_LANGUAGE_STANDARD': 'c++17', }, }] ], "cflags": [ "-std=c++17", ], - 'xcode_settings': { - 'CLANG_CXX_LANGUAGE_STANDARD': 'c++17', - }, }, { "target_name": "tree_sitter", diff --git a/package.json b/package.json index e4232aff..f23646ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tree-sitter", - "version": "0.20.1", + "version": "0.20.2", "description": "Incremental parsers for node", "author": "Max Brunsfeld", "license": "MIT", diff --git a/src/binding.cc b/src/binding.cc index 8681223b..96ad14f2 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -22,6 +22,6 @@ void InitAll(Local exports) { TreeCursor::Init(exports); } -NODE_MODULE(tree_sitter_runtime_binding, InitAll) +NAN_MODULE_WORKER_ENABLED(tree_sitter_runtime_binding, InitAll) } // namespace node_tree_sitter