Skip to content

Commit

Permalink
Webpack compatibility fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Perry authored and arperry committed Aug 5, 2024
1 parent d5b7a13 commit a1a169e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions lib/pre-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ exports.find = function(package_json_path, opts) {
if (napi.get_napi_build_versions(package_json, opts)) {
napi_build_version = napi.get_best_napi_build_version(package_json, opts);
}
// Try without explicit module root first
const { module } = versioning.evaluate(package_json, opts, napi_build_version);
if (existsSync(module)) {
return module;
}
// Fall back to absolute path
opts = opts || {};
if (!opts.module_root) opts.module_root = path.dirname(package_json_path);
const meta = versioning.evaluate(package_json, opts, napi_build_version);
Expand Down
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mapbox/node-pre-gyp",
"description": "Node.js native addon binary install tool",
"version": "1.0.11",
"version": "1.0.12",
"keywords": [
"native",
"addon",
Expand Down
2 changes: 1 addition & 1 deletion test/app1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ 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");

0 comments on commit a1a169e

Please sign in to comment.