babel-plugin-module-alias
Advanced tools
Comparing version 1.4.1 to 1.5.0
155
lib/index.js
@@ -11,40 +11,12 @@ 'use strict'; | ||
exports.mapModule = mapModule; | ||
var path = require('path'); | ||
var _coverage__file; | ||
function _cover__() { | ||
if (!_coverage__file) _coverage__file = _coverage__getInitialState(); | ||
return _coverage__file; | ||
} | ||
function _coverage__getInitialState() { | ||
var path = '/home/ubuntu/babel-plugin-module-alias/src/index.js', | ||
hash = '17909e775700b870ade40d87bc5c9586'; | ||
var global = new Function('return this')(); | ||
var coverage = global['__coverage__'] || (global['__coverage__'] = {}); | ||
if (coverage[path] && coverage[path].hash === hash) return coverage[path]; | ||
var coverageData = global['JSON'].parse('{"path":"/home/ubuntu/babel-plugin-module-alias/src/index.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0},"statementMap":{"1":{"start":{"line":1,"column":13},"end":{"line":1,"column":28}},"2":{"start":{"line":4,"column":19},"end":{"line":4,"column":21}},"3":{"start":{"line":5,"column":17},"end":{"line":7,"column":22}},"4":{"start":{"line":6,"column":10},"end":{"line":6,"column":20}},"5":{"start":{"line":7,"column":10},"end":{"line":7,"column":22}},"6":{"start":{"line":9,"column":4},"end":{"line":11,"column":7}},"7":{"start":{"line":10,"column":8},"end":{"line":10,"column":57}},"8":{"start":{"line":13,"column":4},"end":{"line":13,"column":18}},"9":{"start":{"line":17,"column":4},"end":{"line":17,"column":51}},"10":{"start":{"line":17,"column":35},"end":{"line":17,"column":51}},"11":{"start":{"line":18,"column":4},"end":{"line":18,"column":49}},"12":{"start":{"line":22,"column":4},"end":{"line":22,"column":42}},"13":{"start":{"line":26,"column":15},"end":{"line":26,"column":40}},"14":{"start":{"line":27,"column":13},"end":{"line":27,"column":35}},"15":{"start":{"line":29,"column":4},"end":{"line":29,"column":25}},"16":{"start":{"line":30,"column":4},"end":{"line":30,"column":21}},"17":{"start":{"line":32,"column":23},"end":{"line":32,"column":46}},"18":{"start":{"line":34,"column":4},"end":{"line":34,"column":45}},"19":{"start":{"line":37,"column":4},"end":{"line":40,"column":5}},"20":{"start":{"line":39,"column":8},"end":{"line":39,"column":29}},"21":{"start":{"line":38,"column":34},"end":{"line":38,"column":60}},"22":{"start":{"line":42,"column":4},"end":{"line":42,"column":68}},"23":{"start":{"line":42,"column":33},"end":{"line":42,"column":68}},"24":{"start":{"line":44,"column":4},"end":{"line":44,"column":24}},"25":{"start":{"line":48,"column":24},"end":{"line":48,"column":41}},"26":{"start":{"line":51,"column":4},"end":{"line":58,"column":5}},"27":{"start":{"line":52,"column":18},"end":{"line":52,"column":39}},"28":{"start":{"line":53,"column":8},"end":{"line":56,"column":9}},"29":{"start":{"line":54,"column":12},"end":{"line":54,"column":30}},"30":{"start":{"line":55,"column":12},"end":{"line":55,"column":18}},"31":{"start":{"line":57,"column":8},"end":{"line":57,"column":26}},"32":{"start":{"line":60,"column":4},"end":{"line":63,"column":5}},"33":{"start":{"line":62,"column":8},"end":{"line":62,"column":20}},"34":{"start":{"line":65,"column":20},"end":{"line":65,"column":62}},"35":{"start":{"line":66,"column":4},"end":{"line":66,"column":40}},"36":{"start":{"line":70,"column":0},"end":{"line":120,"column":2}},"37":{"start":{"line":72,"column":8},"end":{"line":80,"column":9}},"38":{"start":{"line":74,"column":16},"end":{"line":77,"column":17}},"39":{"start":{"line":76,"column":20},"end":{"line":76,"column":84}},"40":{"start":{"line":79,"column":12},"end":{"line":79,"column":19}},"41":{"start":{"line":82,"column":26},"end":{"line":82,"column":52}},"42":{"start":{"line":83,"column":8},"end":{"line":90,"column":9}},"43":{"start":{"line":83,"column":25},"end":{"line":83,"column":59}},"44":{"start":{"line":84,"column":31},"end":{"line":84,"column":93}},"45":{"start":{"line":85,"column":12},"end":{"line":89,"column":13}},"46":{"start":{"line":86,"column":16},"end":{"line":88,"column":19}},"47":{"start":{"line":94,"column":26},"end":{"line":94,"column":46}},"48":{"start":{"line":95,"column":8},"end":{"line":103,"column":9}},"49":{"start":{"line":95,"column":25},"end":{"line":95,"column":59}},"50":{"start":{"line":96,"column":31},"end":{"line":96,"column":93}},"51":{"start":{"line":97,"column":12},"end":{"line":102,"column":13}},"52":{"start":{"line":98,"column":16},"end":{"line":101,"column":19}},"53":{"start":{"line":106,"column":4},"end":{"line":119,"column":6}},"54":{"start":{"line":110,"column":20},"end":{"line":110,"column":88}},"55":{"start":{"line":115,"column":20},"end":{"line":115,"column":87}}},"fnMap":{"1":{"name":null,"line":3,"loc":{"start":{"line":3,"column":0},"end":{"line":14,"column":1}}},"2":{"name":null,"line":9,"loc":{"start":{"line":9,"column":17},"end":{"line":11,"column":5}}},"3":{"name":null,"line":16,"loc":{"start":{"line":16,"column":0},"end":{"line":19,"column":1}}},"4":{"name":null,"line":21,"loc":{"start":{"line":21,"column":0},"end":{"line":23,"column":1}}},"5":{"name":null,"line":25,"loc":{"start":{"line":25,"column":7},"end":{"line":45,"column":1}}},"6":{"name":null,"line":47,"loc":{"start":{"line":47,"column":7},"end":{"line":67,"column":1}}},"7":{"name":null,"line":70,"loc":{"start":{"line":70,"column":15},"end":{"line":120,"column":1}}},"8":{"name":null,"line":71,"loc":{"start":{"line":71,"column":4},"end":{"line":91,"column":5}}},"9":{"name":null,"line":93,"loc":{"start":{"line":93,"column":4},"end":{"line":104,"column":5}}}},"branchMap":{"1":{"line":5,"type":"cond-expr","locations":[{"start":{"line":5,"column":17},"end":{"line":7,"column":22}},{"start":{"line":5,"column":17},"end":{"line":7,"column":22}}]},"2":{"line":17,"type":"if","locations":[{"start":{"line":17,"column":4},"end":{"line":17,"column":51}},{"start":{"line":17,"column":4},"end":{"line":17,"column":51}}]},"3":{"line":37,"type":"if","locations":[{"start":{"line":37,"column":45},"end":{"line":40,"column":5}},{"start":{"line":37,"column":45},"end":{"line":40,"column":5}}]},"4":{"line":42,"type":"if","locations":[{"start":{"line":42,"column":4},"end":{"line":42,"column":68}},{"start":{"line":42,"column":4},"end":{"line":42,"column":68}}]},"5":{"line":53,"type":"if","locations":[{"start":{"line":53,"column":40},"end":{"line":56,"column":9}},{"start":{"line":53,"column":40},"end":{"line":56,"column":9}}]},"6":{"line":60,"type":"if","locations":[{"start":{"line":60,"column":29},"end":{"line":63,"column":5}},{"start":{"line":60,"column":29},"end":{"line":63,"column":5}}]},"7":{"line":72,"type":"if","locations":[{"start":{"line":78,"column":10},"end":{"line":80,"column":9}},{"start":{"line":78,"column":10},"end":{"line":80,"column":9}}]},"8":{"line":73,"type":"binary-expr","locations":[{"start":{"line":73,"column":12},"end":{"line":73,"column":70}},{"start":{"line":73,"column":12},"end":{"line":73,"column":70}}]},"9":{"line":75,"type":"binary-expr","locations":[{"start":{"line":75,"column":20},"end":{"line":75,"column":62}},{"start":{"line":75,"column":20},"end":{"line":75,"column":62}}]},"10":{"line":83,"type":"if","locations":[{"start":{"line":83,"column":61},"end":{"line":90,"column":9}},{"start":{"line":83,"column":61},"end":{"line":90,"column":9}}]},"11":{"line":83,"type":"binary-expr","locations":[{"start":{"line":83,"column":12},"end":{"line":83,"column":21}},{"start":{"line":83,"column":12},"end":{"line":83,"column":21}}]},"12":{"line":85,"type":"if","locations":[{"start":{"line":85,"column":28},"end":{"line":89,"column":13}},{"start":{"line":85,"column":28},"end":{"line":89,"column":13}}]},"13":{"line":95,"type":"if","locations":[{"start":{"line":95,"column":61},"end":{"line":103,"column":9}},{"start":{"line":95,"column":61},"end":{"line":103,"column":9}}]},"14":{"line":95,"type":"binary-expr","locations":[{"start":{"line":95,"column":12},"end":{"line":95,"column":21}},{"start":{"line":95,"column":12},"end":{"line":95,"column":21}}]},"15":{"line":97,"type":"if","locations":[{"start":{"line":97,"column":28},"end":{"line":102,"column":13}},{"start":{"line":97,"column":28},"end":{"line":102,"column":13}}]}}}'); | ||
coverageData.hash = hash; | ||
return coverage[path] = coverageData; | ||
} | ||
_cover__(); | ||
var path = (++_cover__().s['1'], require('path')); | ||
function createFilesMap(state) { | ||
++_cover__().f['1']; | ||
var result = {}; | ||
var opts = Array.isArray(state.opts) ? state.opts : [state.opts]; | ||
var result = (++_cover__().s['2'], {}); | ||
var opts = (++_cover__().s['3'], Array.isArray(state.opts) ? (++_cover__().b['1'][0], (++_cover__().s['4'], state.opts)) : (++_cover__().b['1'][1], (++_cover__().s['5'], [state.opts]))); | ||
++_cover__().s['6']; | ||
opts.forEach(function (moduleMapData) { | ||
++_cover__().f['2']; | ||
++_cover__().s['7']; | ||
result[moduleMapData.expose] = moduleMapData.src; | ||
}); | ||
++_cover__().s['8']; | ||
return result; | ||
@@ -54,12 +26,3 @@ } | ||
function resolve(filename) { | ||
++_cover__().f['3']; | ||
++_cover__().s['9']; | ||
if (path.isAbsolute(filename)) { | ||
++_cover__().b['2'][0]; | ||
++_cover__().s['10']; | ||
return filename; | ||
} else { | ||
++_cover__().b['2'][1]; | ||
}++_cover__().s['11']; | ||
if (path.isAbsolute(filename)) return filename; | ||
return path.resolve(process.cwd(), filename); | ||
@@ -69,5 +32,2 @@ } | ||
function toPosixPath(modulePath) { | ||
++_cover__().f['4']; | ||
++_cover__().s['12']; | ||
return modulePath.replace(/\\/g, '/'); | ||
@@ -77,42 +37,25 @@ } | ||
function mapToRelative(currentFile, module) { | ||
++_cover__().f['5']; | ||
var from = path.dirname(currentFile); | ||
var to = path.normalize(module); | ||
var from = (++_cover__().s['13'], path.dirname(currentFile)); | ||
var to = (++_cover__().s['14'], path.normalize(module)); | ||
++_cover__().s['15']; | ||
from = resolve(from); | ||
++_cover__().s['16']; | ||
to = resolve(to); | ||
var moduleMapped = (++_cover__().s['17'], path.relative(from, to)); | ||
var moduleMapped = path.relative(from, to); | ||
++_cover__().s['18']; | ||
moduleMapped = toPosixPath(moduleMapped); | ||
// Support npm modules instead of directories | ||
++_cover__().s['19']; | ||
if (moduleMapped.indexOf('npm:') !== -1) { | ||
++_cover__().b['3'][0]; | ||
var _moduleMapped$split = moduleMapped.split('npm:'); | ||
var _moduleMapped$split = (++_cover__().s['21'], moduleMapped.split('npm:')); | ||
var _moduleMapped$split2 = _slicedToArray(_moduleMapped$split, 2); | ||
var npmModuleName = _moduleMapped$split2[1]; | ||
++_cover__().s['20']; | ||
return npmModuleName; | ||
} else { | ||
++_cover__().b['3'][1]; | ||
} | ||
++_cover__().s['22']; | ||
if (moduleMapped[0] !== '.') { | ||
++_cover__().b['4'][0]; | ||
++_cover__().s['23']; | ||
moduleMapped = './' + moduleMapped; | ||
} else { | ||
++_cover__().b['4'][1]; | ||
}++_cover__().s['24']; | ||
if (moduleMapped[0] !== '.') moduleMapped = './' + moduleMapped; | ||
return moduleMapped; | ||
@@ -122,77 +65,37 @@ } | ||
function mapModule(source, file, filesMap) { | ||
++_cover__().f['6']; | ||
var moduleSplit = source.split('/'); | ||
var moduleSplit = (++_cover__().s['25'], source.split('/')); | ||
var src = void 0; | ||
++_cover__().s['26']; | ||
while (moduleSplit.length) { | ||
var m = (++_cover__().s['27'], moduleSplit.join('/')); | ||
++_cover__().s['28']; | ||
var m = moduleSplit.join('/'); | ||
if (filesMap.hasOwnProperty(m)) { | ||
++_cover__().b['5'][0]; | ||
++_cover__().s['29']; | ||
src = filesMap[m]; | ||
++_cover__().s['30']; | ||
break; | ||
} else { | ||
++_cover__().b['5'][1]; | ||
} | ||
++_cover__().s['31']; | ||
moduleSplit.pop(); | ||
} | ||
++_cover__().s['32']; | ||
if (!moduleSplit.length) { | ||
++_cover__().b['6'][0]; | ||
++_cover__().s['33']; | ||
// no mapping available | ||
return null; | ||
} else { | ||
++_cover__().b['6'][1]; | ||
} | ||
var newPath = (++_cover__().s['34'], source.replace(moduleSplit.join('/'), src)); | ||
++_cover__().s['35']; | ||
var newPath = source.replace(moduleSplit.join('/'), src); | ||
return mapToRelative(file, newPath); | ||
} | ||
++_cover__().s['36']; | ||
exports.default = function (_ref) { | ||
var t = _ref.types; | ||
++_cover__().f['7']; | ||
function transformRequireCall(nodePath, state, filesMap) { | ||
++_cover__().f['8']; | ||
++_cover__().s['37']; | ||
if ((++_cover__().b['8'][0], !t.isIdentifier(nodePath.node.callee, { name: 'require' })) && (++_cover__().b['8'][1], (++_cover__().s['38'], !((++_cover__().b['9'][0], t.isMemberExpression(nodePath.node.callee)) && (++_cover__().b['9'][1], (++_cover__().s['39'], t.isIdentifier(nodePath.node.callee.object, { name: 'require' }))))))) { | ||
++_cover__().b['7'][0]; | ||
++_cover__().s['40']; | ||
if (!t.isIdentifier(nodePath.node.callee, { name: 'require' }) && !(t.isMemberExpression(nodePath.node.callee) && t.isIdentifier(nodePath.node.callee.object, { name: 'require' }))) { | ||
return; | ||
} else { | ||
++_cover__().b['7'][1]; | ||
} | ||
var moduleArg = (++_cover__().s['41'], nodePath.node.arguments[0]); | ||
++_cover__().s['42']; | ||
if ((++_cover__().b['11'][0], moduleArg) && (++_cover__().b['11'][1], (++_cover__().s['43'], moduleArg.type === 'StringLiteral'))) { | ||
++_cover__().b['10'][0]; | ||
var modulePath = (++_cover__().s['44'], mapModule(moduleArg.value, state.file.opts.filename, filesMap)); | ||
++_cover__().s['45']; | ||
var moduleArg = nodePath.node.arguments[0]; | ||
if (moduleArg && moduleArg.type === 'StringLiteral') { | ||
var modulePath = mapModule(moduleArg.value, state.file.opts.filename, filesMap); | ||
if (modulePath) { | ||
++_cover__().b['12'][0]; | ||
++_cover__().s['46']; | ||
nodePath.replaceWith(t.callExpression(nodePath.node.callee, [t.stringLiteral(modulePath)])); | ||
} else { | ||
++_cover__().b['12'][1]; | ||
} | ||
} else { | ||
++_cover__().b['10'][1]; | ||
} | ||
@@ -202,25 +105,11 @@ } | ||
function transformImportCall(nodePath, state, filesMap) { | ||
++_cover__().f['9']; | ||
var moduleArg = (++_cover__().s['47'], nodePath.node.source); | ||
++_cover__().s['48']; | ||
if ((++_cover__().b['14'][0], moduleArg) && (++_cover__().b['14'][1], (++_cover__().s['49'], moduleArg.type === 'StringLiteral'))) { | ||
++_cover__().b['13'][0]; | ||
var modulePath = (++_cover__().s['50'], mapModule(moduleArg.value, state.file.opts.filename, filesMap)); | ||
++_cover__().s['51']; | ||
var moduleArg = nodePath.node.source; | ||
if (moduleArg && moduleArg.type === 'StringLiteral') { | ||
var modulePath = mapModule(moduleArg.value, state.file.opts.filename, filesMap); | ||
if (modulePath) { | ||
++_cover__().b['15'][0]; | ||
++_cover__().s['52']; | ||
nodePath.replaceWith(t.importDeclaration(nodePath.node.specifiers, t.stringLiteral(modulePath))); | ||
} else { | ||
++_cover__().b['15'][1]; | ||
} | ||
} else { | ||
++_cover__().b['13'][1]; | ||
} | ||
} | ||
++_cover__().s['53']; | ||
return { | ||
@@ -230,4 +119,2 @@ visitor: { | ||
exit: function exit(nodePath, state) { | ||
++_cover__().s['54']; | ||
return transformRequireCall(nodePath, state, createFilesMap(state)); | ||
@@ -238,4 +125,2 @@ } | ||
exit: function exit(nodePath, state) { | ||
++_cover__().s['55']; | ||
return transformImportCall(nodePath, state, createFilesMap(state)); | ||
@@ -242,0 +127,0 @@ } |
{ | ||
"name": "babel-plugin-module-alias", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"main": "lib/index.js", | ||
@@ -49,3 +49,3 @@ "description": "Babel plugin to rewrite the path in require() and ES6 import", | ||
"lint": "eslint src test", | ||
"compile": "babel src --out-dir lib", | ||
"compile": "cross-env NODE_ENV=production babel src --out-dir lib", | ||
"pretest": "npm run lint", | ||
@@ -52,0 +52,0 @@ "test": "cross-env NODE_ENV=test nyc npm run test:suite", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
0
0
9822
97