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

jsbundle

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsbundle - npm Package Compare versions

Comparing version 0.13.2 to 0.13.3

34

filters/logger/index.js

@@ -6,6 +6,6 @@ var parser = require('uglify-js').parser;

var LOG_LEVELS = {
'off': 0,
'off': 0,
'error': 1,
'warn': 2,
'info': 3,
'warn': 2,
'info': 3,
'debug': 4,

@@ -42,6 +42,7 @@ 'trace': 5

var logLevel = this[1][2];
var token = this[0];
var startPos = token.start.pos + replacementOffset;
var endPos = token.end.endpos + replacementOffset;
if (allowedLogLevelsSet[logLevel] !== true) {
var token = this[0];
var startPos = token.start.pos + replacementOffset;
var endPos = token.end.endpos + replacementOffset;
src = src.substring(0, startPos) + '/* ' +

@@ -51,2 +52,14 @@ src.substring(startPos, endPos) + ' */' +

replacementOffset += '/* */'.length;
} else {
var stringToInject = '"' + logLevel.charAt(0) + '[" + __shortfilename + "]:"';
if (this[2].length > 0) {
stringToInject += ', ';
}
var logStatement = src.substring(startPos, endPos);
var logFnRegex = new RegExp('(^\\s*logger\\s*\\.\\s*' + logLevel + '\\s*\\(\s*)');
logStatement = logStatement.replace(logFnRegex, '$1' + stringToInject);
src = src.substring(0, startPos) +
logStatement +
src.substring(endPos);
replacementOffset += stringToInject.length;
}

@@ -59,12 +72,13 @@ }

if (logLevel === "off") {
if (logLevel === 'off') {
return src;
} else {
return 'var logger = new (require(' + JSON.stringify(loggerFile) + '))(__filename);\n' + src;
return 'var __shortfilename = String(__filename).split("/");\n\
__shortfilename = __shortfilename.slice(__shortfilename.length - 3).join("/");\n\
var logger = new (require(' + JSON.stringify(loggerFile) + '));\n' + src;
}
},
requires: logLevel === "off" ? [] : [ loggerFile ], // must be absolute paths
lineDelta: logLevel === "off" ? 0 : 1
lineDelta: logLevel === "off" ? 0 : 3
}
}

@@ -71,0 +85,0 @@

@@ -1,59 +0,65 @@

function Logger(name) {
var nameParts = String(name).split('/');
this._name = nameParts.slice(nameParts.length - 3).join('/');
function Logger() {
if (this.log) {
this.trace = this.log;
this.log = void 0;
}
}
var logMethods = ['error', 'warn', 'info', 'debug', 'trace'];
for (var index = 0, len = logMethods.length; index < len; ++index) {
(function(index, funcName) {
Logger.prototype[funcName] = function() {
var message = [funcName[0], '[', this._name, ']'].join('');
var args = Array.prototype.slice.call(arguments);
var stack_traces = [];
// logger.trace -> console.log
funcName = funcName === 'trace' ? 'log' : funcName;
if (!console) {
return;
}
if (typeof args[0] === 'string') {
message += ': ' + args.shift();
}
for (var i = 0, len = args.length; i < len; ++i) {
if (args[i] && args[i].stack) {
stack_traces.push(args[i].stack);
if (typeof console !== 'undefined' && typeof console.log === 'function') {
Logger.prototype = console;
} else { // for the dreaded IE, which doesn't allow console.log.apply
function getLogFunction(name) {
return function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
if (typeof console !== 'undefined') {
switch (arguments.length) {
case 0:
console[name]();
break;
case 1:
console[name](arg0);
break;
case 2:
console[name](arg0, arg1);
break;
case 3:
console[name](arg0, arg1, arg2);
break
case 4:
console[name](arg0, arg1, arg2, arg3);
break;
case 5:
console[name](arg0, arg1, arg2, arg3, arg4);
break;
case 6:
console[name](arg0, arg1, arg2, arg3, arg4, arg5);
break;
case 7:
console[name](arg0, arg1, arg2, arg3, arg4, arg5, arg6);
break;
case 7:
console[name](arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
case 8:
console[name](arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
break;
case 9:
console[name](arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
break;
case 10:
console[name](arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
break;
default:
break;
}
}
};
}
if (console.firebug) {
args.unshift(message);
console[funcName].apply(self, args);
} else {
if (args.length <= 0) {
console[funcName] ? console[funcName](message) :
console.log(message);
} else if (args.length === 1) {
console[funcName] ? console[funcName](message, args[0]) :
console.log(message, args[0]);
} else {
console[funcName] ? console[funcName](message, args) :
console.log(message, args);
}
}
var len = stack_traces.length;
if (len > 0) {
console.log('Listing exception stack traces individually:');
for (var i = 0; i < len; ++i) {
console.log(stack_traces[i]); // why? because in Google Chrome,
// this will make clickable links
}
}
};
})(index, logMethods[index]);
Logger.prototype = {
error: getLogFunction('error'),
warn: getLogFunction('warn'),
info: getLogFunction('info'),
debug: getLogFunction('debug'),
trace: getLogFunction('log')
};
}

@@ -60,0 +66,0 @@

@@ -6,3 +6,3 @@ {

"keywords": "browser require bundle module package static-analysis",
"version": "0.13.2",
"version": "0.13.3",
"repository": {

@@ -9,0 +9,0 @@ "type": "git",

#!/usr/bin/env node
logger.warn(
logger.
warn(
'this code executed!'

@@ -5,0 +6,0 @@ );

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