From 02f378284567f114e7979b2be3de97df5e561591 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Mon, 12 Feb 2018 16:20:17 -0800 Subject: [PATCH] Fixes #60: Add build time flags for deprecation toggling --- README.md | 32 +++++++++++++++++++++---- index.js | 66 +++++++++++++++++++++++++++++++++------------------- package.json | 1 + 3 files changed, 70 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 19fa04f..79fe491 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,8 @@ # Ember 2 Legacy -During the 2.x series in Ember.JS [serveral deprecations were added](https://www.emberjs.com/deprecations/v2.x/) with a target removal version of 3.0. This addon adds back those deprecations and the -deprecated code that was removed. The goal of this addon is to allow Ember users who have deprecations that are preventing them from upgrading to 3.0 a path forward. **After Ember 3.4 is released this -addon will no longer be compatible with Ember**. It should be used to provide extra time for migrating away from deprecations, not as a permanent solution. +During the 2.x series in Ember.JS [serveral deprecations were added](https://www.emberjs.com/deprecations/v2.x/) with a target removal version of 3.0. This addon adds back those deprecations and the deprecated code that was removed. The goal of this addon is to allow Ember users who have deprecations that are preventing them from upgrading to 3.0 a path forward. **After Ember 3.4 is released this addon will no longer be compatible with Ember**. It should be used to provide extra time for migrating away from deprecations, not as a permanent solution. -For more background about what and why APIs are being remove for Ember.JS 3.0 please check out the [Road to Ember 3.0](https://emberjs.com/blog/2017/10/03/the-road-to-ember-3-0.html#toc_api-removals-in-3-0) blog -post which goes into more details. +For more background about what and why APIs are being remove for Ember.JS 3.0 please check out the [Road to Ember 3.0](https://emberjs.com/blog/2017/10/03/the-road-to-ember-3-0.html#toc_api-removals-in-3-0) blog post which goes into more details. ## Installation @@ -16,3 +13,28 @@ ember install ember-2-legacy ## What Deprecations are Covered All [deprecations found here](https://www.emberjs.com/deprecations/v2.x/) which have a `until: 3.0.0` are currently supported by this addon. + +In `ember-cli-build.js` you can specify a config for `ember-2-legacy`. This object has individual flags as key names and they can be turned off simply by setting a flag to `false`. Below is a sample config which shows all of the flag names: + +```js +new EmberApp(defaults, { + 'ember-2-legacy': { + 'ember-k': false, + 'safe-string': false, + 'enumberable-contains': false, + 'underscore-actions': false, + 'reversed-observer-args': false, + 'initializer-arity': false, + 'router-resouce': false, + 'current-when': false, + 'controller-wrapped': false, // TODO better name + 'application-registry': false, + 'immedicate-observer': false, + 'string-fmt': false, + 'ember-freezable': false, + 'component-defaultLayout': false, + 'ember-binding': false, + 'input-transform': false + } +}); +``` diff --git a/index.js b/index.js index f00f027..29b72ea 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,10 @@ /* eslint-env node */ 'use strict' +const debug = require('debug')('ember-2-legacy'); +const version = require('./package.json').version; const mergeTrees = require('broccoli-merge-trees'); const writeFile = require('broccoli-file-creator'); -const version = require('./package.json').version; const VersionChecker = require('ember-cli-version-checker'); const minEmberVersion = '3.0.0-beta.3'; @@ -35,32 +36,35 @@ module.exports = { // do nothing if running with Ember 2.x if (this.emberVersion.lt(minEmberVersion)) { + debug(`Not including polyfills as we are running on ${this.emberVersion()} and require a min of ${minEmberVersion}.`); return; } - this.import('vendor/ember-k.js'); - this.import('vendor/safe-string.js'); - this.import('vendor/enumerable-contains.js'); - this.import('vendor/underscore-actions.js'); - this.import('vendor/reversed-observer.js'); - this.import('vendor/initializer-arity.js'); - this.import('vendor/router-resource.js'); - this.import('vendor/link-to.js'); - this.import('vendor/deprecated-registry.js'); - this.import('vendor/immediate-observer.js'); - this.import('vendor/string-fmt.js'); - this.import('vendor/freezable.js'); - this.import('vendor/component-defaultlayout.js'); - this.import('vendor/binding.js'); - this.import('vendor/text-support.js'); - - // Only include this in 3.0 as it has problems with 2.12 as - // as the AST has changed - const transform = require('./transforms/input'); - this.app.registry.add('htmlbars-ast-plugin', { - name: 'transform-input-on-to-onEvent', - plugin: transform - }); + this.importUnlessFlagged('vendor/ember-k.js', ['ember-k']); + this.importUnlessFlagged('vendor/safe-string.js', ['safe-string']); + this.importUnlessFlagged('vendor/enumerable-contains.js', ['enumerable-contains']); + this.importUnlessFlagged('vendor/underscore-actions.js', ['underscore-actions']); + this.importUnlessFlagged('vendor/reversed-observer.js', ['reversed-observer']); + this.importUnlessFlagged('vendor/initializer-arity.js', ['initializer-arity']); + this.importUnlessFlagged('vendor/router-resource.js', ['router-resource']); + this.importUnlessFlagged('vendor/link-to.js', ['current-when', 'controller-wrapped']); + this.importUnlessFlagged('vendor/deprecated-registry.js', ['application-registry']); + this.importUnlessFlagged('vendor/immediate-observer.js', ['immedicate-observer']); + this.importUnlessFlagged('vendor/string-fmt.js', ['string-fmt']); + this.importUnlessFlagged('vendor/freezable.js', ['ember-freezable']); + this.importUnlessFlagged('vendor/component-defaultlayout.js', ['component-defaultlayout']); + this.importUnlessFlagged('vendor/binding.js', ['ember-binding']); + this.importUnlessFlagged('vendor/text-support.js', ['input-transform']); + + if (this.flagValue('input-transform') !== false) { + const transform = require('./transforms/input'); + this.app.registry.add('htmlbars-ast-plugin', { + name: 'transform-input-on-to-onEvent', + plugin: transform + }); + + debug('including the input transform'); + } }, treeForVendor(rawVendorTree) { @@ -79,5 +83,19 @@ module.exports = { ); return mergeTrees([registerVersionTree, transpiledVendorTree]); + }, + + flagValue(flag) { + let options = this.app.options[this.name] || {}; + return options[flag]; + }, + + importUnlessFlagged(path, flags) { + let shouldImport = flags.every(flag => this.flagValue(flag) !== false); + + if (shouldImport) { + this.import(path); + debug(`including ${path}`); + } } }; diff --git a/package.json b/package.json index f0d0481..dbfdd5c 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "dependencies": { "broccoli-file-creator": "^1.1.1", "broccoli-merge-trees": "^2.0.0", + "debug": "^3.1.0", "ember-cli-babel": "^6.6.0", "ember-cli-version-checker": "^2.1.0" },