Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ module.exports = cls => class Reifier extends cls {
tree: this.diff,
visit: diff => {
const node = diff.ideal
if (node && !node.isRoot && node.package.bundleDependencies &&
if (node && !node.isProjectRoot && node.package.bundleDependencies &&
node.package.bundleDependencies.length) {
maxBundleDepth = Math.max(maxBundleDepth, node.depth)
if (!bundlesByDepth.has(node.depth))
Expand Down Expand Up @@ -811,7 +811,7 @@ module.exports = cls => class Reifier extends cls {
dfwalk({
tree: this.diff,
leave: diff => {
if (!diff.ideal.isRoot)
if (!diff.ideal.isProjectRoot)
nodes.push(diff.ideal)
},
// process adds before changes, ignore removals
Expand Down
21 changes: 12 additions & 9 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class Node {

// true for packages installed directly in the global node_modules folder
get globalTop () {
return this.global && this.parent.isRoot
return this.global && this.parent.isProjectRoot
}

get workspaces () {
Expand Down Expand Up @@ -294,8 +294,11 @@ class Node {
const { name = '', version = '' } = this.package
// root package will prefer package name over folder name,
// and never be called an alias.
const myname = this.isRoot ? name || this.name : this.name
const alias = !this.isRoot && name && myname !== name ? `npm:${name}@` : ''
const { isProjectRoot } = this
const myname = isProjectRoot ? name || this.name
: this.name
const alias = !isProjectRoot && name && myname !== name ? `npm:${name}@`
: ''
return `${myname}@${alias}${version}`
}

Expand Down Expand Up @@ -339,14 +342,14 @@ class Node {
}

[_explain] (edge, seen) {
if (this.isRoot && !this.sourceReference) {
if (this.isProjectRoot && !this.sourceReference) {
return {
location: this.path,
}
}

const why = {
name: this.isRoot ? this.package.name : this.name,
name: this.isProjectRoot ? this.package.name : this.name,
version: this.package.version,
}
if (this.errors.length || !this.package.name || !this.package.version) {
Expand Down Expand Up @@ -384,7 +387,7 @@ class Node {
// and are not keeping it held in this spot anyway.
const edges = []
for (const edge of this.edgesIn) {
if (!edge.valid && !edge.from.isRoot)
if (!edge.valid && !edge.from.isProjectRoot)
continue

edges.push(edge)
Expand Down Expand Up @@ -453,7 +456,7 @@ class Node {
}

get isWorkspace () {
if (this.isRoot)
if (this.isProjectRoot)
return false
const { root } = this
const { type, to } = root.edgesOut.get(this.package.name) || {}
Expand Down Expand Up @@ -904,8 +907,8 @@ class Node {
if (this.isLink)
return node.isLink && this.target.matches(node.target)

// if they're two root nodes, they're different if the paths differ
if (this.isRoot && node.isRoot)
// if they're two project root nodes, they're different if the paths differ
if (this.isProjectRoot && node.isProjectRoot)
return this.path === node.path

// if the integrity matches, then they're the same.
Expand Down
31 changes: 31 additions & 0 deletions test/arborist/rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,34 @@ t.test('workspaces', async t => {
)
})
})

t.test('put bins in the right place for linked-global top pkgs', async t => {
const path = t.testdir({
lib: t.fixture('symlink', 'target'),
target: {
node_modules: {
foo: {
'package.json': JSON.stringify({
name: 'foo',
version: '1.2.3',
bin: 'foo',
}),
foo: 'the bin script',
},
},
},
})
const binpath = resolve(path, isWindows ? 'lib' : 'bin')
const arb = new Arborist({ path: path + '/lib', registry, global: true })
await arb.rebuild()
const expect = isWindows ? [
'foo',
'foo.cmd',
'foo.ps1',
] : ['foo']
const test = isWindows ? 'isFile' : 'isSymbolicLink'
for (const f of expect) {
const p = resolve(binpath, f)
t.equal(fs.lstatSync(p)[test](), true, `${test} ${binpath}/${f}`)
}
})
18 changes: 18 additions & 0 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2163,3 +2163,21 @@ t.test('virtual references to root node has devDep edges', async t => {
})
t.equal(virtualRoot.edgesOut.get('a').type, 'dev')
})

t.test('globaTop set for children of global link root target', async t => {
const root = new Link({
path: '/usr/local/lib',
realpath: '/data/lib',
global: true,
})
root.target = new Node({
path: '/data/lib',
global: true,
root,
})
const gtop = new Node({
parent: root.target,
pkg: { name: 'foo', version: '1.2.3' },
})
t.equal(gtop.globalTop, true)
})