Built motion from commit 44377920.|2.6.11
[motion2.git] / legacy-libs / node-pre-gyp / lib / pre-binding.js
1 "use strict";
2
3 var versioning = require('../lib/util/versioning.js');
4 var napi = require('../lib/util/napi.js');
5 var existsSync = require('fs').existsSync || require('path').existsSync;
6 var path = require('path');
7
8 module.exports = exports;
9
10 exports.usage = 'Finds the require path for the node-pre-gyp installed module';
11
12 exports.validate = function(package_json,opts) {
13     versioning.validate_config(package_json,opts);
14 };
15
16 exports.find = function(package_json_path,opts) {
17    if (!existsSync(package_json_path)) {
18         throw new Error("package.json does not exist at " + package_json_path);
19    }
20    var package_json = require(package_json_path);
21    versioning.validate_config(package_json,opts);
22    var napi_build_version;
23    if (napi.get_napi_build_versions (package_json, opts)) {
24        napi_build_version = napi.get_best_napi_build_version(package_json, opts);
25    }
26    opts = opts || {};
27    if (!opts.module_root) opts.module_root = path.dirname(package_json_path);
28    var meta = versioning.evaluate(package_json,opts,napi_build_version);
29    return meta.module;
30 };