diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 8ace915..0f6aa44 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "6.1.0" + ".": "6.1.1" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 435af6c..0081c96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [6.1.1](https://github.com/npm/hosted-git-info/compare/v6.1.0...v6.1.1) (2022-10-27) + +### Bug Fixes + +* [`f03bfbd`](https://github.com/npm/hosted-git-info/commit/f03bfbd3022c8f6283a991ff879ed97704ac35fa) [#176](https://github.com/npm/hosted-git-info/pull/176) only correct protocols when called from githost (@lukekarrys) + ## [6.1.0](https://github.com/npm/hosted-git-info/compare/v6.0.0...v6.1.0) (2022-10-26) ### Features diff --git a/lib/index.js b/lib/index.js index 65d3d5f..a7339c2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,7 +4,6 @@ const LRU = require('lru-cache') const hosts = require('./hosts.js') const fromUrl = require('./from-url.js') const parseUrl = require('./parse-url.js') -const getProtocols = require('./protocols.js') const cache = new LRU({ max: 1000 }) @@ -22,7 +21,15 @@ class GitHost { } static #gitHosts = { byShortcut: {}, byDomain: {} } - static #protocols = getProtocols() + static #protocols = { + 'git+ssh:': { name: 'sshurl' }, + 'ssh:': { name: 'sshurl' }, + 'git+https:': { name: 'https', auth: true }, + 'git:': { auth: true }, + 'http:': { auth: true }, + 'https:': { auth: true }, + 'git+http:': { auth: true }, + } static addHost (name, host) { GitHost.#gitHosts[name] = host diff --git a/lib/parse-url.js b/lib/parse-url.js index 5f5ac4d..7d5489c 100644 --- a/lib/parse-url.js +++ b/lib/parse-url.js @@ -1,5 +1,4 @@ const url = require('url') -const getProtocols = require('./protocols.js') const lastIndexOfBefore = (str, char, beforeChar) => { const startPosition = str.indexOf(beforeChar) @@ -73,7 +72,7 @@ const correctUrl = (giturl) => { return giturl } -module.exports = (giturl, protocols = getProtocols()) => { - const withProtocol = correctProtocol(giturl, protocols) +module.exports = (giturl, protocols) => { + const withProtocol = protocols ? correctProtocol(giturl, protocols) : giturl return safeUrl(withProtocol) || safeUrl(correctUrl(withProtocol)) } diff --git a/lib/protocols.js b/lib/protocols.js deleted file mode 100644 index 1299884..0000000 --- a/lib/protocols.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = () => ({ - 'git+ssh:': { name: 'sshurl' }, - 'ssh:': { name: 'sshurl' }, - 'git+https:': { name: 'https', auth: true }, - 'git:': { auth: true }, - 'http:': { auth: true }, - 'https:': { auth: true }, - 'git+http:': { auth: true }, -}) diff --git a/package.json b/package.json index 25c757b..6122599 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hosted-git-info", - "version": "6.1.0", + "version": "6.1.1", "description": "Provides metadata and conversions from repository urls for GitHub, Bitbucket and GitLab", "main": "./lib/index.js", "repository": { diff --git a/test/parse-url.js b/test/parse-url.js index aab57a2..54e7d16 100644 --- a/test/parse-url.js +++ b/test/parse-url.js @@ -2,9 +2,16 @@ const t = require('tap') const HostedGit = require('..') const parseUrl = require('../lib/parse-url.js') -t.test('can parse git+ssh url by default', async t => { +t.test('can parse git+ssh urls', async t => { // https://github.com/npm/cli/issues/5278 const u = 'git+ssh://git@abc:frontend/utils.git#6d45447e0c5eb6cd2e3edf05a8c5a9bb81950c79' t.ok(parseUrl(u)) t.ok(HostedGit.parseUrl(u)) }) + +t.test('can parse file urls', async t => { + // https://github.com/npm/cli/pull/5758#issuecomment-1292753331 + const u = 'file:../../../global-prefix/lib/node_modules/@myscope/bar' + t.ok(parseUrl(u)) + t.ok(HostedGit.parseUrl(u)) +})
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: