Skip to content

Rewrite in N-API for Electron 30+ compatibility #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6f6f2a0
Node API upgrade to V8 >= 8
mauricioszabo Jul 27, 2022
8e66cfb
Fixing V8 version for callback API
mauricioszabo Jul 27, 2022
810f0a9
Fix V8 version again
mauricioszabo Jul 27, 2022
4c1c760
Fixed for node versions <17
mauricioszabo Aug 9, 2022
1741f64
Fix typos
savetheclocktower Sep 17, 2024
475b041
Migrate to napi
Nov 22, 2022
eee89ed
Avoid crash when trying to throw exceptions twice
Nov 23, 2022
9a44ec7
Adding a setter for `score`
mauricioszabo Jun 3, 2024
7e09707
Make `superstring` context-safe…
savetheclocktower Sep 19, 2024
ffb42b3
Update Catch2…
savetheclocktower Sep 19, 2024
e5e8480
Get the native tests running.
savetheclocktower Sep 19, 2024
d57d3b1
Ignore `.atom` and `.cache` (the latter is used by `clangd`)
savetheclocktower Sep 19, 2024
b935896
Disable JIT compilation of regexes when running the test suite
savetheclocktower Jun 8, 2025
47bd779
Experiment: bump `node-addon-api` to `7.1.1`
savetheclocktower Jun 8, 2025
db29198
Try a specific version of Node 18
savetheclocktower Jun 8, 2025
e68c50e
Set `NAPI_VERSION`
savetheclocktower Jun 8, 2025
a40ea95
Only test CP437 on Windows
savetheclocktower Jun 8, 2025
741f00f
Bump to latest `node-addon-api`
savetheclocktower Jun 8, 2025
194878f
Split out the context tests
savetheclocktower Jun 8, 2025
04d09f6
Sanity check: skip JIT compilation
savetheclocktower Jun 8, 2025
fe6b753
Use simpler `setuptools` installation
savetheclocktower Jun 8, 2025
430186d
Upgrade to PCRE 10.44
savetheclocktower Jun 8, 2025
c01a8bb
Fix binding.gyp
savetheclocktower Jun 8, 2025
a14e3f9
Remove PCRE 10.23
savetheclocktower Jun 8, 2025
30617a6
Revert to general Node 18 in CI
savetheclocktower Jun 8, 2025
cd6546e
Merge branch 'master' into latest-electron
savetheclocktower Jun 8, 2025
d2b1ac1
Whoops
savetheclocktower Jun 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ jobs:
- macos-latest
- windows-latest
node_version:
- 14
- 16
exclude:
- os: windows-latest
node_version: 14
- os: macos-latest
node_version: 14
- 18
- 20
include:
- os: windows-2019
node_version: 14
Expand Down Expand Up @@ -60,10 +56,7 @@ jobs:
# are incompatible with Python 3.12+, which no-longer ships 'distutils'
# out of the box. 'setuptools' package provides 'distutils'.
if: ${{ runner.os != 'Windows' }}
run: |
python3 -m venv CI_venv
source CI_venv/bin/activate
python3 -m pip install setuptools
run: python3 -m pip install --break-system-packages setuptools

- name: Install Python setuptools (Windows)
# This is needed for Python 3.12+, since many versions of node-gyp
Expand All @@ -78,8 +71,6 @@ jobs:
- name: Install dependencies (Unix-likes)
if: ${{ runner.os != 'Windows' }}
run: |
source CI_venv/bin/activate
npm config set python "$(which python3)"
npm install

- name: Install dependencies (Windows)
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ ext
emsdk-portable

vendor/libiconv
.vscode
.atom
.cache
/bin/
55 changes: 45 additions & 10 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"target_name": "superstring",
"dependencies": [
"superstring_core"
"superstring_core",
],
"sources": [
"src/bindings/bindings.cc",
Expand All @@ -18,8 +18,12 @@
"src/bindings/text-writer.cc",
],
"include_dirs": [
"src/core",
"<!(node -e \"require('nan')\")"
"src/core",
"<!(node -p \"require('node-addon-api').include_dir\")",
],
"defines": [
"NAPI_VERSION=<(napi_build_version)",
"NAPI_DISABLE_CPP_EXCEPTIONS",
],
"conditions": [
['OS=="mac"', {
Expand Down Expand Up @@ -101,7 +105,8 @@
],

"variables": {
"tests": 0
"tests": 0,
"node_version_major%": "<!(node -p \"process.versions.node.split('.')[0]\")"
},

"conditions": [
Expand Down Expand Up @@ -148,11 +153,9 @@
"targets": [{
"target_name": "tests",
"type": "executable",
"cflags_cc": ["-std=c++17"],
"cflags_cc!": ["-fno-exceptions"],
"cflags_cc!": ["-fno-exceptions", "-std=c++17"],
"defines": [
"CATCH_CONFIG_CPP11_NO_IS_ENUM",
"CATCH_CONFIG_CPP17_STRING_VIEW"
"CATCH_CONFIG_CPP11_NO_IS_ENUM"
],
'xcode_settings': {
'CLANG_CXX_LIBRARY': 'libc++',
Expand All @@ -176,25 +179,57 @@
"superstring_core"
],
"conditions": [
['node_version_major>=18', {
"defines+": ["CATCH_CONFIG_CPP17_STRING_VIEW"]
}],
['OS=="mac"', {
'dependencies+': [
'build_libiconv'
],
'cflags': [
'-mmacosx-version-min=10.8'
],
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
'MACOSX_DEPLOYMENT_TARGET': '10.12',
}
},
"postbuilds": [
{
'postbuild_name': 'Adjust vendored libiconv install name',
'action': [
'install_name_tool',
"-change",
"libiconv.2.dylib",
"@executable_path/../../ext/lib/libiconv.2.dylib",
"<(PRODUCT_DIR)/tests"
]

# NOTE: This version of the post-build action
# should be used if we find it necessary to avoid
# changing the `dylib`’s install name in an earlier
# step.
#
# 'action': [
# 'bash',
# '<(module_root_dir)/script/adjust-install-name.sh',
# '<(PRODUCT_DIR)'
# ]
}
]
}]
]
}]
}]
],

"target_defaults": {
"cflags_cc": ["-std=c++11"],
"cflags_cc": ["-std=c++17"],
"conditions": [
['OS=="mac"', {
'cflags+': ['-fvisibility=hidden'],
'cflags_cc+': ['-fvisibility=hidden'],
"xcode_settings": {
'MACOSX_DEPLOYMENT_TARGET': '10.8',
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build:browser": "script/build-browser-version.sh",
"build": "npm run build:node && npm run build:browser",
"test:native": "node ./script/test-native.js",
"test:node": "mocha test/js/*.js",
"test:node": "mocha test/js/*.test.js",
"test:threads": "node ./test/js/threads-outer.js",
"test:browser": "SUPERSTRING_USE_BROWSER_VERSION=1 mocha test/js/*.js",
"test": "npm run test:node && npm run test:browser",
"benchmark": "node benchmark/marker-index.benchmark.js",
Expand All @@ -23,18 +24,19 @@
"text",
"data-structure"
],
"engines": {
"node": ">=16"
},
"author": "Nathan Sobo <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/atom/superstring/issues"
},
"homepage": "https://github.com/atom/superstring",
"dependencies": {
"nan": "^2.14.2"
},
"devDependencies": {
"chai": "^2.0.0",
"mocha": "^2.3.4",
"node-addon-api": "^8.3.1",
"random-seed": "^0.2.0",
"standard": "^4.5.4",
"temp": "^0.8.3",
Expand Down
32 changes: 32 additions & 0 deletions src/bindings/addon-data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <napi.h>

#ifndef SUPERSTRING_ADDON_DATA_H_
#define SUPERSTRING_ADDON_DATA_H_

class AddonData final {
public:
explicit AddonData(Napi::Env _env) {}

// MarkerIndexWrapper
Napi::FunctionReference marker_index_wrapper_constructor;

// PatchWrapper
Napi::FunctionReference patch_wrapper_constructor;
Napi::FunctionReference change_wrapper_constructor;

// TextBufferSnapshotWrapper
Napi::FunctionReference text_buffer_snapshot_wrapper_constructor;

// TextBufferWrapper
Napi::FunctionReference text_buffer_wrapper_constructor;
Napi::FunctionReference regex_constructor;
Napi::FunctionReference subsequence_match_constructor;

// TextReader
Napi::FunctionReference text_reader_constructor;

// TextWriter
Napi::FunctionReference text_writer_constructor;
};

#endif // SUPERSTRING_ADDON_DATA_H_
27 changes: 14 additions & 13 deletions src/bindings/bindings.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#include "addon-data.h"
#include "marker-index-wrapper.h"
#include "nan.h"
#include "patch-wrapper.h"
#include "range-wrapper.h"
#include "point-wrapper.h"
#include "text-writer.h"
#include "text-reader.h"
#include "text-buffer-wrapper.h"
#include "text-buffer-snapshot-wrapper.h"

using namespace v8;
using namespace Napi;

void Init(Local<Object> exports) {
PointWrapper::init();
RangeWrapper::init();
PatchWrapper::init(exports);
MarkerIndexWrapper::init(exports);
TextBufferWrapper::init(exports);
TextWriter::init(exports);
TextReader::init(exports);
TextBufferSnapshotWrapper::init();
Object Init(Env env, Object exports) {
auto* data = new AddonData(env);
env.SetInstanceData(data);

PatchWrapper::init(env, exports);
MarkerIndexWrapper::init(env, exports);
TextBufferWrapper::init(env, exports);
TextWriter::init(env, exports);
TextReader::init(env, exports);
TextBufferSnapshotWrapper::init(env);
return exports;
}

NODE_MODULE(superstring, Init)
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
Loading
Loading