Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const existsAsync = fs.exists || path.exists;
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
const s3_setup = require('./util/s3_setup.js');
const url = require('url');
const url = require('./util/url.js');
// for fetching binaries
const fetch = require('node-fetch');
const tar = require('tar');
Expand Down
2 changes: 1 addition & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
const s3_setup = require('./util/s3_setup.js');
const existsAsync = fs.exists || path.exists;
const url = require('url');
const url = require('./util/url.js');

function publish(gyp, argv, callback) {
const package_json = gyp.package_json;
Expand Down
2 changes: 1 addition & 1 deletion lib/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const log = require('./util/log.js');
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
const s3_setup = require('./util/s3_setup.js');
const url = require('url');
const url = require('./util/url.js');

function unpublish(gyp, argv, callback) {
const package_json = gyp.package_json;
Expand Down
5 changes: 2 additions & 3 deletions lib/util/s3_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

module.exports = exports;

const url = require('url');

module.exports.detect = function(opts) {
const config = {};

const to = opts.hosted_path;
const uri = url.parse(to);
const uri = new URL(to);

if (opts.bucket && opts.region) {
// use user defined settings for host, region, bucket
Expand All @@ -29,7 +28,7 @@ module.exports.detect = function(opts) {
// https://bucket-name.s3.Region.amazonaws.com/key-name (dash Region)
// or in some legacy region of this format:
// https://bucket-name.s3-Region.amazonaws.com/key-name (dot Region)
const parts = uri.hostname.split('.s3');
const parts = uri.hostname.replace(/^\[|\]$/, '').split('.s3');

// there is nothing before the .s3
// not a valid s3 virtual host bucket url
Expand Down
19 changes: 19 additions & 0 deletions lib/util/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

// url.resolve is deprecated because it invokes the deprecated url.parse() internally
// https://nodejs.org/api/url.html#urlresolvefrom-to
module.exports.resolve = function(from, to) {
const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
if (resolvedUrl.protocol === 'resolve:') {
// `from` is a relative URL.
const { pathname, search, hash } = resolvedUrl;

// To keep consistency with deprecated url.resolve(), we need to remove the leading '/' from pathname
if (pathname[0] === '/') {
return pathname.slice(1) + search + hash;
}

return pathname + search + hash;
}
return resolvedUrl.toString();
};
12 changes: 8 additions & 4 deletions lib/util/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module.exports = exports;

const path = require('path');
const semver = require('semver');
const url = require('url');
const detect_libc = require('detect-libc');
const napi = require('./napi.js');
const url = require('./url.js');

let abi_crosswalk;

Expand Down Expand Up @@ -221,9 +221,13 @@ function validate_config(package_json, opts) {
}
if (o) {
// enforce https over http
const protocol = url.parse(o.host).protocol;
if (protocol === 'http:') {
throw new Error("'host' protocol (" + protocol + ") is invalid - only 'https:' is accepted");
try {
const protocol = new URL(o.host).protocol;
if (protocol === 'http:') {
throw new Error("'host' protocol (" + protocol + ") is invalid - only 'https:' is accepted");
}
} catch (err) {
// do nothing
}
}
napi.validate_package_json(package_json, opts);
Expand Down
Loading