@@ -7,9 +7,14 @@ import { outputCreateNewScan } from './output-create-new-scan.mts'
77import { suggestOrgSlug } from './suggest-org-slug.mts'
88import { suggestTarget } from './suggest_target.mts'
99import constants from '../../constants.mts'
10- import { commonFlags , outputFlags } from '../../flags.mts'
10+ import { type MeowFlags , commonFlags , outputFlags } from '../../flags.mts'
1111import { checkCommandInput } from '../../utils/check-input.mts'
12+ import { cmdFlagValueToArray } from '../../utils/cmd.mts'
1213import { determineOrgSlug } from '../../utils/determine-org-slug.mts'
14+ import {
15+ type EcosystemString ,
16+ getEcosystemChoicesForMeow ,
17+ } from '../../utils/ecosystem.mts'
1318import { getOutputKind } from '../../utils/get-output-kind.mts'
1419import { getRepoName , gitBranch } from '../../utils/git.mts'
1520import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
@@ -26,6 +31,42 @@ const {
2631 SOCKET_DEFAULT_REPOSITORY ,
2732} = constants
2833
34+ const reachabilityFlags : MeowFlags = {
35+ reachDisableAnalytics : {
36+ type : 'boolean' ,
37+ description :
38+ 'Disable reachability analytics sharing with Socket. Also disables caching-based optimizations.' ,
39+ } ,
40+ reachAnalysisMemoryLimit : {
41+ type : 'number' ,
42+ description :
43+ 'The maximum memory in MB to use for the reachability analysis. The default is 8192MB.' ,
44+ default : 8192 ,
45+ } ,
46+ reachAnalysisTimeout : {
47+ type : 'number' ,
48+ description :
49+ 'Set timeout for the reachability analysis. Split analysis runs may cause the total scan time to exceed this timeout significantly.' ,
50+ } ,
51+ reachEcosystems : {
52+ type : 'string' ,
53+ isMultiple : true ,
54+ description :
55+ 'List of ecosystems to conduct reachability analysis on, as either a comma separated value or as multiple flags. Defaults to all ecosystems.' ,
56+ } ,
57+ reachContinueOnFailingProjects : {
58+ type : 'boolean' ,
59+ description :
60+ 'Continue reachability analysis even when some projects/workspaces fail. Default is to crash the CLI at the first failing project/workspace.' ,
61+ } ,
62+ reachExcludePaths : {
63+ type : 'string' ,
64+ isMultiple : true ,
65+ description :
66+ 'List of paths to exclude from reachability analysis, as either a comma separated value or as multiple flags.' ,
67+ } ,
68+ }
69+
2970const config : CliCommandConfig = {
3071 commandName : 'create' ,
3172 description : 'Create a new Socket scan and report' ,
@@ -87,19 +128,16 @@ const config: CliCommandConfig = {
87128 description :
88129 'Force override the organization slug, overrides the default org from config' ,
89130 } ,
90- readOnly : {
131+ reach : {
91132 type : 'boolean' ,
92133 default : false ,
93- description :
94- 'Similar to --dry-run except it can read from remote, stops before it would create an actual report' ,
134+ description : 'Run tier 1 full application reachability analysis' ,
95135 } ,
96- reach : {
136+ readOnly : {
97137 type : 'boolean' ,
98138 default : false ,
99- // TODO: Temporarily hide option until Coana side is ironed out.
100- hidden : true ,
101139 description :
102- 'Run tier 1 full application reachability analysis during the scanning process ' ,
140+ 'Similar to --dry-run except it can read from remote, stops before it would create an actual report ' ,
103141 } ,
104142 repo : {
105143 type : 'string' ,
@@ -125,9 +163,23 @@ const config: CliCommandConfig = {
125163 description :
126164 'Set the visibility (true/false) of the scan in your dashboard.' ,
127165 } ,
166+
167+ // Reachability scan flags
168+ ...reachabilityFlags ,
128169 } ,
129170 // TODO: Your project's "socket.yml" file's "projectIgnorePaths".
130- help : ( command , config ) => `
171+ help : ( command , config ) => {
172+ const allFlags = config . flags || { }
173+ const generalFlags : MeowFlags = { }
174+
175+ // Separate general flags from reachability flags
176+ for ( const [ key , value ] of Object . entries ( allFlags ) ) {
177+ if ( ! reachabilityFlags [ key ] ) {
178+ generalFlags [ key ] = value
179+ }
180+ }
181+
182+ return `
131183 Usage
132184 $ ${ command } [options] [TARGET...]
133185
@@ -136,7 +188,10 @@ const config: CliCommandConfig = {
136188 - Permissions: full-scans:create
137189
138190 Options
139- ${ getFlagListOutput ( config . flags ) }
191+ ${ getFlagListOutput ( generalFlags ) }
192+
193+ Reachability Options (when --reach is used)
194+ ${ getFlagListOutput ( reachabilityFlags ) }
140195
141196 Uploads the specified dependency manifest files for Go, Gradle, JavaScript,
142197 Kotlin, Python, and Scala. Files like "package.json" and "requirements.txt".
@@ -172,7 +227,8 @@ const config: CliCommandConfig = {
172227 $ ${ command }
173228 $ ${ command } ./proj --json
174229 $ ${ command } --repo=test-repo --branch=main ./package.json
175- ` ,
230+ `
231+ } ,
176232}
177233
178234export const cmdScanCreate = {
@@ -206,6 +262,10 @@ async function run(
206262 org : orgFlag ,
207263 pullRequest,
208264 reach,
265+ reachAnalysisMemoryLimit,
266+ reachAnalysisTimeout,
267+ reachContinueOnFailingProjects,
268+ reachDisableAnalytics,
209269 readOnly,
210270 setAsAlertsPage : pendingHeadFlag ,
211271 tmp,
@@ -221,11 +281,34 @@ async function run(
221281 markdown : boolean
222282 org : string
223283 pullRequest : number
224- reach : boolean
225284 readOnly : boolean
226285 setAsAlertsPage : boolean
227286 tmp : boolean
287+
288+ // reachability flags
289+ reach : boolean
290+ reachAnalysisTimeout ?: number
291+ reachAnalysisMemoryLimit ?: number
292+ reachContinueOnFailingProjects : boolean
293+ reachDisableAnalytics : boolean
228294 }
295+
296+ // Process comma-separated values for isMultiple flags
297+ const reachEcosystemsRaw = cmdFlagValueToArray ( cli . flags [ 'reachEcosystems' ] )
298+ const reachExcludePaths = cmdFlagValueToArray ( cli . flags [ 'reachExcludePaths' ] )
299+
300+ // Validate ecosystem values
301+ const validEcosystems = getEcosystemChoicesForMeow ( )
302+ const reachEcosystems : EcosystemString [ ] = [ ]
303+ for ( const ecosystem of reachEcosystemsRaw ) {
304+ if ( ! validEcosystems . includes ( ecosystem ) ) {
305+ throw new Error (
306+ `Invalid ecosystem: "${ ecosystem } ". Valid values are: ${ validEcosystems . join ( ', ' ) } ` ,
307+ )
308+ }
309+ reachEcosystems . push ( ecosystem as EcosystemString )
310+ }
311+
229312 let {
230313 autoManifest,
231314 branch : branchName ,
@@ -395,6 +478,52 @@ async function run(
395478 message : 'When --defaultBranch is set, --branch is mandatory' ,
396479 fail : 'missing branch name' ,
397480 } ,
481+ {
482+ nook : true ,
483+ test : reach || ! reachDisableAnalytics ,
484+ message : 'The --reachDisableAnalytics flag requires --reach to be set' ,
485+ pass : 'ok' ,
486+ fail : 'missing --reach flag' ,
487+ } ,
488+ {
489+ nook : true ,
490+ test :
491+ reach ||
492+ reachAnalysisMemoryLimit === undefined ||
493+ reachAnalysisMemoryLimit === 8192 ,
494+ message : 'The --reachAnalysisMemoryLimit flag requires --reach to be set' ,
495+ pass : 'ok' ,
496+ fail : 'missing --reach flag' ,
497+ } ,
498+ {
499+ nook : true ,
500+ test : reach || ! reachAnalysisTimeout ,
501+ message : 'The --reachAnalysisTimeout flag requires --reach to be set' ,
502+ pass : 'ok' ,
503+ fail : 'missing --reach flag' ,
504+ } ,
505+ {
506+ nook : true ,
507+ test : reach || ! reachEcosystems . length ,
508+ message : 'The --reachEcosystems flag requires --reach to be set' ,
509+ pass : 'ok' ,
510+ fail : 'missing --reach flag' ,
511+ } ,
512+ {
513+ nook : true ,
514+ test : reach || ! reachContinueOnFailingProjects ,
515+ message :
516+ 'The --reachContinueOnFailingProjects flag requires --reach to be set' ,
517+ pass : 'ok' ,
518+ fail : 'missing --reach flag' ,
519+ } ,
520+ {
521+ nook : true ,
522+ test : reach || ! reachExcludePaths . length ,
523+ message : 'The --reachExcludePaths flag requires --reach to be set' ,
524+ pass : 'ok' ,
525+ fail : 'missing --reach flag' ,
526+ } ,
398527 )
399528 if ( ! wasValidInput ) {
400529 return
@@ -419,7 +548,15 @@ async function run(
419548 outputKind,
420549 pendingHead : Boolean ( pendingHead ) ,
421550 pullRequest : Number ( pullRequest ) ,
422- reach : Boolean ( reach ) ,
551+ reach : {
552+ runReachabilityAnalysis : Boolean ( reach ) ,
553+ reachContinueOnFailingProjects : Boolean ( reachContinueOnFailingProjects ) ,
554+ reachDisableAnalytics : Boolean ( reachDisableAnalytics ) ,
555+ reachAnalysisTimeout : Number ( reachAnalysisTimeout ) ,
556+ reachAnalysisMemoryLimit : Number ( reachAnalysisMemoryLimit ) ,
557+ reachEcosystems,
558+ reachExcludePaths,
559+ } ,
423560 readOnly : Boolean ( readOnly ) ,
424561 repoName,
425562 report,
0 commit comments