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

@hqjs/babel-plugin-transform-json-imports

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hqjs/babel-plugin-transform-json-imports - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

20

index.js

@@ -1,2 +0,1 @@

const fs = require('fs');
const path = require('path');

@@ -23,3 +22,3 @@

CallExpression(nodePath, stats) {
const { dirname } = stats.opts;
const { dirname, fs = require('fs') } = stats.opts;
if (notRequire(t, nodePath)) return;

@@ -36,3 +35,3 @@ const [requireArg] = nodePath.node.arguments;

ImportDeclaration(nodePath, stats) {
const { dirname } = stats.opts;
const { dirname, fs = require('fs') } = stats.opts;
const { node } = nodePath;

@@ -50,3 +49,3 @@ const { value: modName } = nodePath.node.source;

leftExpression,
t.valueToNode(json),
t.valueToNode(cleanJSON(t, node, json)),
),

@@ -81,1 +80,14 @@ ]));

}
function cleanJSON(t, node, json) {
if (isDestructuredImportExpression(t, node)) {
const res = {};
for (const specifier of node.specifiers) {
const { name } = specifier.imported;
if (name in json) res[name] = json[name];
}
return res;
}
return json;
}

4

package.json
{
"name": "@hqjs/babel-plugin-transform-json-imports",
"version": "0.0.2",
"version": "0.0.3",
"description": "Transform json imports",

@@ -20,3 +20,3 @@ "main": "index.js",

],
"author": "hqjs <hqjsorg@gmail.com>",
"author": "hqjs <hqjs.org@gmail.com>",
"license": "MIT",

@@ -23,0 +23,0 @@ "bugs": {

@@ -9,2 +9,10 @@ # https://hqjs.org

# Usage
```json
{
"plugins": [["hqjs@babel-plugin-transform-json-imports", { "dirname": "/json/root/directory" }]]
}
```
If you are invoking this plugin from javascript it becomes possible to pass filesystem implementation trough `fs` option, it expects the object with `readFileSync` method defined.
# Transformation

@@ -16,3 +24,4 @@ Transforms `.json` imports into inplace definition e.g. having file values.json

"a": 1,
"b": 2
"b": 2,
"c": 3
}

@@ -29,4 +38,4 @@ ```

```js
const values = {a: 1, b: 2};
const values = {a: 1, b: 2, c: 3};
const {a, b} = {a: 1, b: 2};
```

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