diff --git a/packages/ember-application/lib/system/application.js b/packages/ember-application/lib/system/application.js index d40a98abe7a..3db18e3dbcc 100644 --- a/packages/ember-application/lib/system/application.js +++ b/packages/ember-application/lib/system/application.js @@ -3,7 +3,7 @@ @submodule ember-application */ import Ember from 'ember-metal'; // Ember.libraries, LOG_VERSION, Namespace, BOOTED -import { assert, debug } from 'ember-metal/debug'; +import { assert, debug, deprecate } from 'ember-metal/debug'; import isEnabled from 'ember-metal/features'; import { get } from 'ember-metal/property_get'; import { runLoadHooks } from 'ember-runtime/system/lazy_load'; @@ -39,6 +39,15 @@ import Engine from './engine'; var librariesRegistered = false; +let warnedAboutLegacyViewAddon = false; +let warnedAboutLegacyControllerAddon = false; + +// For testing +export function _resetLegacyAddonWarnings() { + warnedAboutLegacyViewAddon = false; + warnedAboutLegacyControllerAddon = false; +} + /** An instance of `Ember.Application` is the starting point for every Ember application. It helps to instantiate, initialize and coordinate the many @@ -594,6 +603,26 @@ const Application = Engine.extend({ _bootSync() { if (this._booted) { return; } + if (Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT && !warnedAboutLegacyViewAddon) { + deprecate( + 'Support for the `ember-legacy-views` addon will end soon, please remove it from your application.', + false, + { id: 'ember-legacy-views', until: '2.6.0', url: 'http://emberjs.com/deprecations/v1.x/#toc_ember-view' } + ); + + warnedAboutLegacyViewAddon = true; + } + + if (Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT && !warnedAboutLegacyControllerAddon) { + deprecate( + 'Support for the `ember-legacy-controllers` addon will end soon, please remove it from your application.', + false, + { id: 'ember-legacy-controllers', until: '2.6.0', url: 'http://emberjs.com/deprecations/v1.x/#toc_objectcontroller' } + ); + + warnedAboutLegacyControllerAddon = true; + } + // Even though this returns synchronously, we still need to make sure the // boot promise exists for book-keeping purposes: if anything went wrong in // the boot process, we need to store the error as a rejection on the boot diff --git a/packages/ember-application/tests/system/application_test.js b/packages/ember-application/tests/system/application_test.js index 3dc9b286379..2e8e2198fc0 100644 --- a/packages/ember-application/tests/system/application_test.js +++ b/packages/ember-application/tests/system/application_test.js @@ -1,8 +1,9 @@ /*globals EmberDev */ import Ember from 'ember-metal/core'; +import assign from 'ember-metal/assign'; import run from 'ember-metal/run_loop'; -import Application from 'ember-application/system/application'; +import Application, { _resetLegacyAddonWarnings } from 'ember-application/system/application'; import DefaultResolver from 'ember-application/system/resolver'; import Router from 'ember-routing/system/router'; import View from 'ember-views/views/view'; @@ -354,3 +355,72 @@ QUnit.test('does not leak itself in onLoad._loaded', function() { run(app, 'destroy'); equal(_loaded.application, undefined); }); + +let originalEmberENV; + +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 + }); + + _resetLegacyAddonWarnings(); + }, + + teardown() { + Ember.ENV = originalEmberENV; + + if (app) { + run(app, 'destroy'); + } + } +}); + +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; + + 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; + + expectDeprecation(() => { + app = run(Application, 'create'); + }, 'Support for the `ember-legacy-views` addon will end soon, please remove it from your application.'); + + run(app, 'destroy'); + + // It should not warn again on second boot + expectNoDeprecation(() => { + app = run(Application, 'create'); + }); +}); + +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; + + app = run(Application, 'create'); +}); + +QUnit.test('it warns about the ember-legacy-controllers addon on first boot when installed', function() { + Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = true; + + expectDeprecation(() => { + app = run(Application, 'create'); + }, 'Support for the `ember-legacy-controllers` addon will end soon, please remove it from your application.'); + + run(app, 'destroy'); + + // It should not warn again on second boot + expectNoDeprecation(() => { + app = run(Application, 'create'); + }); +}); diff --git a/packages/ember-metal/lib/index.js b/packages/ember-metal/lib/index.js index 725b593a3f7..00ac4b4cf3d 100644 --- a/packages/ember-metal/lib/index.js +++ b/packages/ember-metal/lib/index.js @@ -6,7 +6,7 @@ // BEGIN IMPORTS import require, { has } from 'require'; import Ember from 'ember-metal/core'; -import { deprecate, deprecateFunc } from 'ember-metal/debug'; +import { deprecateFunc } from 'ember-metal/debug'; import isEnabled, { FEATURES } from 'ember-metal/features'; import assign from 'ember-metal/assign'; import merge from 'ember-metal/merge'; @@ -367,16 +367,6 @@ if (has('ember-debug')) { } } -deprecate( - 'Support for the `ember-legacy-views` addon will end soon, please remove it from your application.', - !!Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT, - { id: 'ember-legacy-views', until: '2.6.0', url: 'http://emberjs.com/deprecations/v1.x/#toc_ember-view' }); - -deprecate( - 'Support for the `ember-legacy-controllers` addon will end soon, please remove it from your application.', - !!Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT, - { id: 'ember-legacy-controllers', until: '2.6.0', url: 'http://emberjs.com/deprecations/v1.x/#toc_objectcontroller' }); - Ember.create = deprecateFunc('Ember.create is deprecated in favor of Object.create', { id: 'ember-metal.ember-create', until: '3.0.0' }, Object.create); Ember.keys = deprecateFunc('Ember.keys is deprecated in favor of Object.keys', { id: 'ember-metal.ember.keys', until: '3.0.0' }, Object.keys); diff --git a/tests/index.html b/tests/index.html index b266873a094..765367bef8d 100644 --- a/tests/index.html +++ b/tests/index.html @@ -116,6 +116,16 @@ } } + Ember.Debug.registerDeprecationHandler(function (message, options, next) { + var id = options && options.id; + + if (id === 'ember-legacy-views' || id === 'ember-legacy-controllers') { + // Our test suite relies on the legacy semantics... to test the legacy semantics + } else { + next(message, options); + } + }); + window.EmberDev = window.EmberDev || {}; EmberDev.runningProdBuild = !!QUnit.urlParams.prod;