UNPKG

@jjdenhertog/ai-driven-development

Version:

AI-driven development workflow with learning capabilities for Claude

63 lines 2.6 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGitInstance = getGitInstance; exports.cleanupGitInstances = cleanupGitInstances; const simple_git_1 = __importDefault(require("simple-git")); // Cache for git instances by path const gitInstanceCache = new Map(); /** * Get or create a git instance for a specific directory * @param baseDir - The base directory for git operations (defaults to process.cwd()) */ function getGitInstance(baseDir) { const path = baseDir || process.cwd(); // Check if we already have an instance for this path const cached = gitInstanceCache.get(path); if (cached) { return cached.instance; } // Create new AbortController for this instance const controller = new AbortController(); // Create new instance with abort signal and timeout const instance = (0, simple_git_1.default)({ baseDir: path, binary: 'git', maxConcurrentProcesses: 6, abort: controller.signal, timeout: { block: 60000, // 60 seconds timeout for blocking operations }, }); gitInstanceCache.set(path, { instance, controller }); return instance; } /** * Clean up all git instances to allow process to exit cleanly */ function cleanupGitInstances() { return __awaiter(this, void 0, void 0, function* () { // Abort all pending git operations for (const [, { controller }] of gitInstanceCache) { controller.abort(); } // Clear the cache gitInstanceCache.clear(); // Give a small delay to ensure processes are terminated yield new Promise(resolve => { setTimeout(resolve, 100); }); }); } //# sourceMappingURL=getGitInstance.js.map