From 45b49d8ef0519651aa41f22931c69a9239dbd9c2 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 1 Jun 2021 13:54:31 -0700 Subject: [PATCH] Fix Ember global deprecation 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 https://github.com/ember-cli/ember-fetch/issues/337. --- assets/browser-fetch.js.t | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/assets/browser-fetch.js.t b/assets/browser-fetch.js.t index 8d8cfe76..e6081e6a 100644 --- a/assets/browser-fetch.js.t +++ b/assets/browser-fetch.js.t @@ -1,7 +1,14 @@ (function (originalGlobal) { - define('fetch', ['exports'], function(exports) { + if (!require.has('ember')) { + define('ember', ['exports'], function(exports) { + exports['default'] = originalGlobal.Ember; + }); + } + + define('fetch', ['exports', 'ember'], function(exports, Ember) { 'use strict'; - var Promise = originalGlobal.Ember.RSVP.Promise; + var Ember__default = 'default' in Ember ? Ember['default'] : Ember; + var Promise = Ember__default.RSVP.Promise; var supportProps = [ 'FormData', 'FileReader', @@ -49,8 +56,8 @@ return result; } - if (originalGlobal.Ember.Test) { - originalGlobal.Ember.Test.registerWaiter(function() { + if (Ember__default.Test) { + Ember__default.Test.registerWaiter(function() { return pending === 0; });