@@ -45,7 +45,7 @@ class EmberApp {
4545 if ( process . env . APP_CONFIG ) {
4646 let appConfig = JSON . parse ( process . env . APP_CONFIG ) ;
4747 let appConfigKey = this . appName ;
48- if ( ! appConfig . hasOwnProperty ( appConfigKey ) ) {
48+ if ( ! ( appConfigKey in appConfig ) ) {
4949 this . config [ appConfigKey ] = appConfig ;
5050 }
5151 }
@@ -71,9 +71,10 @@ class EmberApp {
7171 * @param {Object } [sandboxGlobals={}] any additional variables to expose in the sandbox or override existing in the sandbox
7272 */
7373 buildSandbox ( distPath , sandboxClass , sandboxGlobals ) {
74+ const { config, appName } = this ;
75+
7476 let sandboxRequire = this . buildWhitelistedRequire ( this . moduleWhitelist , distPath ) ;
75- const config = this . config ;
76- const appName = this . appName ;
77+
7778 function fastbootConfig ( key ) {
7879 if ( ! key ) {
7980 // default to app key
@@ -93,10 +94,11 @@ class EmberApp {
9394 FastBoot : {
9495 require : sandboxRequire ,
9596 config : fastbootConfig ,
97+
9698 get distPath ( ) {
9799 return distPath ;
98- }
99- }
100+ } ,
101+ } ,
100102 } ;
101103
102104 globals = Object . assign ( globals , sandboxGlobals ) ;
@@ -123,13 +125,13 @@ class EmberApp {
123125 let isLegacyWhitelist = this . schemaVersion < FastBootSchemaVersions . strictWhitelist ;
124126
125127 whitelist . forEach ( function ( whitelistedModule ) {
126- debug ( " module whitelisted; module=%s" , whitelistedModule ) ;
128+ debug ( ' module whitelisted; module=%s' , whitelistedModule ) ;
127129
128130 if ( isLegacyWhitelist ) {
129131 let packageName = getPackageName ( whitelistedModule ) ;
130132
131133 if ( packageName !== whitelistedModule && whitelist . indexOf ( packageName ) === - 1 ) {
132- console . error ( "Package '" + packageName + "' is required to be in the whitelist." ) ;
134+ console . error ( "Package '" + packageName + "' is required to be in the whitelist." ) ;
133135 }
134136 }
135137 } ) ;
@@ -161,11 +163,19 @@ class EmberApp {
161163 return require ( moduleName ) ;
162164 }
163165 } else {
164- throw new Error ( "Unable to require module '" + moduleName + "' because it was not in the whitelist." ) ;
166+ throw new Error (
167+ "Unable to require module '" + moduleName + "' because it was not in the whitelist."
168+ ) ;
165169 }
166170 }
167171
168- throw new Error ( "Unable to require module '" + moduleName + "' because its package '" + packageName + "' was not in the whitelist." ) ;
172+ throw new Error (
173+ "Unable to require module '" +
174+ moduleName +
175+ "' because its package '" +
176+ packageName +
177+ "' was not in the whitelist."
178+ ) ;
169179 } ;
170180 }
171181
@@ -174,29 +184,29 @@ class EmberApp {
174184 *
175185 * Loads the app and vendor files in the sandbox (Node vm).
176186 *
177- */
187+ */
178188 loadAppFiles ( ) {
179189 let sandbox = this . sandbox ;
180190 let appFilePaths = this . appFilePaths ;
181191 let vendorFilePaths = this . vendorFilePaths ;
182192
183193 sandbox . eval ( 'sourceMapSupport.install(Error);' ) ;
184194
185- debug ( " evaluating app and vendor files" ) ;
195+ debug ( ' evaluating app and vendor files' ) ;
186196
187197 vendorFilePaths . forEach ( function ( vendorFilePath ) {
188- debug ( " evaluating vendor file %s" , vendorFilePath ) ;
198+ debug ( ' evaluating vendor file %s' , vendorFilePath ) ;
189199 let vendorFile = fs . readFileSync ( vendorFilePath , 'utf8' ) ;
190200 sandbox . eval ( vendorFile , vendorFilePath ) ;
191201 } ) ;
192- debug ( " vendor file evaluated" ) ;
202+ debug ( ' vendor file evaluated' ) ;
193203
194204 appFilePaths . forEach ( function ( appFilePath ) {
195- debug ( " evaluating app file %s" , appFilePath ) ;
205+ debug ( ' evaluating app file %s' , appFilePath ) ;
196206 let appFile = fs . readFileSync ( appFilePath , 'utf8' ) ;
197207 sandbox . eval ( appFile , appFilePath ) ;
198208 } ) ;
199- debug ( " app files evaluated" ) ;
209+ debug ( ' app files evaluated' ) ;
200210 }
201211
202212 /**
@@ -215,7 +225,9 @@ class EmberApp {
215225
216226 // If the application factory couldn't be found, throw an error
217227 if ( ! AppFactory || typeof AppFactory [ 'default' ] !== 'function' ) {
218- throw new Error ( 'Failed to load Ember app from app.js, make sure it was built for FastBoot with the `ember fastboot:build` command.' ) ;
228+ throw new Error (
229+ 'Failed to load Ember app from app.js, make sure it was built for FastBoot with the `ember fastboot:build` command.'
230+ ) ;
219231 }
220232
221233 // Otherwise, return a new `Ember.Application` instance
@@ -325,20 +337,19 @@ class EmberApp {
325337 let disableShoebox = options . disableShoebox || false ;
326338 let destroyAppInstanceInMs = parseInt ( options . destroyAppInstanceInMs , 10 ) ;
327339
328- let shouldRender = ( options . shouldRender !== undefined ) ? options . shouldRender : true ;
340+ let shouldRender = options . shouldRender !== undefined ? options . shouldRender : true ;
329341 let bootOptions = buildBootOptions ( shouldRender ) ;
330- let fastbootInfo = new FastBootInfo (
331- req ,
332- res ,
333- { hostWhitelist : this . hostWhitelist , metadata : options . metadata }
334- ) ;
342+ let fastbootInfo = new FastBootInfo ( req , res , {
343+ hostWhitelist : this . hostWhitelist ,
344+ metadata : options . metadata ,
345+ } ) ;
335346
336347 let doc = bootOptions . document ;
337348
338349 let result = new Result ( {
339350 doc : doc ,
340351 html : html ,
341- fastbootInfo : fastbootInfo
352+ fastbootInfo : fastbootInfo ,
342353 } ) ;
343354
344355 let destroyAppInstanceTimer ;
@@ -347,7 +358,9 @@ class EmberApp {
347358 // This is a failure mechanism so that node process doesn't get wedged if the `visit` never completes.
348359 destroyAppInstanceTimer = setTimeout ( function ( ) {
349360 if ( result . _destroyAppInstance ( ) ) {
350- result . error = new Error ( 'App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms' ) ;
361+ result . error = new Error (
362+ 'App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms'
363+ ) ;
351364 }
352365 } , destroyAppInstanceInMs ) ;
353366 }
@@ -359,7 +372,7 @@ class EmberApp {
359372 createShoebox ( doc , fastbootInfo ) ;
360373 }
361374 } )
362- . catch ( error => result . error = error )
375+ . catch ( error => ( result . error = error ) )
363376 . then ( ( ) => result . _finalize ( ) )
364377 . finally ( ( ) => {
365378 if ( result . _destroyAppInstance ( ) ) {
@@ -381,7 +394,9 @@ class EmberApp {
381394 try {
382395 file = fs . readFileSync ( pkgPath ) ;
383396 } catch ( e ) {
384- throw new Error ( `Couldn't find ${ pkgPath } . You may need to update your version of ember-cli-fastboot.` ) ;
397+ throw new Error (
398+ `Couldn't find ${ pkgPath } . You may need to update your version of ember-cli-fastboot.`
399+ ) ;
385400 }
386401
387402 let manifest ;
@@ -393,15 +408,23 @@ class EmberApp {
393408 manifest = pkg . fastboot . manifest ;
394409 schemaVersion = pkg . fastboot . schemaVersion ;
395410 } catch ( e ) {
396- throw new Error ( `${ pkgPath } was malformed or did not contain a manifest. Ensure that you have a compatible version of ember-cli-fastboot.` ) ;
411+ throw new Error (
412+ `${ pkgPath } was malformed or did not contain a manifest. Ensure that you have a compatible version of ember-cli-fastboot.`
413+ ) ;
397414 }
398415
399416 const currentSchemaVersion = FastBootSchemaVersions . latest ;
400417 // set schema version to 1 if not defined
401418 schemaVersion = schemaVersion || FastBootSchemaVersions . base ;
402- debug ( 'Current schemaVersion from `ember-cli-fastboot` is %s while latest schema version is %s' , schemaVersion , currentSchemaVersion ) ;
419+ debug (
420+ 'Current schemaVersion from `ember-cli-fastboot` is %s while latest schema version is %s' ,
421+ schemaVersion ,
422+ currentSchemaVersion
423+ ) ;
403424 if ( schemaVersion > currentSchemaVersion ) {
404- let errorMsg = chalk . bold . red ( 'An incompatible version between `ember-cli-fastboot` and `fastboot` was found. Please update the version of fastboot library that is compatible with ember-cli-fastboot.' ) ;
425+ let errorMsg = chalk . bold . red (
426+ 'An incompatible version between `ember-cli-fastboot` and `fastboot` was found. Please update the version of fastboot library that is compatible with ember-cli-fastboot.'
427+ ) ;
405428 throw new Error ( errorMsg ) ;
406429 }
407430
@@ -421,13 +444,13 @@ class EmberApp {
421444 }
422445 }
423446
424- debug ( " reading array of app file paths from manifest" ) ;
425- var appFiles = manifest . appFiles . map ( function ( appFile ) {
447+ debug ( ' reading array of app file paths from manifest' ) ;
448+ let appFiles = manifest . appFiles . map ( function ( appFile ) {
426449 return path . join ( distPath , appFile ) ;
427450 } ) ;
428451
429- debug ( " reading array of vendor file paths from manifest" ) ;
430- var vendorFiles = manifest . vendorFiles . map ( function ( vendorFile ) {
452+ debug ( ' reading array of vendor file paths from manifest' ) ;
453+ let vendorFiles = manifest . vendorFiles . map ( function ( vendorFile ) {
431454 return path . join ( distPath , vendorFile ) ;
432455 } ) ;
433456
@@ -468,7 +491,7 @@ function buildBootOptions(shouldRender) {
468491 document : doc ,
469492 rootElement,
470493 shouldRender,
471- _renderMode
494+ _renderMode,
472495 } ;
473496}
474497
@@ -484,10 +507,14 @@ const hasOwnProperty = Object.prototype.hasOwnProperty; // jshint ignore:line
484507
485508function createShoebox ( doc , fastbootInfo ) {
486509 let shoebox = fastbootInfo . shoebox ;
487- if ( ! shoebox ) { return ; }
510+ if ( ! shoebox ) {
511+ return ;
512+ }
488513
489514 for ( let key in shoebox ) {
490- if ( ! hasOwnProperty . call ( shoebox , key ) ) { continue ; } // TODO: remove this later #144, ember-fastboot/ember-cli-fastboot/pull/417
515+ if ( ! hasOwnProperty . call ( shoebox , key ) ) {
516+ continue ;
517+ } // TODO: remove this later #144, ember-fastboot/ember-cli-fastboot/pull/417
491518 let value = shoebox [ key ] ;
492519 let textValue = JSON . stringify ( value ) ;
493520 textValue = escapeJSONString ( textValue ) ;
@@ -507,7 +534,7 @@ const JSON_ESCAPE = {
507534 '>' : '\\u003e' ,
508535 '<' : '\\u003c' ,
509536 '\u2028' : '\\u2028' ,
510- '\u2029' : '\\u2029'
537+ '\u2029' : '\\u2029' ,
511538} ;
512539
513540const JSON_ESCAPE_REGEXP = / [ \u2028 \u2029 & > < ] / g;
0 commit comments