@@ -18,7 +18,7 @@ import { unmockedModulePathPatterns } from './jest.config'
1818dotenv . config ( ) ;
1919
2020export default class ComponentDetection {
21- public static componentDetectionPath = './component-detection' ;
21+ public static componentDetectionPath = process . platform === "win32" ? './component-detection.exe' : './component-detection' ;
2222 public static outputPath = './output.json' ;
2323
2424 // This is the default entry point for this class.
@@ -30,18 +30,18 @@ export default class ComponentDetection {
3030 // Get the latest release from the component-detection repo, download the tarball, and extract it
3131 public static async downloadLatestRelease ( ) {
3232 try {
33- core . debug ( " Downloading latest release" ) ;
33+ core . debug ( ` Downloading latest release for ${ process . platform } ` ) ;
3434 const downloadURL = await this . getLatestReleaseURL ( ) ;
3535 const blob = await ( await fetch ( new URL ( downloadURL ) ) ) . blob ( ) ;
3636 const arrayBuffer = await blob . arrayBuffer ( ) ;
3737 const buffer = Buffer . from ( arrayBuffer ) ;
3838
3939 // Write the blob to a file
40- core . debug ( " Writing binary to file" ) ;
41- await fs . writeFileSync ( this . componentDetectionPath , buffer , { mode : 0o777 , flag : 'w' } ) ;
40+ core . debug ( ` Writing binary to file ${ this . componentDetectionPath } ` ) ;
41+ await fs . writeFileSync ( this . componentDetectionPath , buffer , { mode : 0o777 , flag : 'w' } ) ;
4242 } catch ( error : any ) {
4343 core . error ( error ) ;
44- }
44+ }
4545 }
4646
4747 // Run the component-detection CLI on the path specified
@@ -64,21 +64,21 @@ export default class ComponentDetection {
6464 return parameters ;
6565 }
6666
67- public static async getManifestsFromResults ( ) : Promise < Manifest [ ] | undefined > {
67+ public static async getManifestsFromResults ( ) : Promise < Manifest [ ] | undefined > {
6868 core . info ( "Getting manifests from results" ) ;
6969 // Parse the result file and add the packages to the package cache
7070 const packageCache = new PackageCache ( ) ;
71- const packages : Array < ComponentDetectionPackage > = [ ] ;
72-
71+ const packages : Array < ComponentDetectionPackage > = [ ] ;
72+
7373 const results = await fs . readFileSync ( this . outputPath , 'utf8' ) ;
74-
74+
7575 var json : any = JSON . parse ( results ) ;
7676 json . componentsFound . forEach ( async ( component : any ) => {
7777 const packageUrl = ComponentDetection . makePackageUrl ( component . component . packageUrl ) ;
78-
78+
7979 if ( ! packageCache . hasPackage ( packageUrl ) ) {
80- const pkg = new ComponentDetectionPackage ( packageUrl , component . component . id ,
81- component . isDevelopmentDependency , component . topLevelReferrers , component . locationsFoundAt , component . containerDetailIds , component . containerLayerIds ) ;
80+ const pkg = new ComponentDetectionPackage ( packageUrl , component . component . id ,
81+ component . isDevelopmentDependency , component . topLevelReferrers , component . locationsFoundAt , component . containerDetailIds , component . containerLayerIds ) ;
8282 packageCache . addPackage ( pkg ) ;
8383 packages . push ( pkg ) ;
8484 }
@@ -108,7 +108,8 @@ export default class ComponentDetection {
108108 if ( pkg . topLevelReferrers . length == 0 ) {
109109 manifests . find ( ( manifest : Manifest ) => manifest . name == location ) ?. addDirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ;
110110 } else {
111- manifests . find ( ( manifest : Manifest ) => manifest . name == location ) ?. addIndirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ; }
111+ manifests . find ( ( manifest : Manifest ) => manifest . name == location ) ?. addIndirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ;
112+ }
112113 } ) ;
113114 } ) ;
114115 return manifests ;
@@ -134,7 +135,7 @@ export default class ComponentDetection {
134135 }
135136
136137 private static async getLatestReleaseURL ( ) : Promise < string > {
137- const githubToken = core . getInput ( 'token' ) || process . env . GITHUB_TOKEN || "" ;
138+ const githubToken = core . getInput ( 'token' ) || process . env . GITHUB_TOKEN || "" ;
138139 const octokit = github . getOctokit ( githubToken ) ;
139140 const owner = "microsoft" ;
140141 const repo = "component-detection" ;
@@ -144,8 +145,9 @@ export default class ComponentDetection {
144145 } ) ;
145146
146147 var downloadURL : string = "" ;
148+ const assetName = process . platform === "win32" ? "component-detection-win-x64.exe" : "component-detection-linux-x64" ;
147149 latestRelease . data . assets . forEach ( ( asset : any ) => {
148- if ( asset . name === "component-detection-linux-x64" ) {
150+ if ( asset . name === assetName ) {
149151 downloadURL = asset . browser_download_url ;
150152 }
151153 } ) ;
@@ -155,8 +157,8 @@ export default class ComponentDetection {
155157}
156158
157159class ComponentDetectionPackage extends Package {
158-
159- constructor ( packageUrl : string , public id : string , public isDevelopmentDependency :boolean , public topLevelReferrers : [ ] ,
160+
161+ constructor ( packageUrl : string , public id : string , public isDevelopmentDependency : boolean , public topLevelReferrers : [ ] ,
160162 public locationsFoundAt : [ ] , public containerDetailIds : [ ] , public containerLayerIds : [ ] ) {
161163 super ( packageUrl ) ;
162164 }
0 commit comments