Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Use node-pre-gyp again to cache grpc binary
Browse files Browse the repository at this point in the history
So that we don't have to build grpc c++ library each time the npm
package is installed. The binary is uploaded to releases in github
repo using node-pre-gyp-github tool and it is fetched by node-pre-gyp
from there.
  • Loading branch information
Jan Kryl committed Jan 6, 2021
1 parent d4f6cfb commit 205d0a4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
11 changes: 11 additions & 0 deletions packages/grpc-native-core/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,17 @@
"ares",
"address_sorting"
]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node"],
"destination": "<(module_path)"
}
]
}
]
}
18 changes: 15 additions & 3 deletions packages/grpc-native-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grpc-uds",
"version": "0.1.4",
"version": "0.1.6",
"author": "Jan Kryl & Google Inc.",
"description": "TEMPORARY and EXPERIMENTAL gRPC Library for Node supporting Unix Domain Sockets",
"homepage": "https://grpc.io/",
Expand All @@ -19,15 +19,20 @@
"lib": "src"
},
"scripts": {
"build": "node-gyp rebuild",
"build": "node-pre-gyp build",
"electron-build": "node-pre-gyp configure build --runtime=electron --disturl=https://atom.io/download/atom-shell",
"coverage": "istanbul cover ./node_modules/.bin/_mocha test",
"install": "node-gyp rebuild",
"install": "node-pre-gyp install --fallback-to-build --library=static_library",
"prepack": "git submodule update --init --recursive && npm install"
},
"bundledDependencies": [
"node-pre-gyp"
],
"dependencies": {
"lodash.camelcase": "^4.3.0",
"lodash.clone": "^4.5.0",
"nan": "^2.13.2",
"node-pre-gyp": "^0.13.0",
"protobufjs": "^5.0.3"
},
"devDependencies": {
Expand All @@ -44,6 +49,13 @@
"engines": {
"node": ">=4"
},
"binary": {
"module_name": "grpc_node",
"module_path": "src/node/extension_binary/{node_abi}-{platform}-{arch}-{libc}",
"host": "https://github.com/jkryl/grpc-node/releases/download/",
"remote_path": "{version}",
"package_name": "{node_abi}-{platform}-{arch}-{libc}.tar.gz"
},
"files": [
"LICENSE",
"README.md",
Expand Down
27 changes: 26 additions & 1 deletion packages/grpc-native-core/src/grpc_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,40 @@

'use strict';

var binary = require('node-pre-gyp/lib/pre-binding');
var path = require('path');
var binding_path =
binary.find(path.resolve(path.join(__dirname, '../package.json')));
var binding;
try {
binding = require('../build/Release/grpc_node.node');
binding = require(binding_path);
} catch (e) {
let fs = require('fs');
let searchPath = path.dirname(path.dirname(binding_path));
let searchName = path.basename(path.dirname(binding_path));
let foundNames;
try {
foundNames = fs.readdirSync(searchPath);
} catch (readDirError) {
let message = `The gRPC binary module was not installed. This may be fixed by running "npm rebuild"
Original error: ${e.message}`;
let error = new Error(message);
error.code = e.code;
throw error;
}
if (foundNames.indexOf(searchName) === -1) {
let message = `Failed to load gRPC binary module because it was not installed for the current system
Expected directory: ${searchName}
Found: [${foundNames.join(', ')}]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: ${e.message}`;
let error = new Error(message);
error.code = e.code;
throw error;
} else {
e.message = `Failed to load ${binding_path}. ${e.message}`;
throw e;
}
}

module.exports = binding;

0 comments on commit 205d0a4

Please sign in to comment.