Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan You <yyou@google.com>2014-05-14 21:05:14 +0400
committerisaacs <i@izs.me>2014-05-23 05:02:44 +0400
commit05bf3a765b471c9ad3898a51498b10d6c10b250e (patch)
tree26f4b8c910f5936e3337b8ebd162791e86829a0a
parent0c123255398d6e2c9a072e5dba429b826c65ebf9 (diff)
fix `npm ls` labeling issue
-rw-r--r--lib/ls.js7
-rw-r--r--test/tap/ls-depth-unmet.js97
-rw-r--r--test/tap/ls-depth-unmet/package.json10
3 files changed, 110 insertions, 4 deletions
diff --git a/lib/ls.js b/lib/ls.js
index efe503b62..12e4d2edc 100644
--- a/lib/ls.js
+++ b/lib/ls.js
@@ -128,8 +128,7 @@ function getLite (data, noname) {
var dep = data.dependencies[d]
if (typeof dep === "string") {
lite.problems = lite.problems || []
- var p
- if (data.depth >= maxDepth) {
+ if (data.depth > maxDepth) {
p = "max depth reached: "
} else {
p = "missing: "
@@ -223,14 +222,14 @@ function makeArchy (data, long, dir) {
function makeArchy_ (data, long, dir, depth, parent, d) {
var color = npm.color
if (typeof data === "string") {
- if (depth < npm.config.get("depth")) {
+ if (depth -1 <= npm.config.get("depth")) {
// just missing
var p = parent.link || parent.path
var unmet = "UNMET DEPENDENCY"
if (color) {
unmet = "\033[31;40m" + unmet + "\033[0m"
}
- data = unmet + " " + d + " " + data
+ data = unmet + " " + d + "@" + data
} else {
data = d+"@"+ data
}
diff --git a/test/tap/ls-depth-unmet.js b/test/tap/ls-depth-unmet.js
new file mode 100644
index 000000000..1ac85efc9
--- /dev/null
+++ b/test/tap/ls-depth-unmet.js
@@ -0,0 +1,97 @@
+var common = require('../common-tap')
+ , test = require('tap').test
+ , path = require('path')
+ , rimraf = require('rimraf')
+ , osenv = require('osenv')
+ , mkdirp = require('mkdirp')
+ , pkg = __dirname + '/ls-depth-unmet'
+ , cache = pkg + '/cache'
+ , tmp = pkg + '/tmp'
+ , node = process.execPath
+ , npm = path.resolve(__dirname, '../../cli.js')
+ , mr = require('npm-registry-mock')
+ , opts = {cwd: pkg}
+
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg + '/cache')
+ rimraf.sync(pkg + '/tmp')
+ rimraf.sync(pkg + '/node_modules')
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(pkg + '/cache')
+ mkdirp.sync(pkg + '/tmp')
+ mr(common.port, function (s) {
+ var cmd = ['install', 'underscore@1.3.1', 'mkdirp', 'test-package-with-one-dep', '--registry=' + common.registry]
+ common.npm(cmd, opts, function (er, c) {
+ if (er) throw er
+ t.equal(c, 0)
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test('npm ls --depth=0', function (t) {
+ common.npm(['ls', '--depth=0'], opts, function (er, c, out) {
+ if (er) throw er
+ t.equal(c, 1)
+ t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
+ , "output contains optimist@0.6.0 and labeled as unmet dependency")
+ t.has(out, /mkdirp@0\.3\.5 extraneous/
+ , "output contains mkdirp@0.3.5 and labeled as extraneous")
+ t.has(out, /underscore@1\.3\.1 invalid/
+ , "output contains underscore@1.3.1 and labeled as invalid")
+ t.has(out, /test-package-with-one-dep@0\.0\.0\n/
+ , "output contains test-package-with-one-dep@0.0.0 and has no labels")
+ t.doesNotHave(out, /test-package@0\.0\.0/
+ , "output does not contain test-package@0.0.0 which is at depth=1")
+ t.end()
+ })
+})
+
+test('npm ls --depth=1', function (t) {
+ common.npm(['ls', '--depth=1'], opts, function (er, c, out) {
+ if (er) throw er
+ t.equal(c, 1)
+ t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
+ , "output contains optimist@0.6.0 and labeled as unmet dependency")
+ t.has(out, /mkdirp@0\.3\.5 extraneous/
+ , "output contains mkdirp@0.3.5 and labeled as extraneous")
+ t.has(out, /underscore@1\.3\.1 invalid/
+ , "output contains underscore@1.3.1 and labeled as invalid")
+ t.has(out, /test-package-with-one-dep@0\.0\.0\n/
+ , "output contains test-package-with-one-dep@0.0.0 and has no labels")
+ t.has(out, /test-package@0\.0\.0/
+ , "output contains test-package@0.0.0 which is at depth=1")
+ t.end()
+ })
+})
+
+test('npm ls --depth=Infinity', function (t) {
+ // travis has a preconfigured depth=0, in general we can not depend
+ // on the default value in all environments, so explictly set it here
+ common.npm(['ls', '--depth=Infinity'], opts, function (er, c, out) {
+ if (er) throw er
+ t.equal(c, 1)
+ t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
+ , "output contains optimist@0.6.0 and labeled as unmet dependency")
+ t.has(out, /mkdirp@0\.3\.5 extraneous/
+ , "output contains mkdirp@0.3.5 and labeled as extraneous")
+ t.has(out, /underscore@1\.3\.1 invalid/
+ , "output contains underscore@1.3.1 and labeled as invalid")
+ t.has(out, /test-package-with-one-dep@0\.0\.0\n/
+ , "output contains test-package-with-one-dep@0.0.0 and has no labels")
+ t.has(out, /test-package@0\.0\.0/
+ , "output contains test-package@0.0.0 which is at depth=1")
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
diff --git a/test/tap/ls-depth-unmet/package.json b/test/tap/ls-depth-unmet/package.json
new file mode 100644
index 000000000..391fa8d5b
--- /dev/null
+++ b/test/tap/ls-depth-unmet/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "ls-depth-umnet",
+ "author": "Evan You",
+ "version": "0.0.0",
+ "dependencies": {
+ "test-package-with-one-dep": "0.0.0",
+ "underscore": "1.5.1",
+ "optimist": "0.6.0"
+ }
+} \ No newline at end of file