Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
ls: install: Stop warning about cruft in module directories
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Sep 17, 2015
1 parent 95ee92c commit a127801
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Installer.prototype.run = function (cb) {
if (self.idealTree) {
self.idealTree.warnings.forEach(function (warning) {
if (warning.code === 'EPACKAGEJSON' && self.global) return
if (warning.code === 'ENOTDIR') return
log.warn(warning.code, warning.message)
})
}
Expand Down
11 changes: 10 additions & 1 deletion lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,15 @@ function alphasort (a, b) {
: a < b ? -1 : 0
}

function isCruft (data) {
return data.extraneous && data.error && data.error.code === 'ENOTDIR'
}

function getLite (data, noname) {
var lite = {}

if (isCruft(data)) return lite

var maxDepth = npm.config.get('depth')

if (!noname && data.name) lite.name = data.name
Expand Down Expand Up @@ -376,7 +383,9 @@ function makeArchy_ (data, long, dir, depth, parent, d) {
out.nodes = []
if (depth <= npm.config.get('depth')) {
out.nodes = Object.keys(data.dependencies || {})
.sort(alphasort).map(function (d) {
.sort(alphasort).filter(function (d) {
return !isCruft(data.dependencies[d])
}).map(function (d) {
return makeArchy_(data.dependencies[d], long, dir, depth + 1, data, d)
})
}
Expand Down
43 changes: 43 additions & 0 deletions test/tap/cruft-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'
var fs = require('graceful-fs')
var path = require('path')
var mkdirpSync = require('mkdirp').sync
var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')

var base = path.join(__dirname, path.basename(__filename, '.js'))
var cruft = path.join(base, 'node_modules', 'cruuuft')
var pkg = {
name: 'example',
version: '1.0.0',
dependencies: {}
}

function setup () {
mkdirpSync(path.dirname(cruft))
fs.writeFileSync(cruft, 'this is some cruft for sure')
fs.writeFileSync(path.join(base, 'package.json'), JSON.stringify(pkg))
}

function cleanup () {
rimraf.sync(base)
}

test('setup', function (t) {
cleanup()
setup()
t.done()
})

test('cruft', function (t) {
common.npm(['ls'], {cwd: base}, function (er, code, stdout, stderr) {
t.is(stderr, '', 'no warnings or errors from ls')
t.done()
})
})

test('cleanup', function (t) {
cleanup()
t.done()
})

0 comments on commit a127801

Please sign in to comment.