@@ -57,57 +57,52 @@ export default class ComponentDetection {
5757
5858 private static async getManifestsFromResults ( ) : Promise < Manifest [ ] | undefined > {
5959 core . info ( "Getting manifests from results" ) ;
60- try {
61- // Parse the result file and add the packages to the package cache
62- const packageCache = new PackageCache ( ) ;
63- const packages : Array < ComponentDetectionPackage > = [ ] ;
64-
65- const results = await fs . readFileSync ( this . outputPath , 'utf8' ) ;
60+ // Parse the result file and add the packages to the package cache
61+ const packageCache = new PackageCache ( ) ;
62+ const packages : Array < ComponentDetectionPackage > = [ ] ;
63+
64+ const results = await fs . readFileSync ( this . outputPath , 'utf8' ) ;
65+
66+ var json : any = JSON . parse ( results ) ;
67+ json . componentsFound . forEach ( async ( component : any ) => {
68+ const packageUrl = ComponentDetection . makePackageUrl ( component . component . packageUrl ) ;
6669
67- var json : any = JSON . parse ( results ) ;
68- json . componentsFound . forEach ( async ( component : any ) => {
69- const packageUrl = ComponentDetection . makePackageUrl ( component . component . packageUrl ) ;
70-
71- if ( ! packageCache . hasPackage ( packageUrl ) ) {
72- const pkg = new ComponentDetectionPackage ( packageUrl , component . component . id ,
73- component . isDevelopmentDependency , component . topLevelReferrers , component . locationsFoundAt , component . containerDetailIds , component . containerLayerIds ) ;
74- packageCache . addPackage ( pkg ) ;
75- packages . push ( pkg ) ;
70+ if ( ! packageCache . hasPackage ( packageUrl ) ) {
71+ const pkg = new ComponentDetectionPackage ( packageUrl , component . component . id ,
72+ component . isDevelopmentDependency , component . topLevelReferrers , component . locationsFoundAt , component . containerDetailIds , component . containerLayerIds ) ;
73+ packageCache . addPackage ( pkg ) ;
74+ packages . push ( pkg ) ;
75+ }
76+ } ) ;
77+
78+ // Set the transitive dependencies
79+ core . debug ( "Sorting out transitive dependencies" ) ;
80+ packages . forEach ( async ( pkg : ComponentDetectionPackage ) => {
81+ pkg . topLevelReferrers . forEach ( async ( referrer : any ) => {
82+ const referrerPackage = packageCache . lookupPackage ( ComponentDetection . makePackageUrl ( referrer . packageUrl ) ) ;
83+ if ( referrerPackage ) {
84+ referrerPackage . dependsOn ( pkg ) ;
7685 }
7786 } ) ;
87+ } ) ;
7888
79- // Set the transitive dependencies
80- core . debug ( "Sorting out transitive dependencies" ) ;
81- packages . forEach ( async ( pkg : ComponentDetectionPackage ) => {
82- pkg . topLevelReferrers . forEach ( async ( referrer : any ) => {
83- const referrerPackage = packageCache . lookupPackage ( ComponentDetection . makePackageUrl ( referrer . packageUrl ) ) ;
84- if ( referrerPackage ) {
85- referrerPackage . dependsOn ( pkg ) ;
86- }
87- } ) ;
88- } ) ;
89+ // Create manifests
90+ const manifests : Array < Manifest > = [ ] ;
8991
90- // Create manifests
91- const manifests : Array < Manifest > = [ ] ;
92-
93- // Check the locationsFoundAt for every package and add each as a manifest
94- packages . forEach ( async ( pkg : ComponentDetectionPackage ) => {
95- pkg . locationsFoundAt . forEach ( async ( location : any ) => {
96- if ( ! manifests [ location . filePath ] ) {
97- const manifest = new Manifest ( location . filePath , location . filePath ) ;
98- manifests . push ( manifest ) ;
99- }
100- if ( pkg . topLevelReferrers . length == 0 ) {
101- manifests . find ( ( manifest : Manifest ) => manifest . file == location . filePath ) ?. addDirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ;
102- } else {
103- manifests . find ( ( manifest : Manifest ) => manifest . file == location . filePath ) ?. addIndirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ; }
104- } ) ;
92+ // Check the locationsFoundAt for every package and add each as a manifest
93+ packages . forEach ( async ( pkg : ComponentDetectionPackage ) => {
94+ pkg . locationsFoundAt . forEach ( async ( location : any ) => {
95+ if ( ! manifests [ location . filePath ] ) {
96+ const manifest = new Manifest ( location . filePath , location . filePath ) ;
97+ manifests . push ( manifest ) ;
98+ }
99+ if ( pkg . topLevelReferrers . length == 0 ) {
100+ manifests . find ( ( manifest : Manifest ) => manifest . file == location . filePath ) ?. addDirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ;
101+ } else {
102+ manifests . find ( ( manifest : Manifest ) => manifest . file == location . filePath ) ?. addIndirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ; }
105103 } ) ;
106- return manifests ;
107- } catch ( error : any ) {
108- core . error ( error ) ;
109- return undefined ;
110- }
104+ } ) ;
105+ return manifests ;
111106 }
112107
113108 private static getDependencyScope ( pkg : ComponentDetectionPackage ) {
0 commit comments