@opencode/util 0.0.0-dev-21922 → 0.0.0-dev-44
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/dist/cross-spawn-spawner.js +19 -0
- package/dist/record.d.ts +2 -0
- package/dist/record.js +2 -0
- package/package.json +2 -1
|
@@ -13,6 +13,18 @@ import { filesystem, path } from "./effect/app-node-platform.js";
|
|
|
13
13
|
import { Teardown } from "./teardown.js";
|
|
14
14
|
/** Closing a child's scope escalates to SIGKILL after this, unless the command sets its own `forceKillAfter`. */
|
|
15
15
|
export const RELEASE_FORCE_KILL_AFTER = "3 seconds";
|
|
16
|
+
// Process groups of running children. Exiting without stopping them (a shutdown deadline, a second signal, a
|
|
17
|
+
// crash) would orphan them, so a synchronous exit hook kills whatever is left.
|
|
18
|
+
const groups = new Set();
|
|
19
|
+
let hooked = false;
|
|
20
|
+
const killGroups = () => groups.forEach((pid) => {
|
|
21
|
+
try {
|
|
22
|
+
globalThis.process.kill(-pid, "SIGKILL");
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Already gone.
|
|
26
|
+
}
|
|
27
|
+
});
|
|
16
28
|
const toError = (err) => (err instanceof globalThis.Error ? err : new globalThis.Error(String(err)));
|
|
17
29
|
const toTag = (err) => {
|
|
18
30
|
switch (err.code) {
|
|
@@ -239,6 +251,7 @@ const makeCrossSpawnSpawner = Effect.gen(function* () {
|
|
|
239
251
|
resume(Effect.fail(toPlatformError("spawn", err, command)));
|
|
240
252
|
});
|
|
241
253
|
proc.on("exit", (...args) => {
|
|
254
|
+
groups.delete(proc.pid);
|
|
242
255
|
exit = args;
|
|
243
256
|
Deferred.doneUnsafe(exited, Exit.succeed(args));
|
|
244
257
|
});
|
|
@@ -251,6 +264,12 @@ const makeCrossSpawnSpawner = Effect.gen(function* () {
|
|
|
251
264
|
Deferred.doneUnsafe(closed, Exit.succeed(exit ?? args));
|
|
252
265
|
});
|
|
253
266
|
proc.on("spawn", () => {
|
|
267
|
+
if (opts.detached && globalThis.process.platform !== "win32") {
|
|
268
|
+
if (!hooked)
|
|
269
|
+
globalThis.process.once("exit", killGroups);
|
|
270
|
+
hooked = true;
|
|
271
|
+
groups.add(proc.pid);
|
|
272
|
+
}
|
|
254
273
|
settle = Teardown.track(`child ${proc.pid} running: ${[command.command, ...command.args].join(" ").slice(0, 200)}`);
|
|
255
274
|
resume(Effect.succeed([proc, closed, exited, () => settle()]));
|
|
256
275
|
});
|
package/dist/record.d.ts
ADDED
package/dist/record.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/util",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-44",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "bun run script/build.ts",
|
|
42
|
+
"pack": "bun run script/pack.ts",
|
|
42
43
|
"test": "bun test --only-failures",
|
|
43
44
|
"typecheck": "bun check --no-script",
|
|
44
45
|
"typecheck:tsc": "tsc --noEmit",
|