[Pkg-javascript-commits] [node-normalize-git-url] 01/02: Imported Upstream version 3.0.1
Thorsten Alteholz
alteholz at moszumanska.debian.org
Sun Mar 27 15:34:38 UTC 2016
This is an automated email from the git hooks/post-receive script.
alteholz pushed a commit to branch master
in repository node-normalize-git-url.
commit 9527acd9e0e1f5adcafcda5e2b2cc9fe7b2c3d98
Author: Thorsten Alteholz <debian at alteholz.de>
Date: Sun Mar 27 17:34:35 2016 +0200
Imported Upstream version 3.0.1
---
.eslintrc | 19 ++++++++++++++++
.npmignore | 1 +
CHANGELOG.md | 5 ++++
LICENSE | 13 +++++++++++
README.md | 40 ++++++++++++++++++++++++++++++++
normalize-git-url.js | 38 +++++++++++++++++++++++++++++++
package.json | 33 +++++++++++++++++++++++++++
test/basic.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 213 insertions(+)
diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..b54e30f
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,19 @@
+{
+ "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
+ }
+}
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..c2658d7
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1 @@
+node_modules/
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..f2d2b94
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,5 @@
+### 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))
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d21147b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..da3d78e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,40 @@
+# 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.
diff --git a/normalize-git-url.js b/normalize-git-url.js
new file mode 100644
index 0000000..db0022a
--- /dev/null
+++ b/normalize-git-url.js
@@ -0,0 +1,38 @@
+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
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..334e36c
--- /dev/null
+++ b/package.json
@@ -0,0 +1,33 @@
+{
+ "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 <ogd at aoaioxxysz.net>",
+ "license": "ISC",
+ "bugs": {
+ "url": "https://github.com/npm/normalize-git-url/issues"
+ },
+ "homepage": "https://github.com/npm/normalize-git-url"
+}
diff --git a/test/basic.js b/test/basic.js
new file mode 100644
index 0000000..37952d6
--- /dev/null
+++ b/test/basic.js
@@ -0,0 +1,64 @@
+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 at 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 at 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 at github.com:/npm/npm.git', branch: 'v1.0.28' }
+ )
+ t.same(
+ normalize('git+ssh://git@github.com:org/repo#dev'),
+ { url: 'git at 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 at github.com:org/repo#dev'),
+ { url: 'git at 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 at 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 at github.com:npm/npm-proto.git', branch: 'othiym23/organized' }
+ )
+
+ t.end()
+})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-normalize-git-url.git
More information about the Pkg-javascript-commits
mailing list