diff options
author | isaacs <i@izs.me> | 2014-02-15 05:33:03 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-02-15 05:33:03 +0400 |
commit | bb6fb4d158f175ddeb2956b361f854c273b6bed0 (patch) | |
tree | 0764197a5625d1d590242d08dd932557fcaab028 | |
parent | 3ce6905bf6b0963956d7dbb8a89fc29d379de91c (diff) |
read-installed@1.0.0
-rw-r--r-- | lib/install.js | 2 | ||||
-rw-r--r-- | lib/ls.js | 3 | ||||
-rw-r--r-- | lib/prune.js | 3 | ||||
-rw-r--r-- | lib/rebuild.js | 3 | ||||
-rw-r--r-- | lib/utils/completion/installed-deep.js | 8 | ||||
-rw-r--r-- | node_modules/read-installed/README.md | 13 | ||||
-rw-r--r-- | node_modules/read-installed/package.json | 26 | ||||
-rw-r--r-- | node_modules/read-installed/read-installed.js | 28 | ||||
-rw-r--r-- | node_modules/read-installed/test/basic.js | 29 | ||||
-rw-r--r-- | package.json | 2 |
10 files changed, 79 insertions, 38 deletions
diff --git a/lib/install.js b/lib/install.js index f0604a9ce..e08df124d 100644 --- a/lib/install.js +++ b/lib/install.js @@ -187,7 +187,7 @@ function install (args, cb_) { } function findPeerInvalid (where, cb) { - readInstalled(where, log.warn, function (er, data) { + readInstalled(where, { log: log.warn }, function (er, data) { if (er) return cb(er) cb(null, findPeerInvalid_(data.dependencies, [])) @@ -36,7 +36,8 @@ function ls (args, silent, cb) { }) var depth = npm.config.get("depth") - readInstalled(dir, depth, log.warn, function (er, data) { + var opt = { depth: depth, log: log.warn } + readInstalled(dir, opt, function (er, data) { var bfs = bfsify(data, args) , lite = getLite(bfs) diff --git a/lib/prune.js b/lib/prune.js index 0e13da13b..b4836cc6d 100644 --- a/lib/prune.js +++ b/lib/prune.js @@ -21,7 +21,8 @@ function prune (args, cb) { }) function next() { - readInstalled(npm.prefix, npm.config.get("depth"), function (er, data) { + var opt = { depth: npm.config.get("depth") } + readInstalled(npm.prefix, opt, function (er, data) { if (er) return cb(er) prune_(args, data, cb) }) diff --git a/lib/rebuild.js b/lib/rebuild.js index 7cea3efff..a156acccf 100644 --- a/lib/rebuild.js +++ b/lib/rebuild.js @@ -14,7 +14,8 @@ rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]" rebuild.completion = require("./utils/completion/installed-deep.js") function rebuild (args, cb) { - readInstalled(npm.prefix, npm.config.get("depth"), function (er, data) { + var opt = { depth: npm.config.get("depth") } + readInstalled(npm.prefix, opt, 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 b49d7bb77..99e320788 100644 --- a/lib/utils/completion/installed-deep.js +++ b/lib/utils/completion/installed-deep.js @@ -6,12 +6,16 @@ var npm = require("../../npm.js") function installedDeep (opts, cb) { var local , global + , depth = npm.config.get("depth") + , opt = { depth: depth } + if (npm.config.get("global")) local = [], next() - else readInstalled(npm.prefix, npm.config.get("depth"), function (er, data) { + else readInstalled(npm.prefix, opt, function (er, data) { local = getNames(data || {}) next() }) - readInstalled(npm.config.get("prefix"), npm.config.get("depth"), function (er, data) { + + readInstalled(npm.config.get("prefix"), opt, function (er, data) { global = getNames(data || {}) next() }) diff --git a/node_modules/read-installed/README.md b/node_modules/read-installed/README.md index 616371ef9..535a8496f 100644 --- a/node_modules/read-installed/README.md +++ b/node_modules/read-installed/README.md @@ -5,12 +5,21 @@ structure with all the data. npm uses this. +## 1.0.0 + +Breaking changes in `1.0.0`: + +The second argument is now an `Object` that contains the following keys: + + * `depth` optional, defaults to Infinity + * `log` optional log Function + * `dev` optional, dev=true to mark devDeps as extraneous + ## Usage ```javascript var readInstalled = require("read-installed") -// depth is optional, defaults to Infinity -readInstalled(folder, depth, logFunction, function (er, data) { +readInstalled(folder, { depth, log, dev }, function (er, data) { ... }) ``` diff --git a/node_modules/read-installed/package.json b/node_modules/read-installed/package.json index 41f16e288..16836d266 100644 --- a/node_modules/read-installed/package.json +++ b/node_modules/read-installed/package.json @@ -1,23 +1,39 @@ { "name": "read-installed", "description": "Read all the installed packages in a folder, and return a tree structure with all the data.", - "version": "0.2.5", + "version": "1.0.0", "repository": { "type": "git", "url": "git://github.com/isaacs/read-installed" }, "main": "read-installed.js", "scripts": { - "test": "node test/basic.js" + "test": "tap ./test/" }, "dependencies": { "semver": "2", "slide": "~1.1.3", - "read-package-json": "1" + "read-package-json": "1", + "graceful-fs": "~2" }, "optionalDependencies": { "graceful-fs": "~2" }, - "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", - "license": "ISC" + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "license": "ISC", + "devDependencies": { + "tap": "~0.4.8" + }, + "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## 1.0.0\n\nBreaking changes in `1.0.0`:\n\nThe second argument is now an `Object` that contains the following keys:\n\n * `depth` optional, defaults to Infinity\n * `log` optional log Function\n * `dev` optional, dev=true to mark devDeps as extraneous\n\n## Usage\n\n```javascript\nvar readInstalled = require(\"read-installed\")\nreadInstalled(folder, { depth, log, dev }, function (er, data) {\n ...\n})\n```\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/isaacs/read-installed/issues" + }, + "homepage": "https://github.com/isaacs/read-installed", + "_id": "read-installed@1.0.0", + "_from": "read-installed@latest" } diff --git a/node_modules/read-installed/read-installed.js b/node_modules/read-installed/read-installed.js index 2920d7d66..9ca482dab 100644 --- a/node_modules/read-installed/read-installed.js +++ b/node_modules/read-installed/read-installed.js @@ -101,17 +101,14 @@ var url = require("url") module.exports = readInstalled -function readInstalled (folder, depth_, log_, cb_) { - var depth = Infinity, log = function () {}, cb - for (var i = 1; i < arguments.length - 1; i++) { - if (typeof arguments[i] === 'number') - depth = arguments[i] - else if (typeof arguments[i] === 'function') - log = arguments[i] +function readInstalled (folder, opts, cb) { + if (typeof opts === 'function') { + cb = opts + opts = {} } - cb = arguments[i] + var depth = Infinity || opts.depth, log = function () {} || opts.log, dev = false || opts.dev - readInstalled_(folder, null, null, null, 0, depth, function (er, obj) { + readInstalled_(folder, null, null, null, 0, depth, dev, 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. @@ -121,7 +118,7 @@ function readInstalled (folder, depth_, log_, cb_) { } var rpSeen = {} -function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { +function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, dev, cb) { var installed , obj , real @@ -177,7 +174,7 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { obj.realName = name || obj.name obj.dependencies = obj.dependencies || {} - // "foo":"http://blah" is always presumed valid + // "foo":"http://blah" and "foo":"latest" are always presumed valid if (reqver && semver.validRange(reqver, true) && !semver.satisfies(obj.version, reqver, true)) { @@ -186,7 +183,7 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { if (parent && !(name in parent.dependencies) - && !(name in (parent.devDependencies || {}))) { + && (dev || !(name in (parent.devDependencies || {})))) { obj.extraneous = true } obj.path = obj.path || folder @@ -198,7 +195,7 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { //if (depth >= maxDepth) return cb(null, obj) asyncMap(installed, function (pkg, cb) { var rv = obj.dependencies[pkg] - if (!rv && obj.devDependencies) rv = obj.devDependencies[pkg] + if (!rv && obj.devDependencies && !dev) rv = obj.devDependencies[pkg] if (depth >= maxDepth) { // just try to get the version number var pkgfolder = path.resolve(folder, "node_modules", pkg) @@ -220,6 +217,7 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { readInstalled_( path.resolve(folder, "node_modules/"+pkg) , obj, pkg, obj.dependencies[pkg], depth + 1, maxDepth + , dev , cb ) }, function (er, installedData) { @@ -285,9 +283,9 @@ function findUnmet (obj, log) { r = r.link ? null : r.parent continue } + // "foo":"http://blah" and "foo":"latest" are always presumed valid if ( typeof deps[d] === "string" - // url deps presumed innocent. - && !url.parse(deps[d]).protocol + && semver.validRange(deps[d], true) && !semver.satisfies(found.version, deps[d], true)) { // the bad thing will happen log("unmet dependency", obj.path + " requires "+d+"@'"+deps[d] diff --git a/node_modules/read-installed/test/basic.js b/node_modules/read-installed/test/basic.js index 2b0c03983..a6c5ff546 100644 --- a/node_modules/read-installed/test/basic.js +++ b/node_modules/read-installed/test/basic.js @@ -1,15 +1,26 @@ var readInstalled = require("../read-installed.js") -var util = require("util") -console.error("testing") +var json = require("../package.json") +var known = [].concat(Object.keys(json.dependencies) + , Object.keys(json.optionalDependencies) + , Object.keys(json.devDependencies)).sort() +var test = require("tap").test +var path = require("path") -var called = 0 -readInstalled(process.cwd(), console.error, 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)) +test("make sure that it works", function (t) { + readInstalled(path.join(__dirname, "../"), { + log: console.error + }, function (er, map) { + t.notOk(er, "er should be bull") + t.ok(map, "map should be data") + if (er) return console.error(er.stack || er.message) + cleanup(map) + var deps = Object.keys(map.dependencies).sort() + t.equal(known.length, deps.length, "array lengths are equal") + t.deepEqual(known, deps, "arrays should be equal") + t.notOk(map.dependencies.tap.extraneous, 'extraneous not set on devDep') + t.end() + }) }) - var seen = [] function cleanup (map) { if (seen.indexOf(map) !== -1) return diff --git a/package.json b/package.json index 7a4065e83..d6c937950 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "ansi": "~0.2.1", "npm-registry-client": "~0.4.2", "read-package-json": "~1.1.7", - "read-installed": "~0.2.2", + "read-installed": "~1.0.0", "glob": "~3.2.6", "init-package-json": "0.0.14", "osenv": "0", |