@@ -5,7 +5,6 @@ const Path = require('path');
5
5
const Topo = require ( 'topo' ) ;
6
6
7
7
8
-
9
8
const internals = { } ;
10
9
11
10
@@ -47,13 +46,14 @@ internals.queue = (tree) => {
47
46
return topo . nodes ;
48
47
} ;
49
48
50
- internals . runScript = ( stage , { childPkg , path, cwd } ) => {
49
+ internals . runScript = ( stage , { pkg , path, cwd, unsafePerm } ) => {
51
50
52
51
console . log ( ) ;
53
- console . log ( `==========> ${ stage } ${ path } ...` ) ;
52
+ console . log ( `==========> ${ stage } ${ path || pkg . name } ...` ) ;
54
53
55
- return Npm . runScript ( childPkg , stage , Path . join ( cwd , path ) , {
54
+ return Npm . runScript ( pkg , stage , Path . join ( cwd , path ) , {
56
55
dir : cwd ,
56
+ unsafePerm, // @todo : find an official way to do this for top level package
57
57
log : Object . assign ( {
58
58
pause : ( ) => { } ,
59
59
clearProgress : ( ) => { } ,
@@ -70,6 +70,9 @@ exports.run = async (cmd = 'install') => {
70
70
71
71
const cwd = process . cwd ( ) ;
72
72
const pkg = require ( Path . join ( cwd , 'package.json' ) ) ;
73
+
74
+ pkg . _id = `${ pkg . name } @${ pkg . version } ` ; // @todo : find an official way to do this for top level package
75
+
73
76
const shrinkwrap = require ( Path . join ( cwd , 'npm-shrinkwrap.json' ) ) ;
74
77
75
78
const tree = Npm . logicalTree ( pkg , shrinkwrap ) ;
@@ -82,13 +85,13 @@ exports.run = async (cmd = 'install') => {
82
85
83
86
const childPkg = require ( Path . join ( cwd , path , 'package.json' ) ) ;
84
87
85
- return [ path , childPkg ] ;
88
+ return { path, childPkg } ;
86
89
} )
87
- . filter ( ( [ , childPkg ] ) => {
90
+ . filter ( ( { childPkg } ) => {
88
91
89
92
return childPkg . scripts && ( childPkg . scripts [ cmd ] || childPkg . scripts [ `pre${ cmd } ` ] || childPkg . scripts [ `post${ childPkg } ` ] ) ;
90
93
} )
91
- . filter ( ( [ path , childPkg ] ) => {
94
+ . filter ( ( { path, childPkg } ) => {
92
95
93
96
const name = childPkg . name ;
94
97
@@ -103,15 +106,22 @@ exports.run = async (cmd = 'install') => {
103
106
return allowScripts [ name ] ;
104
107
} ) ;
105
108
106
- for ( const [ path , childPkg ] of allowedScripts ) {
107
- await internals . runScript ( 'preinstall' , { childPkg, path, cwd } ) ;
109
+ await internals . runScript ( 'preinstall' , { pkg, path : '' , cwd, unsafePerm : true } ) ;
110
+
111
+ for ( const { path, childPkg } of allowedScripts ) {
112
+ await internals . runScript ( 'preinstall' , { pkg : childPkg , path, cwd } ) ;
108
113
}
109
114
110
- for ( const [ path , childPkg ] of allowedScripts ) {
111
- await internals . runScript ( 'install' , { childPkg, path, cwd } ) ;
115
+ for ( const { path, childPkg } of allowedScripts ) {
116
+ await internals . runScript ( 'install' , { pkg : childPkg , path, cwd } ) ;
112
117
}
113
118
114
- for ( const [ path , childPkg ] of allowedScripts ) {
115
- await internals . runScript ( 'postinstall' , { childPkg, path, cwd } ) ;
119
+ for ( const { path, childPkg } of allowedScripts ) {
120
+ await internals . runScript ( 'postinstall' , { pkg : childPkg , path, cwd } ) ;
116
121
}
122
+
123
+ await internals . runScript ( 'install' , { pkg, path : '' , cwd, unsafePerm : true } ) ;
124
+ await internals . runScript ( 'postinstall' , { pkg, path : '' , cwd, unsafePerm : true } ) ;
125
+ await internals . runScript ( 'prepublish' , { pkg, path : '' , cwd, unsafePerm : true } ) ;
126
+ await internals . runScript ( 'prepare' , { pkg, path : '' , cwd, unsafePerm : true } ) ;
117
127
} ;
0 commit comments