Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Commit eb97f72

Browse files
committed
Fork, support Node 19 and use GitHub Actions
1 parent 16f7319 commit eb97f72

File tree

14 files changed

+167
-63
lines changed

14 files changed

+167
-63
lines changed

.appveyor.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
release:
11+
types:
12+
- released
13+
14+
jobs:
15+
16+
test:
17+
strategy:
18+
matrix:
19+
os:
20+
- ubuntu-latest
21+
- macos-latest
22+
- windows-latest
23+
node:
24+
- 14
25+
- 16
26+
- 18
27+
# These fail with a useless error message
28+
exclude:
29+
- os: windows-latest
30+
node: 16
31+
- os: windows-latest
32+
node: 18
33+
fail-fast: false
34+
name: Testing Node ${{ matrix.node }} on ${{ matrix.os }}
35+
runs-on: ${{ matrix.os }}
36+
steps:
37+
- uses: actions/checkout@v3
38+
with:
39+
submodules: true
40+
fetch-depth: 0
41+
- uses: actions/setup-node@v3
42+
with:
43+
node-version: ${{ matrix.node }}
44+
- name: Update node-gyp
45+
if: ${{ matrix.os == 'windows-latest' && matrix.node == '14' }}
46+
run: |
47+
$WhereNode = Get-Command node | Select-Object -ExpandProperty Definition
48+
$NodeDirPath = Split-Path $WhereNode -Parent
49+
$NodeModulesPath = $NodeDirPath + "\node_modules\npm\node_modules\npm-lifecycle"
50+
cd $NodeModulesPath
51+
npm install [email protected]
52+
- run: npm install
53+
- run: npm test
54+
55+
publish:
56+
if: ${{ github.event_name == 'release' }}
57+
name: Publishing to NPM
58+
runs-on: ubuntu-latest
59+
needs: test
60+
steps:
61+
- uses: actions/checkout@v3
62+
with:
63+
submodules: true
64+
fetch-depth: 0
65+
- uses: actions/setup-node@v3
66+
with:
67+
node-version: 18
68+
registry-url: https://registry.npmjs.org
69+
- run: npm publish --access public
70+
env:
71+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
72+
73+
prebuild:
74+
strategy:
75+
matrix:
76+
os:
77+
- ubuntu-latest
78+
- macos-latest
79+
- windows-latest
80+
fail-fast: false
81+
name: Prebuild on ${{ matrix.os }}
82+
runs-on: ${{ matrix.os }}
83+
needs: publish
84+
steps:
85+
- uses: actions/checkout@v3
86+
with:
87+
submodules: true
88+
fetch-depth: 0
89+
- uses: actions/setup-node@v3
90+
with:
91+
node-version: 18
92+
- run: npm install --ignore-scripts
93+
- run: npx --no-install prebuild -r node -t 10.0.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0 -u ${{ secrets.GH_TOKEN }}
94+
# Prebuilding for Electron 13+ on Windows fails with
95+
# win_delay_load_hook.cc
96+
# conversions.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class v8::Local<class v8::ArrayBuffer> __cdecl v8::ArrayBuffer::New(class v8::Isolate *,class std::shared_ptr<class v8::BackingStore>)" (__imp_?New@ArrayBuffer@v8@@SA?AV?$Local@VArrayBuffer@v8@@@2@PEAVIsolate@2@V?$shared_ptr@VBackingStore@v8@@@std@@@Z) referenced in function "void __cdecl node_tree_sitter::InitConversions(class v8::Local<class v8::Object>)" (?InitConversions@node_tree_sitter@@YAXV?$Local@VObject@v8@@@v8@@@Z) [D:\a\node-tree-sitter\node-tree-sitter\build\tree_sitter_runtime_binding.vcxproj]
97+
- if: matrix.os != 'windows-latest'
98+
run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0 -u ${{ secrets.GH_TOKEN }}
99+
# - if: matrix.os == 'windows-latest'
100+
# run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0 --arch ia32 -u ${{ secrets.GH_TOKEN }}
101+
- if: matrix.os == 'macos-latest'
102+
run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0 --arch arm64 -u ${{ secrets.GH_TOKEN }}

binding.gyp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
"vendor/superstring",
2121
"<!(node -e \"require('nan')\")",
2222
],
23-
'conditions': [
24-
['OS == "mac"', {
25-
'xcode_settings': {
26-
'MACOSX_DEPLOYMENT_TARGET': '10.9',
27-
},
28-
}]
29-
],
30-
"cflags": [
31-
"-std=c++17",
32-
],
33-
'xcode_settings': {
34-
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
23+
"cflags_cc": ["-std=c++17"],
24+
"xcode_settings": {
25+
"MACOSX_DEPLOYMENT_TARGET": "10.7",
26+
"OTHER_CPLUSPLUSFLAGS": ["-std=c++17", "-stdlib=libc++"],
27+
},
28+
"msvs_settings": {
29+
"VCCLCompilerTool": {
30+
"AdditionalOptions": [
31+
"/std:c++17",
32+
],
33+
"RuntimeLibrary": 0,
34+
},
3535
},
3636
},
3737
{
@@ -49,7 +49,10 @@
4949
]
5050
}
5151
],
52-
'variables': { 'runtime%': 'node' },
52+
'variables': {
53+
'runtime%': 'node',
54+
'openssl_fips': '',
55+
},
5356
'conditions': [
5457
['runtime=="electron"', { 'defines': ['NODE_RUNTIME_ELECTRON=1'] }],
5558
]

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
let binding;
22
try {
3-
binding = require('./build/Release/tree_sitter_runtime_binding');
3+
binding = require('./build/Release/tree_sitter_runtime_binding.node');
44
} catch (e) {
55
try {
6-
binding = require('./build/Debug/tree_sitter_runtime_binding');
6+
binding = require('./build/Debug/tree_sitter_runtime_binding.node');
77
} catch (_) {
88
throw e;
99
}

package.json

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "tree-sitter",
3-
"version": "0.20.1",
4-
"description": "Incremental parsers for node",
2+
"name": "@curlconverter/tree-sitter",
3+
"version": "0.0.8",
4+
"description": "fork of incremental parsers for node with Node 19 support",
55
"author": "Max Brunsfeld",
66
"license": "MIT",
77
"repository": {
88
"type": "git",
9-
"url": "http://github.com/tree-sitter/node-tree-sitter.git"
9+
"url": "http://github.com/curlconverter/node-tree-sitter.git"
1010
},
1111
"keywords": [
1212
"parser",
@@ -15,21 +15,27 @@
1515
"main": "index.js",
1616
"types": "tree-sitter.d.ts",
1717
"dependencies": {
18-
"nan": "^2.14.0",
19-
"prebuild-install": "^6.0.1"
18+
"nan": "^2.17.0",
19+
"prebuild-install": "^7.1.1"
2020
},
2121
"devDependencies": {
22-
"@types/node": "^14.14.31",
23-
"chai": "^4.3.3",
24-
"mocha": "^8.3.1",
25-
"prebuild": "^10.0.1",
26-
"superstring": "^2.4.2",
22+
"@types/node": "^18.14.6",
23+
"chai": "^4.3.7",
24+
"mocha": "^10.2.0",
25+
"node-gyp": "^9.3.1",
26+
"prebuild": "^11.0.4",
27+
"@curlconverter/superstring": "^0.0.2",
2728
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#master"
2829
},
30+
"overrides": {
31+
"prebuild": {
32+
"node-gyp": "$node-gyp"
33+
}
34+
},
2935
"scripts": {
3036
"install": "prebuild-install || node-gyp rebuild",
3137
"build": "node-gyp build",
32-
"prebuild": "prebuild -r electron -t 3.0.0 -t 4.0.0 -t 4.0.4 -t 5.0.0 --strip && prebuild -t 10.12.0 -t 12.13.0 --strip",
38+
"prebuild": "prebuild -r electron -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 -t 22.0.0 -t 23.0.0 --strip && prebuild -t 10.0.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0 --strip",
3339
"prebuild:upload": "prebuild --upload-all",
3440
"test": "mocha"
3541
}

src/conversions.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void InitConversions(Local<Object> exports) {
3434
v8::Local<v8::Object> bufferView;
3535
bufferView = node::Buffer::New(Isolate::GetCurrent(), point_transfer_buffer, 0, 2 * sizeof(uint32_t)).ToLocalChecked();
3636
auto js_point_transfer_buffer = node::Buffer::Data(bufferView);
37-
#elif V8_MAJOR_VERSION >= 8
37+
#elif V8_MAJOR_VERSION >= 9
3838
auto backing_store = ArrayBuffer::NewBackingStore(point_transfer_buffer, 2 * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
3939
auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
4040
#else

src/logger.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,24 @@ void Logger::Log(void *payload, TSLogType type, const char *message_str) {
4141

4242
Local<Value> argv[3] = { name, params, type_name };
4343
TryCatch try_catch(Isolate::GetCurrent());
44-
Nan::Call(fn, fn->CreationContext()->Global(), 3, argv);
44+
45+
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
46+
Nan::Call(fn, fn->GetCreationContext().ToLocalChecked()->Global(), 3, argv);
47+
#else
48+
Nan::Call(fn, fn->CreationContext()->Global(), 3, argv);
49+
#endif
4550
if (try_catch.HasCaught()) {
4651
Local<Value> log_argv[2] = {
4752
Nan::New("Error in debug callback:").ToLocalChecked(),
4853
try_catch.Exception()
4954
};
5055

51-
Local<Object> console = Local<Object>::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());
56+
57+
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
58+
Local<Object> console = Local<Object>::Cast(Nan::Get(fn->GetCreationContext().ToLocalChecked()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());
59+
#else
60+
Local<Object> console = Local<Object>::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());
61+
#endif
5262
Local<Function> error_fn = Local<Function>::Cast(Nan::Get(console, Nan::New("error").ToLocalChecked()).ToLocalChecked());
5363
Nan::Call(error_fn, console, 2, log_argv);
5464
}

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static inline void setup_transfer_buffer(uint32_t node_count) {
3535
v8::Local<v8::Object> bufferView;
3636
bufferView = node::Buffer::New(Isolate::GetCurrent(), transfer_buffer, 0, transfer_buffer_length * sizeof(uint32_t)).ToLocalChecked();
3737
auto js_point_transfer_buffer = node::Buffer::Data(bufferView);
38-
#elif V8_MAJOR_VERSION >= 8
38+
#elif V8_MAJOR_VERSION >= 9
3939
auto backing_store = ArrayBuffer::NewBackingStore(transfer_buffer, transfer_buffer_length * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
4040
auto js_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
4141
#else

src/parser.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ class CallbackInput {
6060
uint32_t utf16_unit = byte / 2;
6161
Local<Value> argv[2] = { Nan::New<Number>(utf16_unit), PointToJS(position) };
6262
TryCatch try_catch(Isolate::GetCurrent());
63-
auto maybe_result_value = Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
63+
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
64+
auto maybe_result_value = Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv);
65+
#else
66+
auto maybe_result_value = Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
67+
#endif
6468
if (try_catch.HasCaught()) return nullptr;
6569

6670
Local<Value> result_value;
@@ -364,7 +368,11 @@ void Parser::ParseTextBuffer(const Nan::FunctionCallbackInfo<Value> &info) {
364368
delete input;
365369
Local<Value> argv[] = {Tree::NewInstance(result)};
366370
auto callback = info[0].As<Function>();
367-
Nan::Call(callback, callback->CreationContext()->Global(), 1, argv);
371+
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
372+
Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 1, argv);
373+
#else
374+
Nan::Call(callback, callback->CreationContext()->Global(), 1, argv);
375+
#endif
368376
return;
369377
}
370378
}

src/tree.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void Tree::GetEditedRange(const Nan::FunctionCallbackInfo<Value> &info) {
196196

197197
void Tree::PrintDotGraph(const Nan::FunctionCallbackInfo<Value> &info) {
198198
Tree *tree = ObjectWrap::Unwrap<Tree>(info.This());
199-
ts_tree_print_dot_graph(tree->tree_, stderr);
199+
ts_tree_print_dot_graph(tree->tree_, 2);
200200
info.GetReturnValue().Set(info.This());
201201
}
202202

0 commit comments

Comments
 (0)