UNPKG

@nodesecure/scanner

Version:

A package API to run a static analysis of your module's dependencies.

53 lines 1.39 kB
// Import Node.js Dependencies import { EventEmitter } from "node:events"; import { performance } from "node:perf_hooks"; export const ScannerLoggerEvents = { error: "error", done: "depWalkerFinished", analysis: { tree: "walkTree", tarball: "tarball", registry: "registry" }, manifest: { read: "readManifest", fetch: "fetchManifest" } }; export class Logger extends EventEmitter { events = new Map(); start(eventName) { if (this.events.has(eventName)) { return this; } this.events.set(eventName, { startedAt: performance.now(), count: 0 }); this.emit("start", eventName); return this; } tick(eventName) { if (!this.events.has(eventName)) { return this; } this.events.get(eventName).count++; this.emit("tick", eventName); return this; } count(eventName) { return this.events.get(eventName)?.count ?? 0; } end(eventName) { if (!this.events.has(eventName)) { return this; } const data = this.events.get(eventName); this.emit("end", eventName, { ...data, executionTime: performance.now() - data.startedAt }); return this; } } //# sourceMappingURL=logger.class.js.map