@@ -120,7 +120,7 @@ function filterByEnv (data) {
120
120
var keys = Object . keys ( devDependencies )
121
121
if ( production && ! dev && keys . indexOf ( name ) !== - 1 ) return
122
122
if ( dev && ! production && keys . indexOf ( name ) === - 1 ) return
123
- if ( ! dev && keys . indexOf ( name ) !== - 1 && typeof data . dependencies [ name ] === 'string' ) return
123
+ if ( ! dev && keys . indexOf ( name ) !== - 1 && data . dependencies [ name ] . missing ) return
124
124
dependencies [ name ] = data . dependencies [ name ]
125
125
} )
126
126
data . dependencies = dependencies
@@ -175,19 +175,19 @@ function getLite (data, noname) {
175
175
if ( deps . length ) {
176
176
lite . dependencies = deps . map ( function ( d ) {
177
177
var dep = data . dependencies [ d ]
178
- if ( typeof dep === 'string' ) {
178
+ if ( dep . missing && ! dep . optional ) {
179
179
lite . problems = lite . problems || [ ]
180
180
var p
181
181
if ( data . depth > maxDepth ) {
182
182
p = 'max depth reached: '
183
183
} else {
184
184
p = 'missing: '
185
185
}
186
- p += d + '@' + dep +
186
+ p += d + '@' + dep . requiredBy +
187
187
', required by ' +
188
188
data . name + '@' + data . version
189
189
lite . problems . push ( p )
190
- return [ d , { required : dep , missing : true } ]
190
+ return [ d , { required : dep . requiredBy , missing : true } ]
191
191
} else if ( dep . peerMissing ) {
192
192
lite . problems = lite . problems || [ ]
193
193
var p = 'peer dep missing: ' +
@@ -228,7 +228,7 @@ function bfsify (root) {
228
228
var deps = current . dependencies = current . dependencies || { }
229
229
Object . keys ( deps ) . forEach ( function ( d ) {
230
230
var dep = deps [ d ]
231
- if ( typeof dep !== 'object' ) return
231
+ if ( dep . missing ) return
232
232
if ( seen . indexOf ( dep ) !== - 1 ) {
233
233
if ( npm . config . get ( 'parseable' ) || ! npm . config . get ( 'long' ) ) {
234
234
delete deps [ d ]
@@ -279,16 +279,20 @@ function makeArchy (data, long, dir) {
279
279
}
280
280
281
281
function makeArchy_ ( data , long , dir , depth , parent , d ) {
282
- if ( typeof data === 'string' ) {
282
+ if ( data . missing ) {
283
283
if ( depth - 1 <= npm . config . get ( 'depth' ) ) {
284
284
// just missing
285
- var unmet = 'UNMET DEPENDENCY'
285
+ var unmet = 'UNMET ' + ( data . optional ? 'OPTIONAL ' : '' ) + ' DEPENDENCY'
286
286
if ( npm . color ) {
287
- unmet = color . bgBlack ( color . red ( unmet ) )
287
+ if ( data . optional ) {
288
+ unmet = color . bgBlack ( color . yellow ( unmet ) )
289
+ } else {
290
+ unmet = color . bgBlack ( color . red ( unmet ) )
291
+ }
288
292
}
289
- data = unmet + ' ' + d + '@' + data
293
+ data = unmet + ' ' + d + '@' + data . requiredBy
290
294
} else {
291
- data = d + '@' + data
295
+ data = d + '@' + data . requiredBy
292
296
}
293
297
return data
294
298
}
@@ -399,16 +403,16 @@ function makeParseable (data, long, dir, depth, parent, d) {
399
403
function makeParseable_ ( data , long , dir , depth , parent , d ) {
400
404
if ( data . hasOwnProperty ( '_found' ) && data . _found !== true ) return ''
401
405
402
- if ( typeof data === 'string' ) {
403
- if ( data . depth < npm . config . get ( 'depth' ) ) {
406
+ if ( data . missing ) {
407
+ if ( depth < npm . config . get ( 'depth' ) ) {
404
408
data = npm . config . get ( 'long' )
405
409
? path . resolve ( parent . path , 'node_modules' , d ) +
406
- ':' + d + '@' + JSON . stringify ( data ) + ':INVALID:MISSING'
410
+ ':' + d + '@' + JSON . stringify ( data . requiredBy ) + ':INVALID:MISSING'
407
411
: ''
408
412
} else {
409
- data = path . resolve ( data . path || '' , 'node_modules' , d || '' ) +
413
+ data = path . resolve ( dir || '' , 'node_modules' , d || '' ) +
410
414
( npm . config . get ( 'long' )
411
- ? ':' + d + '@' + JSON . stringify ( data ) +
415
+ ? ':' + d + '@' + JSON . stringify ( data . requiredBy ) +
412
416
':' + // no realpath resolved
413
417
':MAXDEPTH'
414
418
: '' )
0 commit comments