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,97 @@ 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 . rootDependencyName ) ;
102+ const rootDependency = dependencies . find (
103+ ( [ name ] ) => name === data . rootDependencyName
104+ ) ;
103105 const rootContributors = [
104106 rootDependency [ 1 ] . metadata . author ,
105107 ...rootDependency [ 1 ] . metadata . maintainers ,
106108 ...rootDependency [ 1 ] . metadata . publishers
107109 ] ;
108- for ( const [ packageName , descriptor ] of dataEntries ) {
109- const contributors = [ descriptor . metadata . author , ...descriptor . metadata . maintainers , ...descriptor . metadata . publishers ] ;
110+
111+ const extractor = new Extractors . Payload ( data , [
112+ new Extractors . Probes . Licenses ( ) ,
113+ new Extractors . Probes . Extensions ( ) ] ) ;
114+
115+ const { extensions, licenses } = extractor . extractAndMerge ( ) ;
116+
117+ this . extensions = extensions ;
118+ this . licenses = licenses ;
119+
120+ for ( const [ packageName , descriptor ] of dependencies ) {
121+ const contributors = [
122+ descriptor . metadata . author , ...descriptor . metadata . maintainers , ...descriptor . metadata . publishers
123+ ] ;
110124 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 ) ) ;
125+ const {
126+ id,
127+ usedBy,
128+ flags,
129+ size,
130+ author,
131+ warnings,
132+ links
133+ } = opt ;
134+ const filteredWarnings = warnings . filter (
135+ ( row ) => ! this . warningsToIgnore . has ( row . kind )
136+ ) ;
114137 const hasWarnings = filteredWarnings . length > 0 ;
115138
116139 opt . name = packageName ;
117140 opt . version = currVersion ;
118141 opt . hidden = false ;
119142 opt . hasWarnings = hasWarnings ;
120143
121- this . computeExtension ( composition . extensions ) ;
122- this . computeLicense ( uniqueLicenseIds ) ;
123- this . computeAuthor ( author , `${ packageName } @${ currVersion } ` , contributors ) ;
144+ this . computeAuthor (
145+ author ,
146+ `${ packageName } @${ currVersion } ` ,
147+ contributors
148+ ) ;
124149
125150 if ( flags . includes ( "hasIndirectDependencies" ) ) {
126151 this . indirectDependencies ++ ;
127152 }
128- this . size + = size ;
153+ this . size = size ;
129154
130155 const flagStr = utils . getFlagsEmojisInlined (
131156 flags ,
132- hasWarnings ? this . flagsToIgnore : new Set ( [ ...this . flagsToIgnore , "hasWarnings" ] )
157+ hasWarnings
158+ ? this . flagsToIgnore
159+ : new Set ( [ ...this . flagsToIgnore , "hasWarnings" ] )
133160 ) ;
134- const isFriendly = window . settings . config . showFriendlyDependencies & rootContributors . some (
135- ( rootContributor ) => contributors . some ( ( contributor ) => {
161+ const isFriendly =
162+ window . settings . config . showFriendlyDependencies &
163+ rootContributors . some ( ( rootContributor ) => contributors . some ( ( contributor ) => {
136164 if ( contributor === null || rootContributor === null ) {
137165 return false ;
138166 }
139- else if ( contributor . email && contributor . email === rootContributor . email ) {
167+ else if (
168+ contributor . email &&
169+ contributor . email === rootContributor . email
170+ ) {
140171 return true ;
141172 }
142- else if ( contributor . name && contributor . name === rootContributor . name ) {
173+ else if (
174+ contributor . name &&
175+ contributor . name === rootContributor . name
176+ ) {
143177 return true ;
144178 }
145179
146180 return false ;
147181 } )
148- ) ;
182+ ) ;
149183 opt . isFriendly = isFriendly ;
150184 this . packages . push ( {
151185 id,
@@ -170,7 +204,10 @@ export default class NodeSecureDataSet extends EventTarget {
170204 this . rawNodesData . push ( Object . assign ( { id, label } , color ) ) ;
171205
172206 for ( const [ name , version ] of Object . entries ( usedBy ) ) {
173- this . rawEdgesData . push ( { from : id , to : data . dependencies [ name ] . versions [ version ] . id } ) ;
207+ this . rawEdgesData . push ( {
208+ from : id ,
209+ to : data . dependencies [ name ] . versions [ version ] . id
210+ } ) ;
174211 }
175212 }
176213 }
@@ -187,25 +224,13 @@ export default class NodeSecureDataSet extends EventTarget {
187224 return null ;
188225 }
189226
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-
204227 computeAuthor ( author , spec , contributors = [ ] ) {
205228 if ( author === null ) {
206229 return ;
207230 }
208- const contributor = contributors . find ( ( contributor ) => contributor . email === author . email && contributor . npmAvatar !== null ) ;
231+ const contributor = contributors . find (
232+ ( contributor ) => contributor . email === author . email && contributor . npmAvatar !== null
233+ ) ;
209234
210235 if ( this . authors . has ( author . name ) ) {
211236 this . authors . get ( author . name ) . packages . add ( spec ) ;
@@ -229,7 +254,10 @@ export default class NodeSecureDataSet extends EventTarget {
229254 }
230255
231256 isHighlighted ( contact ) {
232- return this . #highligthedContacts. names . has ( contact . name ) || this . #highligthedContacts. emails . has ( contact . email ) ;
257+ return (
258+ this . #highligthedContacts. names . has ( contact . name ) ||
259+ this . #highligthedContacts. emails . has ( contact . email )
260+ ) ;
233261 }
234262
235263 findPackagesByName ( name ) {
0 commit comments