@@ -66,18 +66,20 @@ module.exports = {
6666 * which allows us to use the `import()` method to tell it to include a file
6767 * from our `vendor` tree into the final built app.
6868 */
69- included : function ( ) {
69+ included : function ( ) {
7070 this . _super . included . apply ( this , arguments ) ;
7171
7272 let isApp = ! this . project . isEmberCLIAddon ( ) ;
7373
7474 let hasEmberFetch = ! ! this . project . findAddonByName ( 'ember-fetch' ) ;
75- let hasEmberCliFastboot = ! ! this . project . findAddonByName ( 'ember-cli-fastboot' ) ;
75+ let hasEmberCliFastboot =
76+ ! ! this . project . findAddonByName ( 'ember-cli-fastboot' ) ;
7677
7778 let emberSource = new VersionChecker ( this . project ) . for ( 'ember-source' ) ;
78- let hasEmberSourceModules = emberSource . exists ( ) && emberSource . gte ( '4.4.0' ) ;
79+ let hasEmberSourceModules =
80+ emberSource . exists ( ) && emberSource . gte ( '4.4.0' ) ;
7981
80- if ( isApp && hasEmberCliFastboot && ! hasEmberFetch ) {
82+ if ( isApp && hasEmberCliFastboot && ! hasEmberFetch ) {
8183 throw new Error ( `Ember fetch is not installed as top-level dependency of the application using fastboot. Add ember-fetch as dependecy in application's package.json.
8284 For details check here - https://github.com/ember-cli/ember-fetch#top-level-addon` ) ;
8385 }
@@ -89,13 +91,16 @@ module.exports = {
8991 importTarget = this ;
9092 }
9193
92- app . _fetchBuildConfig = Object . assign ( {
93- preferNative : false ,
94- nativePromise : false ,
95- alwaysIncludePolyfill : false ,
96- hasEmberSourceModules,
97- browsers : this . project . targets && this . project . targets . browsers
98- } , app . options [ 'ember-fetch' ] ) ;
94+ app . _fetchBuildConfig = Object . assign (
95+ {
96+ preferNative : false ,
97+ nativePromise : false ,
98+ alwaysIncludePolyfill : false ,
99+ hasEmberSourceModules,
100+ browsers : this . project . targets && this . project . targets . browsers ,
101+ } ,
102+ app . options [ 'ember-fetch' ]
103+ ) ;
99104
100105 importTarget . import ( 'vendor/ember-fetch.js' , {
101106 exports : {
@@ -104,9 +109,9 @@ module.exports = {
104109 'Headers' ,
105110 'Request' ,
106111 'Response' ,
107- 'AbortController'
108- ]
109- }
112+ 'AbortController' ,
113+ ] ,
114+ } ,
110115 } ) ;
111116 } ,
112117
@@ -120,37 +125,51 @@ module.exports = {
120125 * the correct version of the polyfill at the `vendor/ember-fetch.js` path.
121126 */
122127 treeForVendor ( ) {
123- let babelAddon = this . addons . find ( addon => addon . name === 'ember-cli-babel' ) ;
128+ let babelAddon = this . addons . find (
129+ ( addon ) => addon . name === 'ember-cli-babel'
130+ ) ;
124131
125132 const app = this . _findApp ( ) ;
126133 const options = app . _fetchBuildConfig ;
127134
128135 let browserTree = this . treeForBrowserFetch ( options ) ;
129136 if ( babelAddon ) {
130- browserTree = debug ( babelAddon . transpileTree ( browserTree , {
131- 'ember-cli-babel' : {
132- compileModules : false ,
133- } ,
134- } ) , 'after-babel' ) ;
135-
137+ browserTree = debug (
138+ babelAddon . transpileTree ( browserTree , {
139+ 'ember-cli-babel' : {
140+ compileModules : false ,
141+ } ,
142+ } ) ,
143+ 'after-babel'
144+ ) ;
136145 } else {
137- this . ui . writeWarnLine ( '[ember-fetch] Could not find `ember-cli-babel` addon, opting out of transpilation!' )
146+ this . ui . writeWarnLine (
147+ '[ember-fetch] Could not find `ember-cli-babel` addon, opting out of transpilation!'
148+ ) ;
138149 }
139150
140151 const preferNative = options . preferNative ;
141152
142- return debug ( map ( browserTree , ( content ) => `if (typeof FastBoot === 'undefined') {
153+ return debug (
154+ map (
155+ browserTree ,
156+ ( content ) => `if (typeof FastBoot === 'undefined') {
143157 var preferNative = ${ preferNative } ;
144158 ${ content }
145- }` ) , 'wrapped' ) ;
159+ }`
160+ ) ,
161+ 'wrapped'
162+ ) ;
146163 } ,
147164
148165 // Only include public/fetch-fastboot.js if top level addon
149166 treeForPublic ( ) {
150- const fastbootEnabled = process . env . FASTBOOT_DISABLED !== 'true'
151- && ! ! this . project . findAddonByName ( 'ember-cli-fastboot' ) ;
167+ const fastbootEnabled =
168+ process . env . FASTBOOT_DISABLED !== 'true' &&
169+ ! ! this . project . findAddonByName ( 'ember-cli-fastboot' ) ;
152170 return ! this . parent . parent && fastbootEnabled
153- ? this . _super . treeForPublic . apply ( this , arguments ) : null ;
171+ ? this . _super . treeForPublic . apply ( this , arguments )
172+ : null ;
154173 } ,
155174
156175 cacheKeyForTree ( treeType ) {
@@ -175,52 +194,73 @@ module.exports = {
175194 treeForBrowserFetch ( options ) {
176195 const browsers = options . browsers ;
177196 // To skip including the polyfill, `preferNative` needs to be `true` AND `alwaysIncludePolyfill` needs to be `false` (default)
178- const alwaysIncludePolyfill = ! options . preferNative || options . alwaysIncludePolyfill ;
179- const needsFetchPolyfill = alwaysIncludePolyfill || ! this . _checkSupports ( 'fetch' , browsers ) ;
180- const needsAbortControllerPolyfill = alwaysIncludePolyfill || ! this . _checkSupports ( 'abortcontroller' , browsers ) ;
197+ const alwaysIncludePolyfill =
198+ ! options . preferNative || options . alwaysIncludePolyfill ;
199+ const needsFetchPolyfill =
200+ alwaysIncludePolyfill || ! this . _checkSupports ( 'fetch' , browsers ) ;
201+ const needsAbortControllerPolyfill =
202+ alwaysIncludePolyfill ||
203+ ! this . _checkSupports ( 'abortcontroller' , browsers ) ;
181204
182205 const inputNodes = [ ] ;
183206 const inputFiles = [ ] ;
184207
185208 if ( needsAbortControllerPolyfill ) {
186- const abortcontrollerNode = debug ( new Rollup ( path . dirname ( path . dirname ( require . resolve ( 'abortcontroller-polyfill' ) ) ) , {
187- rollup : {
188- input : 'src/abortcontroller-polyfill.js' ,
189- output : {
190- file : 'abortcontroller.js' ,
191- // abortcontroller is polyfill only, the name is only required by rollup iife
192- name : 'AbortController' ,
193- format : 'iife'
209+ const abortcontrollerNode = debug (
210+ new Rollup (
211+ path . dirname (
212+ path . dirname ( require . resolve ( 'abortcontroller-polyfill' ) )
213+ ) ,
214+ {
215+ rollup : {
216+ input : 'src/abortcontroller-polyfill.js' ,
217+ output : {
218+ file : 'abortcontroller.js' ,
219+ // abortcontroller is polyfill only, the name is only required by rollup iife
220+ name : 'AbortController' ,
221+ format : 'iife' ,
222+ } ,
223+ } ,
194224 }
195- }
196- } ) , 'abortcontroller' ) ;
225+ ) ,
226+ 'abortcontroller'
227+ ) ;
197228
198229 inputNodes . push ( abortcontrollerNode ) ;
199230 inputFiles . push ( 'abortcontroller.js' ) ;
200231 }
201232
202233 if ( needsFetchPolyfill ) {
203- const fetchNode = debug ( new Rollup ( path . dirname ( path . dirname ( require . resolve ( 'whatwg-fetch' ) ) ) , {
204- rollup : {
205- input : 'fetch.js' ,
206- output : {
207- file : 'fetch.js' ,
208- name : 'WHATWGFetch' ,
209- format : 'iife'
234+ const fetchNode = debug (
235+ new Rollup (
236+ path . dirname ( path . dirname ( require . resolve ( 'whatwg-fetch' ) ) ) ,
237+ {
238+ rollup : {
239+ input : 'fetch.js' ,
240+ output : {
241+ file : 'fetch.js' ,
242+ name : 'WHATWGFetch' ,
243+ format : 'iife' ,
244+ } ,
245+ } ,
210246 }
211- }
212- } ) , 'whatwg-fetch' ) ;
247+ ) ,
248+ 'whatwg-fetch'
249+ ) ;
213250
214251 inputNodes . push ( fetchNode ) ;
215252 inputFiles . push ( 'fetch.js' ) ;
216253 }
217254
218- const polyfillNode = debug ( concat ( new MergeTrees ( inputNodes ) , {
219- inputFiles,
220- allowNone : true ,
221- outputFile : 'ember-fetch.js' ,
222- sourceMapConfig : { enabled : false }
223- } ) , 'after-concat' ) ;
255+ const polyfillNode = debug (
256+ concat ( new MergeTrees ( inputNodes ) , {
257+ inputFiles,
258+ allowNone : true ,
259+ outputFile : 'ember-fetch.js' ,
260+ sourceMapConfig : { enabled : false } ,
261+ } ) ,
262+ 'after-concat'
263+ ) ;
224264
225265 const moduleHeader = this . _getModuleHeader ( options ) ;
226266
@@ -231,7 +271,7 @@ module.exports = {
231271 moduleBody : content ,
232272 } ;
233273 } ) ,
234- " browser-fetch"
274+ ' browser-fetch'
235275 ) ;
236276 } ,
237277
@@ -286,8 +326,12 @@ define('fetch', ['exports'], function(exports) {
286326 let app ;
287327 let current = this ;
288328 do {
289- app = current . app || this ;
290- } while ( current . parent && current . parent . parent && ( current = current . parent ) ) ;
329+ app = current . app || this ;
330+ } while (
331+ current . parent &&
332+ current . parent . parent &&
333+ ( current = current . parent )
334+ ) ;
291335
292336 return app ;
293337 }
0 commit comments