Skip to content

Commit

Permalink
Move ENV, environment, context stuff to 'ember-environment' WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
krisselden committed Apr 15, 2016
1 parent 75cd6e3 commit 93f1a8f
Show file tree
Hide file tree
Showing 91 changed files with 613 additions and 604 deletions.
7 changes: 4 additions & 3 deletions lib/packages.js
Expand Up @@ -4,14 +4,15 @@ var features = JSON.parse(featuresJson).features;

var packages = {
'container': {trees: null, requirements: []},
'ember-metal': {trees: null, vendorRequirements: ['backburner']},
'ember-environment': {trees: null, requirements: [], skipTests: true},
'ember-metal': {trees: null, requirements: ['ember-environment'], vendorRequirements: ['backburner']},
'ember-metal-views': {trees: null, vendorRequirements: ['dom-helper', 'morph-range', 'morph-attr']},
'ember-debug': {trees: null, requirements: ['ember-metal'], testing: true},
'ember-runtime': {trees: null, vendorRequirements: ['rsvp'], requirements: ['container', 'ember-metal']},
'ember-runtime': {trees: null, vendorRequirements: ['rsvp'], requirements: ['container', 'ember-environment', 'ember-metal']},
'ember-views': {trees: null, requirements: ['ember-runtime', 'ember-metal-views']},
'ember-extension-support': {trees: null, requirements: ['ember-application']},
'ember-testing': {trees: null, requirements: ['ember-application', 'ember-routing'], testing: true},
'ember-template-compiler': {trees: null, requirements: ['ember-metal'], vendorRequirements: ['htmlbars-runtime'], templateCompilerVendor: ['simple-html-tokenizer', 'morph-range', 'htmlbars-runtime', 'htmlbars-util', 'htmlbars-compiler', 'htmlbars-syntax', 'htmlbars-test-helpers', 'backburner']},
'ember-template-compiler': {trees: null, requirements: ['ember-metal', 'ember-environment'], vendorRequirements: ['htmlbars-runtime'], templateCompilerVendor: ['simple-html-tokenizer', 'morph-range', 'htmlbars-runtime', 'htmlbars-util', 'htmlbars-compiler', 'htmlbars-syntax', 'htmlbars-test-helpers', 'backburner']},
'ember-htmlbars': {trees: null, vendorRequirements: ['htmlbars-util', 'htmlbars-runtime'], requirements: ['ember-metal-views'], testingVendorRequirements: [ 'htmlbars-test-helpers'], hasTemplates: true},
'ember-routing': {trees: null, vendorRequirements: ['router', 'route-recognizer'],
requirements: ['ember-runtime', 'ember-views']},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -34,7 +34,7 @@
"ember-cli-sauce": "^1.4.2",
"ember-cli-yuidoc": "0.8.3",
"ember-publisher": "0.0.7",
"emberjs-build": "0.6.4",
"emberjs-build": "0.7.0",
"express": "^4.5.0",
"finalhandler": "^0.4.0",
"github": "^0.2.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/container/lib/container.js
@@ -1,4 +1,4 @@
import Ember from 'ember-metal/core';
import { ENV } from 'ember-environment';
import { assert, deprecate } from 'ember-metal/debug';
import dictionary from 'ember-metal/dictionary';
import isEnabled from 'ember-metal/features';
Expand Down Expand Up @@ -263,7 +263,7 @@ function factoryFor(container, fullName, options = {}) {
if (factory === undefined) { return; }

var type = fullName.split(':')[0];
if (!factory || typeof factory.extend !== 'function' || (!Ember.MODEL_FACTORY_INJECTIONS && type === 'model')) {
if (!factory || typeof factory.extend !== 'function' || (!ENV.MODEL_FACTORY_INJECTIONS && type === 'model')) {
if (factory && typeof factory._onLookup === 'function') {
factory._onLookup(fullName);
}
Expand Down
13 changes: 0 additions & 13 deletions packages/container/lib/index.js
@@ -1,23 +1,10 @@
import Ember from 'ember-metal/core';

/*
Public API for the container is still in flux.
The public API, specified on the application namespace should be considered the stable API.
// @module container
@private
*/

/*
Flag to enable/disable model factory injections (disabled by default).
If model factory injections are enabled, models should not be
accessed globally (only through `container.lookupFactory('model:modelName'))`);
*/
Ember.MODEL_FACTORY_INJECTIONS = false;

if (Ember.ENV && typeof Ember.ENV.MODEL_FACTORY_INJECTIONS !== 'undefined') {
Ember.MODEL_FACTORY_INJECTIONS = !!Ember.ENV.MODEL_FACTORY_INJECTIONS;
}

import Registry from 'container/registry';
import Container from 'container/container';
import { getOwner, setOwner } from 'container/owner';
Expand Down
13 changes: 7 additions & 6 deletions packages/container/tests/container_test.js
@@ -1,4 +1,5 @@
import Ember from 'ember-metal/core';
import { ENV } from 'ember-environment';
import { get } from 'ember-metal/property_get';
import Registry from 'container/registry';
import factory from 'container/tests/test-helpers/factory';
import { getOwner, OWNER } from 'container/owner';
Expand All @@ -8,10 +9,10 @@ var originalModelInjections;

QUnit.module('Container', {
setup() {
originalModelInjections = Ember.MODEL_FACTORY_INJECTIONS;
originalModelInjections = ENV.MODEL_FACTORY_INJECTIONS;
},
teardown() {
Ember.MODEL_FACTORY_INJECTIONS = originalModelInjections;
ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections;
}
});

Expand Down Expand Up @@ -239,7 +240,7 @@ QUnit.test('An invalid factory throws an error', function() {
});

QUnit.test('Injecting a failed lookup raises an error', function() {
Ember.MODEL_FACTORY_INJECTIONS = true;
ENV.MODEL_FACTORY_INJECTIONS = true;

var registry = new Registry();
var container = registry.container();
Expand Down Expand Up @@ -552,7 +553,7 @@ QUnit.test('A deprecated `container` property is appended to every object instan
let postController = container.lookup('controller:post');

expectDeprecation(function() {
Ember.get(postController, 'container');
get(postController, 'container');
}, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.');

expectDeprecation(function() {
Expand Down Expand Up @@ -602,7 +603,7 @@ QUnit.test('A deprecated `container` property is appended to every object instan
let postController = container.lookup('controller:post');

expectDeprecation(function() {
Ember.get(postController, 'container');
get(postController, 'container');
}, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.');

expectDeprecation(function() {
Expand Down
12 changes: 1 addition & 11 deletions packages/container/tests/registry_test.js
@@ -1,18 +1,8 @@
import Ember from 'ember-metal/core';
import { Registry } from 'container';
import factory from 'container/tests/test-helpers/factory';
import isEnabled from 'ember-metal/features';

var originalModelInjections;

QUnit.module('Registry', {
setup() {
originalModelInjections = Ember.MODEL_FACTORY_INJECTIONS;
},
teardown() {
Ember.MODEL_FACTORY_INJECTIONS = originalModelInjections;
}
});
QUnit.module('Registry');

QUnit.test('A registered factory is returned from resolve', function() {
var registry = new Registry();
Expand Down
Expand Up @@ -6,18 +6,15 @@
import { deprecate } from 'ember-metal/debug';
import { get } from 'ember-metal/property_get';
import { set } from 'ember-metal/property_set';
import symbol from 'ember-metal/symbol';
import run from 'ember-metal/run_loop';
import { computed } from 'ember-metal/computed';
import { buildFakeRegistryWithDeprecations } from 'ember-runtime/mixins/registry_proxy';
import assign from 'ember-metal/assign';
import environment from 'ember-metal/environment';
import { environment } from 'ember-environment';
import RSVP from 'ember-runtime/ext/rsvp';
import jQuery from 'ember-views/system/jquery';
import EngineInstance from './engine-instance';

export const INTERNAL_BOOT_OPTIONS = symbol('INTERNAL_BOOT_OPTIONS');

let BootOptions;

/**
Expand Down
16 changes: 9 additions & 7 deletions packages/ember-application/lib/system/application.js
Expand Up @@ -2,9 +2,11 @@
@module ember
@submodule ember-application
*/
import Ember from 'ember-metal'; // Ember.libraries, LOG_VERSION, Namespace, BOOTED
import Ember from 'ember-metal'; // Ember.libraries, Ember.BOOTED, Ember.testing
import { ENV } from 'ember-environment';
import { assert, debug, warn, deprecate } from 'ember-metal/debug';
import { get } from 'ember-metal/property_get';
import Namespace from 'ember-runtime/system/namespace';
import { runLoadHooks } from 'ember-runtime/system/lazy_load';
import run from 'ember-metal/run_loop';
import Controller from 'ember-runtime/controllers/controller';
Expand Down Expand Up @@ -32,7 +34,7 @@ import ContainerDebugAdapter from 'ember-extension-support/container_debug_adapt
import { _loaded } from 'ember-runtime/system/lazy_load';
import { buildFakeRegistryWithDeprecations } from 'ember-runtime/mixins/registry_proxy';
import { privatize as P } from 'container/registry';
import environment from 'ember-metal/environment';
import { environment } from 'ember-environment';
import RSVP from 'ember-runtime/ext/rsvp';
import Engine, { GLIMMER } from './engine';
import require from 'require';
Expand Down Expand Up @@ -594,7 +596,7 @@ const Application = Engine.extend({
_bootSync() {
if (this._booted) { return; }

if (Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT && !warnedAboutLegacyViewAddon) {
if (ENV._ENABLE_LEGACY_VIEW_SUPPORT && !warnedAboutLegacyViewAddon) {
deprecate(
'Support for the `ember-legacy-views` addon will end soon, please remove it from your application.',
false,
Expand All @@ -604,7 +606,7 @@ const Application = Engine.extend({
warnedAboutLegacyViewAddon = true;
}

if (Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT && !warnedAboutLegacyControllerAddon) {
if (ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT && !warnedAboutLegacyControllerAddon) {
warn(
'Support for the `ember-legacy-controllers` has been removed, please remove it from your application.',
false,
Expand Down Expand Up @@ -735,7 +737,7 @@ const Application = Engine.extend({
// TODO: Is this still needed for _globalsMode = false?
if (!Ember.testing) {
// Eagerly name all classes that are already loaded
Ember.Namespace.processAll();
Namespace.processAll();
Ember.BOOTED = true;
}

Expand Down Expand Up @@ -1174,9 +1176,9 @@ function registerLibraries() {
}

function logLibraryVersions() {
if (Ember.LOG_VERSION) {
if (ENV.LOG_VERSION) {
// we only need to see this once per Application#init
Ember.LOG_VERSION = false;
ENV.LOG_VERSION = false;
var libs = Ember.libraries._registry;

var nameLengths = libs.map(function(item) {
Expand Down
38 changes: 19 additions & 19 deletions packages/ember-application/tests/system/application_test.js
@@ -1,7 +1,7 @@
/*globals EmberDev */

import Ember from 'ember-metal/core';
import assign from 'ember-metal/assign';
import { ENV, context } from 'ember-environment';
import run from 'ember-metal/run_loop';
import Application, { _resetLegacyAddonWarnings } from 'ember-application/system/application';
import DefaultResolver from 'ember-application/system/resolver';
Expand All @@ -22,7 +22,7 @@ var app, application, originalLookup, originalDebug, originalWarn;

QUnit.module('Ember.Application', {
setup() {
originalLookup = Ember.lookup;
originalLookup = context.lookup;
originalDebug = getDebugFunction('debug');
originalWarn = getDebugFunction('warn');

Expand All @@ -37,7 +37,7 @@ QUnit.module('Ember.Application', {
setDebugFunction('debug', originalDebug);
setDebugFunction('warn', originalWarn);

Ember.lookup = originalLookup;
context.lookup = originalLookup;

if (application) {
run(application, 'destroy');
Expand Down Expand Up @@ -91,7 +91,7 @@ QUnit.test('you cannot make two default applications without a rootElement error
});

QUnit.test('acts like a namespace', function() {
var lookup = Ember.lookup = {};
var lookup = context.lookup = {};

run(function() {
app = lookup.TestApp = Application.create({ rootElement: '#two', router: false });
Expand All @@ -116,12 +116,15 @@ QUnit.test('includes deprecated access to `application.registry`', function() {
}, /Using `Application.registry.register` is deprecated. Please use `Application.register` instead./);
});

const originalLogVersion = ENV.LOG_VERSION;

QUnit.module('Ember.Application initialization', {
teardown() {
if (app) {
run(app, 'destroy');
}
Ember.TEMPLATES = {};
ENV.LOG_VERSION = originalLogVersion;
}
});

Expand Down Expand Up @@ -266,7 +269,7 @@ QUnit.test('enable log of libraries with an ENV var', function() {

var messages = [];

Ember.LOG_VERSION = true;
ENV.LOG_VERSION = true;

setDebugFunction('debug', function(message) {
messages.push(message);
Expand All @@ -285,13 +288,12 @@ QUnit.test('enable log of libraries with an ENV var', function() {
equal(messages[3], 'my-lib : ' + '2.0.0a');

Ember.libraries.deRegister('my-lib');
Ember.LOG_VERSION = false;
});

QUnit.test('disable log version of libraries with an ENV var', function() {
var logged = false;

Ember.LOG_VERSION = false;
ENV.LOG_VERSION = false;

setDebugFunction('debug', function(message) {
logged = true;
Expand Down Expand Up @@ -354,16 +356,13 @@ QUnit.test('does not leak itself in onLoad._loaded', function() {
equal(_loaded.application, undefined);
});

let originalEmberENV;
const originalLegacyViewSupport = ENV._ENABLE_LEGACY_VIEW_SUPPORT;
const originalLegacyControllerSupport = ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT;

QUnit.module('Ember.Application - legacy addon deprecation warnings', {
setup() {
originalEmberENV = Ember.ENV;

Ember.ENV = assign({}, originalEmberENV, {
_ENABLE_LEGACY_VIEW_SUPPORT: false,
_ENABLE_LEGACY_CONTROLLER_SUPPORT: false
});
ENV._ENABLE_LEGACY_VIEW_SUPPORT = false;
ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = false;

originalDebug = getDebugFunction('debug');
originalWarn = getDebugFunction('warn');
Expand All @@ -372,7 +371,8 @@ QUnit.module('Ember.Application - legacy addon deprecation warnings', {
},

teardown() {
Ember.ENV = originalEmberENV;
ENV._ENABLE_LEGACY_VIEW_SUPPORT = originalLegacyViewSupport;
ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = originalLegacyControllerSupport;

setDebugFunction('debug', originalDebug);
setDebugFunction('warn', originalWarn);
Expand All @@ -386,13 +386,13 @@ QUnit.module('Ember.Application - legacy addon deprecation warnings', {
QUnit.test('it does not warn about the ember-legacy-views addon on first boot when not installed', function() {
expectNoDeprecation();

Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = false;
ENV._ENABLE_LEGACY_VIEW_SUPPORT = false;

app = run(Application, 'create');
});

QUnit.test('it warns about the ember-legacy-views addon on first boot when installed', function() {
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = true;
ENV._ENABLE_LEGACY_VIEW_SUPPORT = true;

expectDeprecation(() => {
app = run(Application, 'create');
Expand All @@ -409,7 +409,7 @@ QUnit.test('it warns about the ember-legacy-views addon on first boot when insta
QUnit.test('it does not warn about the ember-legacy-controllers addon on first boot when not installed', function() {
expectNoDeprecation();

Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = false;
ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = false;

app = run(Application, 'create');
});
Expand All @@ -420,7 +420,7 @@ QUnit.test('it warns about the ember-legacy-controllers addon on first boot when
return;
}

Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = true;
ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = true;

let warning;
setDebugFunction('warn', function(message, test) {
Expand Down
@@ -1,5 +1,6 @@
/* globals EmberDev */
import Ember from 'ember-metal/core'; // Ember.TEMPLATES
import { context } from 'ember-environment';
import { getDebugFunction, setDebugFunction } from 'ember-metal/debug';
import run from 'ember-metal/run_loop';
import Controller from 'ember-runtime/controllers/controller';
Expand All @@ -20,7 +21,7 @@ var registry, locator, application, originalLookup, originalInfo;

QUnit.module('Ember.Application Dependency Injection - default resolver', {
setup() {
originalLookup = Ember.lookup;
originalLookup = context.lookup;
application = run(Application, 'create');

registry = application.__registry__;
Expand All @@ -30,7 +31,7 @@ QUnit.module('Ember.Application Dependency Injection - default resolver', {

teardown() {
Ember.TEMPLATES = {};
Ember.lookup = originalLookup;
context.lookup = originalLookup;
run(application, 'destroy');
var UserInterfaceNamespace = Namespace.NAMESPACES_BY_ID['UserInterface'];
if (UserInterfaceNamespace) { run(UserInterfaceNamespace, 'destroy'); }
Expand All @@ -40,7 +41,7 @@ QUnit.module('Ember.Application Dependency Injection - default resolver', {
});

QUnit.test('the default resolver can look things up in other namespaces', function() {
var UserInterface = Ember.lookup.UserInterface = Namespace.create();
var UserInterface = context.lookup.UserInterface = Namespace.create();
UserInterface.NavigationController = Controller.extend();

var nav = locator.lookup('controller:userInterface/navigation');
Expand Down

0 comments on commit 93f1a8f

Please sign in to comment.