File tree Expand file tree Collapse file tree 5 files changed +42
-2
lines changed Expand file tree Collapse file tree 5 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ var tree = dependencyTree({
21
21
directory: ' path/to/all/files' ,
22
22
requireConfig: ' path/to/requirejs/config' , // optional
23
23
webpackConfig: ' path/to/webpack/config' , // optional
24
+ nodeModulesConfig: {
25
+ entry: ' module'
26
+ }, // optional
24
27
filter : path => path .indexOf (' node_modules' ) === - 1 , // optional
25
28
nonExistent: [] // optional
26
29
});
@@ -38,6 +41,7 @@ var list = dependencyTree.toList({
38
41
39
42
* ` requireConfig ` : path to a requirejs config for AMD modules (allows for the result of aliased module paths)
40
43
* ` webpackConfig ` : path to a webpack config for aliased modules
44
+ * ` nodeModulesConfig ` : config for resolving entry file for node_modules
41
45
* ` visited ` : object used for avoiding redundant subtree generations via memoization.
42
46
* ` nonExistent ` : array used for storing the list of partial paths that do not exist
43
47
* ` filter ` : a function used to determine if a module (and its subtree) should be included in the dependency tree
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ var Config = require('./lib/Config');
14
14
* @param {String } options.directory - The directory containing all JS files
15
15
* @param {String } [options.requireConfig] - The path to a requirejs config
16
16
* @param {String } [options.webpackConfig] - The path to a webpack config
17
+ * @param {String } [options.nodeModulesConfig] - config for resolving entry file for node_modules
17
18
* @param {Object } [options.visited] - Cache of visited, absolutely pathed files that should not be reprocessed.
18
19
* Format is a filename -> tree as list lookup table
19
20
* @param {Array } [options.nonExistent] - List of partials that do not exist
@@ -105,7 +106,8 @@ module.exports._getDependencies = function(config) {
105
106
directory : config . directory ,
106
107
ast : precinct . ast ,
107
108
config : config . requireConfig ,
108
- webpackConfig : config . webpackConfig
109
+ webpackConfig : config . webpackConfig ,
110
+ nodeModulesConfig : config . nodeModulesConfig
109
111
} ) ;
110
112
111
113
if ( ! result ) {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ function Config(options) {
9
9
this . isListForm = options . isListForm ;
10
10
this . requireConfig = options . config || options . requireConfig ;
11
11
this . webpackConfig = options . webpackConfig ;
12
+ this . nodeModulesConfig = options . nodeModulesConfig ;
12
13
this . detectiveConfig = options . detective || options . detectiveConfig || { } ;
13
14
14
15
this . filter = options . filter ;
Original file line number Diff line number Diff line change 37
37
"dependencies" : {
38
38
"commander" : " ^2.6.0" ,
39
39
"debug" : " ^3.1.0" ,
40
- "filing-cabinet" : " ^1.9 .0" ,
40
+ "filing-cabinet" : " ^1.12 .0" ,
41
41
"precinct" : " ^3.8.0"
42
42
},
43
43
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -856,6 +856,39 @@ describe('dependencyTree', function() {
856
856
} ) ;
857
857
} ) ;
858
858
859
+ describe ( 'when given a CJS file with module property in package.json' , function ( ) {
860
+ beforeEach ( function ( ) {
861
+ mockfs ( {
862
+ [ __dirname + '/es6' ] : {
863
+ [ 'module.entry.js' ] : 'import * as module from "module.entry"' ,
864
+ [ 'node_modules' ] : {
865
+ [ 'module.entry' ] : {
866
+ 'index.main.js' : 'module.exports = function() {};' ,
867
+ 'index.module.js' : 'module.exports = function() {};' ,
868
+ 'package.json' : '{ "main": "index.main.js", "module": "index.module.js" }'
869
+ }
870
+ }
871
+ }
872
+ } ) ;
873
+ } ) ;
874
+
875
+ it ( 'it includes the module entry as dependency' , function ( ) {
876
+ const directory = __dirname + '/es6' ;
877
+ const filename = directory + '/module.entry.js' ;
878
+
879
+ const tree = dependencyTree ( {
880
+ filename,
881
+ directory,
882
+ nodeModulesConfig : {
883
+ entry : 'module'
884
+ }
885
+ } ) ;
886
+ const subTree = tree [ filename ] ;
887
+
888
+ assert . ok ( `${ directory } /node_modules/module.entry/index.module.js` in subTree ) ;
889
+ } ) ;
890
+ } ) ;
891
+
859
892
describe ( 'Config' , function ( ) {
860
893
describe ( 'when cloning' , function ( ) {
861
894
describe ( 'and a detective config was set' , function ( ) {
You can’t perform that action at this time.
0 commit comments