├── .gitignore ├── test ├── fixtures │ ├── if │ │ ├── enabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── disabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ └── dynamic │ │ │ ├── fixture.js │ │ │ └── expected.js │ ├── not-if │ │ ├── disabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── enabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ └── dynamic │ │ │ ├── expected.js │ │ │ └── fixture.js │ ├── ternary │ │ ├── enabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── disabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ └── dynamic │ │ │ ├── expected.js │ │ │ └── fixture.js │ ├── else │ │ ├── disabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── enabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ └── dynamic │ │ │ ├── expected.js │ │ │ └── fixture.js │ ├── preserves-other-imports │ │ ├── expected.js │ │ └── fixture.js │ ├── nested │ │ ├── disabled-disabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── disabled-enabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── enabled-disabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── enabled-enabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── disabled-dynamic │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── dynamic-disabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── dynamic-enabled │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ ├── enabled-dynamic │ │ │ ├── expected.js │ │ │ └── fixture.js │ │ └── dynamic-dynamic │ │ │ ├── expected.js │ │ │ └── fixture.js │ └── multiple-instances │ │ ├── expected.js │ │ └── fixture.js └── test.js ├── CODE_OF_CONDUCT.md ├── package.json ├── .travis.yml ├── README.md ├── index.js └── CHANGELOG.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /test/fixtures/if/enabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (true) { 4 | 'enabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/if/disabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (false) { 4 | 'enabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/not-if/disabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (!false) { 4 | 'disabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/not-if/enabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (!true) { 4 | 'disabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/ternary/enabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | var x = true ? 'enabled' : 'disabled'; 4 | -------------------------------------------------------------------------------- /test/fixtures/if/dynamic/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'enabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/if/enabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('enabled')) { 4 | 'enabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/ternary/disabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | var x = false ? 'enabled' : 'disabled'; 4 | -------------------------------------------------------------------------------- /test/fixtures/if/disabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('disabled')) { 4 | 'enabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/if/dynamic/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'enabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/not-if/disabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (!isEnabled('disabled')) { 4 | 'disabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/not-if/dynamic/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (!isEnabled('dynamic')) { 4 | 'disabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/not-if/dynamic/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (!isEnabled('dynamic')) { 4 | 'disabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/not-if/enabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (!isEnabled('enabled')) { 4 | 'disabled'; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/ternary/dynamic/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | var x = isEnabled('dynamic') ? 'enabled' : 'disabled'; 4 | -------------------------------------------------------------------------------- /test/fixtures/ternary/dynamic/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | var x = isEnabled('dynamic') ? 'enabled' : 'disabled'; 4 | -------------------------------------------------------------------------------- /test/fixtures/ternary/enabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | var x = isEnabled('enabled') ? 'enabled' : 'disabled'; 4 | -------------------------------------------------------------------------------- /test/fixtures/ternary/disabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | var x = isEnabled('disabled') ? 'enabled' : 'disabled'; 4 | -------------------------------------------------------------------------------- /test/fixtures/else/disabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (false) { 4 | 'enabled'; 5 | } else { 6 | 'disabled'; 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/else/enabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (true) { 4 | 'enabled'; 5 | } else { 6 | 'disabled'; 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/else/disabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('disabled')) { 4 | 'enabled'; 5 | } else { 6 | 'disabled'; 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/else/dynamic/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'enabled'; 5 | } else { 6 | 'disabled'; 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/else/dynamic/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'enabled'; 5 | } else { 6 | 'disabled'; 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/else/enabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('enabled')) { 4 | 'enabled'; 5 | } else { 6 | 'disabled'; 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/preserves-other-imports/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled, { FEATURES } from 'features'; 2 | 3 | if (true) { 4 | 'enabled'; 5 | } 6 | 7 | FEATURES; 8 | -------------------------------------------------------------------------------- /test/fixtures/preserves-other-imports/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled, { FEATURES } from 'features'; 2 | 3 | if (isEnabled('enabled')) { 4 | 'enabled'; 5 | } 6 | 7 | FEATURES; 8 | -------------------------------------------------------------------------------- /test/fixtures/nested/disabled-disabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (false) { 4 | 'a'; 5 | if (false) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/disabled-enabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (false) { 4 | 'a'; 5 | if (true) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/enabled-disabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (true) { 4 | 'a'; 5 | if (false) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/enabled-enabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (true) { 4 | 'a'; 5 | if (true) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/disabled-dynamic/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (false) { 4 | 'a'; 5 | if (isEnabled('dynamic')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/dynamic-disabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'a'; 5 | if (false) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/dynamic-enabled/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'a'; 5 | if (true) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/enabled-dynamic/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (true) { 4 | 'a'; 5 | if (isEnabled('dynamic')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/disabled-dynamic/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('disabled')) { 4 | 'a'; 5 | if (isEnabled('dynamic')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/disabled-enabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('disabled')) { 4 | 'a'; 5 | if (isEnabled('enabled')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/dynamic-disabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'a'; 5 | if (isEnabled('disabled')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/dynamic-dynamic/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'a'; 5 | if (isEnabled('dynamic')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/dynamic-dynamic/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'a'; 5 | if (isEnabled('dynamic')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/dynamic-enabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('dynamic')) { 4 | 'a'; 5 | if (isEnabled('enabled')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/enabled-disabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('enabled')) { 4 | 'a'; 5 | if (isEnabled('disabled')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/enabled-dynamic/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('enabled')) { 4 | 'a'; 5 | if (isEnabled('dynamic')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/enabled-enabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('enabled')) { 4 | 'a'; 5 | if (isEnabled('enabled')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/nested/disabled-disabled/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabled from 'features'; 2 | 3 | if (isEnabled('disabled')) { 4 | 'a'; 5 | if (isEnabled('disabled')) { 6 | 'b'; 7 | } 8 | 'c'; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/multiple-instances/expected.js: -------------------------------------------------------------------------------- 1 | import isEnabledOne from 'features-one'; 2 | import isEnabledTwo from 'features-two'; 3 | 4 | true; 5 | false; 6 | isEnabledOne('dynamicOne'); 7 | 8 | true; 9 | false; 10 | isEnabledTwo('dynamicTwo'); 11 | -------------------------------------------------------------------------------- /test/fixtures/multiple-instances/fixture.js: -------------------------------------------------------------------------------- 1 | import isEnabledOne from 'features-one'; 2 | import isEnabledTwo from 'features-two'; 3 | 4 | isEnabledOne('enabledOne'); 5 | isEnabledOne('disabledOne'); 6 | isEnabledOne('dynamicOne'); 7 | 8 | isEnabledTwo('enabledTwo'); 9 | isEnabledTwo('disabledTwo'); 10 | isEnabledTwo('dynamicTwo'); 11 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | The Ember team and community are committed to everyone having a safe and inclusive experience. 2 | 3 | **Our Community Guidelines / Code of Conduct can be found here**: 4 | 5 | http://emberjs.com/guidelines/ 6 | 7 | For a history of updates, see the page history here: 8 | 9 | https://github.com/emberjs/website/commits/master/source/guidelines.html.erb 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-feature-flags", 3 | "version": "0.3.1", 4 | "description": "A babel transform for managing feature flags", 5 | "main": "index.js", 6 | "files": [ 7 | "index.js" 8 | ], 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/ember-cli/babel-plugin-feature-flags" 15 | }, 16 | "keywords": [ 17 | "babel", 18 | "babel-plugin" 19 | ], 20 | "author": "Martin Muñoz ", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/ember-cli/babel-plugin-feature-flags/issues" 24 | }, 25 | "homepage": "https://github.com/ember-cli/babel-plugin-feature-flags", 26 | "devDependencies": { 27 | "babel-core": "^6.26.3", 28 | "mocha": "^5.2.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4" 4 | - "6" 5 | - "8" 6 | - "9" 7 | - "10" 8 | 9 | deploy: 10 | provider: npm 11 | email: stefan.penner+ember-cli@gmail.com 12 | api_key: 13 | secure: aNnum9qCWGvfZScAmQ5yRcgfXhk7i/v4Dl0v77ZDui4C6V/YM0zCVbSprqyxlq72D6DK9R3NVNZyMqYwnUv5GwNDFaz3bZccWT4EnDFMrUMha1UXba9ddH2elO9CaWaaJQcEpMwQ8Z3Iw5TQgqwBm84ypsh8HueGLzTkLodvszvZEVeswoWTIfoDk+RvAG+g/svn7oAJUG4ovwdnz7y2JRKyh69TOprjaV12vos7CuY0FhzFoPUIJSKatwK6avMikqDzWgF95Bkej+Ni96lTRiRPqWmr5vgHbgR+WNdfXTxnwM7Y+0qaqlfseW0mIzB6R7yPoiVSRKctLr0UpZpRM4gPm83Q2qWWKfJLfsKgb30fzP2defIKN6/LHatmVNEKup/C3qwoG860KkzHI2UOjeKPvkLbo2/pVaS2Flz2QZASfAKZzXFOECY/M9FYZOseBy05WQEvDbOK4848HwQ7+nhqQCEpqA6ZXaDUg+OETgISCIS/Xl8JL1WAIuR0wGZKNgaYUzki6wNZYCBy10Z8/rq30eaYkVbELOONLbAPbAsSoH2vu4C5SIIKYot5Hsn4cdVbk2O6857uiZd/jm6CY0aEfRRTWuizA74qHwfArcLMYk2SU0uQU5i07q7yYBvSl14mCoHftbM8jKN8I2EnbPsjpAALVPvToB3PvZizJB4= 14 | on: 15 | tags: true 16 | repo: ember-cli/babel-plugin-feature-flags 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # babel-plugin-feature-flags 2 | 3 | [![Build Status](https://travis-ci.org/ember-cli/babel-plugin-feature-flags.svg?branch=master)](https://travis-ci.org/ember-cli/babel-plugin-feature-flags) 4 | 5 | *This plugin is for Babel 6. If you need to support Babel 5 use the 0.2.x releases.* 6 | 7 | A babel plugin that implements feature flags for enabling and disabling features. This plugin is intended to be followed by a dead code elimination pass (Uglify, babel-plugin-dead-code-elimination, etc.) to remove any unreachable code. 8 | 9 | Feature flags are implemented by looking for call expressions like `isEnabled('my-feature')` and checking if the feature is enabled/disabled/disabled in a feature map that is passed through the plugin options. If the feature is known to be enabled or disabled then the call expression is replace with a boolean literal (`true` or `false` respectively). If the feature is dynamic, than the call expression is left alone. 10 | 11 | ## Example 12 | 13 | Given the `.babelrc` 14 | 15 | ```json 16 | { 17 | "plugins": [["feature-flags", { 18 | "import": { 19 | "module": "my-features" 20 | }, 21 | "features": { 22 | "new-feature": "disabled" 23 | } 24 | }]] 25 | } 26 | ``` 27 | 28 | the JavaScript file 29 | 30 | ```js 31 | import isEnabled from 'my-features'; 32 | 33 | if (isEnabled('new-feature')) { 34 | // code 35 | } 36 | ``` 37 | 38 | will be transformed to 39 | 40 | ```js 41 | import isEnabled from 'my-features'; 42 | 43 | if (false) { 44 | // code 45 | } 46 | ``` 47 | 48 | ## Configuration 49 | 50 | Here are the options that you can pass to the babel plugin. 51 | 52 | - `options.import.module` [`String`]: The name of the module that the feature function is imported from. 53 | - `options.import.name` [`String` (Optional)]: The name of the export that the feature function is imported from. Defaults to `"default"`. 54 | - `options.features` [`Map(String -> 'enabled' | 'disabled' | 'dynamic')`]: An object whose keys are the names of features and whose values determine whether the feature is enabled/disabled/dynamic. 55 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = function(babel) { 2 | var t = babel.types; 3 | 4 | return { 5 | visitor: { 6 | Program: function(path, state) { 7 | var options = state.opts; 8 | 9 | options.features = options.features || {}; 10 | options.import = options.import || {}; 11 | options.import.name = options.import.name || 'default'; 12 | 13 | if (typeof options.import.module !== 'string') { 14 | throw new Error("options.import.module must be the name of a module, e.g. 'my-app/features'"); 15 | } 16 | 17 | Object.keys(options.features).forEach(function(feature) { 18 | var value = options.features[feature]; 19 | 20 | if (typeof value === 'string') { 21 | if (value === 'enabled') { 22 | options.features[feature] = true; 23 | } else if (value === 'disabled') { 24 | options.features[feature] = false; 25 | } else if (value === 'dynamic') { 26 | options.features[feature] = null; 27 | } else { 28 | throw new Error("An unknown feature state '" + value + "' was detected for '" + feature + "'. Valid values are 'enabled', 'disabled' and 'dynamic'"); 29 | } 30 | } 31 | }); 32 | }, 33 | 34 | CallExpression: function(path, state) { 35 | var options = state.opts; 36 | 37 | var callee = path.get('callee'); 38 | if (callee.referencesImport(options.import.module, options.import.name)) { 39 | var featureName = getFeatureName(path.node); 40 | if (featureName in options.features) { 41 | var value = options.features[featureName]; 42 | 43 | if (typeof value === 'boolean') { 44 | path.replaceWith(t.booleanLiteral(value)); 45 | } 46 | } else { 47 | throw new Error("An unknown feature '" + featureName + "' was encountered"); 48 | } 49 | } 50 | } 51 | } 52 | }; 53 | }; 54 | 55 | function getFeatureName(callExpression) { 56 | var argument = callExpression.arguments[0]; 57 | 58 | if (callExpression.arguments.length !== 1 || argument.type !== 'StringLiteral') { 59 | throw new Error("Feature flag function should be called with a single string literal argument"); 60 | } 61 | 62 | return argument.value; 63 | } 64 | 65 | module.exports.baseDir = function() { return __dirname; }; 66 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var fs = require('fs'); 3 | var path = require('path'); 4 | var babel = require('babel-core'); 5 | var applyFeatureFlags = require('../index'); 6 | 7 | function testFixture(name, plugins) { 8 | it(name, function () { 9 | var fixturePath = path.resolve(__dirname, 'fixtures', name, 'fixture.js'); 10 | var expectedPath = path.resolve(__dirname, 'fixtures', name, 'expected.js'); 11 | 12 | var expected = fs.readFileSync(expectedPath).toString(); 13 | var result = babel.transformFileSync(fixturePath, { plugins: plugins }); 14 | 15 | assert.strictEqual(result.code + '\n', expected); 16 | }); 17 | } 18 | 19 | describe('babel-plugin-feature-flags', function() { 20 | describe('basic', function() { 21 | var plugins = [ 22 | [applyFeatureFlags, { 23 | import: { 24 | module: 'features' 25 | }, 26 | features: { 27 | enabled: 'enabled', 28 | disabled: 'disabled', 29 | dynamic: 'dynamic' 30 | } 31 | }] 32 | ]; 33 | 34 | testFixture('if/enabled', plugins); 35 | testFixture('if/disabled', plugins); 36 | testFixture('if/dynamic', plugins); 37 | testFixture('else/enabled', plugins); 38 | testFixture('else/disabled', plugins); 39 | testFixture('else/dynamic', plugins); 40 | testFixture('not-if/enabled', plugins); 41 | testFixture('not-if/disabled', plugins); 42 | testFixture('not-if/dynamic', plugins); 43 | testFixture('ternary/enabled', plugins); 44 | testFixture('ternary/disabled', plugins); 45 | testFixture('ternary/dynamic', plugins); 46 | testFixture('nested/enabled-enabled', plugins); 47 | testFixture('nested/enabled-disabled', plugins); 48 | testFixture('nested/enabled-dynamic', plugins); 49 | testFixture('nested/disabled-enabled', plugins); 50 | testFixture('nested/disabled-disabled', plugins); 51 | testFixture('nested/disabled-dynamic', plugins); 52 | testFixture('nested/dynamic-enabled', plugins); 53 | testFixture('nested/dynamic-disabled', plugins); 54 | testFixture('nested/dynamic-dynamic', plugins); 55 | testFixture('preserves-other-imports', plugins); 56 | }); 57 | 58 | describe('multiple instances', function() { 59 | var plugins = [ 60 | [applyFeatureFlags, { 61 | import: { 62 | module: 'features-one' 63 | }, 64 | features: { 65 | enabledOne: 'enabled', 66 | disabledOne: 'disabled', 67 | dynamicOne: 'dynamic' 68 | } 69 | }], 70 | [applyFeatureFlags, { 71 | import: { 72 | module: 'features-two' 73 | }, 74 | features: { 75 | enabledTwo: 'enabled', 76 | disabledTwo: 'disabled', 77 | dynamicTwo: 'dynamic' 78 | } 79 | }] 80 | ]; 81 | 82 | testFixture('multiple-instances', plugins); 83 | }); 84 | }); 85 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [v0.3.1](https://github.com/ember-cli/babel-plugin-feature-flags/tree/v0.3.1) (2017-03-14) 4 | [Full Changelog](https://github.com/ember-cli/babel-plugin-feature-flags/compare/v0.2.3...v0.3.1) 5 | 6 | **Closed issues:** 7 | 8 | - An in-range update of babel-core is breaking the build 🚨 [\#17](https://github.com/ember-cli/babel-plugin-feature-flags/issues/17) 9 | 10 | **Merged pull requests:** 11 | 12 | - Add baseDir to avoid caching warnings. [\#19](https://github.com/ember-cli/babel-plugin-feature-flags/pull/19) ([rwjblue](https://github.com/rwjblue)) 13 | - CI: Enable automatic NPM deployment for tags [\#18](https://github.com/ember-cli/babel-plugin-feature-flags/pull/18) ([Turbo87](https://github.com/Turbo87)) 14 | - 👻😱 Node.js 0.10 is unmaintained 😱👻 [\#16](https://github.com/ember-cli/babel-plugin-feature-flags/pull/16) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 15 | 16 | ## [v0.2.3](https://github.com/ember-cli/babel-plugin-feature-flags/tree/v0.2.3) (2016-09-28) 17 | [Full Changelog](https://github.com/ember-cli/babel-plugin-feature-flags/compare/v0.2.2...v0.2.3) 18 | 19 | **Implemented enhancements:** 20 | 21 | - Support multiple imports [\#15](https://github.com/ember-cli/babel-plugin-feature-flags/pull/15) ([Turbo87](https://github.com/Turbo87)) 22 | 23 | **Closed issues:** 24 | 25 | - 'broccoli-babel-transpiler is opting out of caching' warning [\#13](https://github.com/ember-cli/babel-plugin-feature-flags/issues/13) 26 | 27 | ## [v0.2.2](https://github.com/ember-cli/babel-plugin-feature-flags/tree/v0.2.2) (2016-08-10) 28 | [Full Changelog](https://github.com/ember-cli/babel-plugin-feature-flags/compare/v0.3.0...v0.2.2) 29 | 30 | **Merged pull requests:** 31 | 32 | - Enable caching based on options. [\#12](https://github.com/ember-cli/babel-plugin-feature-flags/pull/12) ([rwjblue](https://github.com/rwjblue)) 33 | - Update package.json [\#11](https://github.com/ember-cli/babel-plugin-feature-flags/pull/11) ([locks](https://github.com/locks)) 34 | - Update mocha to version 3.0.0 🚀 [\#10](https://github.com/ember-cli/babel-plugin-feature-flags/pull/10) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 35 | 36 | ## [v0.3.0](https://github.com/ember-cli/babel-plugin-feature-flags/tree/v0.3.0) (2016-06-13) 37 | [Full Changelog](https://github.com/ember-cli/babel-plugin-feature-flags/compare/v0.2.1...v0.3.0) 38 | 39 | **Implemented enhancements:** 40 | 41 | - Babel 6 [\#5](https://github.com/ember-cli/babel-plugin-feature-flags/issues/5) 42 | - Port plugin to Babel 6 plugin API [\#6](https://github.com/ember-cli/babel-plugin-feature-flags/pull/6) ([Turbo87](https://github.com/Turbo87)) 43 | 44 | **Closed issues:** 45 | 46 | - Add a README [\#1](https://github.com/ember-cli/babel-plugin-feature-flags/issues/1) 47 | 48 | **Merged pull requests:** 49 | 50 | - Add README.md [\#9](https://github.com/ember-cli/babel-plugin-feature-flags/pull/9) ([mmun](https://github.com/mmun)) 51 | - Add support for multiple instances of the plugin [\#8](https://github.com/ember-cli/babel-plugin-feature-flags/pull/8) ([mmun](https://github.com/mmun)) 52 | - Make tests simpler [\#7](https://github.com/ember-cli/babel-plugin-feature-flags/pull/7) ([mmun](https://github.com/mmun)) 53 | 54 | ## [v0.2.1](https://github.com/ember-cli/babel-plugin-feature-flags/tree/v0.2.1) (2016-06-10) 55 | **Closed issues:** 56 | 57 | - Better support for unknown feature flags [\#2](https://github.com/ember-cli/babel-plugin-feature-flags/issues/2) 58 | 59 | **Merged pull requests:** 60 | 61 | - Implement a dead code elimination friendly strategy [\#4](https://github.com/ember-cli/babel-plugin-feature-flags/pull/4) ([mmun](https://github.com/mmun)) 62 | - Remove `+` at beginning of every line [\#3](https://github.com/ember-cli/babel-plugin-feature-flags/pull/3) ([pangratz](https://github.com/pangratz)) 63 | 64 | 65 | 66 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* --------------------------------------------------------------------------------