Repository navigation
Compatible with Windows system path #670
Copy link
Copy link
Open
Description
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @mapbox/node-pre-gyp@1.0.9 for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/@mapbox/node-pre-gyp/lib/install.js b/node_modules/@mapbox/node-pre-gyp/lib/install.js
index 617dd86..fbf6ac7 100644
--- a/node_modules/@mapbox/node-pre-gyp/lib/install.js
+++ b/node_modules/@mapbox/node-pre-gyp/lib/install.js
@@ -209,9 +209,8 @@ function install(gyp, argv, callback) {
}
makeDir(to).then(() => {
- const fileName = from.startsWith('file://') && from.slice('file://'.length);
- if (fileName) {
- extract_from_local(fileName, to, after_place);
+ if (opts.use_local_mirror) {
+ extract_from_local(from, to, after_place);
} else {
place_binary(from, to, opts, after_place);
}
diff --git a/node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js b/node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js
index 825cfa1..c53813e 100644
--- a/node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js
+++ b/node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js
@@ -274,7 +274,7 @@ module.exports.get_process_runtime = get_process_runtime;
const default_package_name = '{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz';
const default_remote_path = '';
-module.exports.evaluate = function(package_json, options, napi_build_version) {
+module.exports.evaluate = function (package_json, options, napi_build_version) {
options = options || {};
validate_config(package_json, options); // options is a suitable substitute for opts in this case
const v = package_json.version;
@@ -307,14 +307,19 @@ module.exports.evaluate = function(package_json, options, napi_build_version) {
toolset: options.toolset || '', // address https://github.com/mapbox/node-pre-gyp/issues/119
bucket: package_json.binary.bucket,
region: package_json.binary.region,
- s3ForcePathStyle: package_json.binary.s3ForcePathStyle || false
+ s3ForcePathStyle: package_json.binary.s3ForcePathStyle || false,
};
- // support host mirror with npm config `--{module_name}_binary_host_mirror`
- // e.g.: https://github.com/node-inspector/v8-profiler/blob/master/package.json#L25
- // > npm install v8-profiler --profiler_binary_host_mirror=https://npm.taobao.org/mirrors/node-inspector/
+ // support host mirror with npm config `--{module_name}_binary_host_mirror`
+ // e.g.: https://github.com/node-inspector/v8-profiler/blob/master/package.json#L25
+ // > npm install v8-profiler --profiler_binary_host_mirror=https://npm.taobao.org/mirrors/node-inspector/
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.use_local_mirror = opts.host.startsWith('file://');
+ if (opts.use_local_mirror) {
+ opts.host = opts.host.slice('file://'.length);
+ }
+ // console.log(opts)
opts.module_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) {
@@ -329,7 +334,7 @@ module.exports.evaluate = function(package_json, options, napi_build_version) {
const package_name = package_json.binary.package_name ? package_json.binary.package_name : default_package_name;
opts.package_name = eval_template(package_name, opts);
opts.staged_tarball = path.join('build/stage', opts.remote_path, opts.package_name);
- opts.hosted_path = url.resolve(opts.host, opts.remote_path);
- opts.hosted_tarball = url.resolve(opts.hosted_path, opts.package_name);
+ opts.hosted_path = opts.use_local_mirror ? path.resolve(opts.host, opts.remote_path) : url.resolve(opts.host, opts.remote_path);
+ opts.hosted_tarball = opts.use_local_mirror ? path.resolve(opts.hosted_path, opts.package_name) : url.resolve(opts.hosted_path, opts.package_name);
return opts;
};This issue body was partially generated by patch-package.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity