Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make this work with webpack #622

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/node-pre-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ Object.defineProperty(exports, 'find', {
enumerable: true
});

Object.defineProperty(exports, 'findUsingPackageJson', {
get: function() {
return require('./pre-binding').findUsingPackageJson;
},
enumerable: true
});

// in the following, "my_module" is using node-pre-gyp to
// prebuild and install pre-built binaries. "main_module"
// is using "my_module".
Expand Down
19 changes: 12 additions & 7 deletions lib/pre-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ exports.validate = function(package_json, opts) {
versioning.validate_config(package_json, opts);
};

exports.findUsingPackageJson = function (package_json, opts) {
versioning.validate_config(package_json, opts);
let napi_build_version;
if (napi.get_napi_build_versions(package_json, opts)) {
napi_build_version = napi.get_best_napi_build_version(package_json, opts);
}

return versioning.evaluate(package_json, opts, napi_build_version);
};

exports.find = function(package_json_path, opts) {
if (!existsSync(package_json_path)) {
throw new Error(package_json_path + 'does not exist');
Expand All @@ -22,13 +32,8 @@ exports.find = function(package_json_path, opts) {
prog.setBinaryHostProperty();
const package_json = prog.package_json;

versioning.validate_config(package_json, opts);
let napi_build_version;
if (napi.get_napi_build_versions(package_json, opts)) {
napi_build_version = napi.get_best_napi_build_version(package_json, opts);
}
opts = opts || {};
if (!opts.module_root) opts.module_root = path.dirname(package_json_path);
const meta = versioning.evaluate(package_json, opts, napi_build_version);
return meta.module;

return exports.findUsingPackageJson(package_json, opts).module;
};
6 changes: 3 additions & 3 deletions lib/util/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,14 @@ module.exports.evaluate = function(package_json, options, napi_build_version) {
const validModuleName = opts.module_name.replace('-', '_');
const host = process.env['npm_config_' + validModuleName + '_binary_host_mirror'] || package_json.binary.host;
opts.host = fix_slashes(eval_template(host, opts));
opts.module_path = eval_template(package_json.binary.module_path, opts);
opts.module_relative_path = eval_template(package_json.binary.module_path, opts);
// now we resolve the module_path to ensure it is absolute so that binding.gyp variables work predictably
if (options.module_root) {
// resolve relative to known module root: works for pre-binding require
opts.module_path = path.join(options.module_root, opts.module_path);
opts.module_path = path.join(options.module_root, opts.module_relative_path);
} else {
// resolve relative to current working directory: works for node-pre-gyp commands
opts.module_path = path.resolve(opts.module_path);
opts.module_path = path.resolve(opts.module_relative_path);
}
opts.module = path.join(opts.module_path, opts.module_name + '.node');
opts.remote_path = package_json.binary.remote_path ? drop_double_slashes(fix_slashes(eval_template(package_json.binary.remote_path, opts))) : default_remote_path;
Expand Down
10 changes: 9 additions & 1 deletion test/app1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ var path = require('path')
var binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json')));
var binding = require(binding_path);

require('assert').equal(binding.hello(),"hello");
require('assert').equal(binding.hello(),"hello");

var binding_path_using_package_json = binary.findUsingPackageJson(require('./package.json'));
var binding_using_package_json = require('./' + path.join(
binding_path_using_package_json.module_relative_path,
binding_path_using_package_json.module_name
) + '.node');

require('assert').equal(binding_using_package_json.hello(),"hello");