@@ -22,15 +22,12 @@ import {
2222  type  Configuration , 
2323  type  Locator , 
2424  type  LocatorHash , 
25-   type  Manifest , 
26-   type  Package , 
2725  type  Project , 
2826  structUtils , 
2927  type  Workspace 
3028}  from  '@yarnpkg/core' 
3129import  {  type  PortablePath ,  xfs  }  from  '@yarnpkg/fslib' 
3230import  {  PackageURL  }  from  'packageurl-js' 
33- import  *  as  ids  from  'spdx-license-ids/index.json' 
3431
3532import  { 
3633  type  BuildtimeDependencies , 
@@ -40,8 +37,7 @@ import {
4037
4138const  licenseFactory  =  new  CDX . Factories . LicenseFactory ( ) 
4239const  npmPurlFactory  =  new  CDX . Factories . PackageUrlFactory ( 'npm' ) 
43- const  externalReferenceFactory  = 
44-   new  CDX . Factories . FromNodePackageJson . ExternalReferenceFactory ( ) 
40+ const  externalReferenceFactory  =  new  CDX . Factories . FromNodePackageJson . ExternalReferenceFactory ( ) 
4541const  componentBuilder  =  new  CDX . Builders . FromNodePackageJson . ComponentBuilder ( 
4642  externalReferenceFactory , 
4743  licenseFactory 
@@ -58,8 +54,6 @@ export interface OutputOptions {
5854  /** Output file name. */ 
5955  outputFile : PortablePath  |  typeof  stdOutOutput 
6056  componentType : CDX . Enums . ComponentType 
61-   /** If component licenses shall be included. */ 
62-   licenses : boolean 
6357  reproducible : boolean 
6458} 
6559
@@ -83,15 +77,13 @@ export async function generateSBOM (
8377  const  allDependencies  =  await  traverseWorkspace ( 
8478    project , 
8579    workspace , 
86-     config , 
87-     outputOptions . licenses 
80+     config 
8881  ) 
8982  const  componentModels  =  new  Map < LocatorHash ,  CDX . Models . Component > ( ) 
9083  // Build models without their dependencies. 
9184  for  ( const  pkgInfo  of  allDependencies )  { 
9285    const  component  =  packageInfoToCycloneComponent ( 
9386      pkgInfo , 
94-       outputOptions . licenses , 
9587      outputOptions . reproducible 
9688    ) 
9789    componentModels . set ( pkgInfo . package . locatorHash ,  component ) 
@@ -226,7 +218,6 @@ function getAuthorName (manifestRawAuthor: unknown): string | undefined {
226218 */ 
227219function  packageInfoToCycloneComponent  ( 
228220  pkgInfo : PackageInfo , 
229-   licenses : boolean , 
230221  reproducible : OutputOptions [ 'reproducible' ] 
231222) : CDX . Models . Component  { 
232223  const  manifest  =  pkgInfo . manifest 
@@ -248,12 +239,6 @@ function packageInfoToCycloneComponent (
248239  // @FIXME  dont use any `locatorhash` for this purpose - but maybe something that is actually universally reproducible? 
249240  // -- like `package-name@version` - which is a discriminated unique value for yarn universe 
250241  component . bomRef . value  =  pkgInfo . package . locatorHash 
251-   if  ( licenses )  { 
252-     addLicenseInfo ( manifest ,  pkgInfo ,  component ) 
253-   }  else  { 
254-     // @FIXME  why should this be needed anyway? 
255-     component . licenses . clear ( ) 
256-   } 
257242
258243  const  devirtualizedLocator  =  structUtils . ensureDevirtualizedLocator ( 
259244    pkgInfo . package 
@@ -292,84 +277,3 @@ function gitHubPackagePurl (
292277  } 
293278  return  undefined 
294279} 
295- 
296- /** 
297-  * Adds license data to component if available. 
298-  * @FIXME  remove this license attachment as it isi just wrong 
299-  */ 
300- function  addLicenseInfo  ( 
301-   manifest : Manifest , 
302-   pkgInfo : PackageInfo , 
303-   component : CDX . Models . Component 
304- ) : void   { 
305-   if  ( component . licenses . size  ===  1 )  { 
306-     const  license  =  component . licenses . values ( ) . next ( ) . value 
307-     // eslint-disable-next-line  @typescript-eslint/strict-boolean-expressions 
308-     if  ( pkgInfo . licenseFileContent  && 
309-       ( license  instanceof  CDX . Models . NamedLicense  || 
310-         license  instanceof  CDX . Models . SpdxLicense ) 
311-     )  { 
312-       license . text  =  new  CDX . Models . Attachment ( pkgInfo . licenseFileContent ) 
313-     } 
314-   }  else  if  ( component . licenses . size  ===  0 )  { 
315-     attemptFallbackLicense ( manifest ,  pkgInfo . package ,  component ) 
316-   } 
317- } 
318- 
319- /** 
320-  * Attempts to parse bogus but unambigous licenses and augments the component model. 
321-  * @FIXME  remove this license guessing as iti is incomplete and wrong 
322-  */ 
323- function  attemptFallbackLicense  ( 
324-   manifest : Manifest , 
325-   pkg : Package , 
326-   component : CDX . Models . Component 
327- ) : void   { 
328-   // eslint-disable-next-line  @typescript-eslint/strict-boolean-expressions 
329-   if  ( manifest . raw . license )  { 
330-     process . stderr . write ( 
331-       `Package ${ structUtils . stringifyLocator (  
332-         pkg  
333-       ) }   has invalid "license" property. See https://docs.npmjs.com/cli/v10/configuring-npm/package-json#license\n`
334-     ) 
335-     // eslint-disable-next-line @typescript-eslint/no-unsafe-argument 
336-     if  ( ids . includes ( manifest . raw . license ?. type ) )  { 
337-       process . stderr . write ( 
338-         `Adding ${  
339-           manifest . raw . license ?. type  
340-         }   as fallback for ${ structUtils . stringifyLocator ( pkg ) }  \n`
341-       ) 
342-       component . licenses . add ( 
343-         // eslint-disable-next-line @typescript-eslint/no-unsafe-argument 
344-         licenseFactory . makeFromString ( manifest . raw . license ?. type ) 
345-       ) 
346-     } 
347-   }  else 
348-     // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions 
349-     if  ( manifest . raw . licenses )  { 
350-       process . stderr . write ( 
351-       `Package ${ structUtils . stringifyLocator (  
352-         pkg  
353-       ) }   has invalid "licenses" property. See https://docs.npmjs.com/cli/v10/configuring-npm/package-json#license\n`
354-       ) 
355-       if  ( 
356-         Array . isArray ( manifest . raw . licenses )  && 
357-       manifest . raw . licenses . every ( ( outdatedLicense )  => 
358-         // eslint-disable-next-line @typescript-eslint/no-unsafe-argument 
359-         ids . includes ( outdatedLicense . type ) 
360-       ) 
361-       )  { 
362-         for  ( const  outdatedLicense  of  manifest . raw . licenses )  { 
363-           process . stderr . write ( 
364-           `Adding ${  
365-             outdatedLicense . type  
366-           }   as fallback for ${ structUtils . stringifyLocator ( pkg ) }  \n`
367-           ) 
368-           component . licenses . add ( 
369-           // eslint-disable-next-line @typescript-eslint/no-unsafe-argument 
370-             licenseFactory . makeFromString ( outdatedLicense . type ) 
371-           ) 
372-         } 
373-       } 
374-     } 
375- } 
0 commit comments