Files
oh-my-pi/packages/utils/test/fixtures/logger-cache-snapshot.ts
T
can1357 e9888367d1 refactor: migrated packages to internal utility modules and removed external dependencies
- Implemented in-house, zero-dependency utility modules in `pi-utils` covering DOM manipulation, markdown parsing, templating, browser automation helpers, and terminal buffers.
- Migrated packages across the repository to consume the new internal utilities and `omptype` schema validators instead of external dependencies.
- Removed multiple external runtime and development dependencies including Zod, Marked, LRU cache, Turndown, and Puppeteer browser packages.
2026-08-05 13:39:09 +02:00

40 lines
1.1 KiB
TypeScript

import * as fs from "node:fs";
import * as nodeModule from "node:module";
interface ModuleConstructorWithCache {
readonly _cache: Record<string, object>;
}
export interface CacheFamily {
readonly modules: number;
readonly bytes: number;
readonly paths: string[];
}
export interface LoggerCacheSnapshot {
readonly rotatingFile: CacheFamily;
readonly externalLogger: CacheFamily;
readonly externalRotator: CacheFamily;
}
const moduleCache = (nodeModule.Module as unknown as ModuleConstructorWithCache)._cache;
function snapshotFamily(segment: string): CacheFamily {
const paths = Object.keys(moduleCache)
.filter(modulePath => modulePath.replaceAll("\\", "/").includes(segment))
.sort();
return {
modules: paths.length,
bytes: paths.reduce((total, modulePath) => total + fs.statSync(modulePath).size, 0),
paths,
};
}
export function snapshotLoggerRuntime(): LoggerCacheSnapshot {
return {
rotatingFile: snapshotFamily("/packages/utils/src/logger/rotating-file.ts"),
externalLogger: snapshotFamily("/node_modules/winston/"),
externalRotator: snapshotFamily("/node_modules/file-stream-rotator/"),
};
}