Skip to content

Commit 0e0ac47

Browse files
Mila Votradovecgjvis
Mila Votradovec
authored andcommitted
feat: allow creation of new DepGraph
1 parent 7eb5ca6 commit 0e0ac47

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,50 @@ export interface DepGraphData {
114114

115115
`DepGraphData` can be used to construct a `DepGraph` instance using `createFromJSON`
116116

117+
### `DepGraphBuilder`
118+
`DepGraphBuilder` is used to create new `DepGraph` instances by adding packages and their connections.
119+
120+
```typescript
121+
/**
122+
* Instantiates build for given package manager
123+
*
124+
* @param pkgManager - package manager for which dependcy graph is created
125+
* @param rootPkg - root package information
126+
*
127+
*/
128+
public constructor(pkgManager: types.PkgManager, rootPkg?: types.PkgInfo)
129+
130+
/**
131+
* Adds node to the graph. Every node represents logical instance of the package in the dependency graph.
132+
*
133+
* @param pkgInfo - name and version of the package
134+
* @param nodeId - identifier for node in the graph, e.g. `package@version`.
135+
* Must uniquely identify this "instance" of the package in the graph,
136+
* so may need to be more than `package@version` for many ecosystems.
137+
* If in doubt - ask a contributor!
138+
* @param nodeInfo - additional node info, e.g. for version provenance
139+
*
140+
*/
141+
public addPkgNode(pkgInfo: types.PkgInfo, nodeId: string, nodeInfo?: types.NodeInfo)
142+
143+
/**
144+
* Makes a connection between parent and its dependency.
145+
*
146+
* @param parentNodeId - id of the parent node
147+
* @param depNodeId - id of the dependency node
148+
*
149+
*/
150+
public connectDep(parentNodeId: string, depNodeId: string)
151+
152+
/**
153+
* Creates an instance of DepGraph
154+
*
155+
* @return DepGraph instance built from provided packages and their connections
156+
*
157+
*/
158+
public build(): types.DepGraph
159+
160+
```
117161
### The `legacy` module
118162

119163
A `DepTree` is a legacy structure used by the Snyk CLI to represent dependency trees. Conversion functions in the `legacy` module ease the gradual migration of code that relies on the legacy format.

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'source-map-support/register';
22

33
export { DepGraphData, DepGraph, PkgManager } from './core/types';
44
export { createFromJSON } from './core/create-from-json';
5+
export { DepGraphBuilder } from './core/builder';
56

67
import * as Errors from './core/errors';
78
export { Errors };

0 commit comments

Comments
 (0)