@@ -472,6 +472,79 @@ 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 : { // eslint-disable-line camelcase
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+
510+ it ( 'it usues correct version of sub package in node module package' , ( ) => {
511+ mockfs ( {
512+ [ path . join ( __dirname , '/es6' ) ] : {
513+ 'module.entry.js' : 'import * as module from "parent_module_a"' ,
514+ node_modules : { // eslint-disable-line camelcase
515+ child_node_module : {
516+ 'index.main.js' : 'module.exports = "child_node_module"' ,
517+ 'package.json' : '{ "main": "index.main.js", "version": "2.0.0"}' ,
518+ } ,
519+ parent_module_a : {
520+ 'index.main.js' : 'import * as child_module from "child_node_module"; module.exports = child_module;' ,
521+ 'package.json' : '{ "main": "index.main.js"}' ,
522+ node_modules : {
523+ child_node_module : {
524+ 'index.main.js' : 'module.exports = "child_node_module_of_parent_a"' ,
525+ 'package.json' : '{ "main": "index.main.js", "version": "1.0.0"}' ,
526+ }
527+ }
528+ }
529+ }
530+ }
531+ } ) ;
532+
533+ const directory = path . join ( __dirname , '/es6' ) ;
534+ const filename = path . normalize ( `${ directory } /module.entry.js` ) ;
535+
536+ const treeList = dependencyTree ( {
537+ filename,
538+ directory,
539+ isListForm : true
540+ } ) ;
541+
542+ assert . ok ( ! treeList . includes ( path . normalize ( `${ directory } /node_modules/child_node_module/index.main.js` ) ) ) ;
543+ assert . ok ( treeList . includes ( path . normalize ( `${ directory } /node_modules/parent_module_a/node_modules/child_node_module/index.main.js` ) ) ) ;
544+
545+ } ) ;
546+ } )
547+
475548 describe ( 'module formats' , ( ) => {
476549 describe ( 'amd' , ( ) => {
477550 testTreesForFormat ( 'amd' ) ;
0 commit comments