@@ -187,6 +187,7 @@ export default async function caxa({
187187 input,
188188 output,
189189 command,
190+ metadataFile = "binary-metadata.json" ,
190191 force = true ,
191192 exclude = defaultExcludes ,
192193 includeNode = true ,
@@ -207,6 +208,7 @@ export default async function caxa({
207208 input : string ;
208209 output : string ;
209210 command : string [ ] ;
211+ metadataFile : string ;
210212 force ?: boolean ;
211213 exclude ?: string [ ] ;
212214 filter ?: fs . CopyFilterSync | fs . CopyFilterAsync ;
@@ -240,16 +242,26 @@ export default async function caxa({
240242 interface Component {
241243 group : string ;
242244 name : string ;
245+ description : string ;
246+ license : string ;
243247 version : string ;
244248 purl : string ;
249+ author : string ;
245250 _rawDeps ?: Record < string , string > ;
246251 }
247252
248253 interface DependencyGraphEntry {
249254 ref : string ;
250255 dependsOn : string [ ] ;
251256 }
252-
257+ const parentName = path . basename ( output ) . replace ( path . extname ( output ) , "") ;
258+ const parentComponent = {
259+ group : "",
260+ name : parentName ,
261+ version : undefined ,
262+ purl : `pkg :generic / ${parentName } `,
263+ "bom - ref ": `pkg :generic / ${parentName } `,
264+ } ;
253265 const components : Component [ ] = [ ] ;
254266 const purlLookup = new Map < string , string > ( ) ;
255267 if ( includeNode ) {
@@ -274,14 +286,22 @@ export default async function caxa({
274286 purl += `${encodeURIComponent ( namespace ) } / `;
275287 }
276288 purl += `${name } @${pkg . version } `;
277-
278289 purlLookup . set ( pkg . name , purl ) ;
279-
290+ const author = pkg . author ;
291+ const authorString =
292+ author instanceof Object
293+ ? `${author . name } ${author . email ? ` < ${author . email } > ` : ""} ${
294+ author . url ? ` ( ${author . url } ) ` : ""
295+ } `
296+ : author ;
280297 components . push ( {
281298 group : namespace ,
282299 name : name ,
300+ description : pkg . description ,
301+ license : pkg . license ,
283302 version : pkg . version ,
284303 purl : purl ,
304+ author : authorString ,
285305 _rawDeps : pkg . dependencies ,
286306 } ) ;
287307 }
@@ -304,18 +324,17 @@ export default async function caxa({
304324 }
305325 delete comp . _rawDeps ;
306326 }
307-
308327 if ( childPurls . length > 0 ) {
309328 dependencies . push ( {
310329 ref : comp . purl ,
311330 dependsOn : childPurls ,
312331 } ) ;
313332 }
314333 }
315-
316334 await fs . writeJson (
317- path . join ( path . dirname ( output ) , " binary - metadata . json " ) ,
335+ path . join ( path . dirname ( output ) , metadataFile ) ,
318336 {
337+ parentComponent ,
319338 components ,
320339 dependencies ,
321340 } ,
@@ -510,6 +529,11 @@ if (url.fileURLToPath(import.meta.url) === (await fs.realpath(process.argv[1])))
510529 "- o , -- output < output > ",
511530 "Path where the executable will be produced . ",
512531 )
532+ . option (
533+ "-- metadata - file ",
534+ "Metadata file name for capturing npm components and dependencies in the bundled binary . ",
535+ "binary - metadata . json ",
536+ )
513537 . option ( "- F , -- no - force ", "Don’t overwrite output if it exists . ")
514538 . option ( "- e , -- exclude < path ...> ", "Paths to exclude from the build . ")
515539 . option ( "- N , -- no - include - node ", "Don’t copy the Node . js executable . ")
0 commit comments