UNPKG

repomix

Version:

A tool to pack repository contents to single file for AI consumption

50 lines 2.41 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { logger } from '../../shared/logger.js'; import { initTaskRunner } from '../../shared/processConcurrency.js'; /** * Calculate token count for git diffs if included */ export const calculateGitDiffMetrics = (config_1, gitDiffResult_1, ...args_1) => __awaiter(void 0, [config_1, gitDiffResult_1, ...args_1], void 0, function* (config, gitDiffResult, deps = { initTaskRunner, }) { var _a; if (!((_a = config.output.git) === null || _a === void 0 ? void 0 : _a.includeDiffs) || !gitDiffResult) { return 0; } // Check if we have any diff content to process if (!gitDiffResult.workTreeDiffContent && !gitDiffResult.stagedDiffContent) { return 0; } const taskRunner = deps.initTaskRunner(1, // Single task for git diff calculation new URL('./workers/gitDiffMetricsWorker.js', import.meta.url).href); try { const startTime = process.hrtime.bigint(); logger.trace('Starting git diff token calculation using worker'); const result = yield taskRunner.run({ workTreeDiffContent: gitDiffResult.workTreeDiffContent, stagedDiffContent: gitDiffResult.stagedDiffContent, encoding: config.tokenCount.encoding, }); const endTime = process.hrtime.bigint(); const duration = Number(endTime - startTime) / 1e6; logger.trace(`Git diff token calculation completed in ${duration.toFixed(2)}ms`); return result; } catch (error) { logger.error('Error during git diff token calculation:', error); throw error; } finally { // Always cleanup worker pool yield taskRunner.cleanup(); } }); //# sourceMappingURL=calculateGitDiffMetrics.js.map