Skip to content

Commit 52a2ad0

Browse files
committed
feat: graphToDepTree sets .type to pkgManager.name
to maintain backwards compatibility with Rubygems trees that were assumed to have the `.type` field, and with some other legacy parts that used to set `.type` with the name of the package-manager
1 parent c60d332 commit 52a2ad0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/legacy/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface DepTreeDep {
1818
}
1919

2020
interface DepTree extends DepTreeDep {
21+
type?: string;
2122
packageFormatVersion?: string;
2223
targetOS?: {
2324
name: string;
@@ -164,6 +165,7 @@ async function graphToDepTree(depGraphInterface: types.DepGraph, pkgType: string
164165

165166
const depTree = await buildSubtree(depGraph, depGraph.rootNodeId);
166167

168+
depTree.type = depGraph.pkgManager.name;
167169
depTree.packageFormatVersion = constructPackageFormatVersion(pkgType);
168170

169171
const targetOS = constructTargetOS(depGraph);

test/legacy/to-dep-tree.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ describe('dep-trees survive serialisation through dep-graphs', () => {
8080
const outputGraph = depGraphLib.createFromJSON(outputJSON);
8181
const outputTree = await depGraphLib.legacy.graphToDepTree(outputGraph, fixture.pkgType);
8282

83+
expect(outputTree.type).toEqual(fixture.pkgManagerName);
84+
delete outputTree.type;
85+
8386
expect(outputTree).toEqual(inputTree);
8487
});
8588
}
@@ -95,6 +98,8 @@ test('graphToDepTree simple dysmorphic', async () => {
9598
const expectedDepTree = helpers.loadFixture('simple-dep-tree.json');
9699

97100
const depTree = await depGraphLib.legacy.graphToDepTree(depGraph, 'maven');
101+
expect(depTree.type).toEqual('maven');
102+
delete depTree.type;
98103
expect(depTree).toEqual(expectedDepTree);
99104
});
100105

@@ -105,6 +110,9 @@ describe('graphToDepTree with a linux pkgManager', () => {
105110
const expectedDepTree = helpers.loadFixture('os-deb-dep-tree.json');
106111

107112
const depTree = await depGraphLib.legacy.graphToDepTree(depGraph, 'deb');
113+
114+
expect(depTree.type).toEqual('deb');
115+
delete depTree.type;
108116
expect(depTree).toEqual(expectedDepTree);
109117
});
110118

0 commit comments

Comments
 (0)