@velox0/cerver 0.5.0 → 0.5.2

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.
@@ -79,14 +79,16 @@ async function build(opts) {
79
79
  const assets = discoverAssets(publicDir);
80
80
 
81
81
  if (assets.length > 0) {
82
- let totalSize = 0;
83
- for (const a of assets) {
84
- totalSize += a.size;
82
+ const totalSize = assets.reduce((sum, a) => sum + a.size, 0);
83
+ for (let i = 0; i < Math.min(assets.length, 5); i++) {
84
+ const a = assets[i];
85
85
  console.log(
86
86
  ` ${a.servePath} (${(a.size / 1024).toFixed(1)} KB)`
87
87
  );
88
88
  }
89
-
89
+ if (assets.length > 5) {
90
+ console.log(` ... and ${assets.length - 5} more assets`);
91
+ }
90
92
  assetsCode = await generateEmbeddedAssets(assets, config.minify, config.compression);
91
93
  console.log(
92
94
  ` ${assets.length} asset(s), ${(totalSize / 1024).toFixed(1)} KB total` +
@@ -39,10 +39,15 @@ async function dev(opts) {
39
39
  /* Kill existing server */
40
40
  if (serverProcess) {
41
41
  console.log("\n ↻ restarting...\n");
42
- serverProcess.kill("SIGTERM");
43
- serverProcess = null;
44
- /* Small delay for port release */
45
- await new Promise((r) => setTimeout(r, 200));
42
+ const procToKill = serverProcess;
43
+ try {
44
+ procToKill.kill("SIGTERM");
45
+ serverProcess = null;
46
+ } catch (err) {
47
+ console.error(` ✗ failed to kill server: ${err.message}`);
48
+ }
49
+ /* Wait for old process to fully exit so the port is released */
50
+ await waitForExit(procToKill, 2000);
46
51
  }
47
52
 
48
53
  try {
@@ -73,29 +78,50 @@ async function dev(opts) {
73
78
  const env = { ...process.env };
74
79
  if (port) env.CERVER_PORT = port;
75
80
 
76
- serverProcess = spawn(binaryPath, [], {
81
+ const proc = spawn(binaryPath, [], {
77
82
  stdio: "inherit",
78
83
  env,
79
84
  cwd: projectDir,
80
85
  });
81
86
 
82
- serverProcess.on("error", (err) => {
87
+ serverProcess = proc;
88
+
89
+ proc.on("error", (err) => {
83
90
  console.error(` ✗ server error: ${err.message}`);
84
- serverProcess = null;
91
+ if (serverProcess === proc) serverProcess = null;
85
92
  });
86
93
 
87
- serverProcess.on("exit", (code, signal) => {
88
- if (signal !== "SIGTERM" && signal !== "SIGINT") {
94
+ proc.on("exit", (code, signal) => {
95
+ /* Only warn on truly unexpected exits not intentional kills */
96
+ if (serverProcess === proc && signal !== "SIGTERM" && signal !== "SIGINT" && code !== 0) {
89
97
  console.error(` ✗ server exited (code: ${code}, signal: ${signal})`);
90
98
  }
91
- serverProcess = null;
99
+ if (serverProcess === proc) serverProcess = null;
92
100
  });
93
101
  }
94
102
 
95
- function waitForExit(proc) {
103
+ function waitForExit(proc, timeoutMs = 2000) {
96
104
  if (!proc) return Promise.resolve();
105
+ if (proc.exitCode !== null || proc.signalCode !== null) {
106
+ return Promise.resolve();
107
+ }
97
108
  return new Promise((resolve) => {
98
- const done = () => resolve();
109
+ let resolved = false;
110
+ const done = () => {
111
+ if (resolved) return;
112
+ resolved = true;
113
+ clearTimeout(timer);
114
+ proc.removeListener("exit", done);
115
+ proc.removeListener("close", done);
116
+ proc.removeListener("error", done);
117
+ resolve();
118
+ };
119
+ const timer = setTimeout(() => {
120
+ if (resolved) return;
121
+ /* Process did not exit in time — force kill */
122
+ try { proc.kill("SIGKILL"); } catch (_) {}
123
+ done();
124
+ }, timeoutMs);
99
125
  proc.once("exit", done);
100
126
  proc.once("close", done);
101
127
  proc.once("error", done);
@@ -146,7 +172,9 @@ async function dev(opts) {
146
172
  watcher.close();
147
173
  if (debounceTimer) clearTimeout(debounceTimer);
148
174
  if (serverProcess) {
149
- serverProcess.kill("SIGTERM");
175
+ try {
176
+ serverProcess.kill("SIGTERM");
177
+ } catch (_) {}
150
178
  await waitForExit(serverProcess);
151
179
  }
152
180
  process.exit(0);
@@ -96,8 +96,10 @@ function compile(distDir, runtimeDir, opts) {
96
96
  /* On macOS, we need to define _GNU_SOURCE for some functions */
97
97
  args.push("-D_GNU_SOURCE");
98
98
 
99
- console.log(` compiling with ${cc}...`);
100
- console.log(` ${cc} ${args.join(" ")}`);
99
+ /* Debug mode */
100
+ if (opts && opts.compileInfo) {
101
+ console.log(` ${cc} ${args.join(" ")}`);
102
+ }
101
103
 
102
104
  const start = Date.now();
103
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velox0/cerver",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Compile restricted JavaScript server logic into optimized native C binaries",
5
5
  "main": "bin/cerver.js",
6
6
  "bin": {