fmt(js): npm run fix on merge (#86935)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
hermes-seaeye[bot]
2026-08-15 11:39:10 +00:00
committed by GitHub
parent bda83a4737
commit 45af7a71fc
2 changed files with 16 additions and 1 deletions
+2
View File
@@ -10,6 +10,7 @@ import { clearStaleGitLocks, LOCK_NAMES, STALE_LOCK_MIN_AGE_MS } from './gitlock
function makeRepo(): string {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gitlock-test-'))
fs.mkdirSync(path.join(root, '.git'))
return root
}
@@ -18,6 +19,7 @@ function writeLock(root: string, name: string, ageMs: number): string {
fs.writeFileSync(p, '')
const t = new Date(Date.now() - ageMs)
fs.utimesSync(p, t, t)
return p
}
+14 -1
View File
@@ -25,19 +25,24 @@ function gitProcessRunning(): Promise<boolean> {
process.platform === 'win32'
? ['tasklist', ['/FI', 'IMAGENAME eq git.exe', '/FO', 'CSV']]
: ['pgrep', ['-x', 'git']]
execFile(cmd, args, { timeout: 10_000 }, (error, stdout) => {
if (process.platform === 'win32') {
// tasklist exits 0 either way; presence is signaled in stdout.
resolve(Boolean(stdout && stdout.toLowerCase().includes('git.exe')))
return
}
// pgrep: exit 0 = at least one match; 1 = none; other = probe failure.
// On probe failure stay conservative: report "running" so no lock is
// touched when we cannot tell.
if (error && (error as any).code === 1) {
resolve(false)
return
}
resolve(true)
})
})
@@ -47,13 +52,17 @@ function gitProcessRunning(): Promise<boolean> {
// Never throws: a lock we cannot stat or unlink is skipped.
export async function clearStaleGitLocks(
repoRoot: string,
{ minAgeMs = STALE_LOCK_MIN_AGE_MS, isGitRunning = gitProcessRunning }: {
{
minAgeMs = STALE_LOCK_MIN_AGE_MS,
isGitRunning = gitProcessRunning
}: {
minAgeMs?: number
isGitRunning?: () => Promise<boolean>
} = {}
): Promise<string[]> {
const gitDir = path.join(repoRoot, '.git')
const removed: string[] = []
try {
if (!fs.statSync(gitDir).isDirectory()) {
return removed
@@ -67,10 +76,13 @@ export async function clearStaleGitLocks(
}
const cutoff = Date.now() - minAgeMs
for (const name of LOCK_NAMES) {
const lockPath = path.join(gitDir, name)
try {
const st = fs.statSync(lockPath)
if (st.isFile() && st.mtimeMs < cutoff) {
fs.unlinkSync(lockPath)
removed.push(lockPath)
@@ -79,5 +91,6 @@ export async function clearStaleGitLocks(
// Missing or concurrently removed — skipping is always safe.
}
}
return removed
}