@@ -138,72 +138,103 @@ async function report (argv, _dir) {
138138
139139 const isNested = pkgName === nestedPkgName && pkgVersion === nestedPkgVersion
140140
141+ // Processing packages from NCM service
142+ let includedCount = 0 ;
143+ let skippedCount = 0 ;
144+
141145 for ( const { name, version, scores, published } of data ) {
142- let maxSeverity = 0
143- let license = { }
144- const failures = [ ]
146+ let maxSeverity = 0 ;
147+ let license = { } ;
148+ const failures = [ ] ;
145149
146150 for ( const score of scores ) {
147- const severityValue = SEVERITY_RMAP . indexOf ( score . severity )
151+ const severityValue = SEVERITY_RMAP . indexOf ( score . severity ) ;
148152
149153 if ( score . group !== 'compliance' &&
150154 score . group !== 'security' &&
151155 score . group !== 'risk' ) {
152- continue
156+ continue ;
153157 }
154158
155159 if ( severityValue > maxSeverity ) {
156- maxSeverity = severityValue
160+ maxSeverity = severityValue ;
157161 }
158162
159163 if ( score . pass === false ) {
160- failures . push ( score )
161- hasFailures = true
164+ failures . push ( score ) ;
165+ hasFailures = true ;
162166 }
163167
164168 if ( score . name === 'license' ) {
165- license = score
169+ license = score ;
166170 }
167171 }
168172
169- if ( ! version ) {
170- // skip unknown version to make the report consistent
171- continue
173+ // Modified approach to include ALL packages in the report
174+ // Even packages with null/undefined versions will be included with a default version
175+ let effectiveVersion = version ;
176+ if ( effectiveVersion === null || effectiveVersion === undefined ) {
177+ effectiveVersion = '0.0.0' ;
178+ // Using default version 0.0.0 for package
172179 }
173-
180+
181+ // Skip nested packages with severity issues
174182 if ( isNested && ! ! maxSeverity ) {
175- continue
183+ skippedCount ++ ;
184+ // Skipping nested package
185+ continue ;
186+ }
187+
188+ // Check if license has failed, which should upgrade to critical severity
189+ const getLicenseScore = ( { pass } ) => pass === false ? 0 : null ;
190+ if ( license && license . pass === false ) {
191+ maxSeverity = 4 ;
176192 }
177193
178- const getLicenseScore = ( { pass } ) => ! pass ? 0 : null
179- if ( getLicenseScore ( license ) === 0 ) maxSeverity = 4
180-
194+ // Add the package to our report
181195 pkgScores . push ( {
182196 name,
183- version,
197+ version : effectiveVersion , // Use effective version instead of potentially null version
184198 published,
185199 maxSeverity,
186200 failures,
187201 license,
188202 scores
189- } )
203+ } ) ;
204+
205+ includedCount ++ ;
190206 }
207+
208+ // Package processing complete
191209
192210 pkgScores = moduleSort ( pkgScores )
193211
212+ // Process whitelisted packages
194213 const whitelisted = pkgScores . filter ( pkg => whitelist . has ( `${ pkg . name } @${ pkg . version } ` ) )
195214 . map ( pkgScore => ( { ...pkgScore , quantitativeScore : score ( pkgScore . scores , pkgScore . maxSeverity ) } ) )
215+
216+ // Filter out whitelisted packages from the main package list
196217 pkgScores = pkgScores . filter ( pkg => ! whitelist . has ( `${ pkg . name } @${ pkg . version } ` ) )
197218 . map ( pkgScore => ( { ...pkgScore , quantitativeScore : score ( pkgScore . scores , pkgScore . maxSeverity ) } ) )
198219
199220 const npmAudit = ( ) => {
200221 return new Promise ( ( resolve , reject ) => {
201- const npmAuditProcess = spawnSync ( 'npm' , [ 'audit' , '--json' ] , { cwd : dir } )
222+ const npmAuditProcess = spawnSync ( 'npm' , [ 'audit' , '--json' ] , {
223+ cwd : dir ,
224+ timeout : 10000 , // Add a 10 second timeout to prevent hanging
225+ encoding : 'utf8'
226+ } )
227+
202228 if ( npmAuditProcess . error ) {
203229 return reject ( npmAuditProcess . error )
204230 }
205231
206- resolve ( npmAuditProcess . stdout . toString ( ) )
232+ if ( npmAuditProcess . status !== 0 && npmAuditProcess . signal === 'SIGTERM' ) {
233+ // Handle timeout case
234+ return resolve ( '{}' )
235+ }
236+
237+ resolve ( npmAuditProcess . stdout ? npmAuditProcess . stdout . toString ( ) : '{}' )
207238 } )
208239 }
209240
0 commit comments