babel-plugin-module-rewrite
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -6,37 +6,47 @@ 'use strict'; | ||
}); | ||
exports.mapModule = mapModule; | ||
var _path = require('path'); | ||
function getReplaceFunc(replaceFuncPath) { | ||
return require((0, _path.resolve)(process.cwd(), replaceFuncPath));; | ||
} | ||
function getReplaceFunc() { | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
function mapModule(source, file, state) { | ||
var opts = state.opts; | ||
var replaceContainer = getReplaceFunc(opts.replaceFunc); | ||
var replaceFunc = _ref.replaceFunc; | ||
var _ref$replaceHandlerNa = _ref.replaceHandlerName; | ||
var replaceHandlerName = _ref$replaceHandlerNa === undefined ? 'default' : _ref$replaceHandlerNa; | ||
var _ref$resolveFrom = _ref.resolveFrom; | ||
var resolveFrom = _ref$resolveFrom === undefined ? 'process.cwd()' : _ref$resolveFrom; | ||
var replaceContainer = require((0, _path.resolve)(eval(resolveFrom), replaceFunc)); | ||
if (!replaceContainer) { | ||
throw new Error('Cannot find replace function file: ' + opts.replaceFunc); | ||
throw new Error('Cannot find replace function file: ' + replaceFunc); | ||
} | ||
var replaceHandlerName = opts.replaceHandlerName || 'default'; | ||
var replace = replaceContainer[replaceHandlerName] || replaceContainer; | ||
// If the result is not a function, throw | ||
if (!replace || typeof replace !== 'function') { | ||
throw new Error('Cannot find replace handler in: ' + opts.replaceFunc + " with name: " + replaceHandlerName); | ||
throw new Error('Cannot find replace handler in: ' + replaceFunc + " with name: " + replaceHandlerName); | ||
} | ||
var result = replace(source, file, opts); | ||
if (result !== source) { | ||
return result; | ||
} else { | ||
return; | ||
} | ||
return replace; | ||
} | ||
exports.default = function (_ref) { | ||
var t = _ref.types; | ||
exports.default = function (_ref2, a, b) { | ||
var t = _ref2.types; | ||
var cachedReplaceFunction = void 0; | ||
function mapModule(source, file, state) { | ||
var opts = state.opts; | ||
if (!cachedReplaceFunction) { | ||
cachedReplaceFunction = getReplaceFunc(opts); | ||
} | ||
var replace = cachedReplaceFunction; | ||
var result = replace(source, file, opts); | ||
if (result !== source) { | ||
return result; | ||
} else { | ||
return; | ||
} | ||
} | ||
function transformRequireCall(nodePath, state) { | ||
@@ -43,0 +53,0 @@ if (!t.isIdentifier(nodePath.node.callee, { name: 'require' }) && !(t.isMemberExpression(nodePath.node.callee) && t.isIdentifier(nodePath.node.callee.object, { name: 'require' }))) { |
{ | ||
"name": "babel-plugin-module-rewrite", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "description": "Babel plugin to dynamically rewrite the path in require() and ES6 import", |
@@ -1,2 +0,4 @@ | ||
# babel-plugin-module-rewrite [![Version](https://img.shields.io/npm/v/babel-plugin-module-rewrite.svg)](https://www.npmjs.org/package/babel-plugin-module-rewrite) | ||
# babel-plugin-module-rewrite | ||
[![Version](https://img.shields.io/npm/v/babel-plugin-module-rewrite.svg)](https://www.npmjs.org/package/babel-plugin-module-rewrite) | ||
[![Build Status](https://travis-ci.org/liady/babel-plugin-module-rewrite?branch=master)](https://travis-ci.org/liady/babel-plugin-module-rewrite) | ||
@@ -3,0 +5,0 @@ A [babel](http://babeljs.io) plugin to rewrite module imports (and `require`) using a custom function |
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
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
6950
8
74
43
1