@@ -27,7 +27,6 @@ import {
2727 GQL_PR_STATE_OPEN ,
2828} from '../../constants.mts'
2929import { handleApiCall } from '../../utils/api.mts'
30- import { cmdFlagValueToArray } from '../../utils/cmd.mts'
3130import { spawnCoanaDlx } from '../../utils/dlx.mts'
3231import { getErrorCause } from '../../utils/errors.mts'
3332import {
@@ -57,6 +56,7 @@ type DiscoverGhsaIdsOptions = {
5756 cwd ?: string | undefined
5857 limit ?: number | undefined
5958 spinner ?: Spinner | undefined
59+ coanaVersion ?: string | undefined
6060}
6161
6262/**
@@ -66,7 +66,6 @@ type DiscoverGhsaIdsOptions = {
6666async function discoverGhsaIds (
6767 orgSlug : string ,
6868 tarHash : string ,
69- fixConfig : FixConfig ,
7069 options ?: DiscoverGhsaIdsOptions | undefined ,
7170) : Promise < string [ ] > {
7271 const {
@@ -79,31 +78,21 @@ async function discoverGhsaIds(
7978 } as DiscoverGhsaIdsOptions
8079
8180 const foundCResult = await spawnCoanaDlx (
82- [
83- 'compute-fixes-and-upgrade-purls' ,
84- cwd ,
85- '--manifests-tar-hash' ,
86- tarHash ,
87- ...( fixConfig . rangeStyle ? [ '--range-style' , fixConfig . rangeStyle ] : [ ] ) ,
88- ...( fixConfig . minimumReleaseAge
89- ? [ '--minimum-release-age' , fixConfig . minimumReleaseAge ]
90- : [ ] ) ,
91- ...( fixConfig . include . length ? [ '--include' , ...fixConfig . include ] : [ ] ) ,
92- ...( fixConfig . exclude . length ? [ '--exclude' , ...fixConfig . exclude ] : [ ] ) ,
93- ...( fixConfig . disableMajorUpdates ? [ '--disable-major-updates' ] : [ ] ) ,
94- ...( fixConfig . showAffectedDirectDependencies
95- ? [ '--show-affected-direct-dependencies' ]
96- : [ ] ) ,
97- ...fixConfig . unknownFlags ,
98- ] ,
81+ [ 'find-vulnerabilities' , cwd , '--manifests-tar-hash' , tarHash ] ,
9982 orgSlug ,
100- { coanaVersion : fixConfig . coanaVersion , cwd, spinner } ,
83+ { cwd, spinner, coanaVersion : options ?. coanaVersion } ,
84+ { stdio : 'pipe' } ,
10185 )
10286
10387 if ( foundCResult . ok ) {
104- const foundIds = cmdFlagValueToArray (
105- / (?< = V u l n e r a b i l i t i e s f o u n d : ) .* / . exec ( foundCResult . data ) ,
106- )
88+ // Coana prints ghsaIds as json-formatted string on the final line of the output
89+ const foundIds : string [ ] = [ ]
90+ try {
91+ const ghsaIdsRaw = foundCResult . data . trim ( ) . split ( '\n' ) . pop ( )
92+ if ( ghsaIdsRaw ) {
93+ foundIds . push ( ...JSON . parse ( ghsaIdsRaw ) )
94+ }
95+ } catch { }
10796 return limit !== undefined ? foundIds . slice ( 0 , limit ) : foundIds
10897 }
10998 return [ ]
@@ -207,10 +196,11 @@ export async function coanaFix(
207196
208197 let ids : string [ ]
209198 if ( isAll && limit > 0 ) {
210- ids = await discoverGhsaIds ( orgSlug , tarHash , fixConfig , {
199+ ids = await discoverGhsaIds ( orgSlug , tarHash , {
211200 cwd,
212201 limit,
213202 spinner,
203+ coanaVersion,
214204 } )
215205 } else if ( limit > 0 ) {
216206 ids = ghsas . slice ( 0 , limit )
@@ -313,10 +303,11 @@ export async function coanaFix(
313303 let ids : string [ ] | undefined
314304
315305 if ( shouldSpawnCoana && isAll ) {
316- ids = await discoverGhsaIds ( orgSlug , tarHash , fixConfig , {
306+ ids = await discoverGhsaIds ( orgSlug , tarHash , {
317307 cwd,
318308 limit : adjustedLimit ,
319309 spinner,
310+ coanaVersion,
320311 } )
321312 } else if ( shouldSpawnCoana ) {
322313 ids = ghsas . slice ( 0 , adjustedLimit )
0 commit comments