Skip to content

Commit 436c7ee

Browse files
committed
node-addon-api@v3
1 parent 78ad91c commit 436c7ee

6 files changed

Lines changed: 49 additions & 30 deletions

File tree

.github/workflows/main.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
name: Build
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
os: [windows-latest, ubuntu-latest, macos-latest]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v1
17+
18+
- run: npm install
19+
- run: npm test
20+
- run: npm run dist
21+
if: ${{ startsWith(github.event.ref, 'refs/tags') }}
22+
23+
- name: Create release
24+
if: ${{ startsWith(github.event.ref, 'refs/tags') }}
25+
uses: toyobayashi/upload-release-assets@v3.0.0
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
with:
29+
tag_name: ${{ github.event.after }}
30+
release_name: ${{ github.event.after }}
31+
draft: true
32+
prerelease: false
33+
assets: ./dist/*.zip

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
build_from_source=true
22
runtime=electron
3-
target=7.1.7
3+
target=9.0.0
44
toolset=v142
55
disturl=https://electronjs.org/headers
File renamed without changes.

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Win32",
55
"includePath": [
66
"${workspaceFolder}/**",
7-
"${env:HOME}/AppData/Local/node-gyp/Cache/7.1.7/include/node"
7+
"${env:HOME}/AppData/Local/node-gyp/Cache/9.0.0/include/node"
88
],
99
"defines": [
1010
"_DEBUG",

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "electron-asar-encrypt-demo",
3-
"version": "1.0.0",
3+
"version": "0.1.2",
44
"description": "electron-asar-encrypt-demo",
55
"main": "pack.js",
66
"scripts": {
77
"install": "node ./script/keygen",
88
"postinstall": "node ./script/postinstall.js",
9-
"build": "node ./script/js2c&&node-gyp configure --target=7.1.7 --disturl=https://electronjs.org/headers&&node-gyp build",
10-
"build:debug": "node ./script/js2c&&node-gyp configure --target=7.1.7 --disturl=https://electronjs.org/headers&&node-gyp build --debug",
9+
"build": "node ./script/js2c&&node-gyp configure --target=9.0.0 --disturl=https://electronjs.org/headers&&node-gyp build",
10+
"build:debug": "node ./script/js2c&&node-gyp configure --target=9.0.0 --disturl=https://electronjs.org/headers&&node-gyp build --debug",
1111
"test": "npm run build&&node ./script/pack&&node ./script/test",
1212
"dist": "node ./script/dist.js",
1313
"start": "node ./script/start.js"
@@ -19,12 +19,12 @@
1919
"license": "MIT",
2020
"devDependencies": {
2121
"@tybys/cross-zip": "^3.0.4",
22-
"asar": "^2.0.3",
23-
"asar-node": "^2.1.2",
24-
"electron": "7.1.7",
25-
"fs-extra": "^8.1.0",
26-
"node-addon-api": "^2.0.0",
27-
"node-gyp": "^5.1.0",
28-
"terser": "^4.6.4"
22+
"asar": "^3.0.3",
23+
"asar-node": "^2.1.3",
24+
"electron": "9.0.0",
25+
"fs-extra": "^9.0.0",
26+
"node-addon-api": "^3.0.0",
27+
"node-gyp": "^5.1.1",
28+
"terser": "^4.7.0"
2929
}
3030
}

src/main.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,13 @@ static Napi::Value modulePrototypeCompile(const Napi::CallbackInfo& info) {
172172
return oldCompile.Call(info.This(), { content, filename });
173173
}
174174

175-
static Napi::Value _runScript(const Napi::Env& env, const Napi::String& script) {
176-
napi_value res;
177-
NAPI_THROW_IF_FAILED(env, napi_run_script(env, script, &res), env.Undefined());
178-
return Napi::Value(env, res);
179-
}
180-
181-
static Napi::Value _runScript(const Napi::Env& env, const std::string& script) {
182-
return _runScript(env, Napi::String::New(env, script));
183-
}
184-
185-
static Napi::Value _runScript(const Napi::Env& env, const char* script) {
186-
return _runScript(env, Napi::String::New(env, script));
187-
}
188-
189-
static Napi::Function _makeRequireFunction(const Napi::Env& env, const Napi::Object& module) {
190-
Napi::Function _makeRequire = _runScript(env, scriptRequire).As<Napi::Function>();
175+
static Napi::Function _makeRequireFunction(Napi::Env& env, const Napi::Object& module) {
176+
Napi::Function _makeRequire = env.RunScript(scriptRequire).As<Napi::Function>();
191177
return _makeRequire({ module }).As<Napi::Function>();
192178
}
193179

194-
static Napi::Value _getModuleObject(const Napi::Env& env, const Napi::Object& mainModule, const Napi::Object& thisExports) {
195-
Napi::Function _findFunction = _runScript(env, scriptFind).As<Napi::Function>();
180+
static Napi::Value _getModuleObject(Napi::Env& env, const Napi::Object& mainModule, const Napi::Object& thisExports) {
181+
Napi::Function _findFunction = env.RunScript(scriptFind).As<Napi::Function>();
196182
Napi::Value res = _findFunction({ mainModule, thisExports });
197183
if (res.IsNull()) {
198184
Napi::Error::New(env, "Cannot find module object.").ThrowAsJavaScriptException();

0 commit comments

Comments
 (0)