Socket
Socket
Sign inDemoInstall

babel-plugin-name-amd-modules

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-name-amd-modules - npm Package Compare versions

Comparing version 1.7.0-alpha.1158492a to 1.7.0-alpha.1b73ffed

8

lib/__tests__/index.test.js

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

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');

@@ -23,3 +27,5 @@

beforeEach(function () {
_pluginLogger2.default.set(__filename, logger = new _pluginLogger2.default());
babelIpc.set(__filename, {
log: logger = new _pluginLogger2.default()
});
});

@@ -26,0 +32,0 @@

51

lib/index.js

@@ -11,7 +11,10 @@ 'use strict';

var nameVisitor = {
ExpressionStatement: function ExpressionStatement(path, _ref2) {
var opts = _ref2.opts;
ExpressionStatement: function ExpressionStatement(path, state) {
var expression = path.node.expression;
var filenameRelative = state.file.opts.filenameRelative;
var _state$opts = state.opts,
packageName = _state$opts.packageName,
srcPrefixes = _state$opts.srcPrefixes;
var log = state.log;
var node = path.node;
var expression = node.expression;

@@ -21,5 +24,7 @@ if (t.isCallExpression(expression)) {

if (t.isIdentifier(callee, { name: 'define' })) {
var args = expression.arguments;
var insertName = false;

@@ -44,7 +49,7 @@ var unshiftName = true;

if (insertName) {
var packageName = getPackageName(this.opts.packageName, this.filenameRelative);
var normalizedPackageName = normalizePackageName(packageName, filenameRelative);
var moduleName = getModuleName(this.filenameRelative, getSrcPrefixes(opts));
var moduleName = getModuleName(filenameRelative, normalizeSrcPrefixes(srcPrefixes));
var fullModuleName = '' + packageName + moduleName;
var fullModuleName = normalizedPackageName + moduleName;

@@ -57,3 +62,3 @@ if (unshiftName) {

this.log.info('name-amd-modules', 'Set module name to \'' + fullModuleName + '\'');
log.info('name-amd-modules', 'Set module name to \'' + fullModuleName + '\'');

@@ -70,2 +75,12 @@ path.stop();

Program: {
enter: function enter(path, state) {
var _babelIpc$get = babelIpc.get(state, function () {
return {
log: new _pluginLogger2.default()
};
}),
log = _babelIpc$get.log;
state.log = log;
},
exit: function exit(path, state) {

@@ -75,7 +90,3 @@ // We must traverse the AST again because the

// call after exiting Program node :-(
path.traverse(nameVisitor, {
filenameRelative: state.file.opts.filenameRelative,
opts: state.opts,
log: _pluginLogger2.default.get(state)
});
path.traverse(nameVisitor, state);
}

@@ -87,2 +98,6 @@ }

var _babelIpc = require('liferay-npm-build-tools-common/lib/babel-ipc');
var babelIpc = _interopRequireWildcard(_babelIpc);
var _packages = require('liferay-npm-build-tools-common/lib/packages');

@@ -111,8 +126,8 @@

* it is not present.
* @param {object} opts the Babel plugin options
* @param {Array} srcPrefixes the original srcPrefixes
* @return {Array} the normalized srcPrefixes array (with native path
* separators)
*/
function getSrcPrefixes(opts) {
var srcPrefixes = opts.srcPrefixes || ['src/main/resources/META-INF/resources'];
function normalizeSrcPrefixes(srcPrefixes) {
srcPrefixes = srcPrefixes || ['src/main/resources/META-INF/resources'];

@@ -127,3 +142,3 @@ return srcPrefixes.map(function (srcPrefix) {

/**
* Resolve the package name of a JS module file.
* Normalize the package name of a JS module file.
* @param {String} packageName a forced package name or '<package.json>' to get

@@ -143,3 +158,3 @@ * the package name from the nearest ancestor package.json file

*/
function getPackageName(packageName, filenameRelative) {
function normalizePackageName(packageName, filenameRelative) {
packageName = packageName || '<package.json>';

@@ -146,0 +161,0 @@

{
"name": "babel-plugin-name-amd-modules",
"version": "1.7.0-alpha.1158492a",
"version": "1.7.0-alpha.1b73ffed",
"description": "A Babel plugin to give name to AMD modules based on their path and package.",

@@ -15,5 +15,5 @@ "main": "lib/index.js",

"dependencies": {
"liferay-npm-build-tools-common": "1.7.0-alpha.1158492a",
"liferay-npm-build-tools-common": "1.7.0-alpha.1b73ffed",
"read-json-sync": "^1.1.1"
}
}
import * as babel from 'babel-core';
import * as babelIpc from 'liferay-npm-build-tools-common/lib/babel-ipc';
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger';

@@ -8,3 +9,5 @@ import plugin from '../index';

beforeEach(() => {
PluginLogger.set(__filename, (logger = new PluginLogger()));
babelIpc.set(__filename, {
log: (logger = new PluginLogger()),
});
});

@@ -11,0 +14,0 @@

@@ -0,1 +1,2 @@

import * as babelIpc from 'liferay-npm-build-tools-common/lib/babel-ipc';
import * as pkgs from 'liferay-npm-build-tools-common/lib/packages';

@@ -14,11 +15,13 @@ import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger';

const nameVisitor = {
ExpressionStatement(path, {opts}) {
const node = path.node;
const expression = node.expression;
ExpressionStatement(path, state) {
const {node: {expression}} = path;
const {file: {opts: {filenameRelative}}} = state;
const {opts: {packageName, srcPrefixes}} = state;
const {log} = state;
if (t.isCallExpression(expression)) {
const callee = expression.callee;
const {callee} = expression;
if (t.isIdentifier(callee, {name: 'define'})) {
const args = expression.arguments;
const {arguments: args} = expression;

@@ -49,13 +52,14 @@ let insertName = false;

if (insertName) {
const packageName = getPackageName(
this.opts.packageName,
this.filenameRelative
let normalizedPackageName = normalizePackageName(
packageName,
filenameRelative
);
const moduleName = getModuleName(
this.filenameRelative,
getSrcPrefixes(opts)
filenameRelative,
normalizeSrcPrefixes(srcPrefixes)
);
const fullModuleName = `${packageName}${moduleName}`;
const fullModuleName =
normalizedPackageName + moduleName;

@@ -68,3 +72,3 @@ if (unshiftName) {

this.log.info(
log.info(
'name-amd-modules',

@@ -84,2 +88,9 @@ `Set module name to '${fullModuleName}'`

Program: {
enter(path, state) {
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
state.log = log;
},
exit(path, state) {

@@ -89,7 +100,3 @@ // We must traverse the AST again because the

// call after exiting Program node :-(
path.traverse(nameVisitor, {
filenameRelative: state.file.opts.filenameRelative,
opts: state.opts,
log: PluginLogger.get(state),
});
path.traverse(nameVisitor, state);
},

@@ -104,10 +111,8 @@ },

* it is not present.
* @param {object} opts the Babel plugin options
* @param {Array} srcPrefixes the original srcPrefixes
* @return {Array} the normalized srcPrefixes array (with native path
* separators)
*/
function getSrcPrefixes(opts) {
let srcPrefixes = opts.srcPrefixes || [
'src/main/resources/META-INF/resources',
];
function normalizeSrcPrefixes(srcPrefixes) {
srcPrefixes = srcPrefixes || ['src/main/resources/META-INF/resources'];

@@ -123,3 +128,3 @@ return srcPrefixes

/**
* Resolve the package name of a JS module file.
* Normalize the package name of a JS module file.
* @param {String} packageName a forced package name or '<package.json>' to get

@@ -131,3 +136,3 @@ * the package name from the nearest ancestor package.json file

*/
function getPackageName(packageName, filenameRelative) {
function normalizePackageName(packageName, filenameRelative) {
packageName = packageName || '<package.json>';

@@ -134,0 +139,0 @@

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