-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathhandle-scan-reach.mts
More file actions
98 lines (82 loc) · 2.71 KB
/
handle-scan-reach.mts
File metadata and controls
98 lines (82 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { logger } from '@socketsecurity/registry/lib/logger'
import { pluralize } from '@socketsecurity/registry/lib/words'
import { fetchSupportedScanFileNames } from './fetch-supported-scan-file-names.mts'
import { outputScanReach } from './output-scan-reach.mts'
import { performReachabilityAnalysis } from './perform-reachability-analysis.mts'
import constants from '../../constants.mts'
import { checkCommandInput } from '../../utils/check-input.mts'
import { findSocketYmlSync } from '../../utils/config.mts'
import { getPackageFilesForScan } from '../../utils/path-resolve.mts'
import type { ReachabilityOptions } from './perform-reachability-analysis.mts'
import type { OutputKind } from '../../types.mts'
export type HandleScanReachConfig = {
cwd: string
interactive: boolean
orgSlug: string
outputKind: OutputKind
outputPath: string
reachabilityOptions: ReachabilityOptions
targets: string[]
}
export async function handleScanReach({
cwd,
interactive: _interactive,
orgSlug,
outputKind,
outputPath,
reachabilityOptions,
targets,
}: HandleScanReachConfig) {
const { spinner } = constants
// Get supported file names
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner })
if (!supportedFilesCResult.ok) {
await outputScanReach(supportedFilesCResult, {
outputKind,
outputPath,
})
return
}
spinner.start(
'Searching for local manifest files to include in reachability analysis...',
)
const supportedFiles = supportedFilesCResult.data
// Load socket.yml to respect projectIgnorePaths when collecting files.
const socketYmlResult = findSocketYmlSync(cwd)
const socketConfig = socketYmlResult.ok
? socketYmlResult.data?.parsed
: undefined
const packagePaths = await getPackageFilesForScan(targets, supportedFiles, {
config: socketConfig,
cwd,
})
spinner.successAndStop(
`Found ${packagePaths.length} ${pluralize('manifest file', packagePaths.length)} for reachability analysis.`,
)
const wasValidInput = checkCommandInput(outputKind, {
nook: true,
test: packagePaths.length > 0,
fail: 'found no eligible files to analyze',
message:
'TARGET (file/dir) must contain matching / supported file types for reachability analysis',
})
if (!wasValidInput) {
return
}
logger.success(
`Found ${packagePaths.length} local ${pluralize('file', packagePaths.length)}`,
)
spinner.start('Running reachability analysis...')
const result = await performReachabilityAnalysis({
cwd,
orgSlug,
outputPath,
packagePaths,
reachabilityOptions,
spinner,
target: targets[0]!,
uploadManifests: true,
})
spinner.stop()
await outputScanReach(result, { outputKind, outputPath })
}