Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-inline-json-config-values

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-inline-json-config-values - npm Package Compare versions

Comparing version 0.1.5 to 1.0.0

.babelrc

35

lib/index.js
'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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc