diff options
Diffstat (limited to 'deps/npm/node_modules/npm-package-arg/npa.js')
-rw-r--r-- | deps/npm/node_modules/npm-package-arg/npa.js | 74 |
1 files changed, 34 insertions, 40 deletions
diff --git a/deps/npm/node_modules/npm-package-arg/npa.js b/deps/npm/node_modules/npm-package-arg/npa.js index 8333c75f442..883c5401b46 100644 --- a/deps/npm/node_modules/npm-package-arg/npa.js +++ b/deps/npm/node_modules/npm-package-arg/npa.js @@ -3,14 +3,15 @@ var assert = require("assert") var util = require("util") var semver = require("semver") var path = require("path") +var HostedGit = require("hosted-git-info") module.exports = npa var isWindows = process.platform === "win32" || global.FAKE_WINDOWS -var slashRe = isWindows ? /\\|\// : /\// +var slashRe = isWindows ? /\\|[/]/ : /[/]/ -var parseName = /^(?:@([^\/]+?)\/)?([^\/]+?)$/ -var nameAt = /^(@([^\/]+?)\/)?([^\/]+?)@/ +var parseName = /^(?:@([^/]+?)[/])?([^/]+?)$/ +var nameAt = /^(@([^/]+?)[/])?([^/]+?)@/ var debug = util.debuglog ? util.debuglog("npa") : /\bnpa\b/i.test(process.env.NODE_DEBUG || "") ? function () { @@ -25,7 +26,7 @@ function validName (name) { var n = name.trim() if (!n || n.charAt(0) === "." || !n.match(/^[a-zA-Z0-9]/) - || n.match(/[\/\(\)&\?#\|<>@:%\s\\\*'"!~`]/) + || n.match(/[/()&?#|<>@:%\s\\*'"!~`]/) || n.toLowerCase() === "node_modules" || n !== encodeURIComponent(n) || n.toLowerCase() === "favicon.ico") { @@ -70,20 +71,11 @@ function npa (arg) { urlparse = {} } - if (urlparse.protocol) { + if (urlparse.protocol || HostedGit.fromUrl(arg)) { return parseUrl(res, arg, urlparse) } - // parse git stuff - // parse tag/range/local/remote - - if (maybeGitHubShorthand(arg)) { - res.type = "github" - res.spec = arg - return res - } - - // at this point, it's not a url, and not github + // at this point, it's not a url, and not hosted // If it's a valid name, and doesn't already have a name, then assume // $name@"" range // @@ -132,19 +124,20 @@ function parseLocal (res, arg) { res.spec = path.resolve(arg) } -function maybeGitHubShorthand (arg) { - // Note: This does not fully test the git ref format. - // See https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html - // - // The only way to do this properly would be to shell out to - // git-check-ref-format, and as this is a fast sync function, - // we don't want to do that. Just let git fail if it turns - // out that the commit-ish is invalid. - // GH usernames cannot start with . or - - return /^[^@%\/\s\.-][^@%\/\s]*\/[^@\s\/%]+(?:#.*)?$/.test(arg) -} - function parseUrl (res, arg, urlparse) { + var gitHost = HostedGit.fromUrl(arg) + if (gitHost) { + res.type = "hosted" + res.spec = gitHost.toString(), + res.hosted = { + type: gitHost.type, + ssh: gitHost.ssh(), + sshUrl: gitHost.sshurl(), + httpsUrl: gitHost.https(), + directUrl: gitHost.file("package.json") + } + return res + } // check the protocol, and then see if it's git or not switch (urlparse.protocol) { case "git:": @@ -154,23 +147,23 @@ function parseUrl (res, arg, urlparse) { case "git+ftp:": case "git+ssh:": case "git+file:": - res.type = 'git' - res.spec = arg.replace(/^git\+/, '') + res.type = "git" + res.spec = arg.replace(/^git[+]/, "") break - case 'http:': - case 'https:': - res.type = 'remote' + case "http:": + case "https:": + res.type = "remote" res.spec = arg break - case 'file:': - res.type = 'local' + case "file:": + res.type = "local" res.spec = urlparse.pathname - break; + break default: - throw new Error('Unsupported URL Type: ' + arg) + throw new Error("Unsupported URL Type: " + arg) break } @@ -181,7 +174,8 @@ function parseUrl (res, arg, urlparse) { function Result () { if (!(this instanceof Result)) return new Result } -Result.prototype.name = null -Result.prototype.type = null -Result.prototype.spec = null -Result.prototype.raw = null +Result.prototype.name = null +Result.prototype.type = null +Result.prototype.spec = null +Result.prototype.raw = null +Result.prototype.hosted = null |