πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

babel-plugin-import

Package Overview
Dependencies
Maintainers
4
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-import - npm Package Compare versions

Comparing version

to
1.9.0

22

lib/index.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -8,2 +10,4 @@ value: true

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _assert = _interopRequireDefault(require("assert"));

@@ -13,6 +17,2 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _default(_ref) {

@@ -33,6 +33,6 @@ var types = _ref.types;

for (var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _plugin = _step.value;
var plugin = _step.value;
if (_plugin[method]) {
_plugin[method].apply(_plugin, _toConsumableArray(args).concat([context]));
if (plugin[method]) {
plugin[method].apply(plugin, (0, _toConsumableArray2.default)(args).concat([context]));
}

@@ -94,3 +94,5 @@ }

var _loop = function _loop(method) {
var _loop = function _loop() {
var method = methods[_i];
ret.visitor[method] = function () {

@@ -103,5 +105,3 @@ // eslint-disable-line

for (var _i = 0; _i < methods.length; _i++) {
var method = methods[_i];
_loop(method);
_loop();
}

@@ -108,0 +108,0 @@

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -8,2 +10,6 @@ value: true

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _path2 = require("path");

@@ -13,8 +19,2 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function camel2Dash(_str) {

@@ -44,4 +44,3 @@ var str = _str[0].toLowerCase() + _str.substr(1);

function Plugin(libraryName, libraryDirectory, style, camel2DashComponentName, camel2UnderlineComponentName, fileName, customName, types) {
_classCallCheck(this, Plugin);
(0, _classCallCheck2.default)(this, Plugin);
this.specified = null;

@@ -60,3 +59,3 @@ this.libraryObjs = null;

_createClass(Plugin, [{
(0, _createClass2.default)(Plugin, [{
key: "isInGlobalScope",

@@ -285,3 +284,2 @@ value: function isInGlobalScope(path, name) {

}]);
return Plugin;

@@ -288,0 +286,0 @@ }();

{
"name": "babel-plugin-import",
"version": "1.8.0",
"version": "1.9.0",
"description": "Component modular import plugin for babel.",

@@ -12,4 +12,4 @@ "repository": {

"build": "rm -rf lib && ./node_modules/.bin/babel src --out-dir lib --ignore __tests__",
"test": "node_modules/.bin/babel-istanbul cover node_modules/.bin/_mocha -- --require @babel/register --no-timeouts",
"debug": "mocha --require @babel/register --require @babel/polyfill --no-timeouts",
"test": "umi-test --coverage",
"debug": "umi-test",
"lint": "eslint --ext .js src",

@@ -28,10 +28,9 @@ "coveralls": "cat ./coverage/lcov.info | coveralls"

"devDependencies": {
"@babel/cli": "^7.0.0-beta.34",
"@babel/core": "^7.0.0-beta.34",
"@babel/polyfill": "^7.0.0-beta.34",
"@babel/preset-react": "^7.0.0-beta.40",
"@babel/register": "^7.0.0-beta.34",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
"@babel/runtime": "^7.0.0",
"babel-core": "^7.0.0-0",
"babel-istanbul": "^0.12.2",
"babel-preset-umi": "^0.2.0",
"babel-preset-umi": "^1.0.0",
"coveralls": "^2.11.6",

@@ -42,15 +41,9 @@ "eslint": "^2.7.0",

"material-ui": "^0.15.4",
"mocha": "^2.3.4",
"pre-commit": "~1.1.2",
"react-toolbox": "^1.2.5"
"react-toolbox": "^1.2.5",
"umi-test": "^1.0.0"
},
"babel": {
"presets": [
[
"umi",
{
"commonjs": true,
"disableTransform": true
}
]
"umi"
]

@@ -64,4 +57,4 @@ },

"dependencies": {
"@babel/helper-module-imports": "^7.0.0-beta.34"
"@babel/helper-module-imports": "^7.0.0"
}
}
# babel-plugin-import
Modular import plugin for babel, compatible with [antd](https://github.com/ant-design/ant-design), [antd-mobile](https://github.com/ant-design/ant-design-mobile), and so on.
Modular import plugin for babel, compatible with [antd](https://github.com/ant-design/ant-design), [antd-mobile](https://github.com/ant-design/ant-design-mobile), lodash, [material-ui](http://material-ui.com/), and so on.

@@ -99,3 +99,3 @@ [![NPM version](https://img.shields.io/npm/v/babel-plugin-import.svg?style=flat)](https://npmjs.org/package/babel-plugin-import)

{
"libraryName": "material-ui",
"libraryName": "@material-ui/core",
"libraryDirectory": "components", // default: lib

@@ -106,3 +106,3 @@ "camel2DashComponentName": false, // default: true

~`options` can be an array.~ It's not available in bable@7+
~`options` can be an array.~ It's not available in babel@7+

@@ -164,4 +164,49 @@ For Example:

### customName
We can use `customName` to customize import file path.
For example, the default behavior:
```typescript
import { TimePicker } from "antd"
↓ ↓ ↓ ↓ ↓ ↓
var _button = require('antd/lib/time-picker');
```
You can set `camel2DashComponentName` to `false` to disable transfer from camel to dash:
```typescript
import { TimePicker } from "antd"
↓ ↓ ↓ ↓ ↓ ↓
var _button = require('antd/lib/TimePicker');
```
And finally, you can use `customName` to customize each name parsing:
```js
[
"import",
{
"libraryName": "antd",
"customName": (name: string) => {
if (name === 'TimePicker'){
return 'antd/lib/custom-time-picker';
}
return `antd/lib/${name}`;
}
}
]
```
So this result is:
```typescript
import { TimePicker } from "antd"
↓ ↓ ↓ ↓ ↓ ↓
var _button = require('antd/lib/custom-time-picker');
```
### Note
babel-plugin-import will not work properly if you add the library to the webpack config [vendor](https://webpack.github.io/docs/code-splitting.html#split-app-and-vendor-code).