1
1
import { existsSync , promises as fs } from 'node:fs'
2
2
import path from 'node:path'
3
3
4
- import spawn from '@npmcli/promise-spawn'
5
4
import colors from 'yoctocolors-cjs'
6
5
import yargsParse from 'yargs-parser'
6
+ import { runBin } from '@socketsecurity/registry/lib/npm'
7
7
import { pluralize } from '@socketsecurity/registry/lib/words'
8
8
9
9
import constants from '../constants'
@@ -12,8 +12,6 @@ import type { CliSubcommand } from '../utils/meow-with-subcommands'
12
12
13
13
const { cdxgenBinPath, synpBinPath } = constants
14
14
15
- const { execPath } = process
16
-
17
15
const {
18
16
SBOM_SIGN_ALGORITHM , // Algorithm. Example: RS512
19
17
SBOM_SIGN_PRIVATE_KEY , // Location to the RSA private key
@@ -176,11 +174,10 @@ export const cdxgen: CliSubcommand = {
176
174
// Use synp to create a package-lock.json from the yarn.lock,
177
175
// based on the node_modules folder, for a more accurate SBOM.
178
176
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
+ ] )
184
181
yargv . type = 'npm'
185
182
cleanupPackageLock = true
186
183
} catch { }
@@ -189,23 +186,18 @@ export const cdxgen: CliSubcommand = {
189
186
if ( yargv . output === undefined ) {
190
187
yargv . output = 'socket-cdx.json'
191
188
}
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
+ } )
206
198
if ( cleanupPackageLock ) {
207
199
try {
208
- await fs . unlink ( './package-lock.json' )
200
+ await fs . rm ( './package-lock.json' )
209
201
} catch { }
210
202
}
211
203
const fullOutputPath = path . join ( process . cwd ( ) , yargv . output )
0 commit comments