Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ember global #620

Merged
merged 3 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions assets/browser-fetch.js.t
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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;
});

Expand Down
24 changes: 24 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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`);
Expand All @@ -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']);

Expand Down Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -97,5 +98,9 @@
"abortcontroller-polyfill",
"abortcontroller-polyfill/dist/cjs-ponyfill"
]
},
"volta": {
"node": "10.24.1",
"yarn": "1.22.10"
}
}