node-karin 1.9.8 → 1.9.10
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/CHANGELOG.md +31 -0
- package/dist/index.d.ts +121 -54
- package/dist/index.mjs +646 -502
- package/dist/start/index.mjs +23 -25
- package/package.json +1 -1
package/dist/start/index.mjs
CHANGED
|
@@ -7,13 +7,11 @@ import { fork } from 'node:child_process';
|
|
|
7
7
|
// src/start/index.ts
|
|
8
8
|
var isStart = false;
|
|
9
9
|
var child;
|
|
10
|
-
var lastStartTime = 0;
|
|
11
|
-
var isClosing = false;
|
|
12
|
-
var minRestartInterval = 5e3;
|
|
13
10
|
var _filename = fileURLToPath(import.meta.url);
|
|
14
11
|
var _dirname = path.dirname(_filename);
|
|
15
12
|
var getMainPath = () => {
|
|
16
|
-
const
|
|
13
|
+
const isESM = import.meta.url.includes(".mjs");
|
|
14
|
+
const filePath = path.join(_dirname, isESM ? "app.mjs" : "app.ts");
|
|
17
15
|
if (fs.existsSync(filePath)) {
|
|
18
16
|
return filePath;
|
|
19
17
|
}
|
|
@@ -25,31 +23,23 @@ var start = () => {
|
|
|
25
23
|
return child;
|
|
26
24
|
}
|
|
27
25
|
isStart = true;
|
|
28
|
-
lastStartTime = Date.now();
|
|
29
26
|
child = fork(getMainPath());
|
|
30
27
|
child.on("message", (message) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
child.on("exit", (code) => {
|
|
41
|
-
isStart = false;
|
|
42
|
-
if (!isClosing && Date.now() - lastStartTime > minRestartInterval) {
|
|
43
|
-
process.exit(code);
|
|
28
|
+
try {
|
|
29
|
+
const { port, type, token } = JSON.parse(message) || {};
|
|
30
|
+
if (type === "restart") {
|
|
31
|
+
restart(port, token);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (type === "stop") exit();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error("\u5904\u7406\u5B50\u8FDB\u7A0B\u6D88\u606F\u65F6\u51FA\u9519:", error);
|
|
44
37
|
}
|
|
45
38
|
});
|
|
46
|
-
child.
|
|
47
|
-
console.error("\u5B50\u8FDB\u7A0B\u53D1\u751F\u9519\u8BEF:", err);
|
|
48
|
-
});
|
|
39
|
+
child.once("exit", exit);
|
|
49
40
|
return child;
|
|
50
41
|
};
|
|
51
42
|
var restart = async (port, token, isFetch = true) => {
|
|
52
|
-
isClosing = true;
|
|
53
43
|
if (isFetch) {
|
|
54
44
|
await sendExit(port, token);
|
|
55
45
|
}
|
|
@@ -101,7 +91,15 @@ var sendExit = async (port, token) => {
|
|
|
101
91
|
} catch {
|
|
102
92
|
}
|
|
103
93
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
94
|
+
var exit = () => {
|
|
95
|
+
try {
|
|
96
|
+
child.kill("SIGTERM");
|
|
97
|
+
process.kill(child.pid);
|
|
98
|
+
} catch {
|
|
99
|
+
child?.kill();
|
|
100
|
+
} finally {
|
|
101
|
+
process.exit(0);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
process.on("exit", exit);
|
|
107
105
|
start();
|