babel-plugin-inline-json-config-values
Advanced tools
Comparing version 0.1.5 to 1.0.0
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
exports.default = function (_ref) { | ||
var t = _ref.types; | ||
var _path = require('path'); | ||
return { | ||
visitor: { | ||
MemberExpression: function MemberExpression(path, state) { | ||
var node = path.node; | ||
var file = path.file; | ||
var _path2 = _interopRequireDefault(_path); | ||
var re = new RegExp(state.opts.matchPattern, 'g'); | ||
exports['default'] = function (_ref) { | ||
var Plugin = _ref.Plugin; | ||
var t = _ref.types; | ||
return new Plugin('inline-json-config-values', { | ||
visitor: { | ||
MemberExpression: function MemberExpression(node, parent, scope, file) { | ||
var re = new RegExp(file.opts.extra['inline-json-config-values'].matchPattern, 'g'); | ||
if (t.isCallExpression(node.object) && t.isIdentifier(node.object.callee, { name: 'require' }) && t.isLiteral(node.object.arguments[0]) && node.object.arguments[0].value.match(re)) { | ||
var srcPath = _path2['default'].resolve(this.state.opts.filename); | ||
var pkg = require(_path2['default'].join(srcPath, '..', node.object.arguments[0].value)); | ||
var srcPath = _path2.default.resolve(state.file.opts.filename); | ||
var pkg = require(_path2.default.join(srcPath, '..', node.object.arguments[0].value)); | ||
var value = pkg[node.property.name]; | ||
return t.expressionStatement(t.valueToNode(value)); | ||
path.replaceWith(t.expressionStatement(t.valueToNode(value))); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
}; | ||
module.exports = exports['default']; | ||
var _path = require('path'); | ||
var _path2 = _interopRequireDefault(_path); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
{ | ||
"name": "babel-plugin-inline-json-config-values", | ||
"version": "0.1.5", | ||
"version": "1.0.0", | ||
"repository": "mwilliams-change/babel-plugin-inline-json-config-values", | ||
"license": "MIT", | ||
"authors": [ | ||
"Matt Williams <mwilliams@change.org> (https://github.com/mwilliams-change)" | ||
], | ||
"description": "", | ||
"repository": "mwilliams-change/babel-plugin-inline-json-config-values", | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"devDependencies": { | ||
"babel": "^5.6.0" | ||
"babel-cli": "^6.9.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"mocha": "^2.4.5" | ||
}, | ||
"scripts": { | ||
"build": "babel-plugin build", | ||
"push": "babel-plugin publish", | ||
"test": "babel-plugin test" | ||
"clean": "rm -rf lib", | ||
"build": "babel src -d lib", | ||
"example": "npm run build && babel example/input.js -o example/output.js", | ||
"test": "mocha --compilers js:babel-register", | ||
"test:watch": "npm run test -- --watch", | ||
"prepublish": "npm run clean && npm run build" | ||
}, | ||
"keywords": [ | ||
"babel", | ||
"plugin", | ||
"babel-plugin" | ||
] | ||
} |
# babel-plugin-inline-json-config-values | ||
Inline values from a JSON file eg. a config file | ||
## Example | ||
**config.json**: | ||
```json | ||
{ | ||
"foo": "bar" | ||
} | ||
``` | ||
**In** | ||
```js | ||
var foo = require('config').foo; | ||
``` | ||
**Out** | ||
```js | ||
var foo = "bar"; | ||
``` | ||
## Installation | ||
@@ -19,8 +41,3 @@ | ||
{ | ||
"plugins": ["inline-json-config-values"], | ||
"extra": { | ||
"inline-json-config-values": { | ||
"matchPattern": "server-config" | ||
} | ||
} | ||
"plugins": [["inline-json-config-values", {"matchPattern": "config"}]] | ||
} | ||
@@ -39,9 +56,4 @@ ``` | ||
require("babel-core").transform("code", { | ||
"plugins": ["inline-json-config-values"], | ||
"extra": { | ||
"inline-json-config-values": { | ||
"matchPattern": "server-config" | ||
} | ||
} | ||
"plugins": [["inline-json-config-values", {"matchPattern": "config"}]] | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4829
15
60
1
58
4