Skip to content

Commit

Permalink
Fix Ember global deprecation
Browse files Browse the repository at this point in the history
A minimal fix for #600. We should probably follow through with the
refactor suggested by @rwjblue in #600 but that can be done later.

This is probably not very embroider friendly, but neither is the
current code. It's probably easier to just rewrite the shims in
terms of ES modules and embroider macros, i.e. what was suggested
in #337.
  • Loading branch information
chancancode committed Jun 2, 2021
1 parent 3e02036 commit 2fe0569
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 3 additions & 5 deletions assets/browser-fetch.js.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
(function (originalGlobal) {
define('fetch', ['exports'], function(exports) {
'use strict';
var Promise = originalGlobal.Ember.RSVP.Promise;
<%= moduleHeader %>
var supportProps = [
'FormData',
'FileReader',
Expand Down Expand Up @@ -49,8 +47,8 @@
return result;
}

if (originalGlobal.Ember.Test) {
originalGlobal.Ember.Test.registerWaiter(function() {
if (Ember.Test) {
Ember.Test.registerWaiter(function() {
return pending === 0;
});

Expand Down
13 changes: 13 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 @@ -172,6 +173,7 @@ module.exports = {
const alwaysIncludePolyfill = !options.preferNative || options.alwaysIncludePolyfill;
const needsFetchPolyfill = alwaysIncludePolyfill || !this._checkSupports('fetch', browsers);
const needsAbortControllerPolyfill = alwaysIncludePolyfill || !this._checkSupports('abortcontroller', browsers);
const hasRealModules = VersionChecker.forProject(this.project).check({ 'ember-source': '>= 3.27.0' });

const inputNodes = [];
const inputFiles = [];
Expand Down Expand Up @@ -216,8 +218,19 @@ module.exports = {
sourceMapConfig: { enabled: false }
}), 'after-concat');

const moduleHeader = hasRealModules ? `
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
1 change: 1 addition & 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

0 comments on commit 2fe0569

Please sign in to comment.