@@ -11,25 +11,22 @@ import type { PURL_Type } from '../../utils/ecosystem.mts'
1111import type { Spinner } from '@socketsecurity/registry/lib/spinner'
1212
1313export type ReachabilityOptions = {
14- reachDisableAnalytics : boolean
1514 reachAnalysisTimeout : number
1615 reachAnalysisMemoryLimit : number
16+ reachDisableAnalytics : boolean
1717 reachEcosystems : PURL_Type [ ]
1818 reachExcludePaths : string [ ]
1919}
2020
21- export type ReachabilityAnalysisConfig = {
22- branchName ?: string
23- cwd : string
24- orgSlug ?: string
25- packagePaths ?: string [ ]
26- reachabilityOptions : ReachabilityOptions
27- repoName ?: string
28- uploadManifests ?: boolean
29- }
30-
3121export type ReachabilityAnalysisOptions = {
22+ branchName ?: string | undefined
23+ cwd ?: string | undefined
24+ orgSlug ?: string | undefined
25+ packagePaths ?: string [ ] | undefined
26+ reachabilityOptions : ReachabilityOptions
27+ repoName ?: string | undefined
3228 spinner ?: Spinner | undefined
29+ uploadManifests ?: boolean | undefined
3330}
3431
3532export type ReachabilityAnalysisResult = {
@@ -38,22 +35,18 @@ export type ReachabilityAnalysisResult = {
3835}
3936
4037export async function performReachabilityAnalysis (
41- {
38+ options ?: ReachabilityAnalysisOptions | undefined ,
39+ ) : Promise < CResult < ReachabilityAnalysisResult > > {
40+ const {
4241 branchName,
43- cwd,
42+ cwd = process . cwd ( ) ,
4443 orgSlug,
4544 packagePaths,
4645 reachabilityOptions,
4746 repoName,
47+ spinner,
4848 uploadManifests = true ,
49- } : ReachabilityAnalysisConfig ,
50- options ?: ReachabilityAnalysisOptions | undefined ,
51- ) : Promise < CResult < ReachabilityAnalysisResult > > {
52- const { spinner } = {
53- __proto__ : null ,
54- ...options ,
55- } as ReachabilityAnalysisOptions
56-
49+ } = { __proto__ : null , ...options } as ReachabilityAnalysisOptions
5750 let tarHash : string | undefined
5851
5952 if ( uploadManifests && orgSlug && packagePaths ) {
@@ -67,15 +60,15 @@ export async function performReachabilityAnalysis(
6760
6861 const wasSpinning = ! ! spinner ?. isSpinning
6962
70- // Upload manifests to get tar hash
71- spinner ?. start ( 'Uploading manifests for reachability analysis...' )
72-
73- // Exclude DOT_SOCKET_DOT_FACTS_JSON if it was created in previous runs.
74- const filteredPackagePaths = packagePaths . filter (
63+ // Exclude .socket.facts.json from upload.
64+ const filepathsToUpload = packagePaths . filter (
7565 p => ! p . endsWith ( constants . DOT_SOCKET_DOT_FACTS_JSON ) ,
7666 )
67+
68+ spinner ?. start ( 'Uploading manifests for reachability analysis...' )
69+
7770 const uploadCResult = await handleApiCall (
78- sockSdk . uploadManifestFiles ( orgSlug , filteredPackagePaths ) ,
71+ sockSdk . uploadManifestFiles ( orgSlug , filepathsToUpload ) ,
7972 {
8073 desc : 'upload manifests' ,
8174 spinner,
@@ -105,16 +98,12 @@ export async function performReachabilityAnalysis(
10598
10699 spinner ?. start ( )
107100 spinner ?. success ( `Manifests uploaded successfully. Tar hash: ${ tarHash } ` )
108- spinner ?. infoAndStop ( 'Running reachability analysis with Coana...' )
109- } else {
110- const wasSpinning = ! ! spinner ?. isSpinning
111- spinner ?. start ( 'Running reachability analysis with Coana...' )
112- if ( ! wasSpinning ) {
113- spinner ?. stop ( )
114- }
115101 }
116102
117- // Build Coana arguments
103+ spinner ?. start ( )
104+ spinner ?. infoAndStop ( 'Running reachability analysis with Coana...' )
105+
106+ // Build Coana arguments.
118107 const coanaArgs = [
119108 'run' ,
120109 cwd ,
@@ -124,33 +113,27 @@ export async function performReachabilityAnalysis(
124113 constants . DOT_SOCKET_DOT_FACTS_JSON ,
125114 '--disable-report-submission' ,
126115 ...( reachabilityOptions . reachAnalysisTimeout
127- ? [
128- '--analysis-timeout' ,
129- reachabilityOptions . reachAnalysisTimeout . toString ( ) ,
130- ]
116+ ? [ '--analysis-timeout' , `${ reachabilityOptions . reachAnalysisTimeout } ` ]
131117 : [ ] ) ,
132118 ...( reachabilityOptions . reachAnalysisMemoryLimit
133- ? [
134- '--memory-limit' ,
135- reachabilityOptions . reachAnalysisMemoryLimit . toString ( ) ,
136- ]
119+ ? [ '--memory-limit' , `${ reachabilityOptions . reachAnalysisMemoryLimit } ` ]
137120 : [ ] ) ,
138121 ...( reachabilityOptions . reachDisableAnalytics
139122 ? [ '--disable-analytics-sharing' ]
140123 : [ ] ) ,
141- // empty reachEcosystems implies scan all ecosystems
124+ ...( tarHash
125+ ? [ '--run-without-docker' , '--manifests-tar-hash' , tarHash ]
126+ : [ ] ) ,
127+ // Empty reachEcosystems implies scan all ecosystems.
142128 ...( reachabilityOptions . reachEcosystems . length
143129 ? [ '--purl-types' , ...reachabilityOptions . reachEcosystems ]
144130 : [ ] ) ,
145131 ...( reachabilityOptions . reachExcludePaths . length
146- ? [ '--exclude-dirs' , reachabilityOptions . reachExcludePaths . join ( ' ' ) ]
147- : [ ] ) ,
148- ...( tarHash
149- ? [ '--manifests-tar-hash' , tarHash , '--run-without-docker' ]
132+ ? [ '--exclude-dirs' , ...reachabilityOptions . reachExcludePaths ]
150133 : [ ] ) ,
151134 ]
152135
153- // Build environment variables
136+ // Build environment variables.
154137 const env : NodeJS . ProcessEnv = {
155138 ...process . env ,
156139 }
@@ -161,7 +144,6 @@ export async function performReachabilityAnalysis(
161144 env [ 'SOCKET_BRANCH_NAME' ] = branchName
162145 }
163146
164- // Run Coana with the manifests tar hash.
165147 const coanaResult = await spawnCoana ( coanaArgs , {
166148 cwd,
167149 env,
0 commit comments