Skip to content

Commit 6fdde50

Browse files
committed
chore: Add some comments to correctProtocol
1 parent 7b273bb commit 6fdde50

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/parse-url.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@ const correctProtocol = (arg, protocols) => {
2121
return arg
2222
}
2323

24-
const doubleSlash = arg.indexOf('//')
25-
if (doubleSlash === firstColon + 1) {
24+
if (arg.substr(firstColon, 3) === '://') {
25+
// If arg is given as <foo>://<bar>, then this is already a valid URL and
26+
// we assume the user provided a protocol.
2627
return arg
2728
}
2829

2930
const firstAt = arg.indexOf('@')
3031
if (firstAt > -1) {
3132
if (firstAt > firstColon) {
33+
// The URL has the form of <foo>:<bar>@<baz>. We assume this is a git+ssh
34+
// URL.
3235
return `git+ssh://${arg}`
3336
} else {
37+
// The URL has the form of <foo>@<bar> which is likely a shortcut URL
38+
// such as @npm/cli
3439
return arg
3540
}
3641
}
3742

43+
// Correct <foo>:<bar> to <foo>://<bar>
3844
return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}`
3945
}
4046

0 commit comments

Comments
 (0)