fix: use new URL instead of url.parse
This commit is contained in:
1 parent
a7c4a27697
commit
a2c92c1573
2 files changed
+16
-14
No files matched your search
@@ -2,6 +2,7 @@ import fetch from '@pnpm/fetch'
|
||||
import git = require('graceful-git')
|
||||
import HostedGit = require('hosted-git-info')
|
||||
import url = require('url')
|
||||
import { URL } from 'url'
|
||||
|
||||
export type HostedPackageSpec = ({
|
||||
fetchSpec: string,
|
||||
@@ -37,7 +38,7 @@ export default async function parsePref (pref: string): Promise<HostedPackageSpe
|
||||
if (colonsPos === -1) return null
|
||||
const protocol = pref.substr(0, colonsPos)
|
||||
if (protocol && gitProtocols.has(protocol.toLocaleLowerCase())) {
|
||||
const urlparse = url.parse(pref)
|
||||
const urlparse = new URL(pref)
|
||||
if (!urlparse || !urlparse.protocol) return null
|
||||
const match = urlparse.protocol === 'git+ssh:' && matchGitScp(pref)
|
||||
if (match) {
|
||||
@@ -57,12 +58,13 @@ export default async function parsePref (pref: string): Promise<HostedPackageSpe
|
||||
return null
|
||||
}
|
||||
|
||||
function urlToFetchSpec (urlparse: url.Url) {
|
||||
if (urlparse.protocol) {
|
||||
urlparse.protocol = urlparse.protocol.replace(/^git[+]/, '')
|
||||
function urlToFetchSpec (urlparse: URL) {
|
||||
urlparse.hash = ''
|
||||
const fetchSpec = url.format(urlparse)
|
||||
if (fetchSpec.startsWith('git+')) {
|
||||
return fetchSpec.substr(4)
|
||||
}
|
||||
delete urlparse.hash
|
||||
return url.format(urlparse)
|
||||
return fetchSpec
|
||||
}
|
||||
|
||||
async function fromHostedGit (hosted: any): Promise<HostedPackageSpec> { // tslint:disable-line
|
||||
|
||||
@@ -3,7 +3,7 @@ import HttpProxyAgent = require('http-proxy-agent')
|
||||
import HttpsProxyAgent = require('https-proxy-agent')
|
||||
import LRU = require('lru-cache')
|
||||
import SocksProxyAgent = require('socks-proxy-agent')
|
||||
import url = require('url')
|
||||
import { URL } from 'url'
|
||||
import getProcessEnv from './getProcessEnv'
|
||||
|
||||
const HttpsAgent = HttpAgent.HttpsAgent
|
||||
@@ -24,7 +24,7 @@ export default function getAgent (
|
||||
noProxy: boolean,
|
||||
},
|
||||
) {
|
||||
const parsedUri = url.parse(uri)
|
||||
const parsedUri = new URL(uri)
|
||||
const isHttps = parsedUri.protocol === 'https:'
|
||||
const pxuri = getProxyUri(uri, opts)
|
||||
|
||||
@@ -77,7 +77,7 @@ export default function getAgent (
|
||||
}
|
||||
|
||||
function checkNoProxy (uri: string, opts: { noProxy?: boolean }) {
|
||||
const host = url.parse(uri).hostname!.split('.').filter(x => x).reverse()
|
||||
const host = new URL(uri).hostname!.split('.').filter(x => x).reverse()
|
||||
let noproxy = (opts.noProxy || getProcessEnv('no_proxy'))
|
||||
if (typeof noproxy === 'string') {
|
||||
const noproxyArr = noproxy.split(/\s*,\s*/g)
|
||||
@@ -102,7 +102,7 @@ function getProxyUri (
|
||||
noProxy?: boolean,
|
||||
},
|
||||
) {
|
||||
const protocol = url.parse(uri).protocol
|
||||
const { protocol } = new URL(uri)
|
||||
|
||||
let proxy = opts.proxy || (
|
||||
protocol === 'https:' && getProcessEnv('https_proxy')
|
||||
@@ -115,13 +115,13 @@ function getProxyUri (
|
||||
proxy = protocol + '//' + proxy
|
||||
}
|
||||
|
||||
const parsedProxy = (typeof proxy === 'string') ? url.parse(proxy) : proxy
|
||||
const parsedProxy = (typeof proxy === 'string') ? new URL(proxy) : proxy
|
||||
|
||||
return !checkNoProxy(uri, opts) && parsedProxy
|
||||
}
|
||||
|
||||
function getProxy (
|
||||
proxyUrl: url.UrlWithStringQuery,
|
||||
proxyUrl: URL,
|
||||
opts: {
|
||||
ca?: string,
|
||||
cert?: string,
|
||||
@@ -134,14 +134,14 @@ function getProxy (
|
||||
isHttps: boolean,
|
||||
) {
|
||||
let popts = {
|
||||
auth: proxyUrl.auth,
|
||||
auth: (proxyUrl.username ? (proxyUrl.password ? `${proxyUrl.username}:${proxyUrl.password}` : proxyUrl.username) : undefined),
|
||||
ca: opts.ca,
|
||||
cert: opts.cert,
|
||||
host: proxyUrl.hostname,
|
||||
key: opts.key,
|
||||
localAddress: opts.localAddress,
|
||||
maxSockets: opts.maxSockets || 15,
|
||||
path: proxyUrl.path,
|
||||
path: proxyUrl.pathname,
|
||||
port: proxyUrl.port,
|
||||
protocol: proxyUrl.protocol,
|
||||
rejectUnauthorized: opts.strictSSL,
|
||||
|
||||
Reference in new issue
Block a user