File tree Expand file tree Collapse file tree 4 files changed +19
-15
lines changed
Expand file tree Collapse file tree 4 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ const LRU = require('lru-cache')
44const hosts = require ( './hosts.js' )
55const fromUrl = require ( './from-url.js' )
66const parseUrl = require ( './parse-url.js' )
7- const getProtocols = require ( './protocols.js' )
87
98const cache = new LRU ( { max : 1000 } )
109
@@ -22,7 +21,15 @@ class GitHost {
2221 }
2322
2423 static #gitHosts = { byShortcut : { } , byDomain : { } }
25- static #protocols = getProtocols ( )
24+ static #protocols = {
25+ 'git+ssh:' : { name : 'sshurl' } ,
26+ 'ssh:' : { name : 'sshurl' } ,
27+ 'git+https:' : { name : 'https' , auth : true } ,
28+ 'git:' : { auth : true } ,
29+ 'http:' : { auth : true } ,
30+ 'https:' : { auth : true } ,
31+ 'git+http:' : { auth : true } ,
32+ }
2633
2734 static addHost ( name , host ) {
2835 GitHost . #gitHosts[ name ] = host
Original file line number Diff line number Diff line change 11const url = require ( 'url' )
2- const getProtocols = require ( './protocols.js' )
32
43const lastIndexOfBefore = ( str , char , beforeChar ) => {
54 const startPosition = str . indexOf ( beforeChar )
@@ -73,7 +72,7 @@ const correctUrl = (giturl) => {
7372 return giturl
7473}
7574
76- module . exports = ( giturl , protocols = getProtocols ( ) ) => {
77- const withProtocol = correctProtocol ( giturl , protocols )
75+ module . exports = ( giturl , protocols ) => {
76+ const withProtocol = protocols ? correctProtocol ( giturl , protocols ) : giturl
7877 return safeUrl ( withProtocol ) || safeUrl ( correctUrl ( withProtocol ) )
7978}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,9 +2,16 @@ const t = require('tap')
22const HostedGit = require ( '..' )
33const parseUrl = require ( '../lib/parse-url.js' )
44
5- t . test ( 'can parse git+ssh url by default ' , async t => {
5+ t . test ( 'can parse git+ssh urls ' , async t => {
66 // https://github.com/npm/cli/issues/5278
77 const u = 'git+ssh://git@abc:frontend/utils.git#6d45447e0c5eb6cd2e3edf05a8c5a9bb81950c79'
88 t . ok ( parseUrl ( u ) )
99 t . ok ( HostedGit . parseUrl ( u ) )
1010} )
11+
12+ t . test ( 'can parse file urls' , async t => {
13+ // https://github.com/npm/cli/pull/5758#issuecomment-1292753331
14+ const u = 'file:../../../global-prefix/lib/node_modules/@myscope/bar'
15+ t . ok ( parseUrl ( u ) )
16+ t . ok ( HostedGit . parseUrl ( u ) )
17+ } )
You can’t perform that action at this time.
0 commit comments