Skip to content

Commit 3ce4720

Browse files
author
Raulo Erwan
committed
feat(vis-network): use scanner extractors
1 parent 2e60c97 commit 3ce4720

File tree

4 files changed

+23
-43
lines changed

4 files changed

+23
-43
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"@nodesecure/ossf-scorecard-sdk": "^3.2.1",
100100
"@nodesecure/rc": "^5.0.0",
101101
"@nodesecure/report": "4.1.0",
102-
"@nodesecure/scanner": "8.1.0",
102+
"@nodesecure/scanner": "8.2.0",
103103
"@nodesecure/server": "1.0.0",
104104
"@nodesecure/utils": "^2.2.0",
105105
"@nodesecure/vulnera": "^2.0.1",

workspaces/vis-network/src/dataset.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Import Third-party Dependencies
2+
import { Extractors } from "@nodesecure/scanner/extractors";
23
import prettyBytes from "pretty-bytes";
34
import { DataSet } from "vis-data";
45

@@ -93,22 +94,33 @@ export default class NodeSecureDataSet extends EventTarget {
9394
return acc;
9495
}, { names: new Set(), emails: new Set() });
9596

96-
const dataEntries = Object.entries(data.dependencies);
97-
this.dependenciesCount = dataEntries.length;
97+
const dependencies = Object.entries(data.dependencies);
98+
this.dependenciesCount = dependencies.length;
9899

99100
this.rawEdgesData = [];
100101
this.rawNodesData = [];
101102

102-
const rootDependency = dataEntries.find(([name]) => name === data.rootDependency.name);
103+
const rootDependency = dependencies.find(([name]) => name === data.rootDependency.name);
103104
const rootContributors = [
104105
rootDependency[1].metadata.author,
105106
...rootDependency[1].metadata.maintainers,
106107
...rootDependency[1].metadata.publishers
107108
];
108-
for (const [packageName, descriptor] of dataEntries) {
109+
110+
const extractor = new Extractors.Payload(data, [
111+
// new Extractors.Probes.Licenses(),
112+
// new Extractors.Probes.Extensions()
113+
]);
114+
115+
// const result = extractor.extractAndMerge();
116+
117+
// this.extensions = extensions;
118+
// this.licenses = licenses;
119+
120+
for (const [packageName, descriptor] of dependencies) {
109121
const contributors = [descriptor.metadata.author, ...descriptor.metadata.maintainers, ...descriptor.metadata.publishers];
110122
for (const [currVersion, opt] of Object.entries(descriptor.versions)) {
111-
const { id, usedBy, flags, size, uniqueLicenseIds, author, composition, warnings, links } = opt;
123+
const { id, usedBy, flags, size, author, warnings, links } = opt;
112124
const filteredWarnings = warnings
113125
.filter((row) => !this.warningsToIgnore.has(row.kind));
114126
const hasWarnings = filteredWarnings.length > 0;
@@ -118,8 +130,6 @@ export default class NodeSecureDataSet extends EventTarget {
118130
opt.hidden = false;
119131
opt.hasWarnings = hasWarnings;
120132

121-
this.computeExtension(composition.extensions);
122-
this.computeLicense(uniqueLicenseIds);
123133
this.computeAuthor(author, `${packageName}@${currVersion}`, contributors);
124134

125135
if (flags.includes("hasIndirectDependencies")) {
@@ -187,20 +197,6 @@ export default class NodeSecureDataSet extends EventTarget {
187197
return null;
188198
}
189199

190-
computeExtension(extensions) {
191-
for (const extName of extensions) {
192-
if (extName !== "") {
193-
this.extensions[extName] = Reflect.has(this.extensions, extName) ? ++this.extensions[extName] : 1;
194-
}
195-
}
196-
}
197-
198-
computeLicense(uniqueLicenseIds) {
199-
for (const licenseName of uniqueLicenseIds) {
200-
this.licenses[licenseName] = Reflect.has(this.licenses, licenseName) ? ++this.licenses[licenseName] : 1;
201-
}
202-
}
203-
204200
computeAuthor(author, spec, contributors = []) {
205201
if (author === null) {
206202
return;

workspaces/vis-network/test/dataset-payload.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
},
6565
"licenses": [],
6666
"uniqueLicenseIds": [
67-
"Unlicense"
67+
"MIT"
6868
],
6969
"name": "pkg2",
7070
"version": "1.0.3"
@@ -87,7 +87,7 @@
8787
},
8888
"licenses": [],
8989
"uniqueLicenseIds": [
90-
"Unlicense"
90+
"MIT"
9191
],
9292
"name": "pkg2",
9393
"version": "1.0.4"
@@ -127,7 +127,7 @@
127127
},
128128
"licenses": [],
129129
"uniqueLicenseIds": [
130-
"Licence1"
130+
"RND"
131131
]
132132
}
133133
}
@@ -149,7 +149,8 @@
149149
],
150150
"size": 200,
151151
"author": {
152-
"name": "john doe"
152+
"name": "john doe",
153+
"email": "[email protected]"
153154
},
154155
"composition": {
155156
"extensions": [

workspaces/vis-network/test/dataset.test.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ test("NodeSecureDataSet.prettySize", () => {
3838
assert.equal(nsDataSet.prettySize, "1.34 kB", "should convert bytes to human readable string");
3939
});
4040

41-
test("NodeSecureDataSet.computeExtensions", () => {
42-
const nsDataSet = new NodeSecureDataSet();
43-
assert.equal(Object.keys(nsDataSet.extensions).length, 0, "should have 0 extensions");
44-
45-
nsDataSet.computeExtension([".js", ".js", ".json"]);
46-
47-
assert.equal(Object.keys(nsDataSet.extensions).length, 2, "should have 2 extension (js and json)");
48-
assert.equal(nsDataSet.extensions[".js"], 2, "should have 2 '.js' extensions'");
49-
});
50-
5141
test("NodeSecureDataSet.isHighlighted", async() => {
5242
const nsDataSet = new NodeSecureDataSet();
5343
await nsDataSet.init(dataSetPayload);
@@ -63,13 +53,6 @@ test("NodeSecureDataSet.isHighlighted", async() => {
6353
"email: [email protected] should be hightlighted");
6454
});
6555

66-
test("NodeSecureDataSet.computeLicenses", () => {
67-
const nsDataSet = new NodeSecureDataSet();
68-
nsDataSet.computeLicense(["MIT", "MIT", "RND"]);
69-
assert.equal(Object.keys(nsDataSet.licenses).length, 3, "should have 3 licenses (MIT, RND & 1 unknown)");
70-
assert.equal(nsDataSet.licenses.MIT, 2, "should have 2 MIT licenses");
71-
});
72-
7356
test("NodeSecureDataSet.computeAuthors", () => {
7457
const nsDataSet = new NodeSecureDataSet();
7558
nsDataSet.computeAuthor({ name: "John Doe" }, "[email protected]");

0 commit comments

Comments
 (0)