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

logical-tree: Make sure user installed modules are attached to root o…

…f logical tree

PR-URL: #9344
Fixes: #9113
  • Loading branch information...
iarna committed Aug 19, 2015
1 parent b9e57c9 commit 5ab7449e29143150a26a958cb4d92892e8547060
Showing with 73 additions and 0 deletions.
  1. +3 −0 lib/install/logical-tree.js
  2. +70 −0 test/tap/extraneous-dep-cycle-ls-ok.js
@@ -46,6 +46,9 @@ var logicalTree = module.exports = function (tree) {
requiredBy.forEach(function (parentNode) {
parentNode.children = union(parentNode.children, [node])
})
if (node.package._requiredBy.some(function (nodename) { return nodename[0] === '#' })) {
newTree.children = union(newTree.children, [node])
}
})
return newTree
}
@@ -0,0 +1,70 @@
'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(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 = '/Users/rebecca/code/npm/test/tap/extraneous-dep-cycle-ls-ok\n' +
'└─┬ moduleA@1.0.0\n' +
' └── moduleB@1.0.0\n\n'
test('extraneous-dep-cycle', function (t) {
common.npm(['ls'], {cwd: pkg}, function (er, code, stdout, stderr) {
t.ifErr(er, 'install finished successfully')
t.is(stdout, expected, 'ls output shows module')
t.end()
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})

0 comments on commit 5ab7449

Please sign in to comment.