Skip to content

Commit

Permalink
Remove window.Ember global
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jul 23, 2021
1 parent d777bf2 commit 5bbe4b9
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 128 deletions.
16 changes: 0 additions & 16 deletions lib/overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,6 @@ module.exports = class Overrides {

toModule() {
return `
export let onEmberGlobalAccess;
${this.toJS()};
`;
}
Expand All @@ -347,20 +345,6 @@ module.exports = class Overrides {
}
${this.onDotAcces}
onEmberGlobalAccess = ${this.onEmberGlobalAccess};
if (!${this.showAllEmberGlobalDeprecations}) {
onEmberGlobalAccess = once(onEmberGlobalAccess);
}
`;
}

get onEmberGlobalAccess() {
return `
function onEmberGlobalAccess() {
return ${JSON.stringify(this.globalMessage)};
}
`;
}
};
56 changes: 1 addition & 55 deletions packages/@ember/-internals/bootstrap/index.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,10 @@
import { context } from '@ember/-internals/environment';
import { onEmberGlobalAccess } from '@ember/-internals/overrides';
import { deprecate } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import require from 'require';

(function bootstrap() {
let Ember: unknown;

let get = () => {
if (!Ember) {
// tslint:disable-next-line: no-require-imports
Ember = require('ember').default;
}

return Ember;
};

if (DEBUG) {
let defaultHandler = () => {
return 'Usage of the Ember Global is deprecated. You should import the Ember module or the specific API instead.';
};

let handler = onEmberGlobalAccess || defaultHandler;
let _get = get;

get = () => {
let message = handler();

if (message !== null) {
deprecate(message, false, {
id: 'ember-global',
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x/#toc_ember-global',
for: 'ember-source',
since: {
enabled: '3.27.0',
},
});
}

return _get();
};
}

function defineEmber(key: string) {
Object.defineProperty(context.exports, key, {
enumerable: true,
configurable: true,
get,
});
}

// Bootstrap the global
defineEmber('Ember');
defineEmber('Em');

// Bootstrap Node module
// eslint-disable-next-line no-undef
if (typeof module === 'object' && typeof module.require === 'function') {
// tslint:disable-next-line: no-require-imports
module.exports = Ember = require('ember').default;
module.exports = require('ember').default;
}
})();
9 changes: 0 additions & 9 deletions packages/@ember/-internals/overrides/index.d.ts

This file was deleted.

4 changes: 3 additions & 1 deletion tests/node/fastboot-sandbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function buildSandboxContext(precompile) {
URL,

// Convince jQuery not to assume it's in a browser
module: { exports: {} },
module: { exports: {}, require() {} },
};

// Set the global as `window`
Expand All @@ -69,6 +69,8 @@ var EmberENV = {
emberScript.runInContext(context);

let applicationSource = `
let Ember = module.exports;
class Router extends Ember.Router {}
Router.map(function() {
this.route('a');
Expand Down
47 changes: 0 additions & 47 deletions tests/node/overrides-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,6 @@ function infoForApp({
// };
// }

function evalJS(overrides) {
return eval(`
(function () {
let onEmberGlobalAccess;
${overrides.toJS()}
return {
onEmberGlobalAccess: onEmberGlobalAccess,
};
})()
`);
}

QUnit.module('Overrides', function () {
QUnit.module('.addonsInfoFor', function () {
// app
Expand Down Expand Up @@ -593,39 +579,6 @@ QUnit.module('Overrides', function () {
assert.strictEqual(overrides.hasActionableSuggestions, true, 'hasActionableSuggestions');
assert.strictEqual(overrides.hasCompatibleAddons, false, 'hasCompatibleAddons');
assert.strictEqual(overrides.hasDormantAddons, false, 'hasDormantAddons');
assert.strictEqual(
overrides.showAllEmberGlobalDeprecations,
false,
'showAllEmberGlobalDeprecations'
);
assert.deepEqual(overrides.suggestions, [
'Upgrade your `devDependencies` on `ember-cli-babel` to `^7.26.6`.',
]);
assert.equal(
overrides.outdated.length,
1 /* number of different old babel versions */,
'outdated.length'
);
assert.ok(
overrides.buildTimeWarning.startsWith(
'[DEPRECATION] Usage of the Ember Global is deprecated.'
),
'overrides.buildTimeWarning'
);
assert.ok(
overrides.globalMessage.startsWith('Usage of the Ember Global is deprecated.'),
'overrides.globalMessage'
);

let { onEmberGlobalAccess } = evalJS(overrides);

assert.equal(
onEmberGlobalAccess(),
overrides.globalMessage,
'onEmberGlobalAccess() (first call)'
);

assert.strictEqual(onEmberGlobalAccess(), null, 'onEmberGlobalAccess() (second call)');
});

// let project, env;
Expand Down

0 comments on commit 5bbe4b9

Please sign in to comment.