Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/commands/scan/fetch-create-org-full-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export async function fetchCreateOrgFullScan(
// Lazily access constants.spinner.
const { spinner } = constants

spinner.start(`Creating a scan with ${packagePaths.length} packages...`)
spinner.start(
`Sending request to create a scan with ${packagePaths.length} packages...`
)

const result = await handleApiCall(
sockSdk.createOrgFullScan(
Expand All @@ -39,7 +41,7 @@ export async function fetchCreateOrgFullScan(
'Creating scan'
)

spinner.successAndStop('Scan created successfully')
spinner.successAndStop('Completed request to create a new scan.')

if (!result.success) {
handleUnsuccessfulApiResponse('CreateOrgFullScan', result)
Expand Down
7 changes: 4 additions & 3 deletions src/commands/scan/fetch-supported-scan-file-names.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { logger } from '@socketsecurity/registry/lib/logger'

import constants from '../../constants'
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api'
import { setupSdk } from '../../utils/sdk'
Expand All @@ -19,9 +21,8 @@ export async function fetchSupportedScanFileNames(): Promise<
'fetching supported scan file types'
)

spinner.successAndStop(
'Received response while fetched supported scan file types.'
)
spinner.stop()
logger.success('Received response while fetched supported scan file types.')

if (!result.success) {
handleUnsuccessfulApiResponse('getReportSupportedFiles', result)
Expand Down
1 change: 0 additions & 1 deletion src/commands/scan/handle-create-new-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export async function handleCreateNewScan({
cwd,
targets,
supportedFileNames
// socketConfig
)

handleBadInput({
Expand Down
4 changes: 3 additions & 1 deletion src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import process from 'node:process'

import { debugLog } from '@socketsecurity/registry/lib/debug'
import { logger } from '@socketsecurity/registry/lib/logger'
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'

Expand Down Expand Up @@ -27,7 +28,7 @@ export function handleUnsuccessfulApiResponse<T extends SocketSdkOperations>(

throw new AuthError(message)
}
logger.fail(failMsgWithBadge('API returned an error:', message))
logger.fail(failMsgWithBadge('API returned an error', message))
// eslint-disable-next-line n/no-process-exit
process.exit(1)
}
Expand All @@ -40,6 +41,7 @@ export async function handleApiCall<T>(
try {
result = await value
} catch (cause) {
debugLog('handleApiCall[', description, '] error:\n', cause)
throw new Error(`Failed ${description}`, { cause })
}
return result
Expand Down
34 changes: 25 additions & 9 deletions src/utils/path-resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import micromatch from 'micromatch'
import { glob as tinyGlob } from 'tinyglobby'
import which from 'which'

import { debugLog } from '@socketsecurity/registry/lib/debug'
import { debugLog, isDebug } from '@socketsecurity/registry/lib/debug'
import { resolveBinPath } from '@socketsecurity/registry/lib/npm'

import { directoryPatterns } from './ignore-by-default'
Expand Down Expand Up @@ -254,27 +254,43 @@ export async function getPackageFilesForScan(
supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'],
config?: SocketYml | undefined
): Promise<string[]> {
debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths)
debugLog(
`getPackageFilesForScan: resolving ${inputPaths.length} paths:`,
inputPaths
)

// Lazily access constants.spinner.
const { spinner } = constants

spinner.start('Searching for local files to include in scan...')

const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {
cwd,
socketConfig: config
})

debugLog(
`Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`,
entries
)
if (isDebug()) {
spinner.stop()
debugLog(
`Resolved ${inputPaths.length} paths to ${entries.length} local paths`,
entries
)
spinner.start('Searching for files now...')
} else {
spinner.start(
`Resolved ${inputPaths.length} paths to ${entries.length} local paths, searching for files now...`
)
}

const packageFiles = await filterGlobResultToSupportedFiles(
entries,
supportedFiles
)

debugLog(
`Mapped ${entries.length} entries to ${packageFiles.length} files:`,
packageFiles
spinner.successAndStop(
`Found ${packageFiles.length} local file${packageFiles.length === 1 ? '' : 's'}`
)
debugLog('Absolute paths:', packageFiles)

return packageFiles
}