Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

read-installed@2.0.0

  • Loading branch information...
commit 1d29b17f5193d52a5c4faa412a95313dcf41ed91 1 parent ce66256
@isaacs isaacs authored
Showing with 243 additions and 62 deletions.
  1. +1 −1  lib/install.js
  2. +1 −1  lib/ls.js
  3. +4 −1 lib/prune.js
  4. +1 −1  lib/rebuild.js
  5. +1 −1  lib/utils/completion/installed-deep.js
  6. +13 −0 node_modules/read-installed/.npmignore
  7. +6 −4 node_modules/read-installed/README.md
  8. +13 −0 node_modules/read-installed/node_modules/util-extend/README.md
  9. +33 −0 node_modules/read-installed/node_modules/util-extend/extend.js
  10. +23 −0 node_modules/read-installed/node_modules/util-extend/package.json
  11. +10 −0 node_modules/read-installed/node_modules/util-extend/test.js
  12. +6 −5 node_modules/read-installed/package.json
  13. +39 −20 node_modules/read-installed/read-installed.js
  14. +3 −1 node_modules/read-installed/test/basic.js
  15. +25 −0 node_modules/read-installed/test/depth-0.js
  16. +23 −0 node_modules/read-installed/test/depth-1.js
  17. +4 −3 node_modules/read-installed/test/dev.js
  18. +27 −0 node_modules/read-installed/test/fixtures/package.json
  19. +0 −7 node_modules/read-installed/test/fixtures/peer-at-latest/node_modules/debug/package.json
  20. +0 −10 node_modules/read-installed/test/fixtures/peer-at-latest/node_modules/strong-task-emitter/package.json
  21. +2 −2 node_modules/read-installed/test/noargs.js
  22. +1 −1  package.json
  23. +7 −4 test/tap/prune.js
View
2  lib/install.js
@@ -188,7 +188,7 @@ function install (args, cb_) {
}
function findPeerInvalid (where, cb) {
- readInstalled(where, { log: log.warn }, function (er, data) {
+ readInstalled(where, { log: log.warn, dev: true }, function (er, data) {
if (er) return cb(er)
cb(null, findPeerInvalid_(data.dependencies, []))
View
2  lib/ls.js
@@ -36,7 +36,7 @@ function ls (args, silent, cb) {
})
var depth = npm.config.get("depth")
- var opt = { depth: depth, log: log.warn }
+ var opt = { depth: depth, log: log.warn, dev: true }
readInstalled(dir, opt, function (er, data) {
var bfs = bfsify(data, args)
, lite = getLite(bfs)
View
5 lib/prune.js
@@ -21,7 +21,10 @@ function prune (args, cb) {
})
function next() {
- var opt = { depth: npm.config.get("depth"), dev: npm.config.get("production") }
+ var opt = {
+ depth: npm.config.get("depth"),
+ dev: !npm.config.get("production") || npm.config.get("dev")
+ }
readInstalled(npm.prefix, opt, function (er, data) {
if (er) return cb(er)
prune_(args, data, cb)
View
2  lib/rebuild.js
@@ -14,7 +14,7 @@ rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]"
rebuild.completion = require("./utils/completion/installed-deep.js")
function rebuild (args, cb) {
- var opt = { depth: npm.config.get("depth") }
+ var opt = { depth: npm.config.get("depth"), dev: true }
readInstalled(npm.prefix, opt, function (er, data) {
log.info("readInstalled", typeof data)
if (er) return cb(er)
View
2  lib/utils/completion/installed-deep.js
@@ -7,7 +7,7 @@ function installedDeep (opts, cb) {
var local
, global
, depth = npm.config.get("depth")
- , opt = { depth: depth }
+ , opt = { depth: depth, dev: true }
if (npm.config.get("global")) local = [], next()
else readInstalled(npm.prefix, opt, function (er, data) {
View
13 node_modules/read-installed/.npmignore
@@ -0,0 +1,13 @@
+*.swp
+.*.swp
+
+.DS_Store
+*~
+.project
+.settings
+npm-debug.log
+coverage.html
+.idea
+lib-cov
+
+node_modules
View
10 node_modules/read-installed/README.md
@@ -5,21 +5,23 @@ structure with all the data.
npm uses this.
-## 1.0.0
+## 2.0.0
-Breaking changes in `1.0.0`:
+Breaking changes in `2.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
+ * `dev` optional, default false, set to true to include devDependencies
## Usage
```javascript
var readInstalled = require("read-installed")
-readInstalled(folder, { depth, log, dev }, function (er, data) {
+// optional options
+var options = { dev: false, log: fn, depth: 2 }
+readInstalled(folder, options, function (er, data) {
...
})
```
View
13 node_modules/read-installed/node_modules/util-extend/README.md
@@ -0,0 +1,13 @@
+# util-extend
+
+The Node object extending function that Node uses for Node!
+
+## Usage
+
+```js
+var extend = require('util-extend');
+function functionThatTakesOptions(options) {
+ var options = extend(defaults, options);
+ // now any unset options are set to the defaults.
+}
+```
View
33 node_modules/read-installed/node_modules/util-extend/extend.js
@@ -0,0 +1,33 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+module.exports = extend;
+function extend(origin, add) {
+ // Don't do anything if add isn't an object
+ if (!add || typeof add !== 'object') return origin;
+
+ var keys = Object.keys(add);
+ var i = keys.length;
+ while (i--) {
+ origin[keys[i]] = add[keys[i]];
+ }
+ return origin;
+}
View
23 node_modules/read-installed/node_modules/util-extend/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "util-extend",
+ "version": "1.0.1",
+ "description": "Node's internal object extension function",
+ "main": "extend.js",
+ "scripts": {
+ "test": "node test.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/isaacs/util-extend"
+ },
+ "author": "",
+ "license": "MIT",
+ "readmeFilename": "README.md",
+ "readme": "# util-extend\n\nThe Node object extending function that Node uses for Node!\n\n## Usage\n\n```js\nvar extend = require('util-extend');\nfunction functionThatTakesOptions(options) {\n var options = extend(defaults, options);\n // now any unset options are set to the defaults.\n}\n```\n",
+ "bugs": {
+ "url": "https://github.com/isaacs/util-extend/issues"
+ },
+ "homepage": "https://github.com/isaacs/util-extend",
+ "_id": "util-extend@1.0.1",
+ "_from": "util-extend@^1.0.1"
+}
View
10 node_modules/read-installed/node_modules/util-extend/test.js
@@ -0,0 +1,10 @@
+var assert = require('assert');
+var extend = require('./');
+assert.deepEqual(extend({a:1}), {a:1});
+assert.deepEqual(extend({a:1}, []), {a:1});
+assert.deepEqual(extend({a:1}, null), {a:1});
+assert.deepEqual(extend({a:1}, true), {a:1});
+assert.deepEqual(extend({a:1}, false), {a:1});
+assert.deepEqual(extend({a:1}, {b:2}), {a:1, b:2});
+assert.deepEqual(extend({a:1, b:2}, {b:3}), {a:1, b:3});
+console.log('ok');
View
11 node_modules/read-installed/package.json
@@ -1,19 +1,20 @@
{
"name": "read-installed",
"description": "Read all the installed packages in a folder, and return a tree structure with all the data.",
- "version": "1.0.0",
+ "version": "2.0.0",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/read-installed"
},
"main": "read-installed.js",
"scripts": {
- "test": "tap ./test/"
+ "test": "tap ./test/*.js"
},
"dependencies": {
+ "read-package-json": "1",
"semver": "2",
"slide": "~1.1.3",
- "read-package-json": "1",
+ "util-extend": "^1.0.1",
"graceful-fs": "~2"
},
"optionalDependencies": {
@@ -28,12 +29,12 @@
"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",
+ "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## 2.0.0\n\nBreaking changes in `2.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, default false, set to true to include devDependencies\n\n## Usage\n\n```javascript\nvar readInstalled = require(\"read-installed\")\n// optional options\nvar options = { dev: false, log: fn, depth: 2 }\nreadInstalled(folder, options, 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",
+ "_id": "read-installed@2.0.0",
"_from": "read-installed@latest"
}
View
59 node_modules/read-installed/read-installed.js
@@ -98,6 +98,8 @@ var asyncMap = require("slide").asyncMap
var semver = require("semver")
var readJson = require("read-package-json")
var url = require("url")
+var util = require("util")
+var extend = require("util-extend")
module.exports = readInstalled
@@ -105,20 +107,31 @@ function readInstalled (folder, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
+ } else {
+ opts = extend({}, opts)
}
- var depth = Infinity || opts.depth, log = function () {} || opts.log, dev = false || opts.dev
- readInstalled_(folder, null, null, null, 0, depth, dev, function (er, obj) {
+ if (typeof opts.depth !== 'number')
+ opts.depth = Infinity
+
+ opts.depth = Math.max(0, opts.depth)
+
+ if (typeof opts.log !== 'function')
+ opts.log = function () {}
+
+ opts.dev = !!opts.dev
+
+ readInstalled_(folder, null, null, null, 0, opts, 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.
- resolveInheritance(obj, log)
+ resolveInheritance(obj, opts)
cb(null, obj)
})
}
var rpSeen = {}
-function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, dev, cb) {
+function readInstalled_ (folder, parent, name, reqver, depth, opts, cb) {
var installed
, obj
, real
@@ -181,29 +194,36 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, dev, cb)
obj.invalid = true
}
- if (parent
- && !(name in parent.dependencies)
- && (dev || !(name in (parent.devDependencies || {})))) {
- obj.extraneous = true
+ if (parent) {
+ var deps = parent.dependencies || {}
+ var inDeps = name in deps
+ var devDeps = parent.devDependencies || {}
+ var inDev = opts.dev && (name in devDeps)
+ if (!inDeps && !inDev) {
+ obj.extraneous = true
+ }
}
+
obj.path = obj.path || folder
obj.realPath = real
obj.link = link
if (parent && !obj.link) obj.parent = parent
rpSeen[real] = obj
obj.depth = depth
- //if (depth >= maxDepth) return cb(null, obj)
+ //if (depth >= opts.depth) return cb(null, obj)
asyncMap(installed, function (pkg, cb) {
var rv = obj.dependencies[pkg]
- if (!rv && obj.devDependencies && !dev) rv = obj.devDependencies[pkg]
- if (depth >= maxDepth) {
+ if (!rv && obj.devDependencies && opts.dev)
+ rv = obj.devDependencies[pkg]
+
+ if (depth >= opts.depth) {
// just try to get the version number
var pkgfolder = path.resolve(folder, "node_modules", pkg)
, jsonFile = path.resolve(pkgfolder, "package.json")
return readJson(jsonFile, function (er, depData) {
// already out of our depth, ignore errors
if (er || !depData || !depData.version) return cb(null, obj)
- if (depth === maxDepth) {
+ if (depth === opts.depth) {
// edge case, ignore dependencies
depData.dependencies = {}
depData.peerDependencies = {}
@@ -216,8 +236,7 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, dev, cb)
}
readInstalled_( path.resolve(folder, "node_modules/"+pkg)
- , obj, pkg, obj.dependencies[pkg], depth + 1, maxDepth
- , dev
+ , obj, pkg, obj.dependencies[pkg], depth + 1, opts
, cb )
}, function (er, installedData) {
@@ -242,7 +261,7 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, dev, cb)
// starting from a root object, call findUnmet on each layer of children
var riSeen = []
-function resolveInheritance (obj, log) {
+function resolveInheritance (obj, opts) {
if (typeof obj !== "object") return
if (riSeen.indexOf(obj) !== -1) return
riSeen.push(obj)
@@ -250,18 +269,18 @@ function resolveInheritance (obj, log) {
obj.dependencies = {}
}
Object.keys(obj.dependencies).forEach(function (dep) {
- findUnmet(obj.dependencies[dep], log)
+ findUnmet(obj.dependencies[dep], opts)
})
Object.keys(obj.dependencies).forEach(function (dep) {
- resolveInheritance(obj.dependencies[dep], log)
+ resolveInheritance(obj.dependencies[dep], opts)
})
- findUnmet(obj, log)
+ findUnmet(obj, opts)
}
// find unmet deps by walking up the tree object.
// No I/O
var fuSeen = []
-function findUnmet (obj, log) {
+function findUnmet (obj, opts) {
if (fuSeen.indexOf(obj) !== -1) return
fuSeen.push(obj)
//console.error("find unmet", obj.name, obj.parent && obj.parent.name)
@@ -288,7 +307,7 @@ function findUnmet (obj, log) {
&& 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]
+ opts.log("unmet dependency", obj.path + " requires "+d+"@'"+deps[d]
+"' but will load\n"
+found.path+",\nwhich is version "+found.version
)
View
4 node_modules/read-installed/test/basic.js
@@ -1,5 +1,5 @@
var readInstalled = require("../read-installed.js")
-var json = require("../package.json")
+var json = require("./fixtures/package.json")
var known = [].concat(Object.keys(json.dependencies)
, Object.keys(json.optionalDependencies)
, Object.keys(json.devDependencies)).sort()
@@ -8,6 +8,7 @@ var path = require("path")
test("make sure that it works", function (t) {
readInstalled(path.join(__dirname, "../"), {
+ dev: true,
log: console.error
}, function (er, map) {
t.notOk(er, "er should be bull")
@@ -21,6 +22,7 @@ test("make sure that it works", function (t) {
t.end()
})
})
+
var seen = []
function cleanup (map) {
if (seen.indexOf(map) !== -1) return
View
25 node_modules/read-installed/test/depth-0.js
@@ -0,0 +1,25 @@
+var readInstalled = require("../read-installed.js")
+var test = require("tap").test
+var json = require("../package.json")
+var path = require("path")
+var known = [].concat(Object.keys(json.dependencies)
+ , Object.keys(json.optionalDependencies)
+ , Object.keys(json.devDependencies)).sort()
+
+test("make sure that it works with depth=0", function (t) {
+ readInstalled(path.join(__dirname, "../"), {
+ depth: 0
+ }, 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)
+ // Exclude self from dependencies when depth = 0
+ delete map.dependencies[json.name]
+ var subdeps = Object.keys(map.dependencies).reduce(function(acc, dep) {
+ acc += Object.keys(map.dependencies[dep].dependencies).length;
+ return acc;
+ }, 0);
+ t.equal(subdeps, 0, "there should be no sub dependencies")
+ t.end()
+ })
+})
View
23 node_modules/read-installed/test/depth-1.js
@@ -0,0 +1,23 @@
+var readInstalled = require("../read-installed.js")
+var test = require("tap").test
+var json = require("../package.json")
+var path = require("path")
+var known = [].concat(Object.keys(json.dependencies)
+ , Object.keys(json.optionalDependencies)
+ , Object.keys(json.devDependencies)).sort()
+
+test("make sure that it works with depth=1", function (t) {
+ readInstalled(path.join(__dirname, "../"), {
+ depth: 1
+ }, 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)
+ var subdeps = Object.keys(map.dependencies).reduce(function(acc, dep) {
+ acc += Object.keys(map.dependencies[dep].dependencies).length;
+ return acc;
+ }, 0);
+ t.notEqual(subdeps, 0, "there should some sub dependencies")
+ t.end()
+ })
+})
View
7 node_modules/read-installed/test/dev.js
@@ -1,6 +1,6 @@
var readInstalled = require("../read-installed.js")
var test = require("tap").test
-var json = require("../package.json")
+var json = require("./fixtures/package.json")
var path = require("path")
var known = [].concat(Object.keys(json.dependencies)
, Object.keys(json.optionalDependencies)
@@ -8,8 +8,9 @@ var known = [].concat(Object.keys(json.dependencies)
test("make sure that it works without dev deps", function (t) {
readInstalled(path.join(__dirname, "../"), {
- log: console.error
- , dev: true }, function (er, map) {
+ log: console.error,
+ dev: false
+ }, 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)
View
27 node_modules/read-installed/test/fixtures/package.json
@@ -0,0 +1,27 @@
+{
+ "name": "read-installed",
+ "description": "Read all the installed packages in a folder, and return a tree structure with all the data.",
+ "version": "1.0.0",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/isaacs/read-installed"
+ },
+ "main": "read-installed.js",
+ "scripts": {
+ "test": "tap ./test/"
+ },
+ "dependencies": {
+ "semver": "2",
+ "slide": "~1.1.3",
+ "read-package-json": "1",
+ "util-extend":"1"
+ },
+ "optionalDependencies": {
+ "graceful-fs": "~2"
+ },
+ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
+ "license": "ISC",
+ "devDependencies": {
+ "tap": "~0.4.8"
+ }
+}
View
7 node_modules/read-installed/test/fixtures/peer-at-latest/node_modules/debug/package.json
@@ -1,7 +0,0 @@
-{
- "name": "debug",
- "version": "0.7.4",
- "dependencies": {},
- "_id": "debug@0.7.4",
- "_from": "debug@latest"
-}
View
10 node_modules/read-installed/test/fixtures/peer-at-latest/node_modules/strong-task-emitter/package.json
@@ -1,10 +0,0 @@
-{
- "name": "strong-task-emitter",
- "version": "0.0.4",
- "dependencies": {
- "debug": "latest"
- },
- "_id": "strong-task-emitter@0.0.4",
- "_from": "strong-task-emitter@0.0.4",
- "_resolved": "https://registry.npmjs.org/strong-task-emitter/-/strong-task-emitter-0.0.4.tgz"
-}
View
4 node_modules/read-installed/test/noargs.js
@@ -1,6 +1,6 @@
var readInstalled = require("../read-installed.js")
var test = require("tap").test
-var json = require("../package.json")
+var json = require("./fixtures/package.json")
var path = require("path")
var known = [].concat(Object.keys(json.dependencies)
, Object.keys(json.optionalDependencies)
@@ -14,7 +14,7 @@ test("make sure that it works without dev deps", function (t) {
var deps = Object.keys(map.dependencies).sort()
t.equal(deps.length, known.length, "array lengths are equal")
t.deepEqual(deps, known, "arrays should be equal")
- t.notOk(map.dependencies.tap.extraneous, 'extraneous is set on devDep')
+ t.ok(map.dependencies.tap.extraneous, 'extraneous is set on devDep')
t.end()
})
})
View
2  package.json
@@ -70,7 +70,7 @@
"osenv": "0",
"path-is-inside": "~1.0.0",
"read": "~1.0.4",
- "read-installed": "~1.0.0",
+ "read-installed": "^2.0.0",
"read-package-json": "~1.1.7",
"request": "~2.30.0",
"retry": "~0.6.0",
View
11 test/tap/prune.js
@@ -6,6 +6,7 @@ var rimraf = require("rimraf")
var mr = require("npm-registry-mock")
var common = require("../common-tap.js")
var spawn = require("child_process").spawn
+var env = { PATH: process.env.PATH }
var pkg = __dirname + "/prune"
var cache = pkg + "/cache"
@@ -20,14 +21,16 @@ test("reg mock", function (t) {
})
})
+
test("npm install", function (t) {
+ rimraf.sync(pkg + "/node_modules")
var c = spawn(node, [
npm, "install",
"--cache=" + cache,
"--registry=" + common.registry,
"--loglevel=silent",
"--production=false"
- ], { cwd: pkg })
+ ], { cwd: pkg, env: env })
c.stderr.on("data", function(d) {
t.fail("Should not get data on stderr: " + d)
})
@@ -44,7 +47,7 @@ test("npm install test-package", function (t) {
"--registry=" + common.registry,
"--loglevel=silent",
"--production=false"
- ], { cwd: pkg })
+ ], { cwd: pkg, env: env })
c.stderr.on("data", function(d) {
t.fail("Should not get data on stderr: " + d)
})
@@ -65,7 +68,7 @@ test("npm prune", function (t) {
npm, "prune",
"--loglevel=silent",
"--production=false"
- ], { cwd: pkg })
+ ], { cwd: pkg, env: env })
c.stderr.on("data", function(d) {
t.fail("Should not get data on stderr: " + d)
})
@@ -86,7 +89,7 @@ test("npm prune", function (t) {
npm, "prune",
"--loglevel=silent",
"--production"
- ], { cwd: pkg })
+ ], { cwd: pkg, env: env })
c.stderr.on("data", function(d) {
t.fail("Should not get data on stderr: " + d)
})
Please sign in to comment.
Something went wrong with that request. Please try again.