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 1.4.2 to 1.5.0

29

lib/__tests__/index.test.js

@@ -7,2 +7,6 @@ 'use strict';

var _pluginLogger = require('liferay-npm-build-tools-common/lib/plugin-logger');
var _pluginLogger2 = _interopRequireDefault(_pluginLogger);
var _index = require('../index');

@@ -16,2 +20,19 @@

var logger = void 0;
beforeEach(function () {
_pluginLogger2.default.set(__filename, logger = new _pluginLogger2.default());
});
it('logs results correctly', function () {
var source = '\n\trequire(\'a-package.js\');\n\trequire(\'./a-module.js\');\n\t';
babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]
});
expect(logger.messages).toMatchSnapshot();
});
describe('when requiring package default modules', function () {

@@ -22,2 +43,3 @@ it('keeps trailing ".js" from package names', function () {

var _babel$transform = babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]

@@ -34,2 +56,3 @@ }),

var _babel$transform2 = babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]

@@ -48,2 +71,3 @@ }),

var _babel$transform3 = babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]

@@ -60,2 +84,3 @@ }),

var _babel$transform4 = babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]

@@ -72,2 +97,3 @@ }),

var _babel$transform5 = babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]

@@ -86,2 +112,3 @@ }),

var _babel$transform6 = babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]

@@ -98,2 +125,3 @@ }),

var _babel$transform7 = babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]

@@ -110,2 +138,3 @@ }),

var _babel$transform8 = babel.transform(source, {
filenameRelative: __filename,
plugins: [_index2.default]

@@ -112,0 +141,0 @@ }),

30

lib/index.js

@@ -13,5 +13,6 @@ 'use strict';

Identifier: {
exit: function exit(path) {
exit: function exit(path, state) {
var node = path.node;
if (node.name == 'require') {

@@ -36,2 +37,8 @@ var parent = path.parent;

if (!state.normalizeCount) {
state.normalizeCount = 1;
} else {
state.normalizeCount++;
}
argument.value = moduleName;

@@ -42,2 +49,9 @@ }

}
},
Program: {
exit: function exit(path, state) {
if (state.normalizeCount) {
_pluginLogger2.default.get(state).info('normalize-requires', 'Normalized', state.normalizeCount, 'requires');
}
}
}

@@ -48,2 +62,8 @@ }

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 }; }
/**

@@ -68,5 +88,7 @@ * Check whether a module name refers to a package entry point.

return false;
} /**
* @return {object} a babel visitor
*/
}
/**
* @return {object} a babel visitor
*/
//# sourceMappingURL=index.js.map

5

package.json
{
"name": "babel-plugin-normalize-requires",
"version": "1.4.2",
"version": "1.5.0",
"description": "A Babel plugin that rewrites require() calls to normalize them (removing extensions and trailing slashes, for example).",

@@ -13,3 +13,6 @@ "main": "lib/index.js",

"babel-preset-es2015": "^6.24.1"
},
"dependencies": {
"liferay-npm-build-tools-common": "1.5.0"
}
}
import * as babel from 'babel-core';
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger';
import plugin from '../index';
let logger;
beforeEach(() => {
PluginLogger.set(__filename, (logger = new PluginLogger()));
});
it('logs results correctly', () => {
const source = `
require('a-package.js');
require('./a-module.js');
`;
babel.transform(source, {
filenameRelative: __filename,
plugins: [plugin],
});
expect(logger.messages).toMatchSnapshot();
});
describe('when requiring package default modules', () => {

@@ -11,2 +32,3 @@ it('keeps trailing ".js" from package names', () => {

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

@@ -24,2 +46,3 @@ });

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

@@ -39,2 +62,3 @@ });

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

@@ -52,2 +76,3 @@ });

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

@@ -65,2 +90,3 @@ });

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

@@ -80,2 +106,3 @@ });

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

@@ -93,2 +120,3 @@ });

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

@@ -106,2 +134,3 @@ });

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

@@ -108,0 +137,0 @@ });

@@ -0,1 +1,3 @@

import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger';
/**

@@ -8,4 +10,4 @@ * @return {object} a babel visitor

Identifier: {
exit(path) {
const node = path.node;
exit(path, state) {
const {node} = path;

@@ -40,2 +42,8 @@ if (node.name == 'require') {

if (!state.normalizeCount) {
state.normalizeCount = 1;
} else {
state.normalizeCount++;
}
argument.value = moduleName;

@@ -47,2 +55,14 @@ }

},
Program: {
exit(path, state) {
if (state.normalizeCount) {
PluginLogger.get(state).info(
'normalize-requires',
'Normalized',
state.normalizeCount,
'requires'
);
}
},
},
},

@@ -49,0 +69,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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