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

Compatible with Windows system path #670

Open
Meng-Lan opened this issue Oct 21, 2022 · 0 comments
Open

Compatible with Windows system path #670

Meng-Lan opened this issue Oct 21, 2022 · 0 comments

Comments

@Meng-Lan
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @mapbox/[email protected] 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant