Skip to content

Commit

Permalink
node-addon-api@v3
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Jun 1, 2020
1 parent 78ad91c commit 436c7ee
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 30 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build

on: push

jobs:
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1

- run: npm install
- run: npm test
- run: npm run dist
if: ${{ startsWith(github.event.ref, 'refs/tags') }}

- name: Create release
if: ${{ startsWith(github.event.ref, 'refs/tags') }}
uses: toyobayashi/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.after }}
release_name: ${{ github.event.after }}
draft: true
prerelease: false
assets: ./dist/*.zip
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build_from_source=true
runtime=electron
target=7.1.7
target=9.0.0
toolset=v142
disturl=https://electronjs.org/headers
File renamed without changes.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${env:HOME}/AppData/Local/node-gyp/Cache/7.1.7/include/node"
"${env:HOME}/AppData/Local/node-gyp/Cache/9.0.0/include/node"
],
"defines": [
"_DEBUG",
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "electron-asar-encrypt-demo",
"version": "1.0.0",
"version": "0.1.2",
"description": "electron-asar-encrypt-demo",
"main": "pack.js",
"scripts": {
"install": "node ./script/keygen",
"postinstall": "node ./script/postinstall.js",
"build": "node ./script/js2c&&node-gyp configure --target=7.1.7 --disturl=https://electronjs.org/headers&&node-gyp build",
"build:debug": "node ./script/js2c&&node-gyp configure --target=7.1.7 --disturl=https://electronjs.org/headers&&node-gyp build --debug",
"build": "node ./script/js2c&&node-gyp configure --target=9.0.0 --disturl=https://electronjs.org/headers&&node-gyp build",
"build:debug": "node ./script/js2c&&node-gyp configure --target=9.0.0 --disturl=https://electronjs.org/headers&&node-gyp build --debug",
"test": "npm run build&&node ./script/pack&&node ./script/test",
"dist": "node ./script/dist.js",
"start": "node ./script/start.js"
Expand All @@ -19,12 +19,12 @@
"license": "MIT",
"devDependencies": {
"@tybys/cross-zip": "^3.0.4",
"asar": "^2.0.3",
"asar-node": "^2.1.2",
"electron": "7.1.7",
"fs-extra": "^8.1.0",
"node-addon-api": "^2.0.0",
"node-gyp": "^5.1.0",
"terser": "^4.6.4"
"asar": "^3.0.3",
"asar-node": "^2.1.3",
"electron": "9.0.0",
"fs-extra": "^9.0.0",
"node-addon-api": "^3.0.0",
"node-gyp": "^5.1.1",
"terser": "^4.7.0"
}
}
22 changes: 4 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,13 @@ static Napi::Value modulePrototypeCompile(const Napi::CallbackInfo& info) {
return oldCompile.Call(info.This(), { content, filename });
}

static Napi::Value _runScript(const Napi::Env& env, const Napi::String& script) {
napi_value res;
NAPI_THROW_IF_FAILED(env, napi_run_script(env, script, &res), env.Undefined());
return Napi::Value(env, res);
}

static Napi::Value _runScript(const Napi::Env& env, const std::string& script) {
return _runScript(env, Napi::String::New(env, script));
}

static Napi::Value _runScript(const Napi::Env& env, const char* script) {
return _runScript(env, Napi::String::New(env, script));
}

static Napi::Function _makeRequireFunction(const Napi::Env& env, const Napi::Object& module) {
Napi::Function _makeRequire = _runScript(env, scriptRequire).As<Napi::Function>();
static Napi::Function _makeRequireFunction(Napi::Env& env, const Napi::Object& module) {
Napi::Function _makeRequire = env.RunScript(scriptRequire).As<Napi::Function>();
return _makeRequire({ module }).As<Napi::Function>();
}

static Napi::Value _getModuleObject(const Napi::Env& env, const Napi::Object& mainModule, const Napi::Object& thisExports) {
Napi::Function _findFunction = _runScript(env, scriptFind).As<Napi::Function>();
static Napi::Value _getModuleObject(Napi::Env& env, const Napi::Object& mainModule, const Napi::Object& thisExports) {
Napi::Function _findFunction = env.RunScript(scriptFind).As<Napi::Function>();
Napi::Value res = _findFunction({ mainModule, thisExports });
if (res.IsNull()) {
Napi::Error::New(env, "Cannot find module object.").ThrowAsJavaScriptException();
Expand Down

0 comments on commit 436c7ee

Please sign in to comment.