@@ -531,6 +531,43 @@ t.test('store nodes do not load devDependencies as required edges', async t => {
531531 t . notOk ( dep . edgesOut . get ( 'a-dev-dep' ) , 'devDependency of a store node is not a required edge' )
532532} )
533533
534+ t . test ( 'loads an installed transitive optional dep from the linked store' , async t => {
535+ // A transitive optional dep lives as a store sibling, and its edge reports missing === false despite having no target.
536+ // #findMissingEdges must still walk it, or npm sbom/query omit the installed dep.
537+ const path = t . testdir ( {
538+ 'package.json' : JSON . stringify ( {
539+ name : 'root' ,
540+ version : '1.0.0' ,
541+ dependencies : { dep : '1.0.0' } ,
542+ } ) ,
543+ node_modules : {
544+ dep :
t . fixture ( 'symlink' , '.store/[email protected] /node_modules/dep' ) , 545+ '.store' : {
546+ 547+ node_modules : {
548+ dep : {
549+ 'package.json' : JSON . stringify ( {
550+ name : 'dep' ,
551+ version : '1.0.0' ,
552+ optionalDependencies : { opt : '^1.0.0' } ,
553+ } ) ,
554+ } ,
555+ // the optional dep is installed as a store sibling of its consumer
556+ opt : { 'package.json' : JSON . stringify ( { name : 'opt' , version : '1.0.0' } ) } ,
557+ } ,
558+ } ,
559+ } ,
560+ } ,
561+ } )
562+
563+ const tree = await loadActual ( path )
564+ const dep = tree . children . get ( 'dep' ) . target
565+ const edge = dep . edgesOut . get ( 'opt' )
566+ t . ok ( edge && ! edge . error , 'optional edge resolves' )
567+ t . equal ( edge . to ?. name , 'opt' , 'edge resolves to the installed package' )
568+ t . ok ( [ ...tree . inventory . values ( ) ] . some ( n => n . name === 'opt' ) , 'opt is present in the inventory' )
569+ } )
570+
534571t . test ( 'a project located under a .store path still loads its own devDependencies' , async t => {
535572 // The loaded root must never be treated as a store node, even when its own path happens to sit under a node_modules/.store directory.
536573 const path = t . testdir ( {
0 commit comments