@@ -65,6 +65,41 @@ const PATH = require('./utils/path.js')
65
65
66
66
const cmd = ( args , cb ) => exec ( args ) . then ( ( ) => cb ( ) ) . catch ( cb )
67
67
68
+ const run = async ( { args, call, pathArr } ) => {
69
+ // turn list of args into command string
70
+ const script = call || args . map ( escapeArg ) . join ( ' ' ) . trim ( )
71
+
72
+ // do the fakey runScript dance
73
+ // still should work if no package.json in cwd
74
+ const realPkg = await readPackageJson ( `${ npm . localPrefix } /package.json` )
75
+ . catch ( ( ) => ( { } ) )
76
+ const pkg = {
77
+ ...realPkg ,
78
+ scripts : {
79
+ ...( realPkg . scripts || { } ) ,
80
+ npx : script ,
81
+ } ,
82
+ }
83
+
84
+ npm . log . disableProgress ( )
85
+ try {
86
+ return await runScript ( {
87
+ pkg,
88
+ banner : false ,
89
+ // we always run in cwd, not --prefix
90
+ path : process . cwd ( ) ,
91
+ stdioString : true ,
92
+ event : 'npx' ,
93
+ env : {
94
+ PATH : pathArr . join ( delimiter ) ,
95
+ } ,
96
+ stdio : 'inherit' ,
97
+ } )
98
+ } finally {
99
+ npm . log . enableProgress ( )
100
+ }
101
+ }
102
+
68
103
const exec = async args => {
69
104
const { package : packages , call } = npm . flatOptions
70
105
@@ -89,17 +124,10 @@ const exec = async args => {
89
124
}
90
125
91
126
if ( binExists ) {
92
- return await runScript ( {
93
- cmd : [ args [ 0 ] , ...args . slice ( 1 ) . map ( escapeArg ) ] . join ( ' ' ) . trim ( ) ,
94
- banner : false ,
95
- // we always run in cwd, not --prefix
96
- path : process . cwd ( ) ,
97
- stdioString : true ,
98
- event : 'npx' ,
99
- env : {
100
- PATH : pathArr . join ( delimiter ) ,
101
- } ,
102
- stdio : 'inherit' ,
127
+ return await run ( {
128
+ args,
129
+ call : [ args [ 0 ] , ...args . slice ( 1 ) . map ( escapeArg ) ] . join ( ' ' ) . trim ( ) ,
130
+ pathArr,
103
131
} )
104
132
}
105
133
@@ -129,9 +157,6 @@ const exec = async args => {
129
157
if ( needPackageCommandSwap )
130
158
args [ 0 ] = getBinFromManifest ( manis [ 0 ] )
131
159
132
- // turn list of args into command string
133
- const script = call || args . map ( escapeArg ) . join ( ' ' ) . trim ( )
134
-
135
160
// figure out whether we need to install stuff, or if local is fine
136
161
const localArb = new Arborist ( {
137
162
...npm . flatOptions ,
@@ -180,35 +205,7 @@ const exec = async args => {
180
205
pathArr . unshift ( resolve ( installDir , 'node_modules/.bin' ) )
181
206
}
182
207
183
- // do the fakey runScript dance
184
- // still should work if no package.json in cwd
185
- const realPkg = await readPackageJson ( `${ npm . localPrefix } /package.json` )
186
- . catch ( ( ) => ( { } ) )
187
- const pkg = {
188
- ...realPkg ,
189
- scripts : {
190
- ...( realPkg . scripts || { } ) ,
191
- npx : script ,
192
- } ,
193
- }
194
-
195
- npm . log . disableProgress ( )
196
- try {
197
- return await runScript ( {
198
- pkg,
199
- banner : false ,
200
- // we always run in cwd, not --prefix
201
- path : process . cwd ( ) ,
202
- stdioString : true ,
203
- event : 'npx' ,
204
- env : {
205
- PATH : pathArr . join ( delimiter ) ,
206
- } ,
207
- stdio : 'inherit' ,
208
- } )
209
- } finally {
210
- npm . log . enableProgress ( )
211
- }
208
+ return await run ( { args, call, pathArr } )
212
209
}
213
210
214
211
const manifestMissing = ( tree , mani ) => {
0 commit comments