@antelopejs/tooling-configs 0.5.8 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -49
- package/dist/{api-CCOiLN3w.mjs → api-BQLrI_S1.mjs} +19 -2
- package/dist/bin/api-diff.mjs +155 -37
- package/dist/bin/body-check.mjs +6 -3
- package/dist/bin/check-size.mjs +1 -1
- package/dist/bin/checks.mjs +1 -1
- package/dist/bin/comment-proof.mjs +3 -5
- package/dist/bin/garden.mjs +86 -34
- package/dist/bin/lease.mjs +314 -26
- package/dist/bin/ratchet.mjs +4 -4
- package/dist/bin/readme-strip.mjs +1 -1
- package/dist/bin/suppressions.mjs +10 -6
- package/dist/bin/sync.mjs +23 -98
- package/dist/bin/triage.mjs +1 -1
- package/dist/bin/verify.mjs +1 -1
- package/dist/{checks-BC-F8bsv.mjs → checks-BefrkjiT.mjs} +729 -25
- package/dist/{docs-compat-Ft1r2sf0.mjs → docs-compat-CSljVi3O.mjs} +13 -8
- package/dist/eslint.d.mts +13 -4
- package/dist/eslint.mjs +48 -6
- package/dist/guardrails-BfGwehVj.mjs +2414 -0
- package/dist/installed-typescript-6MtIWlE4.mjs +84 -0
- package/dist/oxc/anti-slop/index.mjs +541 -34
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +2 -1854
- package/dist/oxc/lint.d.mts +10 -1
- package/dist/oxc/lint.mjs +13 -5
- package/dist/{oxlint-CCOJqj3d.mjs → oxlint-CkHhK5K_.mjs} +33 -11
- package/dist/{package-DnxZ2CXZ.mjs → package-DDG3YH7W.mjs} +10 -5
- package/dist/{ports-DGP6bPJy.mjs → ports-DAeEJsYh.mjs} +22 -0
- package/dist/{proof-stamp-lyD84zmj.mjs → proof-stamp-BFV7JTZT.mjs} +5 -4
- package/dist/{ratchet-SQ7vTR0i.mjs → ratchet-2FeMs1kh.mjs} +4 -3
- package/dist/{suppression-base-whhvw-IJ.mjs → suppression-base-CYaLZAq7.mjs} +2 -2
- package/dist/{suppression-budget-CtIYSoDO.mjs → suppression-budget-CPDSFg4X.mjs} +1 -1
- package/dist/{suppressions-C79kRvYI.mjs → suppressions-CxPnh4sC.mjs} +2 -2
- package/dist/{templates-Dg188oRC.mjs → templates-HG0fel2S.mjs} +1 -1
- package/dist/{type-aware-rules-DMuN6sHb.mjs → type-aware-rules-Da3769fI.mjs} +9 -1
- package/dist/{typescript--_8og8AM.mjs → typescript-CxfNxyr2.mjs} +59 -98
- package/dist/{workflow-CPcNc8KL.mjs → workflow-C-oBwL2H.mjs} +25 -1
- package/package.json +9 -5
- package/dist/bin/check-interface-ranges.d.mts +0 -1
- package/dist/bin/check-interface-ranges.mjs +0 -44
- package/dist/interface-ranges-CcVSr59f.mjs +0 -116
package/dist/bin/lease.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
3
|
-
import { a as closeServer, c as LOCK_PORT, d as isRole, f as leaseHome, i as claimPort, l as PORT_ROLES, m as parseRecord, n as bindable, o as listenerPids, p as leaseId, r as chooseBlock, s as listensOn, t as accepting, u as isLeaseId } from "../ports-
|
|
3
|
+
import { a as closeServer, c as LOCK_PORT, d as isRole, f as leaseHome, i as claimPort, l as PORT_ROLES, m as parseRecord, n as bindable, o as listenerPids, p as leaseId, r as chooseBlock, s as listensOn, t as accepting, u as isLeaseId } from "../ports-DAeEJsYh.mjs";
|
|
4
4
|
import { a as isServerRole, l as unmarked, o as leaseEnv, s as leaseMarker } from "../env-DT0UJNeL.mjs";
|
|
5
5
|
import { accessSync, closeSync, constants, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, writeFileSync } from "node:fs";
|
|
6
|
-
import { delimiter, join, win32 } from "node:path";
|
|
6
|
+
import { delimiter, join, resolve, win32 } from "node:path";
|
|
7
7
|
import { execFileSync, spawn } from "node:child_process";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
8
9
|
import { homedir } from "node:os";
|
|
9
10
|
import { parseArgs } from "node:util";
|
|
10
11
|
import { setTimeout } from "node:timers/promises";
|
|
@@ -281,13 +282,228 @@ function assertSignallable(pid) {
|
|
|
281
282
|
if (!Number.isInteger(pid) || pid <= 1) throw new Error(`antelopejs-lease: refusing to signal pid ${String(pid)}`);
|
|
282
283
|
}
|
|
283
284
|
//#endregion
|
|
285
|
+
//#region src/lease/windows.ts
|
|
286
|
+
const SOURCE = String.raw`using System;
|
|
287
|
+
using System.Collections.Generic;
|
|
288
|
+
using System.Diagnostics;
|
|
289
|
+
using System.Runtime.InteropServices;
|
|
290
|
+
using System.Text;
|
|
291
|
+
|
|
292
|
+
public static class AntelopeLease {
|
|
293
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
294
|
+
struct Basic { public IntPtr ExitStatus; public IntPtr Peb; public IntPtr Affinity; public IntPtr Priority; public IntPtr Pid; public IntPtr Parent; }
|
|
295
|
+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
296
|
+
struct Startup { public int cb; public string reserved; public string desktop; public string title; public int x; public int y; public int width; public int height; public int columns; public int rows; public int fill; public int flags; public short show; public short reserved2; public IntPtr reserved3; public IntPtr input; public IntPtr output; public IntPtr error; }
|
|
297
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
298
|
+
struct Created { public IntPtr process; public IntPtr thread; public int pid; public int tid; }
|
|
299
|
+
|
|
300
|
+
[DllImport("ntdll.dll")] static extern int NtQueryInformationProcess(IntPtr h, int kind, ref Basic info, int size, out int written);
|
|
301
|
+
[DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr OpenProcess(int access, bool inherit, int pid);
|
|
302
|
+
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr h);
|
|
303
|
+
[DllImport("kernel32.dll")] static extern bool ReadProcessMemory(IntPtr h, IntPtr at, byte[] buffer, IntPtr size, out IntPtr read);
|
|
304
|
+
[DllImport("kernel32.dll")] static extern bool GetProcessTimes(IntPtr h, out long created, out long exited, out long kernel, out long user);
|
|
305
|
+
[DllImport("kernel32.dll")] static extern bool TerminateProcess(IntPtr h, uint code);
|
|
306
|
+
[DllImport("kernel32.dll")] static extern uint WaitForSingleObject(IntPtr h, uint ms);
|
|
307
|
+
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] static extern bool CreateProcessW(string app, StringBuilder line, IntPtr processAttributes, IntPtr threadAttributes, bool inherit, int flags, IntPtr env, string cwd, ref Startup startup, out Created created);
|
|
308
|
+
|
|
309
|
+
const int TERMINATE = 0x1, READ = 0x10, QUERY = 0x400, LIMITED = 0x1000, SYNCHRONIZE = 0x100000;
|
|
310
|
+
const int DETACHED_PROCESS = 0x8, CREATE_NEW_PROCESS_GROUP = 0x200, INVALID_PARAMETER = 87;
|
|
311
|
+
const int MAX_ENVIRONMENT = 1 << 20;
|
|
312
|
+
|
|
313
|
+
static byte[] Read(IntPtr h, long at, int size) {
|
|
314
|
+
var buffer = new byte[size];
|
|
315
|
+
IntPtr read;
|
|
316
|
+
if (at == 0 || !ReadProcessMemory(h, new IntPtr(at), buffer, new IntPtr(size), out read) || read.ToInt64() != size) return null;
|
|
317
|
+
return buffer;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
static long Pointer(IntPtr h, long at) {
|
|
321
|
+
var bytes = Read(h, at, 8);
|
|
322
|
+
return bytes == null ? 0 : BitConverter.ToInt64(bytes, 0);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
static string Text(IntPtr h, long at, long size) {
|
|
326
|
+
if (size <= 0) return "";
|
|
327
|
+
var bytes = Read(h, at, (int)Math.Min(size, MAX_ENVIRONMENT));
|
|
328
|
+
return bytes == null ? "" : Encoding.Unicode.GetString(bytes);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
static long Creation(IntPtr h) {
|
|
332
|
+
long created, exited, kernel, user;
|
|
333
|
+
return GetProcessTimes(h, out created, out exited, out kernel, out user) ? created : 0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
static string Line(IntPtr h, long parameters) {
|
|
337
|
+
var length = Read(h, parameters + 0x70, 2);
|
|
338
|
+
if (length == null) return "";
|
|
339
|
+
return Text(h, Pointer(h, parameters + 0x78), BitConverter.ToUInt16(length, 0)).Replace('\t', ' ').Replace('\r', ' ').Replace('\n', ' ');
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
static bool Holds(IntPtr h, long parameters, string marker) {
|
|
343
|
+
if (marker.Length == 0) return false;
|
|
344
|
+
var environment = Text(h, Pointer(h, parameters + 0x80), Pointer(h, parameters + 0x3F0));
|
|
345
|
+
return Array.IndexOf(environment.Split('\0'), marker) >= 0;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
static void Describe(int pid, string marker) {
|
|
349
|
+
IntPtr h = OpenProcess(QUERY | READ | SYNCHRONIZE, false, pid);
|
|
350
|
+
if (h == IntPtr.Zero) return;
|
|
351
|
+
try {
|
|
352
|
+
if (WaitForSingleObject(h, 0) == 0) return;
|
|
353
|
+
var info = new Basic();
|
|
354
|
+
int written;
|
|
355
|
+
if (NtQueryInformationProcess(h, 0, ref info, Marshal.SizeOf(info), out written) != 0) return;
|
|
356
|
+
long parameters = Pointer(h, info.Peb.ToInt64() + 0x20);
|
|
357
|
+
string command = parameters == 0 ? "" : Line(h, parameters);
|
|
358
|
+
bool marked = parameters != 0 && Holds(h, parameters, marker);
|
|
359
|
+
Console.Out.Write(pid + "\t" + info.Parent.ToInt64() + "\t" + Creation(h) + "\t" + (marked ? "1" : "0") + "\t" + command + "\n");
|
|
360
|
+
} finally {
|
|
361
|
+
CloseHandle(h);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
public static void List(string marker) {
|
|
366
|
+
if (IntPtr.Size != 8) throw new PlatformNotSupportedException("antelopejs-lease reads process tables from a 64-bit PowerShell only");
|
|
367
|
+
foreach (var process in Process.GetProcesses()) {
|
|
368
|
+
int pid = process.Id;
|
|
369
|
+
process.Dispose();
|
|
370
|
+
Describe(pid, marker);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
public static void Kill(string targets, int ms) {
|
|
375
|
+
var held = new List<KeyValuePair<int, IntPtr>>();
|
|
376
|
+
foreach (var target in targets.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) {
|
|
377
|
+
var parts = target.Split(':');
|
|
378
|
+
int pid = int.Parse(parts[0]);
|
|
379
|
+
IntPtr h = OpenProcess(TERMINATE | LIMITED | SYNCHRONIZE, false, pid);
|
|
380
|
+
if (h == IntPtr.Zero) {
|
|
381
|
+
if (Marshal.GetLastWin32Error() != INVALID_PARAMETER) Console.Out.Write(pid + "\n");
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (Creation(h).ToString() != parts[1]) {
|
|
385
|
+
CloseHandle(h);
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
TerminateProcess(h, 1);
|
|
389
|
+
held.Add(new KeyValuePair<int, IntPtr>(pid, h));
|
|
390
|
+
}
|
|
391
|
+
var deadline = DateTime.UtcNow.AddMilliseconds(ms);
|
|
392
|
+
foreach (var pair in held) {
|
|
393
|
+
var left = Math.Max(0, (deadline - DateTime.UtcNow).TotalMilliseconds);
|
|
394
|
+
if (WaitForSingleObject(pair.Value, (uint)left) != 0) Console.Out.Write(pair.Key + "\n");
|
|
395
|
+
CloseHandle(pair.Value);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
public static void Start(string line) {
|
|
400
|
+
var startup = new Startup();
|
|
401
|
+
startup.cb = Marshal.SizeOf(startup);
|
|
402
|
+
Created created;
|
|
403
|
+
if (!CreateProcessW(null, new StringBuilder(line), IntPtr.Zero, IntPtr.Zero, false, DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, IntPtr.Zero, null, ref startup, out created))
|
|
404
|
+
throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
|
|
405
|
+
CloseHandle(created.thread);
|
|
406
|
+
CloseHandle(created.process);
|
|
407
|
+
Console.Out.Write(created.pid + "\n");
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
`;
|
|
411
|
+
const SCRIPT = [
|
|
412
|
+
"$ErrorActionPreference = 'Stop'",
|
|
413
|
+
"[Console]::OutputEncoding = New-Object Text.UTF8Encoding $false",
|
|
414
|
+
"$source = $env:ANTELOPEJS_LEASE_WIN_SOURCE",
|
|
415
|
+
"$op = $env:ANTELOPEJS_LEASE_WIN_OP",
|
|
416
|
+
"$arg = $env:ANTELOPEJS_LEASE_WIN_ARG",
|
|
417
|
+
"$wait = [int]$env:ANTELOPEJS_LEASE_WIN_WAIT",
|
|
418
|
+
"$name = Join-Path ([IO.Path]::GetTempPath()) ('antelopejs-lease-' + $env:ANTELOPEJS_LEASE_WIN_HASH)",
|
|
419
|
+
"$dll = $name + '.dll'",
|
|
420
|
+
"Remove-Item Env:ANTELOPEJS_LEASE_WIN_*",
|
|
421
|
+
"if (-not (Test-Path $dll)) { $own = $name + '-' + $PID + '.dll'; Add-Type -TypeDefinition $source -OutputAssembly $own; try { Move-Item $own $dll -ErrorAction Stop } catch { $dll = $own } }",
|
|
422
|
+
"Add-Type -Path $dll",
|
|
423
|
+
"switch ($op) { 'list' { [AntelopeLease]::List($arg) } 'kill' { [AntelopeLease]::Kill($arg, $wait) } 'start' { [AntelopeLease]::Start($arg) } }"
|
|
424
|
+
].join("; ");
|
|
425
|
+
const HASH = createHash("sha256").update(SOURCE).digest("hex").slice(0, 16);
|
|
426
|
+
const TIMEOUT_MS = 12e4;
|
|
427
|
+
const MAX_OUTPUT_BYTES = 67108864;
|
|
428
|
+
function powershell(op, arg, wait = 0, cwd) {
|
|
429
|
+
const root = process.env.SystemRoot ?? "C:\\Windows";
|
|
430
|
+
return execFileSync(join(root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"), [
|
|
431
|
+
"-NoProfile",
|
|
432
|
+
"-NonInteractive",
|
|
433
|
+
"-ExecutionPolicy",
|
|
434
|
+
"Bypass",
|
|
435
|
+
"-Command",
|
|
436
|
+
SCRIPT
|
|
437
|
+
], {
|
|
438
|
+
encoding: "utf8",
|
|
439
|
+
env: {
|
|
440
|
+
...unmarked(process.env),
|
|
441
|
+
ANTELOPEJS_LEASE_WIN_SOURCE: SOURCE,
|
|
442
|
+
ANTELOPEJS_LEASE_WIN_HASH: HASH,
|
|
443
|
+
ANTELOPEJS_LEASE_WIN_OP: op,
|
|
444
|
+
ANTELOPEJS_LEASE_WIN_ARG: arg,
|
|
445
|
+
ANTELOPEJS_LEASE_WIN_WAIT: String(wait)
|
|
446
|
+
},
|
|
447
|
+
cwd,
|
|
448
|
+
maxBuffer: MAX_OUTPUT_BYTES,
|
|
449
|
+
stdio: [
|
|
450
|
+
"ignore",
|
|
451
|
+
"pipe",
|
|
452
|
+
"pipe"
|
|
453
|
+
],
|
|
454
|
+
timeout: TIMEOUT_MS,
|
|
455
|
+
windowsHide: true
|
|
456
|
+
}).split(/\r?\n/u).filter(Boolean);
|
|
457
|
+
}
|
|
458
|
+
function parseProcess(line) {
|
|
459
|
+
const [pid, ppid, start, marked, ...command] = line.split(" ");
|
|
460
|
+
if (start === void 0 || start === "0") return [];
|
|
461
|
+
return [{
|
|
462
|
+
pid: Number(pid),
|
|
463
|
+
ppid: Number(ppid),
|
|
464
|
+
start,
|
|
465
|
+
command: command.join(" ").replace(/\s+/gu, " ").trim(),
|
|
466
|
+
marked: marked === "1"
|
|
467
|
+
}];
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* The live processes this user may open and read, with whether the environment of each holds the
|
|
471
|
+
* `marker` entry (`NAME=value`) exactly. Reads each process's environment and command line from
|
|
472
|
+
* its process parameters, as `/proc/<pid>/environ` and `cmdline` give them on Linux.
|
|
473
|
+
*/
|
|
474
|
+
function windowsProcesses(marker = "") {
|
|
475
|
+
return powershell("list", marker).flatMap(parseProcess);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Terminates each target still running under the start time it was found with, holding its handle
|
|
479
|
+
* from the check to the kill so a reused pid is never reached, and waits up to `ms` for each to
|
|
480
|
+
* exit. Answers the pids still running then.
|
|
481
|
+
*/
|
|
482
|
+
function windowsTerminate(targets, ms) {
|
|
483
|
+
if (targets.length === 0) return [];
|
|
484
|
+
return powershell("kill", targets.map((target) => `${target.pid}:${target.start}`).join(","), ms).map(Number);
|
|
485
|
+
}
|
|
486
|
+
/** `arg` quoted for a Windows command line, read back unchanged by the C runtime's parser. */
|
|
487
|
+
function quoteWindows(arg) {
|
|
488
|
+
if (arg !== "" && !/[\s"]/u.test(arg)) return arg;
|
|
489
|
+
return `"${arg.replace(/(\\*)"/gu, "$1$1\\\"").replace(/(\\+)$/u, "$1$1")}"`;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Starts `file` with `args` in `cwd` as a process that inherits no handle, has no console, and is
|
|
493
|
+
* no child of this process, with this process's environment less the lease marker. Answers its pid.
|
|
494
|
+
*/
|
|
495
|
+
function windowsStart(file, args, cwd) {
|
|
496
|
+
const [pid] = powershell("start", [file, ...args].map(quoteWindows).join(" "), 0, cwd);
|
|
497
|
+
return Number(pid);
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
284
500
|
//#region src/lease/mongo.ts
|
|
285
501
|
const READY_TIMEOUT_MS = 3e4;
|
|
286
502
|
const KILL_WAIT_MS$1 = 2e3;
|
|
287
503
|
const POLL_MS$1 = 50;
|
|
288
504
|
const STAT_START = 19;
|
|
289
505
|
const DEAD_STATES = /* @__PURE__ */ new Set(["Z", "X"]);
|
|
290
|
-
const CACHED_BINARY = /^mongod-.+-(\d+)\.(\d+)\.(\d+)
|
|
506
|
+
const CACHED_BINARY = /^mongod-.+-(\d+)\.(\d+)\.(\d+)(?:\.exe)?$/u;
|
|
291
507
|
function executable(path) {
|
|
292
508
|
try {
|
|
293
509
|
accessSync(path, constants.X_OK);
|
|
@@ -314,6 +530,13 @@ function newestCached(directory) {
|
|
|
314
530
|
}
|
|
315
531
|
return names.filter((name) => CACHED_BINARY.test(name)).sort(byNewestVersion).map((name) => join(directory, name)).find(executable);
|
|
316
532
|
}
|
|
533
|
+
function onPath(env) {
|
|
534
|
+
if (process.platform === "win32") {
|
|
535
|
+
const found = locateWindows("mongod", env);
|
|
536
|
+
return found.kind === "start" && !found.script ? found.file : void 0;
|
|
537
|
+
}
|
|
538
|
+
return (env.PATH ?? "").split(delimiter).filter(Boolean).map((directory) => join(directory, "mongod")).find(executable);
|
|
539
|
+
}
|
|
317
540
|
/**
|
|
318
541
|
* The mongod a lease runs: `MONGOMS_SYSTEM_BINARY`, else `mongod` on `PATH`, else the newest
|
|
319
542
|
* mongodb-memory-server download in `MONGOMS_DOWNLOAD_DIR` or `~/.cache/mongodb-binaries`.
|
|
@@ -321,7 +544,7 @@ function newestCached(directory) {
|
|
|
321
544
|
function findMongod(env) {
|
|
322
545
|
const system = env.MONGOMS_SYSTEM_BINARY;
|
|
323
546
|
if (system && executable(system)) return system;
|
|
324
|
-
return (env
|
|
547
|
+
return onPath(env) ?? newestCached(env.MONGOMS_DOWNLOAD_DIR || join(homedir(), ".cache", "mongodb-binaries"));
|
|
325
548
|
}
|
|
326
549
|
/** The command line of `pid`, empty once the process has exited, a zombie included. */
|
|
327
550
|
function commandLine(pid) {
|
|
@@ -345,10 +568,20 @@ function commandLine(pid) {
|
|
|
345
568
|
}
|
|
346
569
|
}
|
|
347
570
|
/**
|
|
348
|
-
* The
|
|
349
|
-
*
|
|
571
|
+
* The Windows process whose command line names `dbpath`. mongod holds its `mongod.lock` there
|
|
572
|
+
* unreadable, so the command line is the only record of which process serves the dbpath.
|
|
573
|
+
*/
|
|
574
|
+
function windowsMongod(dbpath) {
|
|
575
|
+
const argument = ` --dbpath ${quoteWindows(dbpath)} `;
|
|
576
|
+
return windowsProcesses().find((entry) => entry.command.includes(argument));
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* The pid of the mongod serving `dbpath`, read from the `mongod.lock` mongod writes there, or on
|
|
580
|
+
* Windows found by its command line. A pid is trusted only while its command line names `dbpath`,
|
|
581
|
+
* so a reused pid never counts.
|
|
350
582
|
*/
|
|
351
583
|
function mongodPid(dbpath) {
|
|
584
|
+
if (process.platform === "win32") return windowsMongod(dbpath)?.pid;
|
|
352
585
|
let text;
|
|
353
586
|
try {
|
|
354
587
|
text = readFileSync(join(dbpath, "mongod.lock"), "utf8").trim();
|
|
@@ -409,11 +642,18 @@ function signal$1(pid, name) {
|
|
|
409
642
|
return;
|
|
410
643
|
}
|
|
411
644
|
}
|
|
645
|
+
/** Terminates the mongod serving `dbpath` on Windows, which has no SIGTERM for a process without a console. */
|
|
646
|
+
function stopWindowsMongod(dbpath) {
|
|
647
|
+
const found = windowsMongod(dbpath);
|
|
648
|
+
if (found === void 0) return;
|
|
649
|
+
if (windowsTerminate([found], KILL_WAIT_MS$1).length > 0) throw new Error(`antelopejs-lease: mongod ${found.pid} was still running ${KILL_WAIT_MS$1 / 1e3} s after it was terminated`);
|
|
650
|
+
}
|
|
412
651
|
/**
|
|
413
652
|
* Stops the mongod serving `dbpath`, if any: SIGTERM and `graceMs` to shut down, then SIGKILL.
|
|
414
653
|
* With `graceMs` 0 it kills at once. Throws when the process outlives the kill.
|
|
415
654
|
*/
|
|
416
655
|
async function stopMongod(dbpath, graceMs) {
|
|
656
|
+
if (process.platform === "win32") return stopWindowsMongod(dbpath);
|
|
417
657
|
const pid = mongodPid(dbpath);
|
|
418
658
|
if (pid === void 0) return;
|
|
419
659
|
const runs = runningCheck(pid, dbpath);
|
|
@@ -433,6 +673,7 @@ async function holder(port) {
|
|
|
433
673
|
}
|
|
434
674
|
/** The command lines of the processes this user may read. */
|
|
435
675
|
function commandLines() {
|
|
676
|
+
if (process.platform === "win32") return windowsProcesses().map((entry) => entry.command);
|
|
436
677
|
if (process.platform === "linux") return readdirSync("/proc").filter((name) => /^\d+$/u.test(name)).map((name) => commandLine(Number(name)));
|
|
437
678
|
try {
|
|
438
679
|
return execFileSync("ps", ["-axo", "command="], {
|
|
@@ -472,18 +713,19 @@ async function ready(port, paths, exited) {
|
|
|
472
713
|
}
|
|
473
714
|
/**
|
|
474
715
|
* Makes sure the lease's own mongod serves `paths.dbpath` on `port`, starting one when none does.
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
716
|
+
* The server is never a child of this process, nor of the command `run` becomes, which would keep
|
|
717
|
+
* it as a zombie after `down`. On Linux and macOS mongod daemonizes itself with `--fork`, and the
|
|
718
|
+
* process this call starts exits once the server accepts connections. Windows has no `--fork`, so
|
|
719
|
+
* mongod starts there detached, with no console and no handle of this process. Two callers at once
|
|
720
|
+
* are safe: mongod locks its dbpath, so the second exits and both wait for the first. mongod gets
|
|
721
|
+
* no `ANTELOPEJS_LEASE`, even when the caller runs under another worktree's lease, so only `down`
|
|
722
|
+
* of its own lease stops it.
|
|
480
723
|
*/
|
|
481
724
|
async function ensureMongod(port, paths, env) {
|
|
482
|
-
if (process.platform === "win32") throw new Error("antelopejs-lease: a lease's own mongod is not supported on Windows, where mongod has no --fork and holds its mongod.lock exclusively; set DMS_MONGO_URL to a server you run");
|
|
483
725
|
if (mongodPid(paths.dbpath) !== void 0) return ready(port, paths, () => true);
|
|
484
726
|
const binary = findMongod(env);
|
|
485
727
|
if (binary === void 0) throw new Error("antelopejs-lease: no mongod on PATH or in ~/.cache/mongodb-binaries; install MongoDB, or set DMS_MONGO_URL to a server you run");
|
|
486
|
-
const
|
|
728
|
+
const args = [
|
|
487
729
|
"--dbpath",
|
|
488
730
|
paths.dbpath,
|
|
489
731
|
"--port",
|
|
@@ -494,9 +736,13 @@ async function ensureMongod(port, paths, env) {
|
|
|
494
736
|
paths.log,
|
|
495
737
|
"--logappend",
|
|
496
738
|
"--wiredTigerCacheSizeGB",
|
|
497
|
-
"0.25"
|
|
498
|
-
|
|
499
|
-
|
|
739
|
+
"0.25"
|
|
740
|
+
];
|
|
741
|
+
if (process.platform === "win32") {
|
|
742
|
+
windowsStart(resolve(binary), args, paths.dbpath);
|
|
743
|
+
return ready(port, paths, () => true);
|
|
744
|
+
}
|
|
745
|
+
const started = spawn(binary, [...args, "--fork"], {
|
|
500
746
|
detached: true,
|
|
501
747
|
stdio: "ignore",
|
|
502
748
|
env: unmarked(process.env)
|
|
@@ -861,28 +1107,70 @@ async function terminate(found, report) {
|
|
|
861
1107
|
for (const target of found) if (!survivors.includes(target)) report(`stopped pid ${target.pid} (${target.command})`);
|
|
862
1108
|
if (survivors.length > 0) throw new Error(`antelopejs-lease: pid ${survivors.map((target) => target.pid).join(", ")} still running ${KILL_WAIT_MS / 1e3} s after SIGKILL`);
|
|
863
1109
|
}
|
|
864
|
-
|
|
1110
|
+
function linuxStopper() {
|
|
1111
|
+
const shield = ancestry();
|
|
1112
|
+
return {
|
|
1113
|
+
discover: (marker) => discover(marker, shield),
|
|
1114
|
+
terminate
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
/** This process and its ancestors in `table`. A parent created after its child is a reused pid, not the parent. */
|
|
1118
|
+
function windowsAncestry(table) {
|
|
1119
|
+
const byPid = new Map(table.map((entry) => [entry.pid, entry]));
|
|
1120
|
+
const pids = /* @__PURE__ */ new Set([process.pid]);
|
|
1121
|
+
let at = byPid.get(process.pid);
|
|
1122
|
+
while (at !== void 0) {
|
|
1123
|
+
const parent = byPid.get(at.ppid);
|
|
1124
|
+
if (parent === void 0 || pids.has(parent.pid) || BigInt(parent.start) > BigInt(at.start)) break;
|
|
1125
|
+
pids.add(parent.pid);
|
|
1126
|
+
at = parent;
|
|
1127
|
+
}
|
|
1128
|
+
return pids;
|
|
1129
|
+
}
|
|
1130
|
+
/** A console host, by its executable. It inherits the environment of the process whose console it hosts, and ending it ends every process on that console, the stop's own included. */
|
|
1131
|
+
const CONSOLE_HOST = /^(?:"(?:[^"]*\\)?|(?:[^"\s]*\\)?)(?:conhost|openconsole)\.exe(?:"|\s|$)/iu;
|
|
1132
|
+
function discoverWindows(marker) {
|
|
1133
|
+
const table = windowsProcesses(marker);
|
|
1134
|
+
const shield = windowsAncestry(table);
|
|
1135
|
+
return table.filter((entry) => entry.marked && !shield.has(entry.pid) && !CONSOLE_HOST.test(entry.command)).map(({ pid, start, command }) => ({
|
|
1136
|
+
pid,
|
|
1137
|
+
start,
|
|
1138
|
+
command
|
|
1139
|
+
}));
|
|
1140
|
+
}
|
|
1141
|
+
/** Windows has no SIGTERM to a process without a console: each target is terminated at once. */
|
|
1142
|
+
async function terminateWindows(found, report) {
|
|
1143
|
+
const survivors = windowsTerminate(found, GRACE_MS);
|
|
1144
|
+
for (const target of found) if (!survivors.includes(target.pid)) report(`stopped pid ${target.pid} (${target.command})`);
|
|
1145
|
+
if (survivors.length > 0) throw new Error(`antelopejs-lease: pid ${survivors.join(", ")} still running ${GRACE_MS / 1e3} s after it was terminated`);
|
|
1146
|
+
}
|
|
1147
|
+
const WINDOWS_STOPPER = {
|
|
1148
|
+
discover: discoverWindows,
|
|
1149
|
+
terminate: terminateWindows
|
|
1150
|
+
};
|
|
1151
|
+
/** Throws unless this platform is Linux or Windows, the ones where a process's environment can be read to find a lease's processes. */
|
|
865
1152
|
function assertStopSupported() {
|
|
866
|
-
if (process.platform !== "linux") throw new Error("antelopejs-lease: down --stop reads
|
|
1153
|
+
if (process.platform !== "linux" && process.platform !== "win32") throw new Error("antelopejs-lease: down --stop reads the environment of each process and runs on Linux and Windows only; stop your servers with their own stop command, then run down");
|
|
867
1154
|
}
|
|
868
1155
|
/**
|
|
869
1156
|
* Stops every process of this user whose environment holds `ANTELOPEJS_LEASE=<id>`, which `run`
|
|
870
1157
|
* exports and every descendant inherits, except this process and its ancestors. Signals each pid
|
|
871
|
-
* alone, never a group: SIGTERM, a few seconds to exit, then SIGKILL
|
|
872
|
-
* again before each signal so a pid the system
|
|
873
|
-
*
|
|
874
|
-
*
|
|
1158
|
+
* alone, never a group: on Linux SIGTERM, a few seconds to exit, then SIGKILL; on Windows it
|
|
1159
|
+
* terminates each at once. The start time is checked again before each signal so a pid the system
|
|
1160
|
+
* reused is never signalled. Scans again after each pass, for processes started meanwhile. Calls
|
|
1161
|
+
* `report` with one line per process that stopped, and throws when one outlives the kill or new
|
|
1162
|
+
* ones keep appearing. Linux reads `/proc`; Windows reads each process's parameters.
|
|
875
1163
|
*/
|
|
876
1164
|
async function stopOwn(id, report) {
|
|
877
1165
|
assertStopSupported();
|
|
878
1166
|
const marker = leaseMarker(id);
|
|
879
|
-
const
|
|
1167
|
+
const stopper = process.platform === "win32" ? WINDOWS_STOPPER : linuxStopper();
|
|
880
1168
|
for (let round = 0; round < ROUNDS; round += 1) {
|
|
881
|
-
const found = discover(marker
|
|
1169
|
+
const found = stopper.discover(marker);
|
|
882
1170
|
if (found.length === 0) return;
|
|
883
|
-
await terminate(found, report);
|
|
1171
|
+
await stopper.terminate(found, report);
|
|
884
1172
|
}
|
|
885
|
-
const left = discover(marker
|
|
1173
|
+
const left = stopper.discover(marker);
|
|
886
1174
|
if (left.length > 0) throw new Error(`antelopejs-lease: pid ${left.map((target) => target.pid).join(", ")} of this lease appeared after ${ROUNDS} rounds of --stop`);
|
|
887
1175
|
}
|
|
888
1176
|
//#endregion
|
package/dist/bin/ratchet.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import { c as parseCeilings, l as readCeilings, t as CEILINGS_FILE } from "../ce
|
|
|
3
3
|
import { n as renamedPaths } from "../renames-L2owF5GD.mjs";
|
|
4
4
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
5
5
|
import { c as repositoryRoot, l as resolveRevision, t as LINT_CONFIG } from "../files-C-JJhExM.mjs";
|
|
6
|
-
import { n as ratchet, r as withPreviousTree } from "../ratchet-
|
|
7
|
-
import {
|
|
8
|
-
import { d as stagedAdditions, f as stagedChanges, u as previousLine } from "../suppression-budget-
|
|
9
|
-
import { n as suppressionBase } from "../suppression-base-
|
|
6
|
+
import { n as ratchet, r as withPreviousTree } from "../ratchet-2FeMs1kh.mjs";
|
|
7
|
+
import { n as lintDiagnostics } from "../oxlint-CkHhK5K_.mjs";
|
|
8
|
+
import { d as stagedAdditions, f as stagedChanges, u as previousLine } from "../suppression-budget-CPDSFg4X.mjs";
|
|
9
|
+
import { n as suppressionBase } from "../suppression-base-CYaLZAq7.mjs";
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { d as toolingRoot } from "../package-
|
|
2
|
+
import { d as toolingRoot } from "../package-DDG3YH7W.mjs";
|
|
3
3
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
4
4
|
import { c as repositoryRoot } from "../files-C-JJhExM.mjs";
|
|
5
5
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
3
3
|
import { c as repositoryRoot, r as changedFiles } from "../files-C-JJhExM.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { c as stagedSuppressions, i as checkSuppressions, l as checkPolicy, s as stagedNames } from "../suppression-budget-
|
|
6
|
-
import { c as suppressionsIn, i as inWorktree } from "../suppressions-
|
|
7
|
-
import { n as suppressionBase, t as raisedCeilings } from "../suppression-base-
|
|
4
|
+
import { t as directiveReport } from "../oxlint-CkHhK5K_.mjs";
|
|
5
|
+
import { c as stagedSuppressions, i as checkSuppressions, l as checkPolicy, s as stagedNames } from "../suppression-budget-CPDSFg4X.mjs";
|
|
6
|
+
import { c as suppressionsIn, i as inWorktree } from "../suppressions-CxPnh4sC.mjs";
|
|
7
|
+
import { n as suppressionBase, t as raisedCeilings } from "../suppression-base-CYaLZAq7.mjs";
|
|
8
8
|
import { readdirSync } from "node:fs";
|
|
9
9
|
import { join, posix } from "node:path";
|
|
10
10
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
@@ -72,9 +72,13 @@ function deadDirectiveFailures(root, files) {
|
|
|
72
72
|
const directives = inWorktree(root, directivesIn, files);
|
|
73
73
|
const readByOxlint = directives.filter(({ file, directive }) => !file.endsWith(".vue") && !(directive.startsWith("eslint-") && lintedByEslint(root, file)));
|
|
74
74
|
const lintable = [...new Set(readByOxlint.map(({ file }) => file))];
|
|
75
|
+
const { unused, unreadable } = lintable.length ? directiveReport(root, lintable) : {
|
|
76
|
+
unused: [],
|
|
77
|
+
unreadable: []
|
|
78
|
+
};
|
|
75
79
|
const dead = /* @__PURE__ */ new Map();
|
|
76
|
-
const unplaced =
|
|
77
|
-
for (const item of
|
|
80
|
+
const unplaced = unreadable.map(({ location, message }) => `${location === void 0 ? "" : `${location}: `}oxlint cannot check the directives here: ${message}. Fix: correct the file so oxlint reads it without errors, then rerun the check.`);
|
|
81
|
+
for (const item of unused) {
|
|
78
82
|
const directive = reported(readByOxlint, item);
|
|
79
83
|
if (directive === void 0) {
|
|
80
84
|
unplaced.push(`${item.file}:${item.line}: ${item.message} Fix: delete the directive.`);
|