11const cacache = require ( 'cacache' )
22const fs = require ( 'fs' )
33const fetch = require ( 'make-fetch-happen' )
4- const Table = require ( 'cli-table3' )
54const which = require ( 'which' )
65const pacote = require ( 'pacote' )
76const { resolve } = require ( 'path' )
@@ -34,57 +33,59 @@ const maskLabel = mask => {
3433
3534const subcommands = [
3635 {
37- groups : [ 'ping' , 'registry' ] ,
38- title : 'npm ping' ,
36+ // Ping is left in as a legacy command but is listed as "connection" to
37+ // make more sense to more people
38+ groups : [ 'connection' , 'ping' , 'registry' ] ,
39+ title : 'Connecting to the registry' ,
3940 cmd : 'checkPing' ,
4041 } , {
4142 groups : [ 'versions' ] ,
42- title : 'npm -v ' ,
43+ title : 'Checking npm version ' ,
4344 cmd : 'getLatestNpmVersion' ,
4445 } , {
4546 groups : [ 'versions' ] ,
46- title : 'node -v ' ,
47+ title : 'Checking node version ' ,
4748 cmd : 'getLatestNodejsVersion' ,
4849 } , {
4950 groups : [ 'registry' ] ,
50- title : 'npm config get registry' ,
51+ title : 'Checking configured npm registry' ,
5152 cmd : 'checkNpmRegistry' ,
5253 } , {
5354 groups : [ 'environment' ] ,
54- title : 'git executable in PATH' ,
55+ title : 'Checking for git executable in PATH' ,
5556 cmd : 'getGitPath' ,
5657 } , {
5758 groups : [ 'environment' ] ,
58- title : 'global bin folder in PATH' ,
59+ title : 'Checking for global bin folder in PATH' ,
5960 cmd : 'getBinPath' ,
6061 } , {
6162 groups : [ 'permissions' , 'cache' ] ,
62- title : 'Perms check on cached files' ,
63+ title : 'Checking permissions on cached files (this may take awhile) ' ,
6364 cmd : 'checkCachePermission' ,
6465 windows : false ,
6566 } , {
6667 groups : [ 'permissions' ] ,
67- title : 'Perms check on local node_modules' ,
68+ title : 'Checking permissions on local node_modules (this may take awhile) ' ,
6869 cmd : 'checkLocalModulesPermission' ,
6970 windows : false ,
7071 } , {
7172 groups : [ 'permissions' ] ,
72- title : 'Perms check on global node_modules' ,
73+ title : 'Checking permissions on global node_modules (this may take awhile) ' ,
7374 cmd : 'checkGlobalModulesPermission' ,
7475 windows : false ,
7576 } , {
7677 groups : [ 'permissions' ] ,
77- title : 'Perms check on local bin folder' ,
78+ title : 'Checking permissions on local bin folder' ,
7879 cmd : 'checkLocalBinPermission' ,
7980 windows : false ,
8081 } , {
8182 groups : [ 'permissions' ] ,
82- title : 'Perms check on global bin folder' ,
83+ title : 'Checking permissions on global bin folder' ,
8384 cmd : 'checkGlobalBinPermission' ,
8485 windows : false ,
8586 } , {
8687 groups : [ 'cache' ] ,
87- title : 'Verify cache contents' ,
88+ title : 'Verifying cache contents (this may take awhile) ' ,
8889 cmd : 'verifyCachedFiles' ,
8990 windows : false ,
9091 } ,
@@ -104,43 +105,28 @@ class Doctor extends BaseCommand {
104105 static params = [ 'registry' ]
105106 static ignoreImplicitWorkspace = false
106107 static usage = [ `[${ subcommands . flatMap ( s => s . groups )
107- . filter ( ( value , index , self ) => self . indexOf ( value ) === index )
108+ . filter ( ( value , index , self ) => self . indexOf ( value ) === index && value !== 'ping' )
108109 . join ( '] [' ) } ]`]
109110
110111 static subcommands = subcommands
111112
112- // minimum width of check column, enough for the word `Check`
113- #checkWidth = 5
114-
115113 async exec ( args ) {
116114 log . info ( 'doctor' , 'Running checkup' )
117115 let allOk = true
118116
119117 const actions = this . actions ( args )
120- this . #checkWidth = actions . reduce ( ( length , item ) =>
121- Math . max ( item . title . length , length ) , this . #checkWidth)
122118
123- if ( ! this . npm . silent ) {
124- this . output ( [ 'Check' , 'Value' , 'Recommendation/Notes' ] . map ( h => this . npm . chalk . underline ( h ) ) )
125- }
126- // Do the actual work
119+ const chalk = this . npm . chalk
127120 for ( const { title, cmd } of actions ) {
128- const item = [ title ]
121+ this . output ( title )
122+ // TODO when we have an in progress indicator that could go here
123+ let result
129124 try {
130- item . push ( true , await this [ cmd ] ( ) )
125+ result = await this [ cmd ] ( )
126+ this . output ( `${ chalk . green ( 'Ok' ) } ${ result ? `\n${ result } ` : '' } \n` )
131127 } catch ( err ) {
132- item . push ( false , err )
133- }
134- if ( ! item [ 1 ] ) {
135128 allOk = false
136- item [ 0 ] = this . npm . chalk . red ( item [ 0 ] )
137- item [ 1 ] = this . npm . chalk . red ( 'not ok' )
138- item [ 2 ] = this . npm . chalk . cyan ( String ( item [ 2 ] ) )
139- } else {
140- item [ 1 ] = this . npm . chalk . green ( 'ok' )
141- }
142- if ( ! this . npm . silent ) {
143- this . output ( item )
129+ this . output ( `${ chalk . red ( 'Not ok' ) } \n${ chalk . cyan ( err ) } \n` )
144130 }
145131 }
146132
@@ -343,38 +329,11 @@ class Doctor extends BaseCommand {
343329 }
344330 }
345331
346- output ( row ) {
347- const t = new Table ( {
348- chars : {
349- top : '' ,
350- 'top-mid' : '' ,
351- 'top-left' : '' ,
352- 'top-right' : '' ,
353- bottom : '' ,
354- 'bottom-mid' : '' ,
355- 'bottom-left' : '' ,
356- 'bottom-right' : '' ,
357- left : '' ,
358- 'left-mid' : '' ,
359- mid : '' ,
360- 'mid-mid' : '' ,
361- right : '' ,
362- 'right-mid' : '' ,
363- middle : ' ' ,
364- } ,
365- style : {
366- 'padding-left' : 0 ,
367- 'padding-right' : 0 ,
368- // setting border here is not necessary visually since we've already
369- // zeroed out all the chars above, but without it cli-table3 will wrap
370- // some of the separator spaces with ansi codes which show up in
371- // snapshots.
372- border : 0 ,
373- } ,
374- colWidths : [ this . #checkWidth, 6 ] ,
375- } )
376- t . push ( row )
377- output . standard ( t . toString ( ) )
332+ output ( ...args ) {
333+ // TODO display layer should do this
334+ if ( ! this . npm . silent ) {
335+ output . standard ( ...args )
336+ }
378337 }
379338
380339 actions ( params ) {
0 commit comments