import { readFileSync, writeFileSync, unlinkSync, existsSync, mkdirSync } from 'node:fs';
import { dirname } from 'node:path';
const defaultDeps = {
    readFileSync: (path, encoding) => readFileSync(path, encoding),
    writeFileSync,
    unlinkSync,
    existsSync,
    mkdirSync: (path, options) => mkdirSync(path, options),
};
export function readPidFile(pidPath, deps = defaultDeps) {
    if (!deps.existsSync(pidPath)) {
        return null;
    }
    try {
        const raw = deps.readFileSync(pidPath, 'utf-8');
        return JSON.parse(raw);
    }
    catch {
        return null;
    }
}
export function writePidFile(pidPath, content, deps = defaultDeps) {
    deps.mkdirSync(dirname(pidPath), { recursive: true });
    deps.writeFileSync(pidPath, JSON.stringify(content, null, 2));
}
export function removePidFile(pidPath, deps = defaultDeps) {
    if (deps.existsSync(pidPath)) {
        deps.unlinkSync(pidPath);
    }
}
export function pidFileExists(pidPath, deps = defaultDeps) {
    return deps.existsSync(pidPath);
}
//# sourceMappingURL=pidFileManager.js.map