@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.
- package/lib/commands/build.js +6 -4
- package/lib/commands/dev.js +41 -13
- package/lib/compiler/compile.js +4 -2
- package/package.json +1 -1
package/lib/commands/build.js
CHANGED
|
@@ -79,14 +79,16 @@ async function build(opts) {
|
|
|
79
79
|
const assets = discoverAssets(publicDir);
|
|
80
80
|
|
|
81
81
|
if (assets.length > 0) {
|
|
82
|
-
|
|
83
|
-
for (
|
|
84
|
-
|
|
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` +
|
package/lib/commands/dev.js
CHANGED
|
@@ -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
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
81
|
+
const proc = spawn(binaryPath, [], {
|
|
77
82
|
stdio: "inherit",
|
|
78
83
|
env,
|
|
79
84
|
cwd: projectDir,
|
|
80
85
|
});
|
|
81
86
|
|
|
82
|
-
serverProcess
|
|
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
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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
|
-
|
|
175
|
+
try {
|
|
176
|
+
serverProcess.kill("SIGTERM");
|
|
177
|
+
} catch (_) {}
|
|
150
178
|
await waitForExit(serverProcess);
|
|
151
179
|
}
|
|
152
180
|
process.exit(0);
|
package/lib/compiler/compile.js
CHANGED
|
@@ -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
|
-
|
|
100
|
-
|
|
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
|
|