@@ -8,6 +8,7 @@ const merge = require('ember-cli-lodash-subset').merge;
88const md5Hex = require ( 'md5-hex' ) ;
99const path = require ( 'path' ) ;
1010const Plugin = require ( 'broccoli-plugin' ) ;
11+ const child_process = require ( 'child_process' ) ;
1112
1213const stringify = require ( 'json-stable-stringify' ) ;
1314
@@ -47,13 +48,18 @@ module.exports = class FastBootConfig extends Plugin {
4748 * and write it to `package.json`.
4849 */
4950 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+ } ) ;
5763 }
5864
5965 writeFileIfContentChanged ( outputPath , content ) {
@@ -124,10 +130,39 @@ module.exports = class FastBootConfig extends Plugin {
124130 } ) ;
125131 }
126132
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 } ) ;
129155 }
130156
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+
131166 updateFastBootManifest ( manifest ) {
132167 this . project . addons . forEach ( addon => {
133168 if ( addon . updateFastBootManifest ) {
@@ -180,6 +215,10 @@ module.exports = class FastBootConfig extends Plugin {
180215 } , null , 2 ) ;
181216 }
182217
218+ lockileToJSONString ( ) {
219+ return { } ;
220+ }
221+
183222 normalizeHostWhitelist ( ) {
184223 if ( ! this . hostWhitelist ) {
185224 return ;
0 commit comments