Skip to content

Commit

Permalink
Restore previous switch statement now that its logic is isolated
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Oct 10, 2014
1 parent a3cb72b commit b294d4d
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions npa.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,37 @@ function parseUrl (res, arg, urlparse) {
https: gitHost.https(),
directUrl: gitHost.file("package.json")
}
return res
}
// check the protocol, and then see if it's git or not
else if (/^git([+](https?|rsync|ftp|ssh|file))?:$/.test(urlparse.protocol) ||
(/^https?:$/.test(urlparse.protocol) && /[.]git$/.test(urlparse.pathname))) {
res.type = "git"
res.spec = arg.replace(/^git[+]/, "")
}
else if (/^https?:$/.test(urlparse.protocol)) {
res.type = "remote"
res.spec = arg
}
else if ("file:" === urlparse.protocol) {
res.type = "local"
res.spec = urlparse.pathname
}
else {
throw new Error("Unsupported URL Type: " + arg)
switch (urlparse.protocol) {
case "git:":
case "git+http:":
case "git+https:":
case "git+rsync:":
case "git+ftp:":
case "git+ssh:":
case "git+file:":
res.type = 'git'
res.spec = arg.replace(/^git\+/, '')
break

case 'http:':
case 'https:':
res.type = 'remote'
res.spec = arg
break

case 'file:':
res.type = 'local'
res.spec = urlparse.pathname
break;

default:
throw new Error('Unsupported URL Type: ' + arg)
break
}

return res
}

Expand Down

0 comments on commit b294d4d

Please sign in to comment.