1+ import { debugDir , debugFn } from '@socketsecurity/registry/lib/debug'
12import { logger } from '@socketsecurity/registry/lib/logger'
3+ import { pluralize } from '@socketsecurity/registry/lib/words'
24
35import { fetchCreateOrgFullScan } from './fetch-create-org-full-scan.mts'
46import { fetchSupportedScanFileNames } from './fetch-supported-scan-file-names.mts'
57import { handleScanReport } from './handle-scan-report.mts'
68import { outputCreateNewScan } from './output-create-new-scan.mts'
9+ import constants from '../../constants.mts'
710import { checkCommandInput } from '../../utils/check-input.mts'
811import { getPackageFilesForScan } from '../../utils/path-resolve.mts'
912import { 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}
0 commit comments