@@ -5,11 +5,12 @@ import events from "node:events";
55
66// Import Third-party Dependencies
77import kleur from "kleur" ;
8+ import semver from "semver" ;
89import filenamify from "filenamify" ;
910import { Spinner } from "@topcli/spinner" ;
1011import ms from "ms" ;
1112import * as i18n from "@nodesecure/i18n" ;
12- import * as Scanner from "@nodesecure/scanner" ;
13+ import * as scanner from "@nodesecure/scanner" ;
1314import { 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) {
8081export 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+ }
0 commit comments