diff options
author | isaacs <i@izs.me> | 2012-06-12 03:37:27 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-06-12 03:37:27 +0400 |
commit | cbf5f60218fc21a6a592a6856d91794477d0652d (patch) | |
tree | 1992b03350e82944ba5899bcf7f6832fc41acac4 | |
parent | a995d4f50d6376d2699c2ba1df4e4f277cfbef62 (diff) |
Use read-installed dependency
-rw-r--r-- | lib/ls.js | 4 | ||||
-rw-r--r-- | lib/prune.js | 4 | ||||
-rw-r--r-- | lib/rebuild.js | 4 | ||||
-rw-r--r-- | lib/utils/completion/installed-deep.js | 6 | ||||
-rw-r--r-- | node_modules/read-installed/README.md | 16 | ||||
-rw-r--r-- | node_modules/read-installed/package.json | 32 | ||||
-rw-r--r-- | node_modules/read-installed/read-installed.js (renamed from lib/utils/read-installed.js) | 67 | ||||
-rw-r--r-- | node_modules/read-installed/test/basic.js | 34 | ||||
-rw-r--r-- | package.json | 6 |
9 files changed, 115 insertions, 58 deletions
@@ -8,7 +8,7 @@ module.exports = exports = ls var npm = require("./npm.js") - , readInstalled = require("./utils/read-installed.js") + , readInstalled = require("read-installed") , output = require("./utils/output.js") , log = require("npmlog") , relativize = require("./utils/relativize.js") @@ -28,7 +28,7 @@ function ls (args, silent, cb) { var dir = path.resolve(npm.dir, "..") - readInstalled(dir, function (er, data) { + readInstalled(dir, npm.config.get("depth"), function (er, data) { var lite = getLite(bfsify(data)) if (er || silent) return cb(er, data, lite) diff --git a/lib/prune.js b/lib/prune.js index 4a02dc1f8..2afb2b998 100644 --- a/lib/prune.js +++ b/lib/prune.js @@ -4,13 +4,13 @@ module.exports = prune prune.usage = "npm prune" -var readInstalled = require("./utils/read-installed.js") +var readInstalled = require("read-installed") , npm = require("./npm.js") prune.completion = require("./utils/completion/installed-deep.js") function prune (args, cb) { - readInstalled(npm.prefix, function (er, data) { + readInstalled(npm.prefix, npm.config.get("depth"), function (er, data) { if (er) return cb(er) prune_(args, data, cb) }) diff --git a/lib/rebuild.js b/lib/rebuild.js index a4a39f7b9..c9f623d6c 100644 --- a/lib/rebuild.js +++ b/lib/rebuild.js @@ -1,7 +1,7 @@ module.exports = rebuild -var readInstalled = require("./utils/read-installed.js") +var readInstalled = require("read-installed") , semver = require("semver") , log = require("npmlog") , path = require("path") @@ -16,7 +16,7 @@ rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]" rebuild.completion = require("./utils/completion/installed-deep.js") function rebuild (args, cb) { - readInstalled(npm.prefix, function (er, data) { + readInstalled(npm.prefix, npm.config.get("depth"), function (er, data) { log.info("readInstalled", typeof data) if (er) return cb(er) var set = filter(data, args) diff --git a/lib/utils/completion/installed-deep.js b/lib/utils/completion/installed-deep.js index 1188f408f..b49d7bb77 100644 --- a/lib/utils/completion/installed-deep.js +++ b/lib/utils/completion/installed-deep.js @@ -1,17 +1,17 @@ module.exports = installedDeep var npm = require("../../npm.js") - , readInstalled = require("../read-installed.js") + , readInstalled = require("read-installed") function installedDeep (opts, cb) { var local , global if (npm.config.get("global")) local = [], next() - else readInstalled(npm.prefix, function (er, data) { + else readInstalled(npm.prefix, npm.config.get("depth"), function (er, data) { local = getNames(data || {}) next() }) - readInstalled(npm.config.get("prefix"), function (er, data) { + readInstalled(npm.config.get("prefix"), npm.config.get("depth"), function (er, data) { global = getNames(data || {}) next() }) diff --git a/node_modules/read-installed/README.md b/node_modules/read-installed/README.md new file mode 100644 index 000000000..59e882fb0 --- /dev/null +++ b/node_modules/read-installed/README.md @@ -0,0 +1,16 @@ +# read-installed + +Read all the installed packages in a folder, and return a tree +structure with all the data. + +npm uses this. + +## Usage + +```javascript +var readInstalled = require("read-installed") +// depth is optional, defaults to Infinity +readInstalled(folder, depth, function (er, data) { + ... +}) +``` diff --git a/node_modules/read-installed/package.json b/node_modules/read-installed/package.json new file mode 100644 index 000000000..3e703bf90 --- /dev/null +++ b/node_modules/read-installed/package.json @@ -0,0 +1,32 @@ +{ + "name": "read-installed", + "description": "Read all the installed packages in a folder, and return a tree structure with all the data.", + "version": "0.0.1", + "repository": { + "type": "git", + "url": "git://github.com/isaacs/read-installed" + }, + "main": "read-installed.js", + "scripts": { + "test": "node test/basic.js" + }, + "dependencies": { + "semver": "~1.0.14", + "slide": "~1.1.3", + "read-package-json": "0", + "graceful-fs": "~1.1.8", + "npmlog": "0" + }, + "optionalDependencies": { + "graceful-fs": "~1.1.8", + "npmlog": "0" + }, + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "readme": "# read-installed\n\nRead all the installed packages in a folder, and return a tree\nstructure with all the data.\n\nnpm uses this.\n\n## Usage\n\n```javascript\nvar readInstalled = require(\"read-installed\")\n// depth is optional, defaults to Infinity\nreadInstalled(folder, depth, function (er, data) {\n ...\n})\n```\n", + "_id": "read-installed@0.0.1", + "_from": "read-installed" +} diff --git a/lib/utils/read-installed.js b/node_modules/read-installed/read-installed.js index 709d746c6..be394225b 100644 --- a/lib/utils/read-installed.js +++ b/node_modules/read-installed/read-installed.js @@ -86,21 +86,30 @@ as far as the left-most node_modules folder. */ +try { + var fs = require("graceful-fs") +} catch (er) { + var fs = require("fs") +} + +try { + var log = require("npmlog") +} catch (_) { + var log = { verbose: noop, info: noop, warn: noop, error: noop } + function noop () {} +} -var npm = require("../npm.js") - , fs = require("graceful-fs") - , path = require("path") - , asyncMap = require("slide").asyncMap - , semver = require("semver") - , readJson = require("read-package-json") - , log = require("npmlog") - , url = require("url") +var path = require("path") +var asyncMap = require("slide").asyncMap +var semver = require("semver") +var readJson = require("read-package-json") +var url = require("url") module.exports = readInstalled -function readInstalled (folder, cb) { - var d = npm.config.get("depth") - readInstalled_(folder, null, null, null, 0, d, function (er, obj) { +function readInstalled (folder, depth, cb) { + if (typeof cb !== "function") cb = depth, depth = Infinity + readInstalled_(folder, null, null, null, 0, depth, function (er, obj) { if (er) return cb(er) // now obj has all the installed things, where they're installed // figure out the inheritance links, now that the object is built. @@ -294,39 +303,3 @@ function copy (obj) { for (var i in obj) o[i] = copy(obj[i]) return o } - -if (module === require.main) { - var util = require("util") - console.error("testing") - - var called = 0 - readInstalled(process.cwd(), function (er, map) { - console.error(called ++) - if (er) return console.error(er.stack || er.message) - cleanup(map) - console.error(util.inspect(map, true, 10, true)) - }) - - var seen = [] - function cleanup (map) { - if (seen.indexOf(map) !== -1) return - seen.push(map) - for (var i in map) switch (i) { - case "_id": - case "path": - case "extraneous": case "invalid": - case "dependencies": case "name": - continue - default: delete map[i] - } - var dep = map.dependencies -// delete map.dependencies - if (dep) { -// map.dependencies = dep - for (var i in dep) if (typeof dep[i] === "object") { - cleanup(dep[i]) - } - } - return map - } -} diff --git a/node_modules/read-installed/test/basic.js b/node_modules/read-installed/test/basic.js new file mode 100644 index 000000000..0f833203f --- /dev/null +++ b/node_modules/read-installed/test/basic.js @@ -0,0 +1,34 @@ +var readInstalled = require("../read-installed.js") +var util = require("util") +console.error("testing") + +var called = 0 +readInstalled(process.cwd(), function (er, map) { + console.error(called ++) + if (er) return console.error(er.stack || er.message) + cleanup(map) + console.error(util.inspect(map, true, 10, true)) +}) + +var seen = [] +function cleanup (map) { + if (seen.indexOf(map) !== -1) return + seen.push(map) + for (var i in map) switch (i) { + case "_id": + case "path": + case "extraneous": case "invalid": + case "dependencies": case "name": + continue + default: delete map[i] + } + var dep = map.dependencies +// delete map.dependencies + if (dep) { +// map.dependencies = dep + for (var i in dep) if (typeof dep[i] === "object") { + cleanup(dep[i]) + } + } + return map +} diff --git a/package.json b/package.json index 23e2146d2..3064e126e 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,8 @@ "npmlog": "0", "ansi": "~0.1.2", "npm-registry-client": "0", - "read-package-json": "0" + "read-package-json": "0", + "read-installed": "0" }, "bundleDependencies": [ "slide", @@ -91,7 +92,8 @@ "npmlog", "ansi", "npm-registry-client", - "read-package-json" + "read-package-json", + "read-installed" ], "devDependencies": { "ronn": "https://github.com/isaacs/ronnjs/tarball/master" |