diff options
-rw-r--r-- | node_modules/hosted-git-info/lib/from-url.js | 80 | ||||
-rw-r--r-- | node_modules/hosted-git-info/lib/index.js | 16 | ||||
-rw-r--r-- | node_modules/hosted-git-info/lib/parse-url.js | 79 | ||||
-rw-r--r-- | node_modules/hosted-git-info/lib/protocols.js | 9 | ||||
-rw-r--r-- | node_modules/hosted-git-info/package.json | 8 | ||||
-rw-r--r-- | package-lock.json | 8 | ||||
-rw-r--r-- | package.json | 2 |
7 files changed, 107 insertions, 95 deletions
diff --git a/node_modules/hosted-git-info/lib/from-url.js b/node_modules/hosted-git-info/lib/from-url.js index b3e519e1f..efc1247d5 100644 --- a/node_modules/hosted-git-info/lib/from-url.js +++ b/node_modules/hosted-git-info/lib/from-url.js @@ -1,44 +1,6 @@ 'use strict' -const url = require('url') - -const safeUrl = (u) => { - try { - return new url.URL(u) - } catch { - // this fn should never throw - } -} - -const lastIndexOfBefore = (str, char, beforeChar) => { - const startPosition = str.indexOf(beforeChar) - return str.lastIndexOf(char, startPosition > -1 ? startPosition : Infinity) -} - -// accepts input like git:github.com:user/repo and inserts the // after the first : -const correctProtocol = (arg, protocols) => { - const firstColon = arg.indexOf(':') - const proto = arg.slice(0, firstColon + 1) - if (Object.prototype.hasOwnProperty.call(protocols, proto)) { - return arg - } - - const firstAt = arg.indexOf('@') - if (firstAt > -1) { - if (firstAt > firstColon) { - return `git+ssh://${arg}` - } else { - return arg - } - } - - const doubleSlash = arg.indexOf('//') - if (doubleSlash === firstColon + 1) { - return arg - } - - return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}` -} +const parseUrl = require('./parse-url') // look for github shorthand inputs, such as npm/cli const isGitHubShorthand = (arg) => { @@ -71,49 +33,13 @@ const isGitHubShorthand = (arg) => { secondSlashOnlyAfterHash } -// attempt to correct an scp style url so that it will parse with `new URL()` -const correctUrl = (giturl) => { - // ignore @ that come after the first hash since the denotes the start - // of a committish which can contain @ characters - const firstAt = lastIndexOfBefore(giturl, '@', '#') - // ignore colons that come after the hash since that could include colons such as: - // git@github.com:user/package-2#semver:^1.0.0 - const lastColonBeforeHash = lastIndexOfBefore(giturl, ':', '#') - - if (lastColonBeforeHash > firstAt) { - // the last : comes after the first @ (or there is no @) - // like it would in: - // proto://hostname.com:user/repo - // username@hostname.com:user/repo - // :password@hostname.com:user/repo - // username:password@hostname.com:user/repo - // proto://username@hostname.com:user/repo - // proto://:password@hostname.com:user/repo - // proto://username:password@hostname.com:user/repo - // then we replace the last : with a / to create a valid path - giturl = giturl.slice(0, lastColonBeforeHash) + '/' + giturl.slice(lastColonBeforeHash + 1) - } - - if (lastIndexOfBefore(giturl, ':', '#') === -1 && giturl.indexOf('//') === -1) { - // we have no : at all - // as it would be in: - // username@hostname.com/user/repo - // then we prepend a protocol - giturl = `git+ssh://${giturl}` - } - - return giturl -} - module.exports = (giturl, opts, { gitHosts, protocols }) => { if (!giturl) { return } - const correctedUrl = isGitHubShorthand(giturl) - ? `github:${giturl}` - : correctProtocol(giturl, protocols) - const parsed = safeUrl(correctedUrl) || safeUrl(correctUrl(correctedUrl)) + const correctedUrl = isGitHubShorthand(giturl) ? `github:${giturl}` : giturl + const parsed = parseUrl(correctedUrl, protocols) if (!parsed) { return } diff --git a/node_modules/hosted-git-info/lib/index.js b/node_modules/hosted-git-info/lib/index.js index 89805ebb4..65d3d5f37 100644 --- a/node_modules/hosted-git-info/lib/index.js +++ b/node_modules/hosted-git-info/lib/index.js @@ -3,6 +3,8 @@ 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 }) @@ -20,15 +22,7 @@ class GitHost { } static #gitHosts = { byShortcut: {}, byDomain: {} } - 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 #protocols = getProtocols() static addHost (name, host) { GitHost.#gitHosts[name] = host @@ -55,6 +49,10 @@ class GitHost { return cache.get(key) } + static parseUrl (url) { + return parseUrl(url) + } + #fill (template, opts) { if (typeof template !== 'function') { return null diff --git a/node_modules/hosted-git-info/lib/parse-url.js b/node_modules/hosted-git-info/lib/parse-url.js new file mode 100644 index 000000000..5f5ac4d37 --- /dev/null +++ b/node_modules/hosted-git-info/lib/parse-url.js @@ -0,0 +1,79 @@ +const url = require('url') +const getProtocols = require('./protocols.js') + +const lastIndexOfBefore = (str, char, beforeChar) => { + const startPosition = str.indexOf(beforeChar) + return str.lastIndexOf(char, startPosition > -1 ? startPosition : Infinity) +} + +const safeUrl = (u) => { + try { + return new url.URL(u) + } catch { + // this fn should never throw + } +} + +// accepts input like git:github.com:user/repo and inserts the // after the first : +const correctProtocol = (arg, protocols) => { + const firstColon = arg.indexOf(':') + const proto = arg.slice(0, firstColon + 1) + if (Object.prototype.hasOwnProperty.call(protocols, proto)) { + return arg + } + + const firstAt = arg.indexOf('@') + if (firstAt > -1) { + if (firstAt > firstColon) { + return `git+ssh://${arg}` + } else { + return arg + } + } + + const doubleSlash = arg.indexOf('//') + if (doubleSlash === firstColon + 1) { + return arg + } + + return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}` +} + +// attempt to correct an scp style url so that it will parse with `new URL()` +const correctUrl = (giturl) => { + // ignore @ that come after the first hash since the denotes the start + // of a committish which can contain @ characters + const firstAt = lastIndexOfBefore(giturl, '@', '#') + // ignore colons that come after the hash since that could include colons such as: + // git@github.com:user/package-2#semver:^1.0.0 + const lastColonBeforeHash = lastIndexOfBefore(giturl, ':', '#') + + if (lastColonBeforeHash > firstAt) { + // the last : comes after the first @ (or there is no @) + // like it would in: + // proto://hostname.com:user/repo + // username@hostname.com:user/repo + // :password@hostname.com:user/repo + // username:password@hostname.com:user/repo + // proto://username@hostname.com:user/repo + // proto://:password@hostname.com:user/repo + // proto://username:password@hostname.com:user/repo + // then we replace the last : with a / to create a valid path + giturl = giturl.slice(0, lastColonBeforeHash) + '/' + giturl.slice(lastColonBeforeHash + 1) + } + + if (lastIndexOfBefore(giturl, ':', '#') === -1 && giturl.indexOf('//') === -1) { + // we have no : at all + // as it would be in: + // username@hostname.com/user/repo + // then we prepend a protocol + giturl = `git+ssh://${giturl}` + } + + return giturl +} + +module.exports = (giturl, protocols = getProtocols()) => { + const withProtocol = correctProtocol(giturl, protocols) + return safeUrl(withProtocol) || safeUrl(correctUrl(withProtocol)) +} diff --git a/node_modules/hosted-git-info/lib/protocols.js b/node_modules/hosted-git-info/lib/protocols.js new file mode 100644 index 000000000..129988459 --- /dev/null +++ b/node_modules/hosted-git-info/lib/protocols.js @@ -0,0 +1,9 @@ +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/node_modules/hosted-git-info/package.json b/node_modules/hosted-git-info/package.json index 35feb7e15..25c757b8c 100644 --- a/node_modules/hosted-git-info/package.json +++ b/node_modules/hosted-git-info/package.json @@ -1,6 +1,6 @@ { "name": "hosted-git-info", - "version": "6.0.0", + "version": "6.1.0", "description": "Provides metadata and conversions from repository urls for GitHub, Bitbucket and GitLab", "main": "./lib/index.js", "repository": { @@ -33,8 +33,8 @@ "lru-cache": "^7.5.1" }, "devDependencies": { - "@npmcli/eslint-config": "^3.0.1", - "@npmcli/template-oss": "4.5.1", + "@npmcli/eslint-config": "^4.0.0", + "@npmcli/template-oss": "4.7.1", "tap": "^16.0.1" }, "files": [ @@ -54,6 +54,6 @@ }, "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", - "version": "4.5.1" + "version": "4.7.1" } } diff --git a/package-lock.json b/package-lock.json index 72797972f..e84cc520f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -104,7 +104,7 @@ "fs-minipass": "^2.1.0", "glob": "^8.0.1", "graceful-fs": "^4.2.10", - "hosted-git-info": "^6.0.0", + "hosted-git-info": "^6.1.0", "ini": "^3.0.1", "init-package-json": "^4.0.1", "is-cidr": "^4.0.2", @@ -6021,9 +6021,9 @@ } }, "node_modules/hosted-git-info": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-6.0.0.tgz", - "integrity": "sha512-NURrKJX36ihI69iCqcvN4uuIk9fHcc1C+uax/5fPh4Tr5WJnATir+QM/CMJNKrcOOvxQDsAdS5C9oJliM80X7g==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-6.1.0.tgz", + "integrity": "sha512-HGLEbnDnxaXOoVjyE4gR+zEzQ/jvdPBVbVvDiRedZsn7pKx45gic0G1HGZBZ94RyJz0e6pBMeInIh349TAvHCQ==", "inBundle": true, "dependencies": { "lru-cache": "^7.5.1" diff --git a/package.json b/package.json index da601ae0e..6f3d997bb 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "fs-minipass": "^2.1.0", "glob": "^8.0.1", "graceful-fs": "^4.2.10", - "hosted-git-info": "^6.0.0", + "hosted-git-info": "^6.1.0", "ini": "^3.0.1", "init-package-json": "^4.0.1", "is-cidr": "^4.0.2", |