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

@phenomnomnominal/debug

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@phenomnomnominal/debug - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

38

dist/debug.js

@@ -1,25 +0,31 @@

import nodeModule from 'module';
import { DebuggerΩ } from './debugger';
export function debug(options = {}) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debug = void 0;
var tslib_1 = require("tslib");
var module_1 = tslib_1.__importDefault(require("module"));
var debugger_1 = require("./debugger");
function debug(options) {
if (options === void 0) { options = {}; }
if (options.enabled) {
const d = new DebuggerΩ(options);
Object.keys(require.cache).forEach((requirePath) => {
const module = require.cache[requirePath];
if (module && d.shouldWrap(requirePath)) {
d.wrap(module.exports);
var d_1 = new debugger_1.DebuggerΩ(options);
Object.keys(require.cache).forEach(function (requirePath) {
var module = require.cache[requirePath];
if (module && d_1.shouldWrap(requirePath)) {
d_1.wrap(module.exports);
}
});
const original = nodeModule.Module.prototype.require;
const debugRequire = function (id) {
const Module = nodeModule.Module;
const requirePath = Module._resolveFilename(id, this);
const module = original.apply(this, [id]);
if (module && d.shouldWrap(requirePath)) {
return d.wrap(module);
var original_1 = module_1.default.Module.prototype.require;
var debugRequire = function (id) {
var Module = module_1.default.Module;
var requirePath = Module._resolveFilename(id, this);
var module = original_1.apply(this, [id]);
if (module && d_1.shouldWrap(requirePath)) {
return d_1.wrap(module);
}
return module;
};
nodeModule.Module.prototype.require = Object.assign(debugRequire, original);
module_1.default.Module.prototype.require = Object.assign(debugRequire, original_1);
}
}
exports.debug = debug;
//# sourceMappingURL=debug.js.map

@@ -1,29 +0,34 @@

import { parseScript } from 'esprima';
import { query } from 'esquery';
import nodeModule from 'module';
import { performance } from 'perf_hooks';
import { types } from 'util';
import { DebugLoggerΩ } from './logger';
export class DebuggerΩ {
constructor(options) {
const { header = '', ignore = [], include = [] } = options;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebuggerΩ = void 0;
var tslib_1 = require("tslib");
var esprima_1 = require("esprima");
var esquery_1 = require("esquery");
var module_1 = tslib_1.__importDefault(require("module"));
var perf_hooks_1 = require("perf_hooks");
var util_1 = require("util");
var logger_1 = require("./logger");
var DebuggerΩ = /** @class */ (function () {
function DebuggerΩ(options) {
var _a = options.header, header = _a === void 0 ? '' : _a, _b = options.ignore, ignore = _b === void 0 ? [] : _b, _c = options.include, include = _c === void 0 ? [] : _c;
this._include = include;
this._ignore = ignore;
this._logger = new DebugLoggerΩ(options);
this._logger.raw(`${header} starting ${Date.now()}`.trimStart());
this._logger = new logger_1.DebugLoggerΩ(options);
this._logger.raw((header + " starting " + Date.now()).trimStart());
}
shouldWrap(requirePath) {
const isNodeModule = nodeModule.builtinModules.includes(requirePath) || requirePath.includes('node_modules');
const isIncludedModule = this._include.some((regexp) => regexp.test(requirePath));
const isIgnoredModule = this._ignore.some((ignore) => ignore === requirePath);
DebuggerΩ.prototype.shouldWrap = function (requirePath) {
var isNodeModule = module_1.default.builtinModules.includes(requirePath) || requirePath.includes('node_modules');
var isIncludedModule = this._include.some(function (regexp) { return regexp.test(requirePath); });
var isIgnoredModule = this._ignore.some(function (ignore) { return ignore === requirePath; });
return !((isNodeModule && !isIncludedModule) || isIgnoredModule);
}
wrap(module) {
const exports = module;
const exportFunctions = this._getFunctions(exports);
Object.keys(exportFunctions).forEach((functionName) => {
};
DebuggerΩ.prototype.wrap = function (module) {
var _this = this;
var exports = module;
var exportFunctions = this._getFunctions(exports);
Object.keys(exportFunctions).forEach(function (functionName) {
Object.defineProperty(exports, functionName, {
value: new Proxy(exports[functionName], {
apply: this._createFunctionCallWrap(functionName),
construct: this._createConstructorCallWrap(functionName)
apply: _this._createFunctionCallWrap(functionName),
construct: _this._createConstructorCallWrap(functionName)
})

@@ -33,43 +38,46 @@ });

return exports;
}
_createFunctionCallWrap(name) {
return (target, thisArg, args) => {
const startTime = performance.now();
this._logger.start(name, args);
const argNames = this._getArgNames(target);
const result = target.apply(thisArg, this._wrapArgs(argNames, args));
};
DebuggerΩ.prototype._createFunctionCallWrap = function (name) {
var _this = this;
return function (target, thisArg, args) {
var startTime = perf_hooks_1.performance.now();
_this._logger.start(name, args);
var argNames = _this._getArgNames(target);
var result = target.apply(thisArg, _this._wrapArgs(argNames, args));
if (isPromise(result)) {
return result.then((result) => {
const endTime = performance.now();
this._logger.end(name, startTime, endTime, result);
return result.then(function (result) {
var endTime = perf_hooks_1.performance.now();
_this._logger.end(name, startTime, endTime, result);
return result;
});
}
const endTime = performance.now();
this._logger.end(name, startTime, endTime, result);
var endTime = perf_hooks_1.performance.now();
_this._logger.end(name, startTime, endTime, result);
return result;
};
}
_createConstructorCallWrap(name) {
return (target, args) => {
const startTime = performance.now();
this._logger.start(name, args);
const proto = target.prototype;
const prototypeFunctions = this._getFunctions(proto);
Object.keys(prototypeFunctions).forEach((functionName) => {
};
DebuggerΩ.prototype._createConstructorCallWrap = function (name) {
var _this = this;
return function (target, args) {
var startTime = perf_hooks_1.performance.now();
_this._logger.start(name, args);
var proto = target.prototype;
var prototypeFunctions = _this._getFunctions(proto);
Object.keys(prototypeFunctions).forEach(function (functionName) {
Object.defineProperty(proto, functionName, {
value: new Proxy(proto[functionName], {
apply: this._createFunctionCallWrap(`${name}.${functionName}`)
apply: _this._createFunctionCallWrap(name + "." + functionName)
})
});
});
const argNames = this._getArgNames(target);
const instance = new target(...this._wrapArgs(argNames, args));
const endTime = performance.now();
this._logger.end(name, startTime, endTime, instance);
var argNames = _this._getArgNames(target);
var instance = new (target.bind.apply(target, tslib_1.__spreadArrays([void 0], _this._wrapArgs(argNames, args))))();
var endTime = perf_hooks_1.performance.now();
_this._logger.end(name, startTime, endTime, instance);
return instance;
};
}
_wrapArgs(argNames, args) {
return args.map((arg, index) => {
};
DebuggerΩ.prototype._wrapArgs = function (argNames, args) {
var _this = this;
return args.map(function (arg, index) {
if (!isFunction(arg)) {

@@ -79,32 +87,34 @@ return arg;

return new Proxy(arg, {
apply: this._createFunctionCallWrap(argNames[index])
apply: _this._createFunctionCallWrap(argNames[index])
});
});
}
_getArgNames(target) {
let parsed;
};
DebuggerΩ.prototype._getArgNames = function (target) {
var parsed;
try {
parsed = parseScript(`const f = ${target.toString()}`);
parsed = esprima_1.parseScript("const f = " + target.toString());
}
catch (_a) {
parsed = parseScript(`class F { ${target.toString()} }`);
parsed = esprima_1.parseScript("class F { " + target.toString() + " }");
}
const [func] = query(parsed, '[type=/Function/]');
return func.params.map((param) => {
const [identifier] = query(param, 'Identifier');
var func = esquery_1.query(parsed, '[type=/Function/]')[0];
return func.params.map(function (param) {
var identifier = esquery_1.query(param, 'Identifier')[0];
return identifier.name;
});
}
_getFunctions(map) {
const functions = {};
};
DebuggerΩ.prototype._getFunctions = function (map) {
var functions = {};
Object.getOwnPropertyNames(map)
.filter((functionName) => isFunction(map[functionName]) && !types.isProxy(map[functionName]))
.forEach((functionName) => {
.filter(function (functionName) { return isFunction(map[functionName]) && !util_1.types.isProxy(map[functionName]); })
.forEach(function (functionName) {
functions[functionName] = map[functionName];
});
return functions;
}
}
};
return DebuggerΩ;
}());
exports.DebuggerΩ = DebuggerΩ;
function isPromise(value) {
return types.isPromise(value);
return util_1.types.isPromise(value);
}

@@ -111,0 +121,0 @@ function isFunction(value) {

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

export { debug } from './debug';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debug = void 0;
var debug_1 = require("./debug");
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_1.debug; } });
//# sourceMappingURL=index.js.map

@@ -1,6 +0,10 @@

import * as fs from 'fs';
import * as path from 'path';
import { inspect } from 'util';
export class DebugLoggerΩ {
constructor(options) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebugLoggerΩ = void 0;
var tslib_1 = require("tslib");
var fs = tslib_1.__importStar(require("fs"));
var path = tslib_1.__importStar(require("path"));
var util_1 = require("util");
var DebugLoggerΩ = /** @class */ (function () {
function DebugLoggerΩ(options) {
this._depth = 0;

@@ -11,29 +15,29 @@ this._time = options.time || false;

}
raw(logString) {
DebugLoggerΩ.prototype.raw = function (logString) {
this._logger(logString);
}
start(name, args) {
};
DebugLoggerΩ.prototype.start = function (name, args) {
this._depth += 1;
let debugString = this._printDepth(name);
var debugString = this._printDepth(name);
if (this._values) {
debugString += ` args: ${this._printObject(args)}`;
debugString += " args: " + this._printObject(args);
}
this._logger(debugString);
}
end(name, startTime, endTime, result) {
let debugString = this._printDepth(name);
};
DebugLoggerΩ.prototype.end = function (name, startTime, endTime, result) {
var debugString = this._printDepth(name);
if (this._time) {
debugString += ` time: ${endTime - startTime}ms`;
debugString += " time: " + (endTime - startTime) + "ms";
}
if (this._values) {
debugString += ` return: ${this._printObject(result)}`;
debugString += " return: " + this._printObject(result);
}
this._logger(debugString);
this._depth -= 1;
}
_getLogger(relativeLogPath) {
};
DebugLoggerΩ.prototype._getLogger = function (relativeLogPath) {
if (relativeLogPath) {
const absoluteLogPath = path.resolve(process.cwd(), relativeLogPath);
var absoluteLogPath_1 = path.resolve(process.cwd(), relativeLogPath);
return function (logString) {
fs.appendFileSync(absoluteLogPath, `${logString}\n`);
fs.appendFileSync(absoluteLogPath_1, logString + "\n");
};

@@ -43,13 +47,15 @@ }

return function (logString) {
process.stdout.write(`${logString}\n`);
process.stdout.write(logString + "\n");
};
}
}
_printDepth(name) {
return `${'▸'.repeat(this._depth)} ${name}`;
}
_printObject(object) {
return inspect(object, { getters: true, depth: Infinity }).replace(/\n/g, '');
}
}
};
DebugLoggerΩ.prototype._printDepth = function (name) {
return '▸'.repeat(this._depth) + " " + name;
};
DebugLoggerΩ.prototype._printObject = function (object) {
return util_1.inspect(object, { getters: true, depth: Infinity }).replace(/\n/g, '');
};
return DebugLoggerΩ;
}());
exports.DebugLoggerΩ = DebugLoggerΩ;
//# sourceMappingURL=logger.js.map

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

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
{
"name": "@phenomnomnominal/debug",
"version": "0.2.2",
"version": "0.2.3",
"description": "Very lazy tool for adding debug logging",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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