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.1 to 0.2.2

38

dist/debug.js

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

"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 = {}; }
import nodeModule from 'module';
import { DebuggerΩ } from './debugger';
export function debug(options = {}) {
if (options.enabled) {
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 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 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);
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);
}
return module;
};
module_1.default.Module.prototype.require = Object.assign(debugRequire, original_1);
nodeModule.Module.prototype.require = Object.assign(debugRequire, original);
}
}
exports.debug = debug;
//# sourceMappingURL=debug.js.map

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

"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;
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;
this._include = include;
this._ignore = ignore;
this._logger = new logger_1.DebugLoggerΩ(options);
this._logger.raw((header + " starting " + Date.now()).trimStart());
this._logger = new DebugLoggerΩ(options);
this._logger.raw(`${header} starting ${Date.now()}`.trimStart());
}
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; });
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);
return !((isNodeModule && !isIncludedModule) || isIgnoredModule);
};
DebuggerΩ.prototype.wrap = function (module) {
var _this = this;
var exports = module;
var exportFunctions = this._getFunctions(exports);
Object.keys(exportFunctions).forEach(function (functionName) {
}
wrap(module) {
const exports = module;
const exportFunctions = this._getFunctions(exports);
Object.keys(exportFunctions).forEach((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)
})

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

return exports;
};
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));
}
_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));
if (isPromise(result)) {
return result.then(function (result) {
var endTime = perf_hooks_1.performance.now();
_this._logger.end(name, startTime, endTime, result);
return result.then((result) => {
const endTime = performance.now();
this._logger.end(name, startTime, endTime, result);
return result;
});
}
var endTime = perf_hooks_1.performance.now();
_this._logger.end(name, startTime, endTime, result);
const endTime = performance.now();
this._logger.end(name, startTime, endTime, result);
return result;
};
};
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) {
}
_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) => {
Object.defineProperty(proto, functionName, {
value: new Proxy(proto[functionName], {
apply: _this._createFunctionCallWrap(name + "." + functionName)
apply: this._createFunctionCallWrap(`${name}.${functionName}`)
})
});
});
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);
const argNames = this._getArgNames(target);
const instance = new target(...this._wrapArgs(argNames, args));
const endTime = performance.now();
this._logger.end(name, startTime, endTime, instance);
return instance;
};
};
DebuggerΩ.prototype._wrapArgs = function (argNames, args) {
var _this = this;
return args.map(function (arg, index) {
}
_wrapArgs(argNames, args) {
return args.map((arg, index) => {
if (!isFunction(arg)) {

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

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

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

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

"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; } });
export { debug } from './debug';
//# sourceMappingURL=index.js.map

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

"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) {
import * as fs from 'fs';
import * as path from 'path';
import { inspect } from 'util';
export class DebugLoggerΩ {
constructor(options) {
this._depth = 0;

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

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

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

return function (logString) {
process.stdout.write(logString + "\n");
process.stdout.write(`${logString}\n`);
};
}
};
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Ω;
}
_printDepth(name) {
return `${'▸'.repeat(this._depth)} ${name}`;
}
_printObject(object) {
return inspect(object, { getters: true, depth: Infinity }).replace(/\n/g, '');
}
}
//# sourceMappingURL=logger.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};
//# sourceMappingURL=types.js.map
{
"name": "@phenomnomnominal/debug",
"version": "0.2.1",
"version": "0.2.2",
"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