Skip to content

Commit b65300f

Browse files
authored
chore: update @nodesecure/scanner to v7.x (#583)
1 parent f646426 commit b65300f

File tree

7 files changed

+52
-20
lines changed

7 files changed

+52
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@
9494
"@nodesecure/i18n": "^4.0.2",
9595
"@nodesecure/js-x-ray": "^9.2.0",
9696
"@nodesecure/licenses-conformance": "^2.1.0",
97-
"@nodesecure/npm-registry-sdk": "^3.0.0",
97+
"@nodesecure/npm-registry-sdk": "^4.4.0",
9898
"@nodesecure/ossf-scorecard-sdk": "^3.2.1",
9999
"@nodesecure/rc": "^5.0.0",
100100
"@nodesecure/report": "^3.0.0",
101-
"@nodesecure/scanner": "^6.12.0",
101+
"@nodesecure/scanner": "^7.1.0",
102102
"@nodesecure/utils": "^2.2.0",
103103
"@nodesecure/vulnera": "^2.0.1",
104104
"@openally/result": "^1.3.0",

src/commands/report.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Import Third-party Dependencies
22
import { report } from "@nodesecure/report";
3-
import * as Scanner from "@nodesecure/scanner";
3+
import * as scanner from "@nodesecure/scanner";
44

55
// CONSTANTS
66
const kSupportedReporters = new Set(["html", "pdf"]);
@@ -62,7 +62,7 @@ export async function main(repository, options) {
6262
reporters: [...formattedReporters],
6363
saveOnDisk: true
6464
};
65-
const scannerPayload = await Scanner.from(repository);
65+
const scannerPayload = await scanner.from(repository);
6666

6767
const reportPath = await report(
6868
includesAllDeps ? scannerPayload.dependencies : { [repository]: scannerPayload.dependencies[repository] },

src/commands/scanner.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import events from "node:events";
55

66
// Import Third-party Dependencies
77
import kleur from "kleur";
8+
import semver from "semver";
89
import filenamify from "filenamify";
910
import { Spinner } from "@topcli/spinner";
1011
import ms from "ms";
1112
import * as i18n from "@nodesecure/i18n";
12-
import * as Scanner from "@nodesecure/scanner";
13+
import * as scanner from "@nodesecure/scanner";
1314
import { appCache } from "@nodesecure/cache";
1415

1516
// Import Internal Dependencies
@@ -67,7 +68,7 @@ export async function cwd(options) {
6768
contacts
6869
} = options;
6970

70-
const payload = await Scanner.cwd(
71+
const payload = await scanner.cwd(
7172
process.cwd(),
7273
{ maxDepth, usePackageLock: !nolock, fullLockMode: full, vulnerabilityStrategy, highlight:
7374
{ contacts: parseContacts(contacts) } },
@@ -80,7 +81,7 @@ export async function cwd(options) {
8081
export async function from(spec, options) {
8182
const { depth: maxDepth = Infinity, output, silent, contacts, vulnerabilityStrategy } = options;
8283

83-
const payload = await Scanner.from(
84+
const payload = await scanner.from(
8485
spec,
8586
{
8687
maxDepth,
@@ -121,7 +122,7 @@ function initLogger(spec, verbose = true) {
121122
}
122123
};
123124

124-
const logger = new Scanner.Logger();
125+
const logger = new scanner.Logger();
125126
logger.on("start", (eventName) => {
126127
if (!(eventName in spinner)) {
127128
return;
@@ -174,7 +175,12 @@ function initLogger(spec, verbose = true) {
174175
return logger;
175176
}
176177

177-
async function logAndWrite(payload, output = "nsecure-result", options = {}) {
178+
async function logAndWrite(
179+
/** @type {import("@nodesecure/scanner").Payload} */
180+
payload,
181+
output = "nsecure-result",
182+
options = {}
183+
) {
178184
const { local = false } = options;
179185

180186
if (payload === null) {
@@ -184,10 +190,12 @@ async function logAndWrite(payload, output = "nsecure-result", options = {}) {
184190
}
185191

186192
if (payload.warnings.length > 0) {
187-
console.log(`\n ${kleur.yellow().underline().bold("Global Warning:")}\n`);
188-
for (const warning of payload.warnings) {
189-
console.log(kleur.red().bold(warning));
190-
}
193+
console.log(`\n ${kleur.yellow().bold("Global Warning:")}\n`);
194+
const logFn = semver.satisfies(payload.scannerVersion, ">=7.0.0") ?
195+
logGlobalWarningsV7 :
196+
logGlobalWarningsV6;
197+
logFn(payload.warnings);
198+
console.log("");
191199
}
192200

193201
const ret = JSON.stringify(payload, null, 2);
@@ -211,3 +219,24 @@ async function logAndWrite(payload, output = "nsecure-result", options = {}) {
211219

212220
return filePath;
213221
}
222+
223+
function logGlobalWarningsV7(
224+
/** @type {import("@nodesecure/scanner").GlobalWarning[]} */
225+
warnings
226+
) {
227+
for (const warning of warnings) {
228+
const isTypoSquatting = warning.type === "typo-squatting";
229+
230+
const type = kleur[isTypoSquatting ? "cyan" : "yellow"]().bold(`${warning.type}`);
231+
console.log(kleur.gray().bold(`[${type}] ${warning.message}`));
232+
}
233+
}
234+
235+
function logGlobalWarningsV6(
236+
/** @type {string[]} */
237+
warnings
238+
) {
239+
for (const warning of warnings) {
240+
console.log(kleur.yellow().bold(warning));
241+
}
242+
}

workspaces/documentation-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
2626
"license": "MIT",
2727
"dependencies": {
28-
"@nodesecure/flags": "^2.4.0",
28+
"@nodesecure/flags": "^3.0.3",
2929
"@nodesecure/js-x-ray": "^9.2.0",
3030
"highlight.js": "^11.10.0",
3131
"markdown-it": "^14.1.0"

workspaces/server/src/websocket/commands/search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Import Third-party Dependencies
2-
import * as Scanner from "@nodesecure/scanner";
2+
import * as scanner from "@nodesecure/scanner";
33
import type { PayloadsList } from "@nodesecure/cache";
44

55
// Import Internal Dependencies
@@ -63,7 +63,7 @@ export async function* search(
6363
logger.info(`[ws|search](scan ${pkg} in progress)`);
6464
yield { status: "SCAN" as const, pkg };
6565

66-
const payload = await Scanner.from(pkg, { maxDepth: 4 });
66+
const payload = await scanner.from(pkg, { maxDepth: 4 });
6767
const name = payload.rootDependencyName;
6868
const version = Object.keys(payload.dependencies[name].versions)[0];
6969

workspaces/vis-network/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"vis-network": "^9.1.9"
3030
},
3131
"devDependencies": {
32-
"@nodesecure/flags": "^2.4.0",
33-
"@nodesecure/scanner": "^6.0.2"
32+
"@nodesecure/flags": "^3.0.3",
33+
"@nodesecure/scanner": "^7.1.0"
3434
}
35-
}
35+
}

workspaces/vis-network/src/dataset.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default class NodeSecureDataSet extends EventTarget {
5656
) {
5757
console.log("[NodeSecureDataSet] Initialization started...");
5858
let FLAGS;
59+
/** @type {import("@nodesecure/scanner").Payload | null} */
5960
let data;
6061
this.reset();
6162

@@ -76,7 +77,9 @@ export default class NodeSecureDataSet extends EventTarget {
7677
return;
7778
}
7879

79-
this.warnings = data.warnings;
80+
this.warnings = data.warnings.map(
81+
(warning) => (typeof warning === "string" ? warning : warning.message)
82+
);
8083

8184
this.#highligthedContacts = data.highlighted.contacts
8285
.reduce((acc, { name, email }) => {

0 commit comments

Comments
 (0)