11import { existsSync , promises as fs } from 'node:fs'
22import path from 'node:path'
33
4- import spawn from '@npmcli/promise-spawn'
54import colors from 'yoctocolors-cjs'
65import yargsParse from 'yargs-parser'
6+ import { runBin } from '@socketsecurity/registry/lib/npm'
77import { pluralize } from '@socketsecurity/registry/lib/words'
88
99import constants from '../constants'
@@ -12,8 +12,6 @@ import type { CliSubcommand } from '../utils/meow-with-subcommands'
1212
1313const { cdxgenBinPath, synpBinPath } = constants
1414
15- const { execPath } = process
16-
1715const {
1816 SBOM_SIGN_ALGORITHM , // Algorithm. Example: RS512
1917 SBOM_SIGN_PRIVATE_KEY , // Location to the RSA private key
@@ -176,11 +174,10 @@ export const cdxgen: CliSubcommand = {
176174 // Use synp to create a package-lock.json from the yarn.lock,
177175 // based on the node_modules folder, for a more accurate SBOM.
178176 try {
179- await spawn (
180- execPath ,
181- [ await fs . realpath ( synpBinPath ) , '--source-file' , './yarn.lock' ] ,
182- { shell : true }
183- )
177+ await runBin ( await fs . realpath ( synpBinPath ) , [
178+ '--source-file' ,
179+ './yarn.lock'
180+ ] )
184181 yargv . type = 'npm'
185182 cleanupPackageLock = true
186183 } catch { }
@@ -189,23 +186,18 @@ export const cdxgen: CliSubcommand = {
189186 if ( yargv . output === undefined ) {
190187 yargv . output = 'socket-cdx.json'
191188 }
192- await spawn (
193- execPath ,
194- [ await fs . realpath ( cdxgenBinPath ) , ...argvToArray ( yargv ) ] ,
195- {
196- env : {
197- NODE_ENV : '' ,
198- SBOM_SIGN_ALGORITHM ,
199- SBOM_SIGN_PRIVATE_KEY ,
200- SBOM_SIGN_PUBLIC_KEY
201- } ,
202- shell : true ,
203- stdio : 'inherit'
204- }
205- )
189+ await runBin ( await fs . realpath ( cdxgenBinPath ) , argvToArray ( yargv ) , {
190+ env : {
191+ NODE_ENV : '' ,
192+ SBOM_SIGN_ALGORITHM ,
193+ SBOM_SIGN_PRIVATE_KEY ,
194+ SBOM_SIGN_PUBLIC_KEY
195+ } ,
196+ stdio : 'inherit'
197+ } )
206198 if ( cleanupPackageLock ) {
207199 try {
208- await fs . unlink ( './package-lock.json' )
200+ await fs . rm ( './package-lock.json' )
209201 } catch { }
210202 }
211203 const fullOutputPath = path . join ( process . cwd ( ) , yargv . output )
0 commit comments