@@ -8,6 +8,7 @@ const merge = require('ember-cli-lodash-subset').merge;
8
8
const md5Hex = require ( 'md5-hex' ) ;
9
9
const path = require ( 'path' ) ;
10
10
const Plugin = require ( 'broccoli-plugin' ) ;
11
+ const child_process = require ( 'child_process' ) ;
11
12
12
13
const stringify = require ( 'json-stable-stringify' ) ;
13
14
@@ -47,13 +48,18 @@ module.exports = class FastBootConfig extends Plugin {
47
48
* and write it to `package.json`.
48
49
*/
49
50
build ( ) {
50
- this . buildConfig ( ) ;
51
- this . buildDependencies ( ) ;
52
- this . buildManifest ( ) ;
53
- this . buildHostWhitelist ( ) ;
54
-
55
- let outputPath = path . join ( this . outputPath , 'package.json' ) ;
56
- this . writeFileIfContentChanged ( outputPath , this . toJSONString ( ) ) ;
51
+ return Promise . all ( [
52
+ this . buildConfig ( ) ,
53
+ this . buildDependencies ( ) ,
54
+ this . buildManifest ( ) ,
55
+ this . buildHostWhitelist ( )
56
+ ] ) . then ( ( ) => {
57
+ let packageOutputPath = path . join ( this . outputPath , 'package.json' ) ;
58
+ this . writeFileIfContentChanged ( packageOutputPath , this . toJSONString ( ) ) ;
59
+
60
+ // let lockfileOutputPath = path.join(this.outputPath, 'package-lock.json');
61
+ // this.writeFileIfContentChanged(lockfileOutputPath, this.lockileToJSONString());
62
+ } ) ;
57
63
}
58
64
59
65
writeFileIfContentChanged ( outputPath , content ) {
@@ -124,10 +130,39 @@ module.exports = class FastBootConfig extends Plugin {
124
130
} ) ;
125
131
}
126
132
127
- this . dependencies = dependencies ;
128
- this . moduleWhitelist = uniq ( moduleWhitelist ) ;
133
+ return this . updateDependencies ( dependencies , moduleWhitelist ) ;
134
+ }
135
+
136
+ dependenciesChanged ( dependencies ) {
137
+ return stringify ( dependencies ) !== stringify ( this . dependencies ) ;
138
+ }
139
+
140
+ getPackageLock ( dependencies ) {
141
+ let packagePath = path . join ( this . project . root , 'package.json' ) ;
142
+ let lockfilePath = path . join ( this . project . root , 'package-lock.json' ) ;
143
+ let tmpFolder = path . join ( this . outputPath , 'package-lock-generator' ) ;
144
+
145
+ fs . mkdirSync ( tmpFolder )
146
+ fs . symlinkSync ( packagePath , path . join ( tmpFolder , 'package.json' ) ) ;
147
+ fs . symlinkSync ( lockfilePath , path . join ( tmpFolder , 'package-lock.json' ) ) ;
148
+ child_process . execSync ( 'npm install --cache=tmp' , { cwd : tmpFolder } ) ;
149
+ fs . unlinkSync ( path . join ( tmpFolder , 'package.json' ) ) ;
150
+ fs . unlinkSync ( path . join ( tmpFolder , 'package-lock.json' ) ) ;
151
+
152
+ // Run install again, only from cache.
153
+ fs . writeFileSync ( path . join ( tmpFolder , 'package.json' ) , stringify ( { dependencies } ) ) ;
154
+ child_process . execSync ( 'npm install --cache=tmp --offline' , { cwd : tmpFolder } ) ;
129
155
}
130
156
157
+ updateDependencies ( dependencies , moduleWhitelist ) {
158
+ if ( this . dependenciesChanged ( dependencies ) ) {
159
+ this . getPackageLock ( dependencies ) ;
160
+ }
161
+
162
+ this . dependencies = dependencies ;
163
+ this . moduleWhitelist = moduleWhitelist ;
164
+ }
165
+
131
166
updateFastBootManifest ( manifest ) {
132
167
this . project . addons . forEach ( addon => {
133
168
if ( addon . updateFastBootManifest ) {
@@ -180,6 +215,10 @@ module.exports = class FastBootConfig extends Plugin {
180
215
} , null , 2 ) ;
181
216
}
182
217
218
+ lockileToJSONString ( ) {
219
+ return { } ;
220
+ }
221
+
183
222
normalizeHostWhitelist ( ) {
184
223
if ( ! this . hostWhitelist ) {
185
224
return ;
0 commit comments