@@ -17,8 +17,8 @@ import { Context } from '@actions/github/lib/context'
1717import { unmockedModulePathPatterns } from './jest.config'
1818dotenv . config ( ) ;
1919export default class ComponentDetection {
20- private componentDetectionPath = './component-detection' ;
21- private outputPath = './output.json' ;
20+ protected static componentDetectionPath = './component-detection' ;
21+ protected static outputPath = './output.json' ;
2222
2323 // This is the default entry point for this class.
2424 static async scanAndGetManifests ( path : string ) : Promise < Manifest [ ] | undefined > {
@@ -29,13 +29,13 @@ export default class ComponentDetection {
2929 // Get the latest release from the component-detection repo, download the tarball, and extract it
3030 private static async downloadLatestRelease ( ) {
3131 try {
32- const downloadURL = await getLatestReleaseURL ( ) ;
32+ const downloadURL = await this . getLatestReleaseURL ( ) ;
3333 const blob = await ( await fetch ( new URL ( downloadURL ) ) ) . blob ( ) ;
3434 const arrayBuffer = await blob . arrayBuffer ( ) ;
3535 const buffer = Buffer . from ( arrayBuffer ) ;
3636
3737 // Write the blob to a file
38- await fs . writeFile ( componentDetectionPath , buffer , { mode : 0o777 , flag : 'w' } ,
38+ await fs . writeFile ( this . componentDetectionPath , buffer , { mode : 0o777 , flag : 'w' } ,
3939 ( err : any ) => {
4040 if ( err ) {
4141 core . error ( err ) ;
@@ -49,7 +49,7 @@ export default class ComponentDetection {
4949 // Run the component-detection CLI on the path specified
5050 private static async runComponentDetection ( path : string ) {
5151 try {
52- await exec . exec ( `${ componentDetectionPath } scan --SourceDirectory ${ path } --ManifestFile ${ outputPath } ` ) ;
52+ await exec . exec ( `${ this . componentDetectionPath } scan --SourceDirectory ${ path } --ManifestFile ${ this . outputPath } ` ) ;
5353 } catch ( error : any ) {
5454 core . error ( error ) ;
5555 }
@@ -62,11 +62,11 @@ export default class ComponentDetection {
6262 const packageCache = new PackageCache ( ) ;
6363 const packages : Array < ComponentDetectionPackage > = [ ] ;
6464
65- const results = await fs . readFileSync ( outputPath , 'utf8' ) ;
65+ const results = await fs . readFileSync ( this . outputPath , 'utf8' ) ;
6666
6767 var json : any = JSON . parse ( results ) ;
6868 json . componentsFound . forEach ( async ( component : any ) => {
69- const packageUrl = makePackageUrl ( component . component . packageUrl ) ;
69+ const packageUrl = ComponentDetection . makePackageUrl ( component . component . packageUrl ) ;
7070
7171 if ( ! packageCache . hasPackage ( packageUrl ) ) {
7272 const pkg = new ComponentDetectionPackage ( packageUrl , component . component . id ,
@@ -79,7 +79,7 @@ export default class ComponentDetection {
7979 // Set the transitive dependencies
8080 packages . forEach ( async ( pkg : ComponentDetectionPackage ) => {
8181 pkg . toplevelReferrers . forEach ( async ( referrer : any ) => {
82- const referrerPackage = packageCache . lookupPackage ( makePackageUrl ( referrer . packageUrl ) ) ;
82+ const referrerPackage = packageCache . lookupPackage ( ComponentDetection . makePackageUrl ( referrer . packageUrl ) ) ;
8383 if ( referrerPackage ) {
8484 referrerPackage . dependsOn ( pkg ) ;
8585 }
@@ -97,9 +97,9 @@ export default class ComponentDetection {
9797 manifests . push ( manifest ) ;
9898 }
9999 if ( pkg . toplevelReferrers . length == 0 ) {
100- manifests . find ( ( manifest : Manifest ) => manifest . file == location . filePath ) ?. addDirectDependency ( pkg , getDependencyScope ( pkg ) ) ;
100+ manifests . find ( ( manifest : Manifest ) => manifest . file == location . filePath ) ?. addDirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ;
101101 } else {
102- manifests . find ( ( manifest : Manifest ) => manifest . file == location . filePath ) ?. addIndirectDependency ( pkg , getDependencyScope ( pkg ) ) ; }
102+ manifests . find ( ( manifest : Manifest ) => manifest . file == location . filePath ) ?. addIndirectDependency ( pkg , ComponentDetection . getDependencyScope ( pkg ) ) ; }
103103 } ) ;
104104 } ) ;
105105 core . debug ( JSON . stringify ( manifests ) ) ;
@@ -129,7 +129,7 @@ export default class ComponentDetection {
129129 return packageUrl ;
130130 }
131131
132- private static getLatestReleaseURL ( ) : Promise < string > {
132+ private static async getLatestReleaseURL ( ) : Promise < string > {
133133 const githubToken = core . getInput ( 'token' ) || process . env . GITHUB_TOKEN2 || "" ;
134134 const octokit = github . getOctokit ( githubToken ) ;
135135 const owner = "microsoft" ;
0 commit comments