You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

babel-plugin-feature-flags

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-feature-flags - npm Package Compare versions

Comparing version

to
0.2.3

test/fixtures/import-name/expected.js

35

index.js

@@ -6,9 +6,16 @@ var stringify = require('json-stable-stringify');

options.features = options.features || {};
options.import = options.import || {};
options.import.name = options.import.name || 'default';
options.imports = options.imports || [];
if (typeof options.import.module !== 'string') {
throw new Error("options.import.module must be the name of a module, e.g. 'my-app/features'");
if (options.import) {
options.imports.push(options.import);
}
options.imports.forEach(function(_import) {
_import.name = _import.name || 'default';
if (typeof _import.module !== 'string') {
throw new Error("options.import.module must be the name of a module, e.g. 'my-app/features'");
}
});
Object.keys(options.features).forEach(function(feature) {

@@ -36,14 +43,16 @@ var value = options.features[feature];

var callee = this.get('callee');
if (callee.referencesImport(options.import.module, options.import.name)) {
var featureName = getFeatureName(node);
if (featureName in options.features) {
var value = options.features[featureName];
options.imports.forEach(function(_import) {
if (callee.referencesImport(_import.module, _import.name)) {
var featureName = getFeatureName(node);
if (featureName in options.features) {
var value = options.features[featureName];
if (typeof value === 'boolean') {
this.replaceWith(t.literal(value));
if (typeof value === 'boolean') {
this.replaceWith(t.literal(value));
}
} else {
file.log.error("An unknown feature '" + featureName + "'' was encountered");
}
} else {
file.log.error("An unknown feature '" + featureName + "'' was encountered");
}
}
}.bind(this));
}

@@ -50,0 +59,0 @@ });

{
"name": "babel-plugin-feature-flags",
"version": "0.2.2",
"version": "0.2.3",
"description": "A babel transform for managing feature flags",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -55,3 +55,28 @@ var assert = require('assert');

testFixture('preserves-other-imports', options);
testFixture('import-name', {
import: {
module: 'features',
name: 'isFeatureEnabled'
},
features: {
enabled: 'enabled',
disabled: 'disabled',
dynamic: 'dynamic'
}
});
testFixture('multiple-imports', {
imports: [{
module: 'features'
}, {
module: 'other-features',
name: 'isFeatureEnabled'
}],
features: {
enabled: 'enabled',
disabled: 'disabled',
dynamic: 'dynamic'
}
});
it('provides a baseDir', function() {

@@ -58,0 +83,0 @@ var expectedPath = path.join(__dirname, '..');