Skip to content

Commit 54f762d

Browse files
committed
fix: replace deprecated url.parse with WHATWG URL API for Node 24
1 parent 14fe6fd commit 54f762d

File tree

6 files changed

+11
-16
lines changed

6 files changed

+11
-16
lines changed

lib/install.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const existsAsync = fs.exists || path.exists;
1111
const versioning = require('./util/versioning.js');
1212
const napi = require('./util/napi.js');
1313
const s3_setup = require('./util/s3_setup.js');
14-
const url = require('url');
1514
// for fetching binaries
1615
const fetch = require('node-fetch');
1716
const tar = require('tar');
@@ -38,7 +37,7 @@ function place_binary_authenticated(opts, targetDir, callback) {
3837
try {
3938
const config = s3_setup.detect(opts);
4039
const s3 = s3_setup.get_s3(config);
41-
const key_name = url.resolve(config.prefix, opts.package_name);
40+
const key_name = path.posix.join(config.prefix, opts.package_name);
4241

4342
log.info('install', 'Downloading from S3:', config.bucket, key_name);
4443

lib/publish.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const versioning = require('./util/versioning.js');
1111
const napi = require('./util/napi.js');
1212
const s3_setup = require('./util/s3_setup.js');
1313
const existsAsync = fs.exists || path.exists;
14-
const url = require('url');
1514

1615
function publish(gyp, argv, callback) {
1716
const package_json = gyp.package_json;
@@ -27,7 +26,7 @@ function publish(gyp, argv, callback) {
2726
const config = s3_setup.detect(opts);
2827
const s3 = s3_setup.get_s3(config);
2928

30-
const key_name = url.resolve(config.prefix, opts.package_name);
29+
const key_name = path.posix.join(config.prefix, opts.package_name);
3130
const s3_opts = {
3231
Bucket: config.bucket,
3332
Key: key_name

lib/unpublish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const log = require('./util/log.js');
88
const versioning = require('./util/versioning.js');
99
const napi = require('./util/napi.js');
1010
const s3_setup = require('./util/s3_setup.js');
11-
const url = require('url');
11+
const path = require('path');
1212

1313
function unpublish(gyp, argv, callback) {
1414
const package_json = gyp.package_json;
1515
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
1616
const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
1717
const config = s3_setup.detect(opts);
1818
const s3 = s3_setup.get_s3(config);
19-
const key_name = url.resolve(config.prefix, opts.package_name);
19+
const key_name = path.posix.join(config.prefix, opts.package_name);
2020
const s3_opts = {
2121
Bucket: config.bucket,
2222
Key: key_name

lib/util/s3_setup.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
module.exports = exports;
44

5-
const url = require('url');
6-
75
module.exports.detect = function(opts) {
86
const config = {};
97

108
const to = opts.hosted_path;
11-
const uri = url.parse(to);
9+
const uri = new URL(to);
1210

1311
if (opts.bucket && opts.region) {
1412
// use user defined settings for host, region, bucket

lib/util/versioning.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = exports;
44

55
const path = require('path');
66
const semver = require('semver');
7-
const url = require('url');
87
const detect_libc = require('detect-libc');
98
const napi = require('./napi.js');
109

@@ -221,7 +220,7 @@ function validate_config(package_json, opts) {
221220
}
222221
if (o) {
223222
// enforce https over http
224-
const protocol = url.parse(o.host).protocol;
223+
const protocol = new URL(o.host).protocol;
225224
if (protocol === 'http:') {
226225
throw new Error("'host' protocol (" + protocol + ") is invalid - only 'https:' is accepted");
227226
}
@@ -333,10 +332,10 @@ module.exports.evaluate = function(package_json, options, napi_build_version) {
333332
// when using s3ForcePathStyle the bucket is part of the http object path
334333
// add it
335334
if (opts.s3ForcePathStyle) {
336-
opts.hosted_path = url.resolve(opts.host, drop_double_slashes(`${opts.bucket}/${opts.remote_path}`));
335+
opts.hosted_path = new URL(drop_double_slashes(`${opts.bucket}/${opts.remote_path}`), opts.host).href;
337336
} else {
338-
opts.hosted_path = url.resolve(opts.host, opts.remote_path);
337+
opts.hosted_path = new URL(opts.remote_path, opts.host).href;
339338
}
340-
opts.hosted_tarball = url.resolve(opts.hosted_path, opts.package_name);
339+
opts.hosted_tarball = new URL(opts.package_name, opts.hosted_path).href;
341340
return opts;
342341
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@mapbox/node-pre-gyp",
2+
"name": "@yrambler2001/node-pre-gyp",
33
"description": "Node.js native addon binary install tool",
4-
"version": "2.0.4-pre.0",
4+
"version": "2.0.4",
55
"keywords": [
66
"native",
77
"addon",

0 commit comments

Comments
 (0)