@@ -47,6 +47,25 @@ internals.queue = (tree) => {
47
47
return topo . nodes ;
48
48
} ;
49
49
50
+ internals . runScript = ( stage , { childPkg, path, cwd } ) => {
51
+
52
+ console . log ( ) ;
53
+ console . log ( `==========> ${ stage } ${ path } ...` ) ;
54
+
55
+ Npm . runScript ( childPkg , stage , Path . join ( cwd , path ) , {
56
+ dir : cwd ,
57
+ log : Object . assign ( {
58
+ pause : ( ) => { } ,
59
+ clearProgress : ( ) => { } ,
60
+ showProgress : ( ) => { } ,
61
+ verbose : ( ) => { } ,
62
+ silly : ( ) => { } ,
63
+ resume : ( ) => { }
64
+ } , console ) ,
65
+ config : { }
66
+ } ) ;
67
+ } ;
68
+
50
69
exports . run = ( cmd = 'install' ) => {
51
70
52
71
const cwd = process . cwd ( ) ;
@@ -56,9 +75,9 @@ exports.run = (cmd = 'install') => {
56
75
const tree = Npm . logicalTree ( pkg , shrinkwrap ) ;
57
76
const queue = internals . queue ( tree ) ;
58
77
59
- const allowed = pkg . allowScripts || { } ;
78
+ const allowScripts = pkg . allowScripts || { } ;
60
79
61
- queue
80
+ const allowedScripts = queue
62
81
. map ( ( path ) => {
63
82
64
83
const childPkg = require ( Path . join ( cwd , path , 'package.json' ) ) ;
@@ -73,46 +92,17 @@ exports.run = (cmd = 'install') => {
73
92
74
93
const name = childPkg . name ;
75
94
76
- if ( allowed [ name ] === undefined ) {
95
+ if ( allowScripts [ name ] === undefined ) {
77
96
throw new Error ( `No entry for ${ name } ` ) ;
78
97
}
79
98
80
- if ( ! allowed [ name ] ) {
99
+ if ( ! allowScripts [ name ] ) {
81
100
console . warn ( `==========> skip ${ path } (because it is not allowed in package.json)` ) ;
82
101
}
83
102
84
- return allowed [ name ] ;
85
- } )
86
- . forEach ( ( [ path , childPkg ] ) => {
87
-
88
- console . log ( `==========> install ${ path } ...` ) ;
89
-
90
- Npm . runScript ( childPkg , 'install' , Path . join ( cwd , path ) , {
91
- dir : cwd ,
92
- log : Object . assign ( {
93
- pause : ( ) => { } ,
94
- clearProgress : ( ) => { } ,
95
- showProgress : ( ) => { } ,
96
- verbose : ( ) => { } ,
97
- silly : ( ) => { } ,
98
- resume : ( ) => { }
99
- } , console ) ,
100
- config : { }
101
- } ) ;
102
-
103
- console . log ( `==========> postinstall ${ path } ...` ) ;
104
-
105
- Npm . runScript ( childPkg , 'postinstall' , Path . join ( cwd , path ) , {
106
- dir : cwd ,
107
- log : Object . assign ( {
108
- pause : ( ) => { } ,
109
- clearProgress : ( ) => { } ,
110
- showProgress : ( ) => { } ,
111
- verbose : ( ) => { } ,
112
- silly : ( ) => { } ,
113
- resume : ( ) => { }
114
- } , console ) ,
115
- config : { }
116
- } ) ;
103
+ return allowScripts [ name ] ;
117
104
} ) ;
105
+
106
+ allowedScripts . forEach ( ( [ path , childPkg ] ) => internals . runScript ( 'install' , { childPkg, path, cwd } ) ) ;
107
+ allowedScripts . forEach ( ( [ path , childPkg ] ) => internals . runScript ( 'postinstall' , { childPkg, path, cwd } ) ) ;
118
108
} ;
0 commit comments