@@ -29,20 +29,39 @@ var color = require('ansicolors')
2929var styles = require ( 'ansistyles' )
3030var table = require ( 'text-table' )
3131var semver = require ( 'semver' )
32- var npa = require ( 'npm-package -arg' )
32+ var npa = require ( 'libnpm/parse -arg' )
3333var pickManifest = require ( 'npm-pick-manifest' )
3434var fetchPackageMetadata = require ( './fetch-package-metadata.js' )
3535var mutateIntoLogicalTree = require ( './install/mutate-into-logical-tree.js' )
3636var npm = require ( './npm.js' )
37+ const npmConfig = require ( './config/figgy-config.js' )
38+ const figgyPudding = require ( 'figgy-pudding' )
39+ const packument = require ( 'libnpm/packument' )
3740var long = npm . config . get ( 'long' )
38- var mapToRegistry = require ( './utils/map-to-registry.js' )
3941var isExtraneous = require ( './install/is-extraneous.js' )
4042var computeMetadata = require ( './install/deps.js' ) . computeMetadata
4143var computeVersionSpec = require ( './install/deps.js' ) . computeVersionSpec
4244var moduleName = require ( './utils/module-name.js' )
4345var output = require ( './utils/output.js' )
4446var ansiTrim = require ( './utils/ansi-trim' )
4547
48+ const OutdatedConfig = figgyPudding ( {
49+ also : { } ,
50+ color : { } ,
51+ depth : { } ,
52+ dev : 'development' ,
53+ development : { } ,
54+ global : { } ,
55+ json : { } ,
56+ only : { } ,
57+ parseable : { } ,
58+ prod : 'production' ,
59+ production : { } ,
60+ save : { } ,
61+ 'save-dev' : { } ,
62+ 'save-optional' : { }
63+ } )
64+
4665function uniq ( list ) {
4766 // we maintain the array because we need an array, not iterator, return
4867 // value.
@@ -68,26 +87,27 @@ function outdated (args, silent, cb) {
6887 cb = silent
6988 silent = false
7089 }
90+ let opts = OutdatedConfig ( npmConfig ( ) )
7191 var dir = path . resolve ( npm . dir , '..' )
7292
7393 // default depth for `outdated` is 0 (cf. `ls`)
74- if ( npm . config . get ( ' depth' ) === Infinity ) npm . config . set ( ' depth' , 0 )
94+ if ( opts . depth ) opts = opts . concat ( { depth : 0 } )
7595
7696 readPackageTree ( dir , andComputeMetadata ( function ( er , tree ) {
7797 if ( ! tree ) return cb ( er )
7898 mutateIntoLogicalTree ( tree )
79- outdated_ ( args , '' , tree , { } , 0 , function ( er , list ) {
99+ outdated_ ( args , '' , tree , { } , 0 , opts , function ( er , list ) {
80100 list = uniq ( list || [ ] ) . sort ( function ( aa , bb ) {
81101 return aa [ 0 ] . path . localeCompare ( bb [ 0 ] . path ) ||
82102 aa [ 1 ] . localeCompare ( bb [ 1 ] )
83103 } )
84104 if ( er || silent || list . length === 0 ) return cb ( er , list )
85- if ( npm . config . get ( ' json' ) ) {
86- output ( makeJSON ( list ) )
87- } else if ( npm . config . get ( ' parseable' ) ) {
88- output ( makeParseable ( list ) )
105+ if ( opts . json ) {
106+ output ( makeJSON ( list , opts ) )
107+ } else if ( opts . parseable ) {
108+ output ( makeParseable ( list , opts ) )
89109 } else {
90- var outList = list . map ( makePretty )
110+ var outList = list . map ( x => makePretty ( x , opts ) )
91111 var outHead = [ 'Package' ,
92112 'Current' ,
93113 'Wanted' ,
@@ -97,7 +117,7 @@ function outdated (args, silent, cb) {
97117 if ( long ) outHead . push ( 'Package Type' , 'Homepage' )
98118 var outTable = [ outHead ] . concat ( outList )
99119
100- if ( npm . color ) {
120+ if ( opts . color ) {
101121 outTable [ 0 ] = outTable [ 0 ] . map ( function ( heading ) {
102122 return styles . underline ( heading )
103123 } )
@@ -116,7 +136,7 @@ function outdated (args, silent, cb) {
116136}
117137
118138// [[ dir, dep, has, want, latest, type ]]
119- function makePretty ( p ) {
139+ function makePretty ( p , opts ) {
120140 var depname = p [ 1 ]
121141 var has = p [ 2 ]
122142 var want = p [ 3 ]
@@ -136,7 +156,7 @@ function makePretty (p) {
136156 columns [ 6 ] = homepage
137157 }
138158
139- if ( npm . color ) {
159+ if ( opts . color ) {
140160 columns [ 0 ] = color [ has === want || want === 'linked' ? 'yellow' : 'red' ] ( columns [ 0 ] ) // dep
141161 columns [ 2 ] = color . green ( columns [ 2 ] ) // want
142162 columns [ 3 ] = color . magenta ( columns [ 3 ] ) // latest
@@ -167,7 +187,7 @@ function makeParseable (list) {
167187 } ) . join ( os . EOL )
168188}
169189
170- function makeJSON ( list ) {
190+ function makeJSON ( list , opts ) {
171191 var out = { }
172192 list . forEach ( function ( p ) {
173193 var dep = p [ 0 ]
@@ -177,7 +197,7 @@ function makeJSON (list) {
177197 var want = p [ 3 ]
178198 var latest = p [ 4 ]
179199 var type = p [ 6 ]
180- if ( ! npm . config . get ( ' global' ) ) {
200+ if ( ! opts . global ) {
181201 dir = path . relative ( process . cwd ( ) , dir )
182202 }
183203 out [ depname ] = { current : has ,
@@ -193,11 +213,11 @@ function makeJSON (list) {
193213 return JSON . stringify ( out , null , 2 )
194214}
195215
196- function outdated_ ( args , path , tree , parentHas , depth , cb ) {
216+ function outdated_ ( args , path , tree , parentHas , depth , opts , cb ) {
197217 if ( ! tree . package ) tree . package = { }
198218 if ( path && tree . package . name ) path += ' > ' + tree . package . name
199219 if ( ! path && tree . package . name ) path = tree . package . name
200- if ( depth > npm . config . get ( ' depth' ) ) {
220+ if ( depth > opts . depth ) {
201221 return cb ( null , [ ] )
202222 }
203223 var types = { }
@@ -227,11 +247,14 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
227247 // (All the save checking here is because this gets called from npm-update currently
228248 // and that requires this logic around dev deps.)
229249 // FIXME: Refactor npm update to not be in terms of outdated.
230- var dev = npm . config . get ( 'dev' ) || / ^ d e v ( e l o p m e n t ) ? $ / . test ( npm . config . get ( 'also' ) )
231- var prod = npm . config . get ( 'production' ) || / ^ p r o d ( u c t i o n ) ? $ / . test ( npm . config . get ( 'only' ) )
232- if ( ( dev || ! prod ) &&
233- ( npm . config . get ( 'save-dev' ) || (
234- ! npm . config . get ( 'save' ) && ! npm . config . get ( 'save-optional' ) ) ) ) {
250+ var dev = opts . dev || / ^ d e v ( e l o p m e n t ) ? $ / . test ( opts . also )
251+ var prod = opts . production || / ^ p r o d ( u c t i o n ) ? $ / . test ( opts . only )
252+ if (
253+ ( dev || ! prod ) &&
254+ (
255+ opts [ 'save-dev' ] || ( ! opts . save && ! opts [ 'save-optional' ] )
256+ )
257+ ) {
235258 Object . keys ( tree . missingDevDeps ) . forEach ( function ( name ) {
236259 deps . push ( {
237260 package : { name : name } ,
@@ -245,15 +268,15 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
245268 } )
246269 }
247270
248- if ( npm . config . get ( 'save-dev' ) ) {
271+ if ( opts [ 'save-dev' ] ) {
249272 deps = deps . filter ( function ( dep ) { return pkg . devDependencies [ moduleName ( dep ) ] } )
250273 deps . forEach ( function ( dep ) {
251274 types [ moduleName ( dep ) ] = 'devDependencies'
252275 } )
253- } else if ( npm . config . get ( ' save' ) ) {
276+ } else if ( opts . save ) {
254277 // remove optional dependencies from dependencies during --save.
255278 deps = deps . filter ( function ( dep ) { return ! pkg . optionalDependencies [ moduleName ( dep ) ] } )
256- } else if ( npm . config . get ( 'save-optional' ) ) {
279+ } else if ( opts [ 'save-optional' ] ) {
257280 deps = deps . filter ( function ( dep ) { return pkg . optionalDependencies [ moduleName ( dep ) ] } )
258281 deps . forEach ( function ( dep ) {
259282 types [ moduleName ( dep ) ] = 'optionalDependencies'
@@ -262,7 +285,7 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
262285 var doUpdate = dev || (
263286 ! prod &&
264287 ! Object . keys ( parentHas ) . length &&
265- ! npm . config . get ( ' global' )
288+ ! opts . global
266289 )
267290 if ( doUpdate ) {
268291 Object . keys ( pkg . devDependencies || { } ) . forEach ( function ( k ) {
@@ -300,13 +323,13 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
300323 required = computeVersionSpec ( tree , dep )
301324 }
302325
303- if ( ! long ) return shouldUpdate ( args , dep , name , has , required , depth , path , cb )
326+ if ( ! long ) return shouldUpdate ( args , dep , name , has , required , depth , path , opts , cb )
304327
305- shouldUpdate ( args , dep , name , has , required , depth , path , cb , types [ name ] )
328+ shouldUpdate ( args , dep , name , has , required , depth , path , opts , cb , types [ name ] )
306329 } , cb )
307330}
308331
309- function shouldUpdate ( args , tree , dep , has , req , depth , pkgpath , cb , type ) {
332+ function shouldUpdate ( args , tree , dep , has , req , depth , pkgpath , opts , cb , type ) {
310333 // look up the most recent version.
311334 // if that's what we already have, or if it's not on the args list,
312335 // then dive into it. Otherwise, cb() with the data.
@@ -322,6 +345,7 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, cb, type) {
322345 tree ,
323346 has ,
324347 depth + 1 ,
348+ opts ,
325349 cb )
326350 }
327351
@@ -350,11 +374,9 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, cb, type) {
350374 } else if ( parsed . type === 'file' ) {
351375 return updateLocalDeps ( )
352376 } else {
353- return mapToRegistry ( dep , npm . config , function ( er , uri , auth ) {
354- if ( er ) return cb ( er )
355-
356- npm . registry . get ( uri , { auth : auth } , updateDeps )
357- } )
377+ return packument ( dep , opts . concat ( {
378+ 'prefer-online' : true
379+ } ) ) . nodeify ( updateDeps )
358380 }
359381
360382 function updateLocalDeps ( latestRegistryVersion ) {
0 commit comments