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

babel-plugin-normalize-requires

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-normalize-requires - npm Package Compare versions

Comparing version 2.6.2 to 2.6.3-alpha.126

LICENSE.md

171

lib/index.js

@@ -1,79 +0,71 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (_ref) {
var t = _ref.types;
return {
visitor: {
Identifier: {
exit: function exit(path, state) {
var node = path.node;
if (node.name == 'require') {
var parent = path.parent;
if (t.isCallExpression(parent)) {
var argument = parent.arguments[0];
if (t.isLiteral(argument) && argument.value) {
var moduleName = argument.value;
if (typeof moduleName === 'string' && !isPackageName(moduleName)) {
if (moduleName.endsWith('.js')) {
moduleName = moduleName.substring(0, moduleName.length - 3);
}
if (moduleName.endsWith('/')) {
moduleName = moduleName.substring(0, moduleName.length - 1);
}
}
if (!state.normalizeCount) {
state.normalizeCount = 1;
} else {
state.normalizeCount++;
}
argument.value = moduleName;
}
}
}
}
},
Program: {
exit: function exit(path, state) {
if (state.normalizeCount) {
var _babelIpc$get = babelIpc.get(state, function () {
return {
log: new _pluginLogger2.default()
};
}),
log = _babelIpc$get.log;
log.info('normalize-requires', 'Normalized', state.normalizeCount, 'requires');
}
}
}
}
};
"use strict";
/**
* © 2017 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var _babelIpc = require('liferay-npm-build-tools-common/lib/babel-ipc');
var babelIpc = _interopRequireWildcard(_babelIpc);
var _pluginLogger = require('liferay-npm-build-tools-common/lib/plugin-logger');
var _pluginLogger2 = _interopRequireDefault(_pluginLogger);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const babelIpc = __importStar(require("liferay-npm-build-tools-common/lib/babel-ipc"));
const plugin_logger_1 = __importDefault(require("liferay-npm-build-tools-common/lib/plugin-logger"));
/**
* @return {object} a babel visitor
*/
function default_1({ types: t }) {
return {
visitor: {
Identifier: {
exit(path, state) {
const { node } = path;
if (node.name == 'require') {
const parent = path.parent;
if (t.isCallExpression(parent)) {
const argument = parent.arguments[0];
if (t.isLiteral(argument) && argument.value) {
let moduleName = argument.value;
if (typeof moduleName === 'string' &&
!isPackageName(moduleName)) {
if (moduleName.endsWith('.js')) {
moduleName = moduleName.substring(0, moduleName.length - 3);
}
if (moduleName.endsWith('/')) {
moduleName = moduleName.substring(0, moduleName.length - 1);
}
}
if (!state.normalizeCount) {
state.normalizeCount = 1;
}
else {
state.normalizeCount++;
}
argument.value = moduleName;
}
}
}
},
},
Program: {
exit(path, state) {
if (state.normalizeCount) {
const { log } = babelIpc.get(state, () => ({
log: new plugin_logger_1.default(),
}));
log.info('normalize-requires', 'Normalized', state.normalizeCount, 'requires');
}
},
},
},
};
}
exports.default = default_1;
/**
* Check whether a module name refers to a package entry point.

@@ -84,20 +76,11 @@ * @param {String} moduleName the name of a JS module

function isPackageName(moduleName) {
var firstSlashIndex = moduleName.indexOf('/');
if (firstSlashIndex == -1) {
return true;
}
var restOfModuleName = moduleName.substring(firstSlashIndex + 1);
if (moduleName.startsWith('@') && restOfModuleName.indexOf('/') == -1) {
return true;
}
return false;
const firstSlashIndex = moduleName.indexOf('/');
if (firstSlashIndex == -1) {
return true;
}
const restOfModuleName = moduleName.substring(firstSlashIndex + 1);
if (moduleName.startsWith('@') && restOfModuleName.indexOf('/') == -1) {
return true;
}
return false;
}
/**
* @return {object} a babel visitor
*/
//# sourceMappingURL=index.js.map
{
"name": "babel-plugin-normalize-requires",
"version": "2.6.2",
"version": "2.6.3-alpha.126+f9a8cd2",
"description": "A Babel plugin that rewrites require() calls to normalize them (removing extensions and trailing slashes, for example).",
"main": "lib/index.js",
"scripts": {
"build": "babel --source-maps -D -d lib src",
"prepublish": "npm run build"
"copyfiles": "node ../../scripts/copyfiles.js",
"build": "tsc && yarn copyfiles",
"prepublish": "yarn build"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.24.1"
"dependencies": {
"liferay-npm-build-tools-common": "2.6.3-alpha.126+f9a8cd2"
},
"dependencies": {
"liferay-npm-build-tools-common": "2.6.2"
}
"gitHead": "f9a8cd23c70ecc6fff238bea906286c1c6cb2ecc"
}

@@ -0,1 +1,7 @@

/**
* © 2017 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
import * as babel from 'babel-core';

@@ -21,3 +27,3 @@ import * as babelIpc from 'liferay-npm-build-tools-common/lib/babel-ipc';

babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -36,3 +42,3 @@ });

const {code} = babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -50,3 +56,3 @@ });

const {code} = babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -66,3 +72,3 @@ });

const {code} = babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -80,3 +86,3 @@ });

const {code} = babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -94,3 +100,3 @@ });

const {code} = babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -110,3 +116,3 @@ });

const {code} = babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -124,3 +130,3 @@ });

const {code} = babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -138,3 +144,3 @@ });

const {code} = babel.transform(source, {
filenameRelative: __filename,
filename: __filename,
plugins: [plugin],

@@ -141,0 +147,0 @@ });

@@ -0,1 +1,7 @@

/**
* © 2017 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
import * as babelIpc from 'liferay-npm-build-tools-common/lib/babel-ipc';

@@ -2,0 +8,0 @@ import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger';

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