babel-plugin-transform-modules
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -10,3 +10,3 @@ var camel = require('lodash.camelcase'); | ||
function transform(transformOption, importName, styleName) { | ||
function transform(transformOption, importName, styleName, hasImportName) { | ||
var isFunction = typeof transformOption === 'function'; | ||
@@ -26,6 +26,6 @@ if (/\.js$/i.test(transformOption) || isFunction) { | ||
return transformFn(importName, styleName); | ||
return transformFn(importName, styleName, hasImportName); | ||
} | ||
if (styleName) { | ||
if (importName === styleName) { | ||
if (!hasImportName && importName === styleName) { | ||
importName += '.css' | ||
@@ -64,2 +64,3 @@ } else { | ||
var ignore = styleOption.ignore; | ||
var hasImportName = !!importName; | ||
if (!importName) { | ||
@@ -71,3 +72,3 @@ importName = styleName; | ||
} | ||
var replace = transform(opts.transform, importName, styleName); | ||
var replace = transform(opts.transform, importName, styleName, hasImportName); | ||
styleTransforms.push(types.importDeclaration([], types.stringLiteral(replace))) | ||
@@ -74,0 +75,0 @@ } |
{ | ||
"name": "babel-plugin-transform-modules", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Transforms member style imports (import {x} from 'y') into default style imports (import x from 'y/lib/x' and import 'y/lib/x/style.css')", | ||
@@ -24,6 +24,25 @@ "keywords": [ | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha --compilers js:babel-register" | ||
"codecov": "codecov", | ||
"unit": "nyc mocha -t 1000 ./test/tests.js", | ||
"test": "npm run unit && npm run codecov" | ||
}, | ||
"author": "AMC Theatres, dolymood", | ||
"license": "ISC", | ||
"nyc": { | ||
"check-coverage": false, | ||
"lines": 99, | ||
"statements": 99, | ||
"functions": 99, | ||
"branches": 99, | ||
"sourceMap": false, | ||
"require": [ | ||
"babel-register" | ||
], | ||
"include": [ | ||
"index.js" | ||
], | ||
"reporter": [ | ||
"lcov" | ||
] | ||
}, | ||
"dependencies": { | ||
@@ -36,5 +55,8 @@ "lodash.camelcase": "^4.3.0", | ||
"babel-core": "^6.6.0", | ||
"babel-plugin-istanbul": "^4.1.5", | ||
"babel-preset-es2015": "^6.6.0", | ||
"mocha": "^2.4.5" | ||
"codecov": "^3.0.0", | ||
"mocha": "^2.4.5", | ||
"nyc": "^11.3.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# babel-plugin-transform-modules | ||
# babel-plugin-transform-modules [![Build Status](https://travis-ci.org/dolymood/babel-plugin-transform-modules.svg?branch=master)](https://travis-ci.org/dolymood/babel-plugin-transform-modules?branch=master) [![codecov.io](http://codecov.io/github/dolymood/babel-plugin-transform-modules/coverage.svg?branch=master)](http://codecov.io/github/dolymood/babel-plugin-transform-modules?branch=master) | ||
Fork https://bitbucket.org/amctheatres/babel-transform-imports , and support import style files like [babel-plugin-component](https://github.com/QingWei-Li/babel-plugin-component). | ||
Fork from https://bitbucket.org/amctheatres/babel-transform-imports , and support import style files like [babel-plugin-component](https://github.com/QingWei-Li/babel-plugin-component). | ||
@@ -118,6 +118,6 @@ Transforms member style imports: | ||
```js | ||
module.exports = function(importName, styleName) { | ||
module.exports = function(importName, styleName, hasImportName) { | ||
if (styleName) { | ||
// set `style: true` option to transform style | ||
if (importName === styleName) { | ||
if (!hasImportName && importName === styleName) { | ||
// full import | ||
@@ -124,0 +124,0 @@ // eg: `import xx from 'my-library'` |
@@ -128,10 +128,11 @@ import assert from 'assert'; | ||
const options = createOptions({ | ||
kebabCase: true, | ||
style: { | ||
ignore: ['Row'] | ||
ignore: ['row'] | ||
} | ||
}); | ||
const code = transform(`import { Grid, Row as row } from 'react-bootstrap';`, options); | ||
const code = transform(`import { Style, Grid, Row as row } from 'react-bootstrap';`, options); | ||
assert.equal(occurrences(fullImportStyleRegex, code), 0, 'number of full imports with style should be 0'); | ||
assert.equal(occurrences(/require\('react-bootstrap\/lib\/.+\/style\.css'\);$/gm, code), 1, 'number of member imports with style should be 1'); | ||
assert.equal(occurrences(/require\('react-bootstrap\/lib\/.+\/style\.css'\);$/gm, code), 2, 'number of member imports with style should be 2'); | ||
}); | ||
@@ -138,0 +139,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28466
9
348
6