From f03bfbd3022c8f6283a991ff879ed97704ac35fa Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 26 Oct 2022 16:42:30 -0700 Subject: [PATCH 1/2] fix: only correct protocols when called from githost --- lib/index.js | 11 +++++++++-- lib/parse-url.js | 5 ++--- lib/protocols.js | 9 --------- test/parse-url.js | 9 ++++++++- 4 files changed, 19 insertions(+), 15 deletions(-) delete mode 100644 lib/protocols.js 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/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)) +}) From 31cdc8d1a8950b8975f7a465338d3d5dabbc672d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 27 Oct 2022 20:00:15 +0000 Subject: [PATCH 2/2] chore: release 6.1.1 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 6 ++++++ package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) 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/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": {