3 * Copyright 2016 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
26 var binary = require('node-pre-gyp/lib/pre-binding');
27 var path = require('path');
29 binary.find(path.resolve(path.join(__dirname, '../package.json')));
32 binding = require(binding_path);
34 let fs = require('fs');
35 let searchPath = path.dirname(path.dirname(binding_path));
36 let searchName = path.basename(path.dirname(binding_path));
39 foundNames = fs.readdirSync(searchPath);
40 } catch (readDirError) {
41 let message = `The gRPC binary module was not installed. This may be fixed by running "npm rebuild"
42 Original error: ${e.message}`;
43 let error = new Error(message);
47 if (foundNames.indexOf(searchName) === -1) {
48 let message = `Failed to load gRPC binary module because it was not installed for the current system
49 Expected directory: ${searchName}
50 Found: [${foundNames.join(', ')}]
51 This problem can often be fixed by running "npm rebuild" on the current system
52 Original error: ${e.message}`;
53 let error = new Error(message);
57 e.message = `Failed to load ${binding_path}. ${e.message}`;
62 module.exports = binding;