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

Commit

Permalink
Add edge.bundled flag, include in explain() output
Browse files Browse the repository at this point in the history
PR-URL: #241
Credit: @kumavis
Close: #241
Reviewed-by: @isaacs
  • Loading branch information
kumavis authored and isaacs committed Mar 1, 2021
1 parent 910f736 commit 63ec6dd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/edge.js
Expand Up @@ -87,16 +87,24 @@ class Edge {

// return the edge data, and an explanation of how that edge came to be here
[_explain] (seen) {
const { error, from } = this
const { error, from, bundled } = this
return {
type: this.type,
name: this.name,
spec: this.spec,
...(bundled ? { bundled } : {}),
...(error ? { error } : {}),
...(from ? { from: from.explain(null, seen) } : {}),
}
}

get bundled () {
if (!this.from)
return false
const { package: { bundleDependencies = [] } } = this.from
return bundleDependencies.includes(this.name)
}

get workspace () {
return this[_type] === 'workspace'
}
Expand Down
64 changes: 64 additions & 0 deletions test/edge.js
Expand Up @@ -440,3 +440,67 @@ t.match(
},
'should return a minimal human-readable representation of the edge obj'
)

const bundleChild = {
name: 'bundle-child',
edgesOut: new Map(),
edgesIn: new Set(),
explain: () => 'bundleChild explanation',
package: { name: 'bundle-child', version: '1.2.3' },
get version () {
return this.package.version
},
isTop: false,
parent: top,
resolve (n) {
return this.parent.resolve(n)
},
addEdgeOut (edge) {
this.edgesOut.set(edge.name, edge)
},
addEdgeIn (edge) {
this.edgesIn.add(edge)
},
}

const bundleParent = {
name: 'bundle-parent',
edgesOut: new Map(),
edgesIn: new Set(),
explain: () => 'bundleParent explanation',
package: { name: 'bundle-parent', version: '5.6.7', bundleDependencies: ['bundle-child'] },
get version () {
return this.package.version
},
isTop: false,
parent: top,
resolve (n) {
return n === 'bundle-child' ? bundleChild : undefined
},
addEdgeOut (edge) {
this.edgesOut.set(edge.name, edge)
},
addEdgeIn (edge) {
this.edgesIn.add(edge)
},
}

const bundledEdge = new Edge({
from: bundleParent,
type: 'prod',
name: 'bundle-child',
spec: '1.2.3',
})

t.ok(bundledEdge.satisfiedBy(bundleChild), 'bundled dependency')
const fromBundleDependencies = bundledEdge.from && bundledEdge.from.package.bundleDependencies
t.deepEqual(fromBundleDependencies, ['bundle-child'], 'edge.from bundledDependencies as expected')
t.deepEqual(bundledEdge.name, 'bundle-child', 'edge name as expected')
t.equal(bundledEdge.bundled, true, 'bundled prop is true')
t.deepEqual(bundledEdge.explain(), {
type: 'prod',
name: 'bundle-child',
spec: '1.2.3',
bundled: true,
from: bundleParent.explain(),
}, 'bundled edge.explain as expected')

0 comments on commit 63ec6dd

Please sign in to comment.