11// Import Third-party Dependencies
2+ import { Extractors } from "@nodesecure/scanner" ;
23import prettyBytes from "pretty-bytes" ;
34import { DataSet } from "vis-data" ;
45
@@ -50,10 +51,7 @@ export default class NodeSecureDataSet extends EventTarget {
5051 this . indirectDependencies = 0 ;
5152 }
5253
53- async init (
54- initialPayload = null ,
55- initialFlags = { }
56- ) {
54+ async init ( initialPayload = null , initialFlags = { } ) {
5755 console . log ( "[NodeSecureDataSet] Initialization started..." ) ;
5856 let FLAGS ;
5957 /** @type {import("@nodesecure/scanner").Payload | null } */
@@ -65,9 +63,10 @@ export default class NodeSecureDataSet extends EventTarget {
6563 FLAGS = initialFlags ;
6664 }
6765 else {
68- ( [ data , FLAGS ] = await Promise . all ( [
69- utils . getJSON ( "/data" ) , utils . getJSON ( "/flags" )
70- ] ) ) ;
66+ [ data , FLAGS ] = await Promise . all ( [
67+ utils . getJSON ( "/data" ) ,
68+ utils . getJSON ( "/flags" )
69+ ] ) ;
7170 }
7271
7372 this . FLAGS = FLAGS ;
@@ -77,12 +76,11 @@ export default class NodeSecureDataSet extends EventTarget {
7776 return ;
7877 }
7978
80- this . warnings = data . warnings . map (
81- ( warning ) => ( typeof warning === "string" ? warning : warning . message )
79+ this . warnings = data . warnings . map ( ( warning ) => ( typeof warning === "string" ? warning : warning . message )
8280 ) ;
8381
84- this . #highligthedContacts = data . highlighted . contacts
85- . reduce ( ( acc , { name, email } ) => {
82+ this . #highligthedContacts = data . highlighted . contacts . reduce (
83+ ( acc , { name, email } ) => {
8684 if ( name ) {
8785 acc . names . add ( name ) ;
8886 }
@@ -91,61 +89,95 @@ export default class NodeSecureDataSet extends EventTarget {
9189 }
9290
9391 return acc ;
94- } , { names : new Set ( ) , emails : new Set ( ) } ) ;
92+ } ,
93+ { names : new Set ( ) , emails : new Set ( ) }
94+ ) ;
9595
96- const dataEntries = Object . entries ( data . dependencies ) ;
97- this . dependenciesCount = dataEntries . length ;
96+ const dependencies = Object . entries ( data . dependencies ) ;
97+ this . dependenciesCount = dependencies . length ;
9898
9999 this . rawEdgesData = [ ] ;
100100 this . rawNodesData = [ ] ;
101101
102- const rootDependency = dataEntries . find ( ( [ name ] ) => name === data . rootDependency . name ) ;
102+ const rootDependency = dependencies . find ( ( [ name ] ) => name === data . rootDependency . name ) ;
103103 const rootContributors = [
104104 rootDependency [ 1 ] . metadata . author ,
105105 ...rootDependency [ 1 ] . metadata . maintainers ,
106106 ...rootDependency [ 1 ] . metadata . publishers
107107 ] ;
108- for ( const [ packageName , descriptor ] of dataEntries ) {
109- const contributors = [ descriptor . metadata . author , ...descriptor . metadata . maintainers , ...descriptor . metadata . publishers ] ;
108+
109+ const extractor = new Extractors . Payload ( data , [
110+ new Extractors . Probes . Licenses ( ) ,
111+ new Extractors . Probes . Extensions ( ) ] ) ;
112+
113+ const { extensions, licenses } = extractor . extractAndMerge ( ) ;
114+
115+ this . extensions = extensions ;
116+ this . licenses = licenses ;
117+
118+ for ( const [ packageName , descriptor ] of dependencies ) {
119+ const contributors = [
120+ descriptor . metadata . author , ...descriptor . metadata . maintainers , ...descriptor . metadata . publishers
121+ ] ;
110122 for ( const [ currVersion , opt ] of Object . entries ( descriptor . versions ) ) {
111- const { id, usedBy, flags, size, uniqueLicenseIds, author, composition, warnings, links } = opt ;
112- const filteredWarnings = warnings
113- . filter ( ( row ) => ! this . warningsToIgnore . has ( row . kind ) ) ;
123+ const {
124+ id,
125+ usedBy,
126+ flags,
127+ size,
128+ author,
129+ warnings,
130+ links
131+ } = opt ;
132+ const filteredWarnings = warnings . filter (
133+ ( row ) => ! this . warningsToIgnore . has ( row . kind )
134+ ) ;
114135 const hasWarnings = filteredWarnings . length > 0 ;
115136
116137 opt . name = packageName ;
117138 opt . version = currVersion ;
118139 opt . hidden = false ;
119140 opt . hasWarnings = hasWarnings ;
120141
121- this . computeExtension ( composition . extensions ) ;
122- this . computeLicense ( uniqueLicenseIds ) ;
123- this . computeAuthor ( author , `${ packageName } @${ currVersion } ` , contributors ) ;
142+ this . computeAuthor (
143+ author ,
144+ `${ packageName } @${ currVersion } ` ,
145+ contributors
146+ ) ;
124147
125148 if ( flags . includes ( "hasIndirectDependencies" ) ) {
126149 this . indirectDependencies ++ ;
127150 }
128- this . size + = size ;
151+ this . size = size ;
129152
130153 const flagStr = utils . getFlagsEmojisInlined (
131154 flags ,
132- hasWarnings ? this . flagsToIgnore : new Set ( [ ...this . flagsToIgnore , "hasWarnings" ] )
155+ hasWarnings
156+ ? this . flagsToIgnore
157+ : new Set ( [ ...this . flagsToIgnore , "hasWarnings" ] )
133158 ) ;
134- const isFriendly = window . settings . config . showFriendlyDependencies & rootContributors . some (
135- ( rootContributor ) => contributors . some ( ( contributor ) => {
159+ const isFriendly =
160+ window . settings . config . showFriendlyDependencies &
161+ rootContributors . some ( ( rootContributor ) => contributors . some ( ( contributor ) => {
136162 if ( contributor === null || rootContributor === null ) {
137163 return false ;
138164 }
139- else if ( contributor . email && contributor . email === rootContributor . email ) {
165+ else if (
166+ contributor . email &&
167+ contributor . email === rootContributor . email
168+ ) {
140169 return true ;
141170 }
142- else if ( contributor . name && contributor . name === rootContributor . name ) {
171+ else if (
172+ contributor . name &&
173+ contributor . name === rootContributor . name
174+ ) {
143175 return true ;
144176 }
145177
146178 return false ;
147179 } )
148- ) ;
180+ ) ;
149181 opt . isFriendly = isFriendly ;
150182 this . packages . push ( {
151183 id,
@@ -170,7 +202,10 @@ export default class NodeSecureDataSet extends EventTarget {
170202 this . rawNodesData . push ( Object . assign ( { id, label } , color ) ) ;
171203
172204 for ( const [ name , version ] of Object . entries ( usedBy ) ) {
173- this . rawEdgesData . push ( { from : id , to : data . dependencies [ name ] . versions [ version ] . id } ) ;
205+ this . rawEdgesData . push ( {
206+ from : id ,
207+ to : data . dependencies [ name ] . versions [ version ] . id
208+ } ) ;
174209 }
175210 }
176211 }
@@ -187,25 +222,13 @@ export default class NodeSecureDataSet extends EventTarget {
187222 return null ;
188223 }
189224
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-
204225 computeAuthor ( author , spec , contributors = [ ] ) {
205226 if ( author === null ) {
206227 return ;
207228 }
208- const contributor = contributors . find ( ( contributor ) => contributor . email === author . email && contributor . npmAvatar !== null ) ;
229+ const contributor = contributors . find (
230+ ( contributor ) => contributor . email === author . email && contributor . npmAvatar !== null
231+ ) ;
209232
210233 if ( this . authors . has ( author . name ) ) {
211234 this . authors . get ( author . name ) . packages . add ( spec ) ;
@@ -229,7 +252,10 @@ export default class NodeSecureDataSet extends EventTarget {
229252 }
230253
231254 isHighlighted ( contact ) {
232- return this . #highligthedContacts. names . has ( contact . name ) || this . #highligthedContacts. emails . has ( contact . email ) ;
255+ return (
256+ this . #highligthedContacts. names . has ( contact . name ) ||
257+ this . #highligthedContacts. emails . has ( contact . email )
258+ ) ;
233259 }
234260
235261 findPackagesByName ( name ) {
0 commit comments