@talend/babel-plugin-import-from-index
Advanced tools
Comparing version 1.3.0 to 1.4.0-alpha.1
{ | ||
"name": "@talend/babel-plugin-import-from-index", | ||
"version": "1.3.0", | ||
"version": "1.4.0-alpha.1", | ||
"description": "Transform default imports from specific path to named import from index", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
const PACKAGES = ['@talend/react-components', 'lodash', 'react-bootstrap', 'redux-saga']; | ||
const hasLib = { | ||
lodash: false, | ||
'react-bootstrap': true, | ||
'@talend/react-components': true, | ||
'redux-saga': false, | ||
}; | ||
const hasNameSupport = { | ||
lodash: true, | ||
'react-bootstrap': true, | ||
'@talend/react-components': false, | ||
'@talend/react-components': true, | ||
'redux-saga': true, | ||
@@ -15,4 +23,15 @@ }; | ||
function find(path) { | ||
return PACKAGES.find(p => path.node.source.value.startsWith(p)); | ||
function find(importDeclarationPath) { | ||
const path = importDeclarationPath.node.source.value; | ||
const found = PACKAGES.find(p => path.startsWith(p)); | ||
if (found && hasLib[found]) { | ||
if (path.replace(found, '').split('/').length > 3) { | ||
console.error(`ERROR: import too deep: ${path}`); | ||
return undefined; | ||
} | ||
} else if (found && path.replace(found, '').split('/').length > 2) { | ||
console.error(`ERROR: import too deep in ${path}`); | ||
return undefined; | ||
} | ||
return found; | ||
} | ||
@@ -19,0 +38,0 @@ |
@@ -64,3 +64,15 @@ import pluginTester from 'babel-plugin-tester'; | ||
}, | ||
{ | ||
code: "import DatalistComponent from '@talend/react-components/lib/Datalist';", | ||
output: "import { Datalist as DatalistComponent } from '@talend/react-components';", | ||
}, | ||
{ | ||
code: "import ResourcePickerComponent from '@talend/react-components/lib/ResourcePicker';", | ||
output: "import { ResourcePicker as ResourcePickerComponent } from '@talend/react-components';" | ||
}, | ||
{ | ||
code: "import Foo from '@talend/react-components/lib/Bar/Foo';", | ||
output: "import Foo from '@talend/react-components/lib/Bar/Foo';" | ||
}, | ||
], | ||
}); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8461
206
2