@@ -36,7 +36,6 @@ module.exports = async (process, validateEngines) => {
3636 log . warn ( 'cli' , validateEngines . unsupportedMessage )
3737 }
3838
39- let cmd
4039 // Now actually fire up npm and run the command.
4140 // This is how to use npm programmatically:
4241 try {
@@ -46,20 +45,15 @@ module.exports = async (process, validateEngines) => {
4645 return exitHandler ( )
4746 }
4847
49- cmd = npm . argv . shift ( )
50- if ( ! cmd ) {
48+ const command = npm . argv . shift ( )
49+ const args = npm . argv
50+
51+ if ( ! command ) {
5152 output . standard ( npm . usage )
5253 process . exitCode = 1
5354 return exitHandler ( )
5455 }
5556
56- // this is async but we dont await it, since its ok if it doesnt
57- // finish before the command finishes running. it uses command and argv
58- // so it must be initiated here, after the command name is set
59- const updateNotifier = require ( './update-notifier.js' )
60- // eslint-disable-next-line promise/catch-or-return
61- updateNotifier ( npm ) . then ( ( msg ) => ( npm . updateNotification = msg ) )
62-
6357 // Options are prefixed by a hyphen-minus (-, \u2d).
6458 // Other dash-type chars look similar but are invalid.
6559 const nonDashArgs = npm . argv . filter ( a => / ^ [ \u2010 - \u2015 \u2212 \uFE58 \uFE63 \uFF0D ] / . test ( a ) )
@@ -71,13 +65,22 @@ module.exports = async (process, validateEngines) => {
7165 )
7266 }
7367
74- await npm . exec ( cmd )
68+ const execPromise = npm . exec ( command , args )
69+
70+ // this is async but we dont await it, since its ok if it doesnt
71+ // finish before the command finishes running. it uses command and argv
72+ // so it must be initiated here, after the command name is set
73+ const updateNotifier = require ( './update-notifier.js' )
74+ // eslint-disable-next-line promise/catch-or-return
75+ updateNotifier ( npm ) . then ( ( msg ) => ( npm . updateNotification = msg ) )
76+
77+ await execPromise
7578 return exitHandler ( )
7679 } catch ( err ) {
7780 if ( err . code === 'EUNKNOWNCOMMAND' ) {
7881 const didYouMean = require ( '../utils/did-you-mean.js' )
79- const suggestions = await didYouMean ( npm . localPrefix , cmd )
80- output . standard ( `Unknown command: "${ cmd } "${ suggestions } \n` )
82+ const suggestions = await didYouMean ( npm . localPrefix , err . command )
83+ output . standard ( `Unknown command: "${ err . command } "${ suggestions } \n` )
8184 output . standard ( 'To see a list of supported npm commands, run:\n npm help' )
8285 process . exitCode = 1
8386 return exitHandler ( )
0 commit comments