babel-plugin-inline-json-import
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -18,2 +18,4 @@ 'use strict'; | ||
var SUPPORTED_MODULES_REGEX = /\.json(!json)?$/; | ||
function babelPluginInlineJsonImports(_ref) { | ||
@@ -31,3 +33,3 @@ var t = _ref.types; | ||
if (moduleName.match(/\.json(!json)?$/)) { | ||
if (moduleName.match(SUPPORTED_MODULES_REGEX)) { | ||
var leftExpression = determineLeftExpression(t, node); | ||
@@ -52,3 +54,3 @@ | ||
if (init != null && init.type === 'CallExpression' && init.callee.type === 'Identifier' && init.callee.name === 'require' && init.arguments.length === 1 && init.arguments[0].type === 'StringLiteral') { | ||
if (init != null && init.type === 'CallExpression' && init.callee.type === 'Identifier' && init.callee.name === 'require' && init.arguments.length === 1 && init.arguments[0].type === 'StringLiteral' && init.arguments[0].value.match(SUPPORTED_MODULES_REGEX)) { | ||
changed = true; | ||
@@ -55,0 +57,0 @@ |
{ | ||
"name": "babel-plugin-inline-json-import", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Inlines JSON file imports straight into JS code", | ||
@@ -13,5 +13,5 @@ "main": "build/index.js", | ||
"babel-preset-es2015": "^6.24.1", | ||
"chai": "^3.5.0", | ||
"mocha": "^3.5.3", | ||
"tmp": "^0.0.29" | ||
"chai": "^4.2.0", | ||
"mocha": "^6.0.2", | ||
"tmp": "^0.0.33" | ||
}, | ||
@@ -34,4 +34,4 @@ "scripts": { | ||
"dependencies": { | ||
"decache": "^4.4.0" | ||
"decache": "^4.5.1" | ||
} | ||
} |
@@ -142,2 +142,24 @@ import fs from 'fs' | ||
it('correctly ignores non-JSON files', () => { | ||
const t = configureTransform() | ||
const result = t(` | ||
import json from '../test/fixtures/example.json' | ||
import abc from 'abc' | ||
import { a, b } from './foo.mp3'; | ||
const file = require('../src/index.js') | ||
const example = require('./example') | ||
`) | ||
expect(normalize(result.code)).to.equal(normalize(` | ||
const json = { example: true } | ||
import abc from 'abc' | ||
import { a, b } from './foo.mp3'; | ||
const file = require('../src/index.js') | ||
const example = require('./example') | ||
`)) | ||
}) | ||
function configureTransform(options = {}, isFile) { | ||
@@ -144,0 +166,0 @@ return function configuredTransform(string) { |
Sorry, the diff of this file is not supported yet
16981
231
Updateddecache@^4.5.1