@phenomnomnominal/debug
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -5,28 +5,38 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var callsite_1 = tslib_1.__importDefault(require("callsite")); | ||
var module_1 = tslib_1.__importDefault(require("module")); | ||
var debugger_1 = require("./debugger"); | ||
var initialised = false; | ||
function debug(options) { | ||
if (options === void 0) { 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); | ||
} | ||
}); | ||
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; | ||
}; | ||
module_1.default.Module.prototype.require = Object.assign(debugRequire, original_1); | ||
var _a = callsite_1.default(), caller = _a[1]; | ||
if (!initialised) { | ||
init(options, caller); | ||
initialised = true; | ||
} | ||
} | ||
} | ||
exports.debug = debug; | ||
function init(options, caller) { | ||
var d = new debugger_1.DebuggerΩ(options); | ||
Object.keys(require.cache).forEach(function (requirePath) { | ||
var module = require.cache[requirePath]; | ||
var isCaller = requirePath === caller.getFileName(); | ||
if (module && !isCaller && d.shouldWrap(requirePath)) { | ||
d.wrap(module.exports); | ||
} | ||
}); | ||
var original = 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.apply(this, [id]); | ||
if (module && d.shouldWrap(requirePath)) { | ||
return d.wrap(module); | ||
} | ||
return module; | ||
}; | ||
module_1.default.Module.prototype.require = Object.assign(debugRequire, original); | ||
} | ||
//# sourceMappingURL=debug.js.map |
@@ -13,7 +13,6 @@ "use strict"; | ||
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; | ||
var _a = options.ignore, ignore = _a === void 0 ? [] : _a, _b = options.include, include = _b === void 0 ? [] : _b; | ||
this._include = include; | ||
this._ignore = ignore; | ||
this._logger = new logger_1.DebugLoggerΩ(options); | ||
this._logger.raw((header + " starting " + Date.now()).trimStart()); | ||
} | ||
@@ -24,3 +23,4 @@ DebuggerΩ.prototype.shouldWrap = function (requirePath) { | ||
var isIgnoredModule = this._ignore.some(function (ignore) { return ignore === requirePath; }); | ||
return !((isNodeModule && !isIncludedModule) || isIgnoredModule); | ||
var isDebuggerModule = requirePath.includes(__dirname); | ||
return !(isDebuggerModule || (isNodeModule && !isIncludedModule) || isIgnoredModule); | ||
}; | ||
@@ -27,0 +27,0 @@ DebuggerΩ.prototype.wrap = function (module) { |
@@ -7,4 +7,6 @@ import { DebugOptions } from './types'; | ||
private _values; | ||
private _name; | ||
constructor(options: Partial<DebugOptions>); | ||
raw(logString: string): void; | ||
name(): number; | ||
private _raw; | ||
start(name: string, args: Array<unknown>): void; | ||
@@ -11,0 +13,0 @@ end(name: string, startTime: number, endTime: number, result: unknown): void; |
@@ -8,10 +8,17 @@ "use strict"; | ||
var util_1 = require("util"); | ||
var index = 0; | ||
var DebugLoggerΩ = /** @class */ (function () { | ||
function DebugLoggerΩ(options) { | ||
this._depth = 0; | ||
var _a = options.header, header = _a === void 0 ? '' : _a; | ||
this._time = options.time || false; | ||
this._values = options.values || false; | ||
this._logger = options.logger || this._getLogger(options.logPath); | ||
this._raw((header + " starting " + Date.now()).trimStart()); | ||
this._name = index++; | ||
} | ||
DebugLoggerΩ.prototype.raw = function (logString) { | ||
DebugLoggerΩ.prototype.name = function () { | ||
return this._name; | ||
}; | ||
DebugLoggerΩ.prototype._raw = function (logString) { | ||
this._logger(logString); | ||
@@ -40,3 +47,5 @@ }; | ||
if (relativeLogPath) { | ||
var absoluteLogPath_1 = path.resolve(process.cwd(), relativeLogPath); | ||
var _a = path.parse(relativeLogPath), dir = _a.dir, name_1 = _a.name, ext = _a.ext; | ||
var logPath = "" + dir + path.sep + name_1 + "." + Date.now() + ext; | ||
var absoluteLogPath_1 = path.resolve(process.cwd(), logPath); | ||
return function (logString) { | ||
@@ -43,0 +52,0 @@ fs.appendFileSync(absoluteLogPath_1, logString + "\n"); |
{ | ||
"name": "@phenomnomnominal/debug", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Very lazy tool for adding debug logging", | ||
@@ -34,2 +34,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@types/callsite": "^1.0.30", | ||
"@types/eslint": "^7.2.4", | ||
@@ -50,2 +51,3 @@ "@types/esprima": "^4.0.2", | ||
"dependencies": { | ||
"callsite": "^1.0.0", | ||
"esprima": "^4.0.1", | ||
@@ -52,0 +54,0 @@ "esquery": "^1.3.1", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24233
294
4
14
+ Addedcallsite@^1.0.0
+ Addedcallsite@1.0.0(transitive)