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

Feature: Edges have a "bundled" getter for when they represents a bundled dependency #241

Merged
merged 1 commit into from Mar 1, 2021

Conversation

kumavis
Copy link
Contributor

@kumavis kumavis commented Feb 22, 2021

when analyzing a dep graph its useful to see if an Edge is a bundledDependencies edge. this is especially useful when trying to understand the provenance of a package's content.

This PR adds a bundled getter property to the Edge.prototype which returns true if its a bundledDependencies edge or not.

References

Related to npm/cli#2750

@isaacs
Copy link
Contributor

isaacs commented Feb 22, 2021

Since it's only checking that the edge.from is the bundler (and not that the node is in a bundle at all), it would be more efficient to check edge.from.package.bundleDependencies.includes(edge.name). This would also mark the edge as a bundling edge, even if it is not resolved.

@isaacs
Copy link
Contributor

isaacs commented Feb 22, 2021

This would be really handy to make the code in a few places easier to follow, I like the idea a lot.

@kumavis
Copy link
Contributor Author

kumavis commented Feb 23, 2021

yeah sounds good, I was thrown off by this part and wasn't sure what the appropriate check was

arborist/lib/node.js

Lines 435 to 440 in 6f99a5e

const eBundler = edge.from.getBundler(path)
if (!eBundler)
continue
if (eBundler === parent)
return eBundler

any situation where it would be bundled but this.to.name would differ from whats in this.from.package.bundleDependencies?

lib/edge.js Outdated Show resolved Hide resolved
lib/edge.js Outdated Show resolved Hide resolved
test/edge.js Outdated Show resolved Hide resolved
@kumavis
Copy link
Contributor Author

kumavis commented Feb 25, 2021

neat. im happy with this

@kumavis kumavis changed the title Feat/edge bundled Feature: Edges have a "bundled" getter for when they represents a bundled dependency Feb 27, 2021
@isaacs isaacs merged commit 63ec6dd into npm:main Mar 1, 2021
@kumavis kumavis deleted the feat/edge-bundled branch March 2, 2021 02:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants