@@ -133,68 +133,69 @@ function cleanTaskArg (arg) {
133133 * This promise object has an extra method: `abort()`.
134134 * @private
135135 */
136- module . exports = async function runTask ( task , options ) {
136+ module . exports = function runTask ( task , options ) {
137137 let cp = null
138- const ansiStyles = ( await ansiStylesPromise ) . default
139138 const promise = new Promise ( ( resolve , reject ) => {
140- const stdin = options . stdin
141- const stdout = wrapLabeling ( task , options . stdout , options . labelState , ansiStyles )
142- const stderr = wrapLabeling ( task , options . stderr , options . labelState , ansiStyles )
143- const stdinKind = detectStreamKind ( stdin , process . stdin )
144- const stdoutKind = detectStreamKind ( stdout , process . stdout )
145- const stderrKind = detectStreamKind ( stderr , process . stderr )
146- const spawnOptions = { stdio : [ stdinKind , stdoutKind , stderrKind ] }
147-
148- // Print task name.
149- if ( options . printName && stdout != null ) {
150- stdout . write ( createHeader (
151- task ,
152- options . packageInfo ,
153- options . stdout . isTTY ,
154- ansiStyles
155- ) )
156- }
157-
158- // Execute.
159- const npmPath = options . npmPath || path . basename ( process . env . npm_execpath ) . startsWith ( 'npx' ) // eslint-disable-line no-process-env
160- ? path . join ( path . dirname ( process . env . npm_execpath ) , path . basename ( process . env . npm_execpath ) . replace ( 'npx' , 'npm' ) ) // eslint-disable-line no-process-env
161- : process . env . npm_execpath // eslint-disable-line no-process-env
162- const npmPathIsJs = typeof npmPath === 'string' && / \. m ? j s / . test ( path . extname ( npmPath ) )
163- const execPath = ( npmPathIsJs ? process . execPath : npmPath || 'npm' )
164- const isYarn = process . env . npm_config_user_agent && process . env . npm_config_user_agent . startsWith ( 'yarn' ) // eslint-disable-line no-process-env
165- const spawnArgs = [ 'run' ]
166-
167- if ( npmPathIsJs ) {
168- spawnArgs . unshift ( npmPath )
169- }
170- if ( ! isYarn ) {
171- Array . prototype . push . apply ( spawnArgs , options . prefixOptions )
172- } else if ( options . prefixOptions . indexOf ( '--silent' ) !== - 1 ) {
173- spawnArgs . push ( '--silent' )
174- }
175- Array . prototype . push . apply ( spawnArgs , parseArgs ( task ) . map ( cleanTaskArg ) )
176-
177- cp = spawn ( execPath , spawnArgs , spawnOptions )
178-
179- // Piping stdio.
180- if ( stdinKind === 'pipe' ) {
181- stdin . pipe ( cp . stdin )
182- }
183- if ( stdoutKind === 'pipe' ) {
184- cp . stdout . pipe ( stdout , { end : false } )
185- }
186- if ( stderrKind === 'pipe' ) {
187- cp . stderr . pipe ( stderr , { end : false } )
188- }
189-
190- // Register
191- cp . on ( 'error' , ( err ) => {
192- cp = null
193- reject ( err )
194- } )
195- cp . on ( 'close' , ( code , signal ) => {
196- cp = null
197- resolve ( { task, code, signal } )
139+ ansiStylesPromise . then ( ( { default : ansiStyles } ) => {
140+ const stdin = options . stdin
141+ const stdout = wrapLabeling ( task , options . stdout , options . labelState , ansiStyles )
142+ const stderr = wrapLabeling ( task , options . stderr , options . labelState , ansiStyles )
143+ const stdinKind = detectStreamKind ( stdin , process . stdin )
144+ const stdoutKind = detectStreamKind ( stdout , process . stdout )
145+ const stderrKind = detectStreamKind ( stderr , process . stderr )
146+ const spawnOptions = { stdio : [ stdinKind , stdoutKind , stderrKind ] }
147+
148+ // Print task name.
149+ if ( options . printName && stdout != null ) {
150+ stdout . write ( createHeader (
151+ task ,
152+ options . packageInfo ,
153+ options . stdout . isTTY ,
154+ ansiStyles
155+ ) )
156+ }
157+
158+ // Execute.
159+ const npmPath = options . npmPath || path . basename ( process . env . npm_execpath ) . startsWith ( 'npx' ) // eslint-disable-line no-process-env
160+ ? path . join ( path . dirname ( process . env . npm_execpath ) , path . basename ( process . env . npm_execpath ) . replace ( 'npx' , 'npm' ) ) // eslint-disable-line no-process-env
161+ : process . env . npm_execpath // eslint-disable-line no-process-env
162+ const npmPathIsJs = typeof npmPath === 'string' && / \. m ? j s / . test ( path . extname ( npmPath ) )
163+ const execPath = ( npmPathIsJs ? process . execPath : npmPath || 'npm' )
164+ const isYarn = process . env . npm_config_user_agent && process . env . npm_config_user_agent . startsWith ( 'yarn' ) // eslint-disable-line no-process-env
165+ const spawnArgs = [ 'run' ]
166+
167+ if ( npmPathIsJs ) {
168+ spawnArgs . unshift ( npmPath )
169+ }
170+ if ( ! isYarn ) {
171+ Array . prototype . push . apply ( spawnArgs , options . prefixOptions )
172+ } else if ( options . prefixOptions . indexOf ( '--silent' ) !== - 1 ) {
173+ spawnArgs . push ( '--silent' )
174+ }
175+ Array . prototype . push . apply ( spawnArgs , parseArgs ( task ) . map ( cleanTaskArg ) )
176+
177+ cp = spawn ( execPath , spawnArgs , spawnOptions )
178+
179+ // Piping stdio.
180+ if ( stdinKind === 'pipe' ) {
181+ stdin . pipe ( cp . stdin )
182+ }
183+ if ( stdoutKind === 'pipe' ) {
184+ cp . stdout . pipe ( stdout , { end : false } )
185+ }
186+ if ( stderrKind === 'pipe' ) {
187+ cp . stderr . pipe ( stderr , { end : false } )
188+ }
189+
190+ // Register
191+ cp . on ( 'error' , ( err ) => {
192+ cp = null
193+ reject ( err )
194+ } )
195+ cp . on ( 'close' , ( code , signal ) => {
196+ cp = null
197+ resolve ( { task, code, signal } )
198+ } )
198199 } )
199200 } )
200201
@@ -205,5 +206,5 @@ module.exports = async function runTask (task, options) {
205206 }
206207 }
207208
208- return await promise
209+ return promise
209210}
0 commit comments