diff options
Diffstat (limited to 'deps/npm/node_modules/hosted-git-info/index.js')
-rw-r--r-- | deps/npm/node_modules/hosted-git-info/index.js | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/deps/npm/node_modules/hosted-git-info/index.js b/deps/npm/node_modules/hosted-git-info/index.js index 21e53fe372..0b08be1553 100644 --- a/deps/npm/node_modules/hosted-git-info/index.js +++ b/deps/npm/node_modules/hosted-git-info/index.js @@ -2,6 +2,8 @@ var url = require('url') var gitHosts = require('./git-host-info.js') var GitHost = module.exports = require('./git-host.js') +var LRU = require('lru-cache') +var cache = new LRU({max: 1000}) var protocolToRepresentationMap = { 'git+ssh:': 'sshurl', @@ -22,17 +24,15 @@ var authProtocols = { 'git+http:': true } -var cache = {} - module.exports.fromUrl = function (giturl, opts) { if (typeof giturl !== 'string') return var key = giturl + JSON.stringify(opts || {}) - if (!(key in cache)) { - cache[key] = fromUrl(giturl, opts) + if (!cache.has(key)) { + cache.set(key, fromUrl(giturl, opts)) } - return cache[key] + return cache.get(key) } function fromUrl (giturl, opts) { @@ -108,9 +108,7 @@ function parseGitUrl (giturl) { var matched = giturl.match(/^([^@]+)@([^:/]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/) if (!matched) { var legacy = url.parse(giturl) - // If we don't have url.URL, then sorry, this is just not fixable. - // This affects Node <= 6.12. - if (legacy.auth && typeof url.URL === 'function') { + if (legacy.auth) { // git urls can be in the form of scp-style/ssh-connect strings, like // git+ssh://user@host.com:some/path, which the legacy url parser // supports, but WhatWG url.URL class does not. However, the legacy @@ -120,7 +118,7 @@ function parseGitUrl (giturl) { // Pull off just the auth and host, so we dont' get the confusing // scp-style URL, then pass that to the WhatWG parser to get the // auth properly escaped. - var authmatch = giturl.match(/[^@]+@[^:/]+/) + const authmatch = giturl.match(/[^@]+@[^:/]+/) /* istanbul ignore else - this should be impossible */ if (authmatch) { var whatwg = new url.URL(authmatch[0]) |