New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-kimport

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-kimport - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.travis.yml

159

lib/index.js

@@ -1,103 +0,88 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports["default"] = _default;
exports.default = function (_ref) {
var types = _ref.types;
var _assert = _interopRequireDefault(require("assert"));
var Programer = {
visitor: {
ImportDeclaration: function ImportDeclaration(path, _ref2) {
var opts = _ref2.opts;
var node = path.node,
source = node.source,
specifiers = node.specifiers;
var _path = require("path");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var currentConfigInstance = opts; //plugin 配置
function transCamel(_str, symbol) {
var str = _str[0].toLowerCase() + _str.substr(1);
if (Array.isArray(opts)) {
currentConfigInstance = opts.find(function (option) {
return option.libraryName === source.value;
}) || {};
}
return str.replace(/([A-Z])/g, function ($1) {
return "".concat(symbol).concat($1.toLowerCase());
});
}
(0, _assert2.default)(currentConfigInstance.libraryName, '\n\n libraryName should be provided! \n\n');
function winPath(path) {
return path.replace(/\\/g, '/');
}
//plugin 配置的依赖库libraryName名称
var libraryName = currentConfigInstance.libraryName || opts.libraryName || 'k-view';
function flatArray(arrParam, depArg) {
var res = [],
depth = depArg || 1,
depNum = 0,
flatMap = function flatMap(arr) {
arr.map(function (item, index, array) {
if (Array.isArray(item)) {
if (depNum < depth) {
depNum++;
flatMap(item);
} else {
res.push(item);
}
} else {
res.push(item);
if (array.length === index + 1) depNum = 0;
}
});
};
//下划线
currentConfigInstance.camel2UnderlineComponentName = typeof currentConfigInstance.camel2UnderlineComponentName === 'undefined' ? false : currentConfigInstance.camel2UnderlineComponentName;
//横杆连接
currentConfigInstance.camel2DashComponentName = typeof currentConfigInstance.camel2DashComponentName === 'undefined' ? false : currentConfigInstance.camel2DashComponentName;
flatMap(arrParam);
return res;
}
// 确认导入库 是否是 .babelrc library属性指定库 以及 如果不是默认导入 才进行按需导入加载
if (libraryName === source.value && !types.isImportDefaultSpecifier(specifiers[0]) && !types.isImportNamespaceSpecifier(specifiers[0])) {
function _default(_ref) {
var types = _ref.types;
var Programer = {
visitor: {
ImportDeclaration: function ImportDeclaration(path, _ref2) {
var opts = _ref2.opts;
var node = path.node,
source = node.source,
specifiers = node.specifiers;
var currentConfigInstance = opts;
var newImports = specifiers.map(function (specifier) {
// 遍历 出导入的每个包的说明描述符
//转换后的文件名
var transformedSourceName = currentConfigInstance.camel2UnderlineComponentName ? winPath(transCamel(specifier.imported.name, '_')) : currentConfigInstance.camel2DashComponentName ? winPath(transCamel(specifier.imported.name, '-')) : specifier.imported.name;
var libraryDirectory = typeof currentConfigInstance.libraryDirectory === 'undefined' ? 'lib' : currentConfigInstance.libraryDirectory;
if (Array.isArray(opts)) {
currentConfigInstance = opts.find(function (option) {
return option.libraryName === source.value;
}) || {};
}
//当前组件路径
var compDirPath = winPath((0, _path.join)(libraryName, libraryDirectory, transformedSourceName));
(0, _assert["default"])(currentConfigInstance.libraryName, '\n\n libraryName should be provided! \n\n');
var libraryName = currentConfigInstance.libraryName || opts.libraryName || 'k-view';
currentConfigInstance.camel2UnderlineComponentName = typeof currentConfigInstance.camel2UnderlineComponentName === 'undefined' ? false : currentConfigInstance.camel2UnderlineComponentName;
currentConfigInstance.camel2DashComponentName = typeof currentConfigInstance.camel2DashComponentName === 'undefined' ? false : currentConfigInstance.camel2DashComponentName;
var compInstancePath = currentConfigInstance.customName ? currentConfigInstance.customName('' + transformedSourceName) : compDirPath + '/index.js';
var compInstanceStylePath = currentConfigInstance.customStyleName ? currentConfigInstance.customStyleName('' + transformedSourceName) : compDirPath + '/style.css';
return [types.importDeclaration([types.importDefaultSpecifier(specifier.local)], types.stringLiteral(compInstancePath)), types.callExpression(types.import(), [types.stringLiteral(compInstanceStylePath)])];
});
newImports = flatArray(newImports, 1);
path.replaceWithMultiple(newImports);
}
}
}
};
return Programer;
};
var _assert = require('assert');
var _assert2 = _interopRequireDefault(_assert);
var _path = require('path');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function transCamel(_str, symbol) {
var str = _str[0].toLowerCase() + _str.substr(1);
return str.replace(/([A-Z])/g, function ($1) {
return '' + symbol + $1.toLowerCase();
});
}
function winPath(path) {
return path.replace(/\\/g, '/');
}
function flatArray(arrParam, depArg) {
var res = [],
depth = depArg || 1,
depNum = 0,
flatMap = function flatMap(arr) {
arr.map(function (item, index, array) {
if (Array.isArray(item)) {
if (depNum < depth) {
depNum++;
flatMap(item);
} else {
res.push(item);
}
} else {
res.push(item);
if (array.length === index + 1) depNum = 0;
}
});
};
flatMap(arrParam);
return res;
if (libraryName === source.value && !types.isImportDefaultSpecifier(specifiers[0]) && !types.isImportNamespaceSpecifier(specifiers[0])) {
var newImports = specifiers.map(function (specifier) {
var transformedSourceName = currentConfigInstance.camel2UnderlineComponentName ? winPath(transCamel(specifier.imported.name, '_')) : currentConfigInstance.camel2DashComponentName ? winPath(transCamel(specifier.imported.name, '-')) : specifier.imported.name;
var libraryDirectory = typeof currentConfigInstance.libraryDirectory === 'undefined' ? 'lib' : currentConfigInstance.libraryDirectory;
var compDirPath = winPath((0, _path.join)(libraryName, libraryDirectory, transformedSourceName));
var compInstancePath = currentConfigInstance.customName ? currentConfigInstance.customName("".concat(transformedSourceName)) : "".concat(compDirPath, "/index.js");
var compInstanceStylePath = currentConfigInstance.customStyleName ? currentConfigInstance.customStyleName("".concat(transformedSourceName)) : "".concat(compDirPath, "/style.css");
return [types.importDeclaration([types.importDefaultSpecifier(specifier.local)], types.stringLiteral(compInstancePath)), types.callExpression(types["import"](), [types.stringLiteral(compInstanceStylePath)])];
});
newImports = flatArray(newImports, 1);
path.replaceWithMultiple(newImports);
}
}
}
};
return Programer;
}
{
"name": "babel-plugin-kimport",
"version": "1.0.1",
"version": "1.0.2",
"description": "A component modular import plugin for babel ",
"main": "index.js",
"main": "lib/index.js",
"scripts": {
"build": "rm -rf lib && babel src --out-dir lib",
"lint": "eslint --ext .js src --fix",
"prepublish": "npm run build"
"release": "standard-version",
"commit": "git add . && git-cz",
"test": "mocha --require @babel/register",
"debug": "mocha --require @babel/register --require @babel/polyfill --no-timeouts"
},
"pre-commit": [
"lint"
],
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"gitHooks": {
"pre-commit": "lint-staged",
"commit-msg": "node scripts/verify-commit.js"
},
"lint-staged": {
"*.js": [
"npm run lint",
"git add"
]
},
"repository": {

@@ -24,10 +39,19 @@ "type": "git",

"license": "MIT",
"homepage": "https://github.com/ElementUI/babel-plugin-kimport#readme",
"bugs": {
"url": "https://github.com/SoldierAb/babel-plugin-kimport/issues"
},
"devDependencies": {
"@babel/cli": "^7.7.7",
"@babel/core": "^7.7.7",
"@babel/helper-module-imports": "^7.7.4",
"@babel/polyfill": "^7.7.0",
"@babel/preset-env": "^7.7.7",
"@babel/register": "^7.7.7",
"@babel/types": "^7.7.4",
"assert": "^2.0.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-types": "^6.26.0",
"babel-eslint": "^10.0.3",
"babylon": "^6.18.0",
"commitizen": "^4.0.3",
"cz-conventional-changelog": "^3.0.2",
"eslint": "^5.10.0",

@@ -39,4 +63,12 @@ "eslint-config-standard": "^12.0.0",

"eslint-plugin-standard": "^4.0.0",
"pre-commit": "^1.2.2"
"git-cz": "^3.3.0",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^1.3.0",
"lint-staged": "^9.5.0",
"mocha": "^7.0.0",
"pre-commit": "^1.2.2",
"standard-version": "^7.0.1",
"yorkie": "^2.0.0"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc