@decohere/flux 0.0.1-dev.20261106.197 → 0.0.1-dev.20261106.209

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.
@@ -8,6 +8,30 @@ import { spawn } from "node:child_process";
8
8
  import { injectable } from "@decohere/crucible/decorators";
9
9
  import { detectPackageManager, packageManagerFromString } from "@decohere/devkit/interop";
10
10
  import { scribe } from "@decohere/scribe";
11
+ /** How long a script gets to stop after SIGTERM before it's killed. */ const STOP_TIMEOUT_MS = 2_000;
12
+ /** Windows has no process groups. There, only the package manager itself gets the signal. */ const USE_PROCESS_GROUP = process.platform !== "win32";
13
+ /** Signal the script's whole group: the package manager exits without stopping what it started. */ function signal(child, name) {
14
+ if (!USE_PROCESS_GROUP || child.pid == null) {
15
+ child.kill(name);
16
+ return;
17
+ }
18
+ try {
19
+ process.kill(-child.pid, name);
20
+ } catch (error) {
21
+ // The whole group has already gone, which is what we wanted.
22
+ if (error.code !== "ESRCH") throw error;
23
+ }
24
+ }
25
+ /** Resolves true once the package manager has exited, or false if it hasn't within `ms`. */ function waitForExit(child, ms) {
26
+ if (child.exitCode != null || child.signalCode != null) return Promise.resolve(true);
27
+ return new Promise((resolve)=>{
28
+ const timer = setTimeout(()=>resolve(false), ms);
29
+ child.once("exit", ()=>{
30
+ clearTimeout(timer);
31
+ resolve(true);
32
+ });
33
+ });
34
+ }
11
35
  export class DeferredScriptRunner {
12
36
  logger = scribe.logger(DeferredScriptRunner.name);
13
37
  children = [];
@@ -19,7 +43,14 @@ export class DeferredScriptRunner {
19
43
  options.script
20
44
  ], {
21
45
  cwd: options.cwd,
22
- stdio: "inherit",
46
+ // Its own process group, so stopping it reaches what the package manager started. A
47
+ // process in another group can't read the terminal, so it gets no stdin.
48
+ stdio: USE_PROCESS_GROUP ? [
49
+ "ignore",
50
+ "inherit",
51
+ "inherit"
52
+ ] : "inherit",
53
+ detached: USE_PROCESS_GROUP,
23
54
  env: process.env,
24
55
  shell: false
25
56
  });
@@ -33,12 +64,11 @@ export class DeferredScriptRunner {
33
64
  return child;
34
65
  }
35
66
  async [Symbol.asyncDispose]() {
36
- for (const child of this.children){
37
- if (!child.killed) {
38
- child.kill("SIGTERM");
39
- }
40
- }
41
- this.children.length = 0;
67
+ const children = this.children.splice(0);
68
+ await Promise.all(children.map(async (child)=>{
69
+ signal(child, "SIGTERM");
70
+ if (!await waitForExit(child, STOP_TIMEOUT_MS)) signal(child, "SIGKILL");
71
+ }));
42
72
  }
43
73
  }
44
74
  DeferredScriptRunner = _ts_decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/flux",
3
- "version": "0.0.1-dev.20261106.197",
3
+ "version": "0.0.1-dev.20261106.209",
4
4
  "description": "Hot module reload server for Node.js ESM applications",
5
5
  "keywords": [
6
6
  "typescript",
@@ -33,12 +33,12 @@
33
33
  "test": "echo \"Error: no test specified\" && exit 1"
34
34
  },
35
35
  "dependencies": {
36
- "@decohere/core": "0.0.1-dev.20261106.197",
37
- "@decohere/crucible": "0.0.1-dev.20261106.197",
38
- "@decohere/devkit": "0.0.1-dev.20261106.197",
39
- "@decohere/forge": "0.0.1-dev.20261106.197",
40
- "@decohere/scribe": "0.0.1-dev.20261106.197",
41
- "@decohere/workspace": "0.0.1-dev.20261106.197",
36
+ "@decohere/core": "0.0.1-dev.20261106.209",
37
+ "@decohere/crucible": "0.0.1-dev.20261106.209",
38
+ "@decohere/devkit": "0.0.1-dev.20261106.209",
39
+ "@decohere/forge": "0.0.1-dev.20261106.209",
40
+ "@decohere/scribe": "0.0.1-dev.20261106.209",
41
+ "@decohere/workspace": "0.0.1-dev.20261106.209",
42
42
  "commander": "^13.1.0"
43
43
  },
44
44
  "devDependencies": {}
@@ -8,7 +8,7 @@ export type DeferredScriptStart = {
8
8
  };
9
9
  /**
10
10
  * Nixpacks-style child processes for foreign packages in a flux serve slice.
11
- * Killed when the Flux container disposes (SIGINT → RootModule teardown).
11
+ * Stopped when the Flux container disposes (SIGINT → RootModule teardown).
12
12
  */
13
13
  export declare class DeferredScriptRunner implements AsyncDisposable {
14
14
  private readonly logger;