@@ -24,25 +24,27 @@ exports.DEFAULT_DEP_SCRIPTS = [
2424 'postinstall' ,
2525] ;
2626
27- exports . runLifecycleScripts = async function runLifecycleScripts ( pkg , root , originPkg , displayName , options ) {
27+ exports . runLifecycleScripts = async function runLifecycleScripts ( pkg , root , originPkg , displayName , globalOptions ) {
2828 const scripts = pkg . scripts || { } ;
2929
3030 // https://docs.npmjs.com/misc/scripts#default-values
3131 // "install": "node-gyp rebuild"
3232 // If there is a binding.gyp file in the root of your package,
3333 // npm will default the install command to compile using node-gyp.
3434 if ( ! scripts . install && ( await utils . exists ( path . join ( root , 'binding.gyp' ) ) ) ) {
35- options . console . warn (
35+ globalOptions . console . warn (
3636 '[npminstall:runscript] %s found binding.gyp file, auto run "node-gyp rebuild", root: %j' ,
3737 displayName , root
3838 ) ;
3939 scripts . install = 'node-gyp rebuild' ;
4040 }
4141
4242 let scriptList = exports . DEFAULT_DEP_SCRIPTS ;
43-
44- if ( ( root === options . root && ! options . global ) || LOCAL_TYPES . includes ( npa ( `${ originPkg . name } @${ originPkg . version } ` ) . type ) ) {
43+ let runInForeground = ! ! globalOptions . foregroundScripts ;
44+ if ( ( root === globalOptions . root && ! globalOptions . global )
45+ || LOCAL_TYPES . includes ( npa ( `${ originPkg . name } @${ originPkg . version } ` ) . type ) ) {
4546 scriptList = exports . DEFAULT_ROOT_SCRIPTS ;
47+ runInForeground = true ;
4648 }
4749
4850 for ( const script of scriptList ) {
@@ -51,7 +53,7 @@ exports.runLifecycleScripts = async function runLifecycleScripts(pkg, root, orig
5153 continue ;
5254 }
5355
54- console . info (
56+ runInForeground && console . info (
5557 '> %s %s %s %s> %s' ,
5658 displayName ,
5759 script ,
@@ -61,26 +63,26 @@ exports.runLifecycleScripts = async function runLifecycleScripts(pkg, root, orig
6163 ) ;
6264 const startTime = Date . now ( ) ;
6365 try {
64- await utils . runScript ( root , cmd , options ) ;
66+ await utils . runScript ( root , cmd , globalOptions , runInForeground ) ;
6567 } catch ( error ) {
66- options . console . warn ( '[npminstall:runscript:error] %s run %s %s error: %s' , chalk . red ( displayName ) , script , cmd , error ) ;
68+ globalOptions . console . warn ( '[npminstall:runscript:error] %s run %s %s error: %s' , chalk . red ( displayName ) , script , cmd , error ) ;
6769 // If post install execute error, make sure this package won't be skipped during next installation.
6870 try {
6971 await utils . unsetInstallDone ( root ) ;
7072 } catch ( e ) {
71- options . console . warn ( chalk . yellow ( `unsetInstallDone: ${ root } error: ${ e } , ignore it` ) ) ;
73+ globalOptions . console . warn ( chalk . yellow ( `unsetInstallDone: ${ root } error: ${ e } , ignore it` ) ) ;
7274 }
7375 if ( originPkg . optional ) {
74- options . console . warn ( chalk . red ( '%s optional error: %s' ) , displayName , error . stack ) ;
76+ globalOptions . console . warn ( chalk . red ( '%s optional error: %s' ) , displayName , error . stack ) ;
7577 continue ;
7678 }
7779 error . message = `run ${ script } error, please remove node_modules before retry!\n${ error . message } ` ;
7880 throw error ;
7981 } finally {
8082 const ts = Date . now ( ) - startTime ;
81- console . info ( '> %s %s, finished in %s' , displayName , script , ms ( ts ) ) ;
82- options . runscriptCount += 1 ;
83- options . runscriptTime += ts ;
83+ runInForeground && console . info ( '> %s %s, finished in %s' , displayName , script , ms ( ts ) ) ;
84+ globalOptions . runscriptCount += 1 ;
85+ globalOptions . runscriptTime += ts ;
8486 }
8587 }
8688} ;
0 commit comments