@@ -36,9 +36,20 @@ function getNodeModuleName(filename) {
36
36
37
37
/* unordered */
38
38
function getDependenciesFor ( filename , avoidCircular , optionsArg = { } ) {
39
+ // backwards compatibility with `nodeModuleNamesOnly` boolean option
40
+ // Using `nodeModuleNames` property moving forward
41
+ if ( ( "nodeModuleNamesOnly" in optionsArg ) && ! ( "nodeModuleNames" in optionsArg ) ) {
42
+ if ( optionsArg . nodeModuleNamesOnly === true ) {
43
+ optionsArg . nodeModuleNames = "only" ;
44
+ }
45
+ if ( optionsArg . nodeModuleNamesOnly === false ) {
46
+ optionsArg . nodeModuleNames = "exclude" ;
47
+ }
48
+ }
49
+
39
50
let options = Object . assign ( {
40
51
allowNotFound : false ,
41
- nodeModuleNamesOnly : false ,
52
+ nodeModuleNames : "exclude" , // also "include" or "only"
42
53
} , optionsArg ) ;
43
54
let absoluteFilename = getAbsolutePath ( filename )
44
55
@@ -71,7 +82,7 @@ function getDependenciesFor(filename, avoidCircular, optionsArg = {}) {
71
82
let relativeFilename = getRelativePath ( mod . filename ) ;
72
83
if ( ! avoidCircular ) {
73
84
avoidCircular = { } ;
74
- } else if ( ! options . nodeModuleNamesOnly ) {
85
+ } else if ( options . nodeModuleNames !== "only" ) {
75
86
dependencies . add ( relativeFilename ) ;
76
87
}
77
88
@@ -82,13 +93,16 @@ function getDependenciesFor(filename, avoidCircular, optionsArg = {}) {
82
93
let relativeChildFilename = getRelativePath ( child . filename ) ;
83
94
let nodeModuleName = getNodeModuleName ( child . filename ) ;
84
95
85
- if ( options . nodeModuleNamesOnly && nodeModuleName ) {
96
+ if ( options . nodeModuleNames !== "exclude" && nodeModuleName ) {
86
97
dependencies . add ( nodeModuleName ) ;
87
- } else if ( nodeModuleName === false && // filter out node_modules
88
- ! dependencies . has ( relativeChildFilename ) && // avoid infinite looping with circular deps
89
- ! avoidCircular [ relativeChildFilename ] ) {
90
- for ( let dependency of getDependenciesFor ( relativeChildFilename , avoidCircular , options ) ) {
91
- dependencies . add ( dependency ) ;
98
+ }
99
+ // Add dependencies of this dependency (not top level node_modules)
100
+ if ( nodeModuleName === false ) {
101
+ if ( ! dependencies . has ( relativeChildFilename ) && // avoid infinite looping with circular deps
102
+ ! avoidCircular [ relativeChildFilename ] ) {
103
+ for ( let dependency of getDependenciesFor ( relativeChildFilename , avoidCircular , options ) ) {
104
+ dependencies . add ( dependency ) ;
105
+ }
92
106
}
93
107
}
94
108
}
0 commit comments