Package Exports
- @beemo/dependency-graph
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@beemo/dependency-graph) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Dependency Graph
Generate a dependency graph for a list of packages, based on their defined dependencies and
peerDependencies.
Installation
yarn add @beemo/dependency-graph
// Or
npm install @beemo/dependency-graph --saveDocumentation
To begin, instantiate an instance of Graph, which accepts a list of optional package.json
objects as the first argument.
import Graph from '@beemo/dependency-graph';
const graph = new Graph([
{
name: '@beemo/core',
},
{
name: '@beemo/cli',
dependencies: {
'@beemo/core': '^1.0.0',
},
},
]);Alternatively, package.json objects can be added dynamically using Graph#addPackage or
Graph#addPackages.
graph.addPackage({
name: '@beemo/driver-jest',
peerDependencies: {
'@beemo/core': '^1.0.0',
'@beemo/driver-babel': '^1.0.0',
},
});Once all packages have been defined, we can generate a graph using these Graph methods:
resolveList- Returns an array of packages in order of most depended on.resolveBatchList- Like the previous, but returns the array batched based on depth.resolveTree- Returns a tree of nodes based on the graph.
// List of packages
graph.resolveList().forEach((pkg) => {
console.log(pkg.name);
});
// List of list of packages
graph.resolveBatchList().forEach((pkgs) => {
pkgs.forEach((pkg) => {
console.log(pkg.name);
});
});
// Tree of nodes
graph.resolveTree().nodes.forEach((node) => {
console.log(node.package.name);
if (node.nodes) {
// Dependents
}
});Will only resolve and return packages that have been defined. Will not return non-defined packages found in
dependenciesandpeerDependencies.