Skip to content

Commit 3c133ff

Browse files
author
Konstantin Yegupov
committed
feat: clarify Pkg.version type (undefined instead of null)
1 parent 9a1b18d commit 3c133ff

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ export interface DepGraph {
4949
};
5050
readonly rootPkg: {
5151
name: string;
52-
version: string | null;
52+
version?: string;
5353
};
5454
// all unique packages in the graph (including root package)
5555
getPkgs(): Array<{
5656
name: string;
57-
version: string | null;
57+
version?: string;
5858
}>;
5959
// all unique packages in the graph, except the root package
6060
getDepPkgs(): Array<{
6161
name: string;
62-
version: string | null;
62+
version?: string;
6363
}>;
6464
pkgPathsToRoot(pkg: Pkg): Array<Array<{
6565
name: string;
66-
version: string | null;
66+
version?: string;
6767
}>>;
6868
countPathsToRoot(pkg: Pkg): number;
6969
toJSON(): DepGraphData;
@@ -89,7 +89,7 @@ export interface DepGraphData {
8989
id: string;
9090
info: {
9191
name: string;
92-
version: string | null;
92+
version?: string;
9393
};
9494
}>;
9595
graph: {

src/core/create-from-json.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ export function createFromJSON(depGraphData: DepGraphData): DepGraph {
2222
const pkgNodes: {[pkgId: string]: Set<string>} = {};
2323

2424
for (const { id, info } of depGraphData.pkgs) {
25-
// TODO: avoid this, instead just use `info` as is
26-
pkgs[id] = info.version ? info : { ...info, version: null } as any;
25+
pkgs[id] = info;
2726
}
2827

2928
for (const node of depGraphData.graph.nodes) {

src/core/dep-graph.ts

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ class DepGraphImpl implements types.DepGraphInternal {
161161
otherDepGraph = createFromJSON(other.toJSON()) as types.DepGraphInternal;
162162
}
163163

164+
// In theory, for the graphs created by standard means, `_.isEquals(this._data, otherDepGraph._data)`
165+
// should suffice, since node IDs will be generated in a predictable way.
166+
// However, to support unconventional node IDs, we run our own deep
167+
// comparison.
164168
return this.nodeEquals(this, this.rootNodeId, otherDepGraph, otherDepGraph.rootNodeId, compareRoot);
165169
}
166170

test/core/create-from-json.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,10 @@ test('fromJSON a pkg missing version field', () => {
759759
const depGraph = depGraphLib.createFromJSON(graphJson as any);
760760
expect(depGraph.getPkgs().sort()).toEqual([
761761
{ name: 'toor', version: '1.0.0' },
762-
{ name: 'foo', version: null },
762+
{ name: 'foo' },
763763
]);
764764
expect(depGraph.getDepPkgs().sort()).toEqual([
765-
{ name: 'foo', version: null },
765+
{ name: 'foo' },
766766
]);
767767
});
768768

0 commit comments

Comments
 (0)