@hile/cli 2.0.7 → 2.0.9
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/dist/exitHook.d.ts +3 -2
- package/dist/exitHook.js +16 -26
- package/dist/index.js +11 -2
- package/package.json +4 -3
package/dist/exitHook.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 注册进程退出钩子。
|
|
3
|
+
* 进程退出时先执行 container.shutdown(),完成后调用 exit() 调度 process.exit()。
|
|
4
|
+
* 若 process.exit() 被 pino/thread-stream 的 Atomics.wait() 阻塞,1s 后 process.abort() 兜底。
|
|
4
5
|
*/
|
|
5
6
|
export declare function registerExitHook(offEvent: () => void): void;
|
|
6
7
|
export declare function useExit(fn: () => void | Promise<void>): Promise<void>;
|
package/dist/exitHook.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import exitHook from 'async-exit-hook';
|
|
2
2
|
import { container } from '@hile/core';
|
|
3
|
-
/**
|
|
4
|
-
const FORCE_EXIT_AFTER_MS =
|
|
3
|
+
/** shutdown 未在该时间内完成时强制退出 */
|
|
4
|
+
const FORCE_EXIT_AFTER_MS = 10_000;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* 注册进程退出钩子。
|
|
7
|
+
* 进程退出时先执行 container.shutdown(),完成后调用 exit() 调度 process.exit()。
|
|
8
|
+
* 若 process.exit() 被 pino/thread-stream 的 Atomics.wait() 阻塞,1s 后 process.abort() 兜底。
|
|
8
9
|
*/
|
|
9
10
|
export function registerExitHook(offEvent) {
|
|
10
11
|
const hook = exitHook;
|
|
@@ -14,17 +15,9 @@ export function registerExitHook(offEvent) {
|
|
|
14
15
|
exitHook(async (exit) => {
|
|
15
16
|
try {
|
|
16
17
|
await container.shutdown();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
process.stdin.unref();
|
|
21
|
-
}
|
|
22
|
-
resolve();
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
18
|
+
if (process.stdin.isTTY) {
|
|
19
|
+
process.stdin.unref();
|
|
20
|
+
}
|
|
28
21
|
}
|
|
29
22
|
catch (e) {
|
|
30
23
|
console.error(e);
|
|
@@ -32,6 +25,10 @@ export function registerExitHook(offEvent) {
|
|
|
32
25
|
finally {
|
|
33
26
|
offEvent();
|
|
34
27
|
exit();
|
|
28
|
+
// process.exit() can hang due to pino/thread-stream exit handlers
|
|
29
|
+
// that use Atomics.wait() to block on worker threads.
|
|
30
|
+
// If we're still running after 1s, force kill.
|
|
31
|
+
setTimeout(() => process.abort(), 1000).unref();
|
|
35
32
|
}
|
|
36
33
|
});
|
|
37
34
|
}
|
|
@@ -39,23 +36,16 @@ export async function useExit(fn) {
|
|
|
39
36
|
exitHook(async (exit) => {
|
|
40
37
|
try {
|
|
41
38
|
await Promise.resolve(fn());
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
process.stdin.unref();
|
|
46
|
-
}
|
|
47
|
-
resolve();
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
reject(e);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
39
|
+
if (process.stdin.isTTY) {
|
|
40
|
+
process.stdin.unref();
|
|
41
|
+
}
|
|
53
42
|
}
|
|
54
43
|
catch (e) {
|
|
55
44
|
console.error(e);
|
|
56
45
|
}
|
|
57
46
|
finally {
|
|
58
47
|
exit();
|
|
48
|
+
setTimeout(() => process.abort(), 1000).unref();
|
|
59
49
|
}
|
|
60
50
|
});
|
|
61
51
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { createRequire } from 'node:module';
|
|
|
9
9
|
import { Registry } from '@hile/micro';
|
|
10
10
|
import { useExit } from './exitHook.js';
|
|
11
11
|
import { listConfigs, getConfig, setConfig, delConfig } from './configs.js';
|
|
12
|
+
import { createLogger } from '@hile/logger';
|
|
12
13
|
const requireCli = createRequire(import.meta.url);
|
|
13
14
|
/** 从包入口文件路径向上找到 `package.json` 的 `name` 与 `packageName` 一致的目录 */
|
|
14
15
|
function packageDirFromResolvedMain(resolvedMain, packageName) {
|
|
@@ -114,12 +115,20 @@ registryCmd
|
|
|
114
115
|
.allowExcessArguments(true)
|
|
115
116
|
.option('--port <port>', '注册中心端口', '9876')
|
|
116
117
|
.option('--host <host>', '注册中心主机', '127.0.0.1')
|
|
118
|
+
.option('--level <level>', '日志级别', 'info')
|
|
119
|
+
.option('--pretty', '美化输出', false)
|
|
117
120
|
.description('启动注册中心')
|
|
118
121
|
.action(async (options) => {
|
|
119
122
|
const port = options.port ? Number(options.port) : 9876;
|
|
120
|
-
const registry = new Registry({
|
|
123
|
+
const registry = new Registry({
|
|
124
|
+
advertiseHost: options.host,
|
|
125
|
+
logger: createLogger({
|
|
126
|
+
level: options.level,
|
|
127
|
+
pretty: !!options.pretty
|
|
128
|
+
})
|
|
129
|
+
});
|
|
121
130
|
useExit(await registry.listen(port));
|
|
122
|
-
|
|
131
|
+
registry.logger.info(`+ registry started on port ${port}`);
|
|
123
132
|
});
|
|
124
133
|
// Registry configs subcommands
|
|
125
134
|
const configs = registryCmd.command('configs');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hile/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@hile/core": "^2.0.1",
|
|
32
|
-
"@hile/
|
|
32
|
+
"@hile/logger": "^2.0.2",
|
|
33
|
+
"@hile/micro": "^2.0.6",
|
|
33
34
|
"async-exit-hook": "^2.0.1",
|
|
34
35
|
"commander": "^14.0.3",
|
|
35
36
|
"glob": "^13.0.6",
|
|
@@ -37,5 +38,5 @@
|
|
|
37
38
|
"tsx": "^4.21.0",
|
|
38
39
|
"yaml": "^2.9.0"
|
|
39
40
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "cf0c977950926cce605271a45a6c970506f6ed97"
|
|
41
42
|
}
|