Skip to content
Browse files

Use read-installed dependency

  • Loading branch information...
1 parent a995d4f commit cbf5f60218fc21a6a592a6856d91794477d0652d @isaacs isaacs committed Jun 11, 2012
View
4 lib/ls.js
@@ -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)
View
4 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)
})
View
4 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)
View
6 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()
})
View
16 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) {
+ ...
+})
+```
View
32 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"
+}
View
67 lib/utils/read-installed.js → ..._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
- }
-}
View
34 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
+}
View
6 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"

0 comments on commit cbf5f60

Please sign in to comment.
Something went wrong with that request. Please try again.