@hile/cli 1.1.2 → 1.1.4

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.
@@ -1,8 +1,5 @@
1
- export interface Shutdownable {
2
- shutdown(): Promise<void>;
3
- }
4
1
  /**
5
2
  * 注册进程退出钩子:进程退出时先执行 container.shutdown(),**仅在其完成后**才执行 offEvent 并 exit。
6
3
  * 若 shutdown() 未完成,进程会挂起,不会被关闭(受 FORCE_EXIT_AFTER_MS 上限保护)。
7
4
  */
8
- export declare function registerExitHook(container: Shutdownable, offEvent: () => void): void;
5
+ export declare function registerExitHook(offEvent: () => void): void;
package/dist/exitHook.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import exitHook from 'async-exit-hook';
2
+ import { container } from '@hile/core';
2
3
  /** 强制退出超时:仅当 shutdown 未在该时间内完成时才强制退出,默认约 24 天,等效于「等 shutdown 完成再退出」 */
3
4
  const FORCE_EXIT_AFTER_MS = 2 ** 31 - 1;
4
5
  /**
5
6
  * 注册进程退出钩子:进程退出时先执行 container.shutdown(),**仅在其完成后**才执行 offEvent 并 exit。
6
7
  * 若 shutdown() 未完成,进程会挂起,不会被关闭(受 FORCE_EXIT_AFTER_MS 上限保护)。
7
8
  */
8
- export function registerExitHook(container, offEvent) {
9
+ export function registerExitHook(offEvent) {
9
10
  const hook = exitHook;
10
11
  if (typeof hook.forceExitTimeout === 'function') {
11
12
  hook.forceExitTimeout(FORCE_EXIT_AFTER_MS);
@@ -13,6 +14,17 @@ export function registerExitHook(container, offEvent) {
13
14
  exitHook(async (exit) => {
14
15
  try {
15
16
  await container.shutdown();
17
+ await new Promise((resolve, reject) => {
18
+ try {
19
+ if (process.stdin.isTTY) {
20
+ process.stdin.unref();
21
+ }
22
+ resolve();
23
+ }
24
+ catch (e) {
25
+ reject(e);
26
+ }
27
+ });
16
28
  }
17
29
  catch (e) {
18
30
  console.error(e);
package/dist/start.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export declare function start(options: {
2
2
  dev: boolean;
3
+ cwd?: string;
3
4
  envFile?: string[];
4
5
  silent?: boolean;
5
6
  }): Promise<void>;
package/dist/start.js CHANGED
@@ -77,7 +77,7 @@ export async function start(options) {
77
77
  const offEvent = !options.silent && process.env.NODE_ENV === 'development'
78
78
  ? container.on(logContainerEvent)
79
79
  : () => { };
80
- const cwd = process.cwd();
80
+ const cwd = options.cwd ?? process.cwd();
81
81
  const files = [];
82
82
  // 加载 package.json 文件
83
83
  // 如果 package.json 中存在 hile.auto_load_packages 属性,则加载该属性值中的所有服务
@@ -89,7 +89,7 @@ export async function start(options) {
89
89
  }
90
90
  }
91
91
  // 加载所有后缀为 boot.ts 或 boot.js 的服务
92
- const directory = resolve(cwd, process.env.HILE_RUNTIME_DIR || (options.dev ? 'src' : 'dist'));
92
+ const directory = resolve(cwd, options.dev ? 'src' : 'dist');
93
93
  const _files = await glob(`**/*.boot.{ts,js}`, { cwd: directory });
94
94
  files.push(..._files.map(file => resolve(directory, file)));
95
95
  // 加载所有自启动服务
@@ -103,6 +103,9 @@ export async function start(options) {
103
103
  if (!fn || !isService(fn))
104
104
  throw new Error(`invalid service file: ${file}`);
105
105
  await loadService(fn);
106
+ if (!options.silent) {
107
+ console.info(`+ [bootstrap] ${file}`);
108
+ }
106
109
  }));
107
110
  // 如果没有服务要加载,则提示
108
111
  if (!files.length) {
@@ -111,5 +114,5 @@ export async function start(options) {
111
114
  return;
112
115
  }
113
116
  // 注册退出钩子,在进程退出时销毁所有服务
114
- registerExitHook(container, offEvent);
117
+ registerExitHook(offEvent);
115
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hile/cli",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -31,5 +31,5 @@
31
31
  "glob": "^13.0.6",
32
32
  "tsx": "^4.21.0"
33
33
  },
34
- "gitHead": "439a7eb90a233d466f97df932782d74dd64a50f2"
34
+ "gitHead": "64f79a1b10cbc557b5b4e72caf369fa328aa180b"
35
35
  }