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.4 to 0.0.5

25

index.js
const path = require('path');
const RELATIVE_PATTERN = /\s*(\.{1,2})\/([^'"]*)/g;
const notJsonImport = modName => !modName.endsWith('.json');
const replace = (baseURI, dirname) =>
(match, dots, rest) => `${baseURI}${path.join(dirname, dots, rest)}`;
const notRequire = (t, nodePath) => {

@@ -22,3 +17,3 @@ const [requireArg, ...rest] = nodePath.node.arguments;

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

@@ -28,5 +23,11 @@ const { node, parent } = nodePath;

const { value: modName } = requireArg;
if (notJsonImport(modName)) return;
const filepath = modName.replace(RELATIVE_PATTERN, replace('', dirname));
const filepath = modName.startsWith('/') ?
`${root}${modName}` :
modName.startsWith('.') ?
path.join(dirname, modName) :
modName;
const json = JSON.parse(fs.readFileSync(filepath, { encoding: 'utf8' }));

@@ -37,3 +38,3 @@

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

@@ -45,3 +46,9 @@ const { value: modName } = nodePath.node.source;

const leftExpression = determineLeftExpression(t, node);
const filepath = modName.replace(RELATIVE_PATTERN, replace('', dirname));
const filepath = modName.startsWith('/') ?
`${root}${modName}` :
modName.startsWith('.') ?
path.join(dirname, modName) :
modName;
const json = JSON.parse(fs.readFileSync(filepath, { encoding: 'utf8' }));

@@ -48,0 +55,0 @@

{
"name": "@hqjs/babel-plugin-transform-json-imports",
"version": "0.0.4",
"version": "0.0.5",
"description": "Transform json imports",

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

@@ -12,3 +12,3 @@ # https://hqjs.org

{
"plugins": [["hqjs@babel-plugin-transform-json-imports", { "dirname": "/json/root/directory" }]]
"plugins": [["hqjs@babel-plugin-transform-json-imports", { "dirname": "/json/directory", "root": "/root/directory" }]]
}

@@ -15,0 +15,0 @@ ```

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