Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable feature flags #3979

Merged
merged 3 commits into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ install:
script:
- ./bin/lint-features
- npm run-script test
- npm run-script test:optional-features
after_success:
- npm run-script production
- "./bin/bower-ember-data-build"
Expand Down
5 changes: 5 additions & 0 deletions addon/features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Ember from 'ember';

export default function isEnabled() {
return Ember.FEATURES.isEnabled(...arguments);
}
20 changes: 15 additions & 5 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
'use strict';

var fs = require('fs');
var featuresJson = fs.readFileSync('config/features.json', { encoding: 'utf8' });
var featureFlags = JSON.parse(featuresJson);

module.exports = function(environment, appConfig) {
var ENV = { };

if (environment === 'testing') {
ENV.EmberENV = {
RAISE_ON_DEPRECATION: true,
ENABLE_DS_FILTER: true
};
ENV.EmberENV = {
FEATURES: featureFlags,
ENABLE_DS_FILTER: true,

// don't raise on deprecation yet, since there are too many thrown errors;
// this should be addressed in another PR
// RAISE_ON_DEPRECATION: true
};

if (environment === 'test-optional-features') {
ENV.EmberENV.ENABLE_OPTIONAL_FEATURES = true;
}

return ENV;
Expand Down
27 changes: 27 additions & 0 deletions lib/enable-optional-features-via-url/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*jshint node:true*/
module.exports = {
name: 'enable-optional-features-via-url',

/**
So the ENABLE_OPTIONAL_FEATURES flag is considered correctly within the
index.html, it needs to be set before Ember.js is loaded. Since there is
currently no way to access the `window` object within config/environment.js
(and hereby check if there is a query parameter present for the checkbox),
a script is injected, before Ember.js is loaded. The script checks if there
is no value yet for the ENABLE_OPTIONAL_FEATURES flag, and if so, it sets
the flag to true when there is a `enableoptionalfeatures` query parameter.
*/
contentFor: function(name) {
if (name === "vendor-prefix") {
var array = [
"<!-- injected by lib/enable-optional-features-via-url -->",
"window.EmberENV = window.EmberENV || {};",
"if (typeof window.EmberENV.ENABLE_OPTIONAL_FEATURES === 'undefined') {",
" window.EmberENV.ENABLE_OPTIONAL_FEATURES = window.location.search.indexOf('enableoptionalfeatures') !== -1;",
"}"
];

return array.join('\n');
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue do you, as an ember-cli resident, have an idea for a nicer solution than this? Basically EmberENV needs to be modified after QUnit is loaded (so we have access to QUnit.urlconfig and before ember is loaded (so the updated, latest version of EmberENV is considered).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is javascript we should probably use JS comments instead of HTML

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is javascript we should probably use JS comments instead of HTML

👍 absolutely

};
6 changes: 6 additions & 0 deletions lib/enable-optional-features-via-url/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "enable-optional-features-via-url",
"keywords": [
"ember-addon"
]
}
10 changes: 10 additions & 0 deletions lib/javascripts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var filterImports = require('babel-plugin-filter-imports');
var featureFlags = require('babel-plugin-feature-flags');
var babel = require('broccoli-babel-transpiler');
var merge = require('broccoli-merge-trees');
var concat = require('broccoli-concat');
var uglify = require('broccoli-uglify-sourcemap');
var stew = require('broccoli-stew');
var version = require('./version');
var fs = require('fs');
var path = require('path');
var Funnel = require('broccoli-funnel');
var versionReplace = require('./version-replace');
Expand Down Expand Up @@ -56,7 +58,15 @@ function debugBuild(packageName, tree) {
}

function strippedBuild(packageName, tree) {
var featuresJson = fs.readFileSync('config/features.json', { encoding: 'utf8' });
var features = JSON.parse(featuresJson);

var plugins = [
featureFlags({
import: { module: 'ember-data/features' },
features: features
}),

filterImports({
'ember-data/debug': [
'assert',
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build": "ember build",
"start": "ember server",
"test": "ember try:testall",
"test:optional-features": "ember test --environment=test-optional-features",
"bower": "bower install",
"production": "ember build --environment=production"
},
Expand All @@ -26,6 +27,7 @@
"ember-cli-babel": "^5.1.3"
},
"devDependencies": {
"babel-plugin-feature-flags": "^0.2.0",
"babel-plugin-filter-imports": "^0.2.0",
"bower": "^1.6.5",
"broccoli-asset-rev": "^2.1.2",
Expand Down Expand Up @@ -64,6 +66,9 @@
"ember-addon"
],
"ember-addon": {
"configPath": "tests/dummy/config"
"configPath": "tests/dummy/config",
"paths": [
"lib/enable-optional-features-via-url"
]
}
}
9 changes: 1 addition & 8 deletions tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ import Ember from 'ember';

setResolver(resolver);

const ENV = Ember.ENV;
const QUNIT_PARAMS = QUnit.urlParams;
const { assert } = QUnit;

ENV.EXTEND_PROTOTYPES = QUNIT_PARAMS.extendprototypes;
ENV.ENABLE_OPTIONAL_FEATURES = QUNIT_PARAMS.enableoptionalfeatures;
ENV.ENABLE_DS_FILTER = true;

QUnit.begin(function() {
Ember.RSVP.configure('onerror', function(reason) {
// only print error messages if they're exceptions;
Expand Down Expand Up @@ -76,6 +70,5 @@ assert.without = function(array, item) {

addEmberAssertions(assert);

QUnit.config.testTimeout= 2000;
QUnit.config.testTimeout = 2000;
QUnit.config.urlConfig.push({ id: 'enableoptionalfeatures', label: "Enable Opt Features" });