Skip to content

Commit 5895609

Browse files
committed
Remove logging from getPackageFilesForScan
1 parent ff5788a commit 5895609

File tree

2 files changed

+43
-59
lines changed

2 files changed

+43
-59
lines changed

src/commands/scan/handle-create-new-scan.mts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { debugDir, debugFn } from '@socketsecurity/registry/lib/debug'
12
import { logger } from '@socketsecurity/registry/lib/logger'
3+
import { pluralize } from '@socketsecurity/registry/lib/words'
24

35
import { fetchCreateOrgFullScan } from './fetch-create-org-full-scan.mts'
46
import { fetchSupportedScanFileNames } from './fetch-supported-scan-file-names.mts'
57
import { handleScanReport } from './handle-scan-report.mts'
68
import { outputCreateNewScan } from './output-create-new-scan.mts'
9+
import constants from '../../constants.mts'
710
import { checkCommandInput } from '../../utils/check-input.mts'
811
import { getPackageFilesForScan } from '../../utils/path-resolve.mts'
912
import { readOrDefaultSocketJson } from '../../utils/socketjson.mts'
@@ -50,7 +53,7 @@ export async function handleCreateNewScan({
5053
tmp: boolean
5154
}): Promise<void> {
5255
if (autoManifest) {
53-
logger.info('Auto generating manifest files ...')
56+
logger.info('Auto-generating manifest files ...')
5457
const sockJson = await readOrDefaultSocketJson(cwd)
5558
const detected = await detectManifestActions(sockJson, cwd)
5659
await generateAutoManifest({
@@ -59,20 +62,26 @@ export async function handleCreateNewScan({
5962
outputKind,
6063
verbose: false,
6164
})
62-
logger.info('Auto generation finished. Proceeding with Scan creation.')
65+
logger.info('Auto-generation finished. Proceeding with Scan creation.')
6366
}
6467

65-
const fileNamesCResult = await fetchSupportedScanFileNames()
66-
if (!fileNamesCResult.ok) {
67-
await outputCreateNewScan(fileNamesCResult, outputKind, interactive)
68+
const supportedFilesCResult = await fetchSupportedScanFileNames()
69+
if (!supportedFilesCResult.ok) {
70+
await outputCreateNewScan(supportedFilesCResult, outputKind, interactive)
6871
return
6972
}
7073

71-
const packagePaths = await getPackageFilesForScan(
74+
// Lazily access constants.spinner.
75+
const { spinner } = constants
76+
77+
spinner.start('Searching for local files to include in scan...')
78+
79+
const supportedFiles = supportedFilesCResult.data
80+
const packagePaths = await getPackageFilesForScan(targets, supportedFiles, {
7281
cwd,
73-
targets,
74-
fileNamesCResult.data,
75-
)
82+
})
83+
84+
spinner.stop()
7685

7786
const wasValidInput = checkCommandInput(outputKind, {
7887
nook: true,
@@ -86,12 +95,18 @@ export async function handleCreateNewScan({
8695
return
8796
}
8897

98+
debugFn(
99+
'notice',
100+
`found: ${packagePaths.length} local ${pluralize('file', packagePaths.length)}`,
101+
)
102+
debugDir('inspect', { packagePaths })
103+
89104
if (readOnly) {
90105
logger.log('[ReadOnly] Bailing now')
91106
return
92107
}
93108

94-
const data = await fetchCreateOrgFullScan(
109+
const fullScanCResult = await fetchCreateOrgFullScan(
95110
packagePaths,
96111
orgSlug,
97112
defaultBranch,
@@ -108,16 +123,16 @@ export async function handleCreateNewScan({
108123
},
109124
)
110125

111-
if (data.ok && report) {
112-
if (data.data?.id) {
126+
if (fullScanCResult.ok && report) {
127+
if (fullScanCResult.data?.id) {
113128
await handleScanReport({
114129
filePath: '-',
115130
fold: 'version',
116131
includeLicensePolicy: true,
117132
orgSlug,
118133
outputKind,
119134
reportLevel: 'error',
120-
scanId: data.data.id,
135+
scanId: fullScanCResult.data.id,
121136
short: false,
122137
})
123138
} else {
@@ -126,13 +141,13 @@ export async function handleCreateNewScan({
126141
ok: false,
127142
message: 'Missing Scan ID',
128143
cause: 'Server did not respond with a scan ID',
129-
data: data.data,
144+
data: fullScanCResult.data,
130145
},
131146
outputKind,
132147
interactive,
133148
)
134149
}
135150
} else {
136-
await outputCreateNewScan(data, outputKind, interactive)
151+
await outputCreateNewScan(fullScanCResult, outputKind, interactive)
137152
}
138153
}

src/utils/path-resolve.mts

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import path from 'node:path'
33

44
import which from 'which'
55

6-
import { debugDir, debugFn, isDebug } from '@socketsecurity/registry/lib/debug'
76
import { resolveBinPathSync } from '@socketsecurity/registry/lib/npm'
8-
import { pluralize } from '@socketsecurity/registry/lib/words'
97

108
import constants from '../constants.mts'
119
import { safeStatsSync } from './fs.mts'
@@ -93,52 +91,23 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
9391
}
9492
}
9593

94+
export type PackageFilesForScanOptions = {
95+
cwd?: string | undefined
96+
config?: SocketYml | undefined
97+
}
98+
9699
export async function getPackageFilesForScan(
97-
cwd: string,
98100
inputPaths: string[],
99101
supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'],
100-
config?: SocketYml | undefined,
102+
options?: PackageFilesForScanOptions | undefined,
101103
): Promise<string[]> {
102-
debugFn('notice', `resolve: ${inputPaths.length} paths`, inputPaths)
103-
104-
// Lazily access constants.spinner.
105-
const { spinner } = constants
106-
107-
const patterns = pathsToGlobPatterns(inputPaths)
108-
109-
spinner.start('Searching for local files to include in scan...')
110-
111-
const entries = await globWithGitIgnore(patterns, {
104+
const { config: socketConfig, cwd = process.cwd() } = {
105+
__proto__: null,
106+
...options,
107+
} as PackageFilesForScanOptions
108+
const entries = await globWithGitIgnore(pathsToGlobPatterns(inputPaths), {
112109
cwd,
113-
socketConfig: config,
110+
socketConfig,
114111
})
115-
116-
if (isDebug('notice')) {
117-
spinner.stop()
118-
119-
debugFn(
120-
'notice',
121-
`Resolved ${inputPaths.length} paths to ${entries.length} local paths:\n`,
122-
entries,
123-
)
124-
125-
spinner.start('Searching for files now...')
126-
} else {
127-
spinner.start(
128-
`Resolved ${inputPaths.length} paths to ${entries.length} local paths, searching for files now...`,
129-
)
130-
}
131-
132-
const packageFiles = await filterGlobResultToSupportedFiles(
133-
entries,
134-
supportedFiles,
135-
)
136-
137-
spinner.successAndStop(
138-
`Found ${packageFiles.length} local ${pluralize('file', packageFiles.length)}`,
139-
)
140-
141-
debugDir('inspect', { packageFiles })
142-
143-
return packageFiles
112+
return await filterGlobResultToSupportedFiles(entries, supportedFiles)
144113
}

0 commit comments

Comments
 (0)