babel-plugin-grommet
Advanced tools
Comparing version 0.4.0 to 0.5.0
13
index.js
@@ -7,7 +7,12 @@ const types = require('babel-types'); | ||
visitor: { | ||
ImportDeclaration: (path) => { | ||
ImportDeclaration: (path, { opts: { dependencies = ['grommet', 'grommet-icons'] } }) => { | ||
const source = path.node.source.value; | ||
const dependency = source.split('/')[0]; | ||
if (source.startsWith('grommet')) { | ||
const context = /(grommet-icons|grommet)(\/(components|themes|utils))?/.exec(source)[0]; | ||
const dependencyPathRegexp = new RegExp( | ||
`(${dependencies.join('|')})(\/(components|themes|utils))?$` | ||
); | ||
const matches = dependencyPathRegexp.exec(source); | ||
if (matches) { | ||
const context = matches[0]; | ||
const modulesInContext = find.fileSync( | ||
@@ -19,3 +24,3 @@ /\.js$/, `./node_modules/${context}` | ||
// remove grommet-icons inside grommet node_modules | ||
file => file.indexOf('grommet/grommet-icons') === -1 | ||
file => file.indexOf(`${dependency}/grommet-icons`) === -1 | ||
).reverse(); // reverse so es6 modules have higher priority | ||
@@ -22,0 +27,0 @@ const memberImports = path.node.specifiers.filter( |
{ | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"name": "babel-plugin-grommet", | ||
@@ -4,0 +4,0 @@ "description": "Babel plugin to transform member style imports into default imports", |
15307
60