Permalink
Browse files

Move abbrev to a submodule/dependency

  • Loading branch information...
1 parent 9e15a43 commit 5630986a1a5c414f8a6185fda08096432da86d6b @isaacs isaacs committed Mar 24, 2011
Showing with 8 additions and 110 deletions.
  1. +3 −0 .gitmodules
  2. +0 −106 lib/utils/abbrev.js
  3. +1 −1 lib/utils/parse-args.js
  4. +1 −0 node_modules/abbrev
  5. +1 −1 npm.js
  6. +2 −2 package.json
View
@@ -1,3 +1,6 @@
[submodule "node_modules/semver"]
path = node_modules/semver
url = git://github.com/isaacs/node-semver.git
+[submodule "node_modules/abbrev"]
+ path = node_modules/abbrev
+ url = git://github.com/isaacs/abbrev-js.git
View
@@ -1,106 +0,0 @@
-
-module.exports = exports = abbrev.abbrev = abbrev
-
-abbrev.monkeyPatch = monkeyPatch
-
-function monkeyPatch () {
- Array.prototype.abbrev = function () { return abbrev(this) }
- Object.prototype.abbrev = function () { return abbrev(Object.keys(this)) }
-}
-
-function abbrev (list) {
- if (arguments.length !== 1 || !Array.isArray(list)) {
- list = Array.prototype.slice.call(arguments, 0)
- }
- for (var i = 0, l = list.length, args = [] ; i < l ; i ++) {
- args[i] = typeof list[i] === "string" ? list[i] : String(list[i])
- }
-
- // sort them lexicographically, so that they're next to their nearest kin
- args = args.sort(lexSort)
-
- // walk through each, seeing how much it has in common with the next and previous
- var abbrevs = {}
- , prev = ""
- for (var i = 0, l = args.length ; i < l ; i ++) {
- var current = args[i]
- , next = args[i + 1] || ""
- , nextMatches = true
- , prevMatches = true
- if (current === next) continue
- for (var j = 0, cl = current.length ; j < cl ; j ++) {
- var curChar = current.charAt(j)
- nextMatches = nextMatches && curChar === next.charAt(j)
- prevMatches = prevMatches && curChar === prev.charAt(j)
- if (nextMatches || prevMatches) continue
- else {
- j ++
- break
- }
- }
- prev = current
- if (j === cl) {
- abbrevs[current] = current
- continue
- }
- for (var a = current.substr(0, j) ; j <= cl ; j ++) {
- abbrevs[a] = current
- a += current.charAt(j)
- }
- }
- return abbrevs
-}
-
-function lexSort (a, b) {
- return a === b ? 0 : a > b ? 1 : -1
-}
-
-
-// tests
-if (module === require.main) {
-
-var assert = require("assert")
- , sys
-sys = require(process.binding("native").util ? "util" : "sys")
-
-console.log("running tests")
-function test (list, expect) {
- var actual = abbrev(list)
- assert.deepEqual(actual, expect,
- "abbrev("+sys.inspect(list)+") === " + sys.inspect(expect) + "\n"+
- "actual: "+sys.inspect(actual))
- actual = abbrev.apply(exports, list)
- assert.deepEqual(abbrev.apply(exports, list), expect,
- "abbrev("+list.map(JSON.stringify).join(",")+") === " + sys.inspect(expect) + "\n"+
- "actual: "+sys.inspect(actual))
-}
-
-test([ "ruby", "ruby", "rules", "rules", "rules" ],
-{ rub: 'ruby'
-, ruby: 'ruby'
-, rul: 'rules'
-, rule: 'rules'
-, rules: 'rules'
-})
-test(["fool", "foom", "pool", "pope"],
-{ fool: 'fool'
-, foom: 'foom'
-, poo: 'pool'
-, pool: 'pool'
-, pop: 'pope'
-, pope: 'pope'
-})
-test(["a", "ab", "abc", "abcd", "abcde", "acde"],
-{ a: 'a'
-, ab: 'ab'
-, abc: 'abc'
-, abcd: 'abcd'
-, abcde: 'abcde'
-, ac: 'acde'
-, acd: 'acde'
-, acde: 'acde'
-})
-
-console.log("pass")
-
-}
View
@@ -3,7 +3,7 @@
var url = require("url")
, path = require("path")
, Stream = require("stream").Stream
- , abbrev = require("./abbrev")
+ , abbrev = require("abbrev")
, log = require("./log")
module.exports = exports = parseArgs
Submodule abbrev added at 3d509e
View
2 npm.js
@@ -18,7 +18,7 @@ var EventEmitter = require("events").EventEmitter
, log = require("./lib/utils/log")
, fs = require("./lib/utils/graceful-fs")
, path = require("path")
- , abbrev = require("./lib/utils/abbrev")
+ , abbrev = require("abbrev")
, which = require("./lib/utils/which")
, semver = require("semver")
, findPrefix = require("./lib/utils/find-prefix")
View
@@ -49,8 +49,8 @@
}
, "main" : "npm"
, "bin" : "./bin/npm.js"
-, "dependencies" : { "semver" : "1" }
-, "bundleDependencies" : [ "semver" ]
+, "dependencies" : { "semver" : "1", "abbrev" : "1" }
+, "bundleDependencies" : [ "semver", "abbrev" ]
, "devDependencies" : { "ronn" : "" }
, "engines" : { "node" : "0.4 || 0.5", "npm" : "1" }
, "scripts" : { "test" : "make test"

0 comments on commit 5630986

Please sign in to comment.