@@ -472,6 +472,77 @@ describe('dependencyTree', () => {
472472 } ) ;
473473 } ) ;
474474
475+ describe ( 'it uses package specific node_module directory when resolving package dependencies' , ( ) => {
476+ testTreesForFormat ( 'commonjs' ) ;
477+
478+ it ( 'it can find sub package in node module package' , ( ) => {
479+ mockfs ( {
480+ [ path . join ( __dirname , '/es6' ) ] : {
481+ 'module.entry.js' : 'import * as module from "parent_module_a"' ,
482+ node_modules : {
483+ parent_module_a : {
484+ 'index.main.js' : 'import * as child_module from "child_node_module"; module.exports = child_module;' ,
485+ 'package.json' : '{ "main": "index.main.js"}' ,
486+ node_modules : {
487+ child_node_module : {
488+ 'index.main.js' : 'module.exports = "child_node_module_of_parent_a"' ,
489+ 'package.json' : '{ "main": "index.main.js"}'
490+ }
491+ }
492+ }
493+ }
494+ }
495+ } ) ;
496+
497+ const directory = path . join ( __dirname , '/es6' ) ;
498+ const filename = path . normalize ( `${ directory } /module.entry.js` ) ;
499+
500+ const treeList = dependencyTree ( {
501+ filename,
502+ directory,
503+ isListForm : true
504+ } ) ;
505+
506+ assert . ok ( treeList . includes ( path . normalize ( `${ directory } /node_modules/parent_module_a/node_modules/child_node_module/index.main.js` ) ) ) ;
507+ } ) ;
508+
509+ it ( 'it uses correct version of sub package in node module package' , ( ) => {
510+ mockfs ( {
511+ [ path . join ( __dirname , '/es6' ) ] : {
512+ 'module.entry.js' : 'import * as module from "parent_module_a"' ,
513+ node_modules : {
514+ child_node_module : {
515+ 'index.main.js' : 'module.exports = "child_node_module"' ,
516+ 'package.json' : '{ "main": "index.main.js", "version": "2.0.0"}'
517+ } ,
518+ parent_module_a : {
519+ 'index.main.js' : 'import * as child_module from "child_node_module"; module.exports = child_module;' ,
520+ 'package.json' : '{ "main": "index.main.js"}' ,
521+ node_modules : {
522+ child_node_module : {
523+ 'index.main.js' : 'module.exports = "child_node_module_of_parent_a"' ,
524+ 'package.json' : '{ "main": "index.main.js", "version": "1.0.0"}'
525+ }
526+ }
527+ }
528+ }
529+ }
530+ } ) ;
531+
532+ const directory = path . join ( __dirname , '/es6' ) ;
533+ const filename = path . normalize ( `${ directory } /module.entry.js` ) ;
534+
535+ const treeList = dependencyTree ( {
536+ filename,
537+ directory,
538+ isListForm : true
539+ } ) ;
540+
541+ assert . ok ( ! treeList . includes ( path . normalize ( `${ directory } /node_modules/child_node_module/index.main.js` ) ) ) ;
542+ assert . ok ( treeList . includes ( path . normalize ( `${ directory } /node_modules/parent_module_a/node_modules/child_node_module/index.main.js` ) ) ) ;
543+ } ) ;
544+ } ) ;
545+
475546 describe ( 'module formats' , ( ) => {
476547 describe ( 'amd' , ( ) => {
477548 testTreesForFormat ( 'amd' ) ;
0 commit comments