Skip to content

Commit

Permalink
Fixes emberjs#60: Add build time flags for deprecation toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
thoov committed Feb 14, 2018
1 parent 98efc16 commit 02f3782
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 29 deletions.
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
}
});
```
66 changes: 42 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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}`);
}
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 02f3782

Please sign in to comment.