@@ -36,7 +36,6 @@ module.exports = async (process, validateEngines) => {
36
36
log . warn ( 'cli' , validateEngines . unsupportedMessage )
37
37
}
38
38
39
- let cmd
40
39
// Now actually fire up npm and run the command.
41
40
// This is how to use npm programmatically:
42
41
try {
@@ -46,20 +45,15 @@ module.exports = async (process, validateEngines) => {
46
45
return exitHandler ( )
47
46
}
48
47
49
- cmd = npm . argv . shift ( )
50
- if ( ! cmd ) {
48
+ const command = npm . argv . shift ( )
49
+ const args = npm . argv
50
+
51
+ if ( ! command ) {
51
52
output . standard ( npm . usage )
52
53
process . exitCode = 1
53
54
return exitHandler ( )
54
55
}
55
56
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
-
63
57
// Options are prefixed by a hyphen-minus (-, \u2d).
64
58
// Other dash-type chars look similar but are invalid.
65
59
const nonDashArgs = npm . argv . filter ( a => / ^ [ \u2010 - \u2015 \u2212 \uFE58 \uFE63 \uFF0D ] / . test ( a ) )
@@ -71,13 +65,22 @@ module.exports = async (process, validateEngines) => {
71
65
)
72
66
}
73
67
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
75
78
return exitHandler ( )
76
79
} catch ( err ) {
77
80
if ( err . code === 'EUNKNOWNCOMMAND' ) {
78
81
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` )
81
84
output . standard ( 'To see a list of supported npm commands, run:\n npm help' )
82
85
process . exitCode = 1
83
86
return exitHandler ( )
0 commit comments