Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-module-rewrite

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-module-rewrite - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

.travis.yml

48

lib/index.js

@@ -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

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