diff --git a/.travis.yml b/.travis.yml index 28add758..1c7472bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,6 +45,9 @@ jobs: env: EMBER_TRY_SCENARIO=ember-lts-3.4 - env: EMBER_TRY_SCENARIO=ember-lts-3.8 - env: EMBER_TRY_SCENARIO=ember-lts-3.12 + - env: EMBER_TRY_SCENARIO=ember-lts-3.16 + - env: EMBER_TRY_SCENARIO=ember-lts-3.20 + - env: EMBER_TRY_SCENARIO=ember-lts-3.24 - env: EMBER_TRY_SCENARIO=ember-release - env: EMBER_TRY_SCENARIO=ember-beta - env: EMBER_TRY_SCENARIO=ember-canary diff --git a/assets/browser-fetch.js.t b/assets/browser-fetch.js.t index 8d8cfe76..480fb6f4 100644 --- a/assets/browser-fetch.js.t +++ b/assets/browser-fetch.js.t @@ -1,7 +1,6 @@ (function (originalGlobal) { - define('fetch', ['exports'], function(exports) { - 'use strict'; - var Promise = originalGlobal.Ember.RSVP.Promise; + <%= moduleHeader %> + var Promise = RSVP.Promise; var supportProps = [ 'FormData', 'FileReader', @@ -49,8 +48,8 @@ return result; } - if (originalGlobal.Ember.Test) { - originalGlobal.Ember.Test.registerWaiter(function() { + if (Ember.Test) { + Ember.Test.registerWaiter(function() { return pending === 0; }); diff --git a/config/ember-try.js b/config/ember-try.js index 29ec241b..739e7a2a 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -30,6 +30,30 @@ module.exports = async function() { } } }, + { + name: 'ember-lts-3.16', + npm: { + devDependencies: { + 'ember-source': '~3.16.0' + } + } + }, + { + name: 'ember-lts-3.20', + npm: { + devDependencies: { + 'ember-source': '~3.20.0' + } + } + }, + { + name: 'ember-lts-3.24', + npm: { + devDependencies: { + 'ember-source': '~3.24.0' + } + } + }, { name: 'ember-release', npm: { diff --git a/index.js b/index.js index d5071b82..66b14847 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,7 @@ const map = stew.map; const Rollup = require('broccoli-rollup'); const BroccoliDebug = require('broccoli-debug'); const calculateCacheKeyForTree = require('calculate-cache-key-for-tree'); +const VersionChecker = require('ember-cli-version-checker'); const debug = BroccoliDebug.buildDebugCallback('ember-fetch'); @@ -73,6 +74,9 @@ module.exports = { let hasEmberFetch = !!this.project.findAddonByName('ember-fetch'); let hasEmberCliFastboot = !!this.project.findAddonByName('ember-cli-fastboot'); + let emberSource = new VersionChecker(this.project).for('ember-source'); + let hasEmberSourceModules = emberSource.exists() && emberSource.gte('3.27.0'); + if(isApp && hasEmberCliFastboot && !hasEmberFetch) { 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. For details check here - https://github.com/ember-cli/ember-fetch#top-level-addon`); @@ -88,6 +92,7 @@ module.exports = { app._fetchBuildConfig = Object.assign({ preferNative: false, alwaysIncludePolyfill: false, + hasEmberSourceModules, browsers: this.project.targets && this.project.targets.browsers }, app.options['ember-fetch']); @@ -216,8 +221,19 @@ module.exports = { sourceMapConfig: { enabled: false } }), 'after-concat'); + const moduleHeader = options.hasEmberSourceModules ? ` + define('fetch', ['exports', 'ember', 'rsvp'], function(exports, Ember__module, RSVP__module) { + 'use strict'; + var Ember = 'default' in Ember__module ? Ember__module['default'] : Ember__module; + var RSVP = 'default' in RSVP__module ? RSVP__module['default'] : RSVP__module;` : ` + define('fetch', ['exports'], function(exports) { + 'use strict'; + var Ember = originalGlobal.Ember; + var RSVP = Ember.RSVP;` + return debug(new Template(polyfillNode, TEMPLATE_PATH, function(content) { return { + moduleHeader, moduleBody: content }; }), 'browser-fetch'); diff --git a/package.json b/package.json index c2a61b22..ff95e0a2 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "caniuse-api": "^3.0.0", "ember-cli-babel": "^7.23.1", "ember-cli-typescript": "^3.1.3", + "ember-cli-version-checker": "^5.1.2", "node-fetch": "^2.6.1", "whatwg-fetch": "^3.6.2" }, @@ -97,5 +98,9 @@ "abortcontroller-polyfill", "abortcontroller-polyfill/dist/cjs-ponyfill" ] + }, + "volta": { + "node": "10.24.1", + "yarn": "1.22.10" } }