fireemu 0.7.0 → 0.8.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.
Files changed (2) hide show
  1. package/bin/fireemu.mjs +32 -16
  2. package/package.json +6 -6
package/bin/fireemu.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // The `fireemu` launcher: find the binary for this platform and become it.
2
+ // The `fireemu` launcher: find the binary for this platform and supervise it.
3
3
  //
4
4
  // `fireemu` itself carries no binary. Each platform's daemon ships in its own package
5
5
  // (`@fireemu/darwin-arm64` and friends), declared here as an optional dependency with an `os`
@@ -11,7 +11,7 @@
11
11
  // `package.json` rather than hard-coded, so it always names the platforms that were actually
12
12
  // published beside this launcher.
13
13
 
14
- import { spawnSync } from "node:child_process";
14
+ import { spawn } from "node:child_process";
15
15
  import { chmodSync, accessSync, constants as fsConstants, readFileSync } from "node:fs";
16
16
  import { createRequire } from "node:module";
17
17
  import { constants as osConstants } from "node:os";
@@ -114,27 +114,43 @@ function main() {
114
114
  process.exit(1);
115
115
  }
116
116
  ensureExecutable(binary.path);
117
- // stdio is inherited, so the daemon reads the real terminal and Ctrl-C reaches it directly:
118
- // the launcher is in the same process group and does not need to forward anything.
119
- const result = spawnSync(binary.path, process.argv.slice(2), {
117
+ // Keep terminal I/O and the foreground process group intact. PID-directed signals only
118
+ // reach this launcher, so forward them and wait for the daemon's own shutdown to finish.
119
+ const child = spawn(binary.path, process.argv.slice(2), {
120
120
  stdio: "inherit",
121
121
  windowsHide: false,
122
122
  });
123
- if (result.error) {
123
+ for (const signal of ["SIGTERM", "SIGINT"]) {
124
+ process.on(signal, () => {
125
+ // Windows delivers console Ctrl-C to the child directly; child.kill would forcefully
126
+ // terminate it instead of requesting graceful shutdown. Only wait on that platform.
127
+ if (process.platform === "win32") return;
128
+ // Do not use child.killed here: it means a signal was sent, not that the child exited.
129
+ if (child.exitCode === null && child.signalCode === null) child.kill(signal);
130
+ });
131
+ }
132
+ child.on("error", (error) => {
133
+ if (child.pid) {
134
+ // A failed signal delivery must not orphan a daemon that is still running.
135
+ process.stderr.write(`fireemu could not signal the daemon: ${error.message}\n`);
136
+ return;
137
+ }
124
138
  const reason =
125
- result.error.code === "ENOENT"
139
+ error.code === "ENOENT"
126
140
  ? `${binary.path} does not exist (from ${binary.from})`
127
- : `${binary.path}: ${result.error.message}`;
141
+ : `${binary.path}: ${error.message}`;
128
142
  process.stderr.write(`fireemu could not start the daemon: ${reason}\n`);
129
143
  process.exit(1);
130
- }
131
- if (result.signal) {
132
- // Report the death the way a shell does, so `fireemu ... ; echo $?` matches running the
133
- // daemon directly.
134
- const number = osConstants.signals[result.signal] ?? 0;
135
- process.exit(128 + number);
136
- }
137
- process.exit(result.status ?? 1);
144
+ });
145
+ child.on("exit", (code, signal) => {
146
+ if (signal) {
147
+ // Report the death the way a shell does, so `fireemu ... ; echo $?` matches running the
148
+ // daemon directly.
149
+ const number = osConstants.signals[signal] ?? 0;
150
+ process.exit(128 + number);
151
+ }
152
+ process.exit(code ?? 1);
153
+ });
138
154
  }
139
155
 
140
156
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fireemu",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "An experimental local runtime for testing Firebase SDK and Functions code",
5
5
  "keywords": [
6
6
  "emulator",
@@ -27,11 +27,11 @@
27
27
  ],
28
28
  "type": "module",
29
29
  "optionalDependencies": {
30
- "@fireemu/darwin-arm64": "0.7.0",
31
- "@fireemu/darwin-x64": "0.7.0",
32
- "@fireemu/linux-x64": "0.7.0",
33
- "@fireemu/linux-arm64": "0.7.0",
34
- "@fireemu/win32-x64": "0.7.0"
30
+ "@fireemu/darwin-arm64": "0.8.0",
31
+ "@fireemu/darwin-x64": "0.8.0",
32
+ "@fireemu/linux-x64": "0.8.0",
33
+ "@fireemu/linux-arm64": "0.8.0",
34
+ "@fireemu/win32-x64": "0.8.0"
35
35
  },
36
36
  "engines": {
37
37
  "node": ">=20"