4 files changed +25
-18
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,23 @@ const gitHosts = require('./git-host-info.js')
3
3
const GitHost = module . exports = require ( './git-host.js' )
4
4
const LRU = require ( 'lru-cache' )
5
5
const parseUrl = require ( './parse-url.js' )
6
- const protocols = require ( './protocols' ) ( gitHosts . byShortcut )
6
+
7
7
const cache = new LRU ( { max : 1000 } )
8
8
9
+ const protocols = {
10
+ 'git+ssh:' : { name : 'sshurl' } ,
11
+ 'ssh:' : { name : 'sshurl' } ,
12
+ 'git+https:' : { name : 'https' , auth : true } ,
13
+ 'git:' : { auth : true } ,
14
+ 'http:' : { auth : true } ,
15
+ 'https:' : { auth : true } ,
16
+ 'git+http:' : { auth : true } ,
17
+ ...Object . keys ( gitHosts . byShortcut ) . reduce ( ( acc , key ) => {
18
+ acc [ key ] = { name : gitHosts . byShortcut [ key ] }
19
+ return acc
20
+ } , { } ) ,
21
+ }
22
+
9
23
module . exports . fromUrl = function ( giturl , opts ) {
10
24
if ( typeof giturl !== 'string' ) {
11
25
return
Original file line number Diff line number Diff line change 1
1
const url = require ( 'url' )
2
- const getProtocols = require ( './protocols.js' )
3
2
4
3
const lastIndexOfBefore = ( str , char , beforeChar ) => {
5
4
const startPosition = str . indexOf ( beforeChar )
@@ -73,7 +72,7 @@ const correctUrl = (giturl) => {
73
72
return giturl
74
73
}
75
74
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
78
77
return safeUrl ( withProtocol ) || safeUrl ( correctUrl ( withProtocol ) )
79
78
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,9 +2,16 @@ const t = require('tap')
2
2
const HostedGit = require ( '..' )
3
3
const parseUrl = require ( '../lib/parse-url.js' )
4
4
5
- t . test ( 'can parse git+ssh url by default ' , async t => {
5
+ t . test ( 'can parse git+ssh urls ' , async t => {
6
6
// https://github.com/npm/cli/issues/5278
7
7
const u = 'git+ssh://git@abc:frontend/utils.git#6d45447e0c5eb6cd2e3edf05a8c5a9bb81950c79'
8
8
t . ok ( parseUrl ( u ) )
9
9
t . ok ( HostedGit . parseUrl ( u ) )
10
10
} )
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
+ } )
0 commit comments