From 43dd49c9782848c25e5b03448c8a0f923f13c158 Mon Sep 17 00:00:00 2001 From: Kat Marchán Date: Tue, 29 Jan 2019 14:43:00 -0800 Subject: deps: upgrade npm to 6.7.0 PR-URL: https://github.com/nodejs/node/pull/25804 Reviewed-By: Myles Borins --- deps/npm/node_modules/npm-registry-fetch/errors.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'deps/npm/node_modules/npm-registry-fetch/errors.js') diff --git a/deps/npm/node_modules/npm-registry-fetch/errors.js b/deps/npm/node_modules/npm-registry-fetch/errors.js index 217f46f977..ba78735fce 100644 --- a/deps/npm/node_modules/npm-registry-fetch/errors.js +++ b/deps/npm/node_modules/npm-registry-fetch/errors.js @@ -1,5 +1,25 @@ 'use strict' +const url = require('url') + +function packageName (href) { + try { + let basePath = url.parse(href).pathname.substr(1) + if (!basePath.match(/^-/)) { + basePath = basePath.split('/') + var index = basePath.indexOf('_rewrite') + if (index === -1) { + index = basePath.length - 1 + } else { + index++ + } + return decodeURIComponent(basePath[index]) + } + } catch (_) { + // this is ok + } +} + class HttpErrorBase extends Error { constructor (method, res, body, spec) { super() @@ -9,6 +29,7 @@ class HttpErrorBase extends Error { this.method = method this.uri = res.url this.body = body + this.pkgid = spec ? spec.toString() : packageName(res.url) } } module.exports.HttpErrorBase = HttpErrorBase -- cgit v1.2.3