package/package.json000644 000765 000024 0000001317 12552024573013024 0ustar00000000 000000 { "name": "normalize-git-url", "version": "3.0.1", "description": "Normalizes Git URLs. For npm, but you can use it too.", "main": "normalize-git-url.js", "directories": { "test": "test" }, "dependencies": {}, "devDependencies": { "tap": "^1.1.0" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "https://github.com/npm/normalize-git-url.git" }, "keywords": [ "git", "github", "url", "normalize", "npm" ], "author": "Forrest L Norvell ", "license": "ISC", "bugs": { "url": "https://github.com/npm/normalize-git-url/issues" }, "homepage": "https://github.com/npm/normalize-git-url" } package/.npmignore000644 000765 000024 0000000016 12537613315012531 0ustar00000000 000000 node_modules/ package/README.md000644 000765 000024 0000002533 12537613315012017 0ustar00000000 000000 # normalize-git-url You have a bunch of Git URLs. You want to convert them to a canonical representation, probably for use inside npm so that it doesn't end up creating a bunch of superfluous cached origins. You use this package. ## Usage ```javascript var ngu = require('normalize-git-url'); var normalized = ngu("git+ssh://git@github.com:organization/repo.git#hashbrowns") // get back: // { // url : "ssh://git@github.com/organization/repo.git", // branch : "hashbrowns" // did u know hashbrowns are delicious? // } ``` ## API There's just the one function, and all it takes is a single parameter, a non-normalized Git URL. ### normalizeGitUrl(url) * `url` {String} The Git URL (very loosely speaking) to be normalized. Returns an object with the following format: * `url` {String} The normalized URL. * `branch` {String} The treeish to be checked out once the repo at `url` is cloned. It doesn't have to be a branch, but it's a lot easier to intuit what the output is for with that name. ## Limitations Right now this doesn't try to special-case GitHub too much -- it doesn't ensure that `.git` is added to the end of URLs, it doesn't prefer `https:` over `http:` or `ssh:`, it doesn't deal with redirects, and it doesn't try to resolve symbolic names to treeish hashcodes. For now, it just tries to account for minor differences in representation. package/LICENSE000644 000765 000024 0000001345 12537613315011545 0ustar00000000 000000 Copyright (c) 2014-2015, Forrest L Norvell Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. package/normalize-git-url.js000644 000765 000024 0000002103 12552024536014446 0ustar00000000 000000 var url = require('url') module.exports = function normalize (u) { var parsed = url.parse(u) // If parsing actually alters the URL, it is almost certainly an // scp-style URL, or an invalid one. var altered = u !== url.format(parsed) // git is so tricky! // if the path is like ssh://foo:22/some/path then it works, but // it needs the ssh:// // If the path is like ssh://foo:some/path then it works, but // only if you remove the ssh:// if (parsed.protocol) { parsed.protocol = parsed.protocol.replace(/^git\+/, '') } // figure out what we should check out. var checkout = parsed.hash && parsed.hash.substr(1) || 'master' parsed.hash = '' var returnedUrl if (altered) { if (u.match(/^git\+https?/) && parsed.pathname.match(/\/?:[^0-9]/)) { returnedUrl = u.replace(/^git\+(.*:[^:]+):(.*)/, '$1/$2') } else { returnedUrl = u.replace(/^(?:git\+)?ssh:\/\//, '') } returnedUrl = returnedUrl.replace(/#[^#]*$/, '') } else { returnedUrl = url.format(parsed) } return { url: returnedUrl, branch: checkout } } package/.eslintrc000644 000765 000024 0000000637 12551270777012376 0ustar00000000 000000 { "env" : { "node" : true }, "rules" : { "semi": [2, "never"], "strict": 0, "quotes": [1, "double", "avoid-escape"], "no-use-before-define": 0, "curly": 0, "no-underscore-dangle": 0, "no-lonely-if": 1, "no-unused-vars": [2, {"vars" : "all", "args" : "after-used"}], "no-mixed-requires": 0, "space-infix-ops": 0, "key-spacing": 0, "no-multi-spaces": 0 } } package/CHANGELOG.md000644 000765 000024 0000000324 12537613315012345 0ustar00000000 000000 ### 1.0.0 (2014-12-25): * [`8b3d874`](https://github.com/npm/normalize-git-url/commit/8b3d874afd14f4cdde65d418e0a35a615c746bba) Initial version, with simple tests. ([@othiym23](https://github.com/othiym23)) package/test/basic.js000644 000765 000024 0000004231 12552024536013131 0ustar00000000 000000 var test = require('tap').test var normalize = require('../normalize-git-url.js') test('basic normalization tests', function (t) { t.same( normalize('git+ssh://user@hostname:project.git#commit-ish'), { url: 'user@hostname:project.git', branch: 'commit-ish' } ) t.same( normalize('git+http://user@hostname/project/blah.git#commit-ish'), { url: 'http://user@hostname/project/blah.git', branch: 'commit-ish' } ) t.same( normalize('git+https://user@hostname/project/blah.git#commit-ish'), { url: 'https://user@hostname/project/blah.git', branch: 'commit-ish' } ) t.same( normalize('git+https://user@hostname:project/blah.git#commit-ish'), { url: 'https://user@hostname/project/blah.git', branch: 'commit-ish' } ) t.same( normalize('git+ssh://git@github.com:npm/npm.git#v1.0.27'), { url: 'git@github.com:npm/npm.git', branch: 'v1.0.27' } ) t.same( normalize('git+ssh://git@github.com:/npm/npm.git#v1.0.28'), { url: 'git@github.com:/npm/npm.git', branch: 'v1.0.28' } ) t.same( normalize('git+ssh://git@github.com:org/repo#dev'), { url: 'git@github.com:org/repo', branch: 'dev' } ) t.same( normalize('git+ssh://git@github.com/org/repo#dev'), { url: 'ssh://git@github.com/org/repo', branch: 'dev' } ) t.same( normalize('git+ssh://foo:22/some/path'), { url: 'ssh://foo:22/some/path', branch: 'master' } ) t.same( normalize('git@github.com:org/repo#dev'), { url: 'git@github.com:org/repo', branch: 'dev' } ) t.same( normalize('git+https://github.com/KenanY/node-uuid'), { url: 'https://github.com/KenanY/node-uuid', branch: 'master' } ) t.same( normalize('git+https://github.com/KenanY/node-uuid#7a018f2d075b03a73409e8356f9b29c9ad4ea2c5'), { url: 'https://github.com/KenanY/node-uuid', branch: '7a018f2d075b03a73409e8356f9b29c9ad4ea2c5' } ) t.same( normalize('git+ssh://git@git.example.com:b/b.git#v1.0.0'), { url: 'git@git.example.com:b/b.git', branch: 'v1.0.0' } ) t.same( normalize('git+ssh://git@github.com:npm/npm-proto.git#othiym23/organized'), { url: 'git@github.com:npm/npm-proto.git', branch: 'othiym23/organized' } ) t.end() })