This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

ls: Elminate warnings about missing package.json at top level

PR-URL: #9343
Fixes: #9113
  • Loading branch information...
iarna committed Aug 19, 2015
1 parent 052ca9e commit 7626e80aa1ac699871a38cbab9e1f1cde61843c2
Showing with 80 additions and 2 deletions.
  1. +2 −1 lib/ls.js
  2. +1 −1 test/tap/ls-l-depth-0.js
  3. +77 −0 test/tap/ls-top-errors.js
View
@@ -146,7 +146,8 @@ function getLite (data, noname) {
lite.problems.push('extraneous: ' + getPackageId(data) + ' ' + (data.path || ''))
}
if (data.error && data.path !== path.resolve(npm.globalDir, '..')) {
if (data.error && data.path !== path.resolve(npm.globalDir, '..') &&
(data.error.code !== 'ENOENT' || noname)) {
lite.invalid = true
lite.problems = lite.problems || []
var message = data.error.message
View
@@ -77,7 +77,7 @@ test('#6311: npm ll --depth=0 duplicates listing', function (t) {
EXEC_OPTS,
function (err, code, stdout, stderr) {
t.ifError(err, 'npm ll ran without error')
t.is(code, 1, 'npm ll complained about there being no package.json')
t.is(code, 0, 'npm ll exited cleanly')
t.notOk(stderr, 'npm ll ran silently')
t.equal(
stdout,
View
@@ -0,0 +1,77 @@
'use strict'
var fs = require('fs')
var path = require('path')
var test = require('tap').test
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var common = require('../common-tap')
var pkg = path.resolve(__dirname, path.basename(__filename, '.js'))
var pathModA = path.join(pkg, 'node_modules', 'moduleA')
var pathModB = path.join(pkg, 'node_modules', 'moduleB')
var modA = {
name: 'moduleA',
version: '1.0.0',
_requiredBy: [ '#USER', '/moduleB' ],
dependencies: {
moduleB: '1.0.0'
}
}
var modB = {
name: 'moduleB',
version: '1.0.0',
_requiredBy: [ '/moduleA' ],
dependencies: {
moduleA: '1.0.0'
}
}
function setup () {
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
'{broken json'
)
mkdirp.sync(pathModA)
fs.writeFileSync(
path.join(pathModA, 'package.json'),
JSON.stringify(modA, null, 2)
)
mkdirp.sync(pathModB)
fs.writeFileSync(
path.join(pathModB, 'package.json'),
JSON.stringify(modB, null, 2)
)
}
function cleanup () {
rimraf.sync(pkg)
}
test('setup', function (t) {
cleanup()
setup()
t.end()
})
var expected =
'npm ERR! error in ' + pkg + ': Failed to parse json\n' +
"npm ERR! Unexpected token 'b' at 1:2\n" +
'npm ERR! {broken json\n' +
'npm ERR! ^\n'
test('ls-top-errors', function (t) {
common.npm(['ls'], {cwd: pkg}, function (er, code, stdout, stderr) {
t.ifErr(er, 'install finished successfully')
t.is(stderr, expected)
t.end()
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})

0 comments on commit 7626e80

Please sign in to comment.