node-karin 1.9.8 → 1.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # 更新日志
2
2
 
3
+ ## [1.9.9](https://github.com/KarinJS/Karin/compare/core-v1.9.8...core-v1.9.9) (2025-06-04)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * close [#450](https://github.com/KarinJS/Karin/issues/450) ([35aa118](https://github.com/KarinJS/Karin/commit/35aa118dc69c6370b9e090437b65e9a39a2a99c2))
9
+
10
+
11
+ ### ⚡️ Performance
12
+
13
+ * 优化获取实时日志文件Api 限制大文件大小 ([a96de40](https://github.com/KarinJS/Karin/commit/a96de404497edbaaa40b10181341d3586234f73e))
14
+
15
+
16
+ ### 💄 Styles
17
+
18
+ * 优化进程显示标题 ([08c284d](https://github.com/KarinJS/Karin/commit/08c284d317172e09b3e60049cbcc84f18355ff90))
19
+
20
+
21
+ ### ♻️ Code Refactoring
22
+
23
+ * 优化子进程管理逻辑 ([f6629f8](https://github.com/KarinJS/Karin/commit/f6629f886e1f3e578353a1aa200543a45b27e0a2))
24
+
3
25
  ## [1.9.8](https://github.com/KarinJS/Karin/compare/core-v1.9.7...core-v1.9.8) (2025-05-24)
4
26
 
5
27
 
package/dist/index.d.ts CHANGED
@@ -8020,14 +8020,20 @@ interface Author {
8020
8020
  name?: string;
8021
8021
  /** 主页 */
8022
8022
  home?: string;
8023
- /** 头像 */
8023
+ /**
8024
+ * 头像
8025
+ * @description https://github.com/[owner].png
8026
+ */
8024
8027
  avatar?: string;
8025
8028
  }
8026
8029
  /**
8027
8030
  * 插件图标
8028
8031
  */
8029
8032
  interface Icon {
8030
- /** 图标名称 */
8033
+ /**
8034
+ * 图标名称
8035
+ * @see https://fonts.google.com/icons
8036
+ */
8031
8037
  name?: string;
8032
8038
  /** 图标大小 */
8033
8039
  size?: number;
package/dist/index.mjs CHANGED
@@ -76,8 +76,8 @@ function getDefaultExportFromCjs(x) {
76
76
  function requireMain() {
77
77
  if (hasRequiredMain) return main$1.exports;
78
78
  hasRequiredMain = 1;
79
- const fs37 = fs15;
80
- const path36 = path;
79
+ const fs38 = fs15;
80
+ const path37 = path;
81
81
  const os5 = require$$2;
82
82
  const crypto9 = require$$22;
83
83
  const packageJson = require$$4;
@@ -180,7 +180,7 @@ function requireMain() {
180
180
  if (options && options.path && options.path.length > 0) {
181
181
  if (Array.isArray(options.path)) {
182
182
  for (const filepath of options.path) {
183
- if (fs37.existsSync(filepath)) {
183
+ if (fs38.existsSync(filepath)) {
184
184
  possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
185
185
  }
186
186
  }
@@ -188,15 +188,15 @@ function requireMain() {
188
188
  possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
189
189
  }
190
190
  } else {
191
- possibleVaultPath = path36.resolve(process.cwd(), ".env.vault");
191
+ possibleVaultPath = path37.resolve(process.cwd(), ".env.vault");
192
192
  }
193
- if (fs37.existsSync(possibleVaultPath)) {
193
+ if (fs38.existsSync(possibleVaultPath)) {
194
194
  return possibleVaultPath;
195
195
  }
196
196
  return null;
197
197
  }
198
198
  function _resolveHome(envPath) {
199
- return envPath[0] === "~" ? path36.join(os5.homedir(), envPath.slice(1)) : envPath;
199
+ return envPath[0] === "~" ? path37.join(os5.homedir(), envPath.slice(1)) : envPath;
200
200
  }
201
201
  function _configVault2(options) {
202
202
  const debug3 = Boolean(options && options.debug);
@@ -212,7 +212,7 @@ function requireMain() {
212
212
  return { parsed };
213
213
  }
214
214
  function configDotenv2(options) {
215
- const dotenvPath = path36.resolve(process.cwd(), ".env");
215
+ const dotenvPath = path37.resolve(process.cwd(), ".env");
216
216
  let encoding = "utf8";
217
217
  const debug3 = Boolean(options && options.debug);
218
218
  if (options && options.encoding) {
@@ -237,7 +237,7 @@ function requireMain() {
237
237
  const parsedAll = {};
238
238
  for (const path210 of optionPaths) {
239
239
  try {
240
- const parsed = DotenvModule.parse(fs37.readFileSync(path210, { encoding }));
240
+ const parsed = DotenvModule.parse(fs38.readFileSync(path210, { encoding }));
241
241
  DotenvModule.populate(parsedAll, parsed, options);
242
242
  } catch (e) {
243
243
  if (debug3) {
@@ -1287,9 +1287,9 @@ var init_data = __esm({
1287
1287
  stream3.on("end", () => resolve(Buffer.concat(chunks)));
1288
1288
  stream3.on("error", (error) => reject(error));
1289
1289
  });
1290
- readFile = async (path36) => {
1290
+ readFile = async (path37) => {
1291
1291
  try {
1292
- const data = await fs5.promises.readFile(path36);
1292
+ const data = await fs5.promises.readFile(path37);
1293
1293
  return data;
1294
1294
  } catch (error) {
1295
1295
  logger.error(error);
@@ -1305,36 +1305,36 @@ var init_data = __esm({
1305
1305
  var readJsonSync, writeJsonSync, readJson, writeJson, json;
1306
1306
  var init_json = __esm({
1307
1307
  "src/utils/fs/json.ts"() {
1308
- readJsonSync = (path36, isThrow = false) => {
1308
+ readJsonSync = (path37, isThrow = false) => {
1309
1309
  try {
1310
- const data = fs5.readFileSync(path36, "utf8");
1310
+ const data = fs5.readFileSync(path37, "utf8");
1311
1311
  return JSON.parse(data);
1312
1312
  } catch (error) {
1313
1313
  if (isThrow) throw error;
1314
1314
  return null;
1315
1315
  }
1316
1316
  };
1317
- writeJsonSync = (path36, data, isThrow = false) => {
1317
+ writeJsonSync = (path37, data, isThrow = false) => {
1318
1318
  try {
1319
- fs5.writeFileSync(path36, JSON.stringify(data, null, 2));
1319
+ fs5.writeFileSync(path37, JSON.stringify(data, null, 2));
1320
1320
  return true;
1321
1321
  } catch (error) {
1322
1322
  if (isThrow) throw error;
1323
1323
  return false;
1324
1324
  }
1325
1325
  };
1326
- readJson = async (path36, isThrow = false) => {
1326
+ readJson = async (path37, isThrow = false) => {
1327
1327
  try {
1328
- const data = await fs5.promises.readFile(path36, "utf8");
1328
+ const data = await fs5.promises.readFile(path37, "utf8");
1329
1329
  return JSON.parse(data);
1330
1330
  } catch (error) {
1331
1331
  if (isThrow) throw error;
1332
1332
  return null;
1333
1333
  }
1334
1334
  };
1335
- writeJson = async (path36, data, isThrow = false) => {
1335
+ writeJson = async (path37, data, isThrow = false) => {
1336
1336
  try {
1337
- await fs5.promises.writeFile(path36, JSON.stringify(data, null, 2));
1337
+ await fs5.promises.writeFile(path37, JSON.stringify(data, null, 2));
1338
1338
  return true;
1339
1339
  } catch (error) {
1340
1340
  if (isThrow) throw error;
@@ -1530,10 +1530,10 @@ var init_yaml = __esm({
1530
1530
  * 获取指定路径的值
1531
1531
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
1532
1532
  */
1533
- get(path36) {
1533
+ get(path37) {
1534
1534
  try {
1535
- if (!path36) return this.document.toJSON();
1536
- return lodash3.get(this.document.toJSON(), path36);
1535
+ if (!path37) return this.document.toJSON();
1536
+ return lodash3.get(this.document.toJSON(), path37);
1537
1537
  } catch (error) {
1538
1538
  logger.error(`[YamlEditor] \u83B7\u53D6\u6570\u636E\u65F6\u51FA\u9519\uFF1A${error}`);
1539
1539
  return null;
@@ -1545,9 +1545,9 @@ var init_yaml = __esm({
1545
1545
  * @param value - 要设置的值 允许的类型:`string`, `boolean`, `number`, `object`, `array`
1546
1546
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1547
1547
  */
1548
- set(path36, value, isSplit = true) {
1548
+ set(path37, value, isSplit = true) {
1549
1549
  try {
1550
- const _path = typeof path36 === "string" ? isSplit ? path36.split(".") : [path36] : path36;
1550
+ const _path = typeof path37 === "string" ? isSplit ? path37.split(".") : [path37] : path37;
1551
1551
  this.document.setIn(_path, value);
1552
1552
  return true;
1553
1553
  } catch (error) {
@@ -1561,11 +1561,11 @@ var init_yaml = __esm({
1561
1561
  * @param value - 要添加的值
1562
1562
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1563
1563
  */
1564
- add(path36, value, isSplit = true) {
1564
+ add(path37, value, isSplit = true) {
1565
1565
  try {
1566
- const _path = typeof path36 === "string" ? isSplit ? path36.split(".") : [path36] : path36;
1566
+ const _path = typeof path37 === "string" ? isSplit ? path37.split(".") : [path37] : path37;
1567
1567
  this.document.addIn(_path, value);
1568
- logger.debug(`[YamlEditor] \u5DF2\u5728 ${path36} \u6DFB\u52A0\u65B0\u7684\u503C`);
1568
+ logger.debug(`[YamlEditor] \u5DF2\u5728 ${path37} \u6DFB\u52A0\u65B0\u7684\u503C`);
1569
1569
  return true;
1570
1570
  } catch (error) {
1571
1571
  logger.error(`[YamlEditor] \u6DFB\u52A0\u6570\u636E\u65F6\u51FA\u9519\uFF1A${error}`);
@@ -1578,9 +1578,9 @@ var init_yaml = __esm({
1578
1578
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1579
1579
  * @returns 是否删除成功
1580
1580
  */
1581
- del(path36, isSplit = true) {
1581
+ del(path37, isSplit = true) {
1582
1582
  try {
1583
- const _path = typeof path36 === "string" ? isSplit ? path36.split(".") : [path36] : path36;
1583
+ const _path = typeof path37 === "string" ? isSplit ? path37.split(".") : [path37] : path37;
1584
1584
  this.document.deleteIn(_path);
1585
1585
  return true;
1586
1586
  } catch (error) {
@@ -1595,9 +1595,9 @@ var init_yaml = __esm({
1595
1595
  * @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
1596
1596
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1597
1597
  */
1598
- append(path36, value, prepend = false, isSplit = true) {
1598
+ append(path37, value, prepend = false, isSplit = true) {
1599
1599
  try {
1600
- const _path = typeof path36 === "string" ? isSplit ? path36.split(".") : [path36] : path36;
1600
+ const _path = typeof path37 === "string" ? isSplit ? path37.split(".") : [path37] : path37;
1601
1601
  let current = this.document.getIn(_path);
1602
1602
  if (!current) {
1603
1603
  current = new YAML.YAMLSeq();
@@ -1608,7 +1608,7 @@ var init_yaml = __esm({
1608
1608
  } else {
1609
1609
  prepend ? current.items.unshift(value) : current.add(value);
1610
1610
  }
1611
- logger.debug(`[YamlEditor] \u5DF2\u5411 ${path36} \u6570\u7EC4${prepend ? "\u5F00\u5934" : "\u672B\u5C3E"}\u6DFB\u52A0\u65B0\u5143\u7D20\uFF1A${value}`);
1611
+ logger.debug(`[YamlEditor] \u5DF2\u5411 ${path37} \u6570\u7EC4${prepend ? "\u5F00\u5934" : "\u672B\u5C3E"}\u6DFB\u52A0\u65B0\u5143\u7D20\uFF1A${value}`);
1612
1612
  return true;
1613
1613
  } catch (error) {
1614
1614
  logger.error(`[YamlEditor] \u5411\u6570\u7EC4\u6DFB\u52A0\u5143\u7D20\u65F6\u51FA\u9519\uFF1A${error}`);
@@ -1621,9 +1621,9 @@ var init_yaml = __esm({
1621
1621
  * @param value - 要删除的值
1622
1622
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1623
1623
  */
1624
- remove(path36, value, isSplit = true) {
1624
+ remove(path37, value, isSplit = true) {
1625
1625
  try {
1626
- const _path = typeof path36 === "string" ? isSplit ? path36.split(".") : [path36] : path36;
1626
+ const _path = typeof path37 === "string" ? isSplit ? path37.split(".") : [path37] : path37;
1627
1627
  const current = this.document.getIn(_path);
1628
1628
  if (!current) {
1629
1629
  logger.error("[YamlEditor] \u6307\u5B9A\u7684\u8DEF\u5F84\u4E0D\u5B58\u5728");
@@ -1639,7 +1639,7 @@ var init_yaml = __esm({
1639
1639
  return false;
1640
1640
  }
1641
1641
  current.items.splice(index6, 1);
1642
- logger.debug(`[YamlEditor] \u5DF2\u4ECE ${path36} \u6570\u7EC4\u5220\u9664\u5143\u7D20\uFF1A${value}`);
1642
+ logger.debug(`[YamlEditor] \u5DF2\u4ECE ${path37} \u6570\u7EC4\u5220\u9664\u5143\u7D20\uFF1A${value}`);
1643
1643
  return true;
1644
1644
  } catch (error) {
1645
1645
  logger.error(`[YamlEditor] \u4ECE\u6570\u7EC4\u5220\u9664\u5143\u7D20\u65F6\u51FA\u9519\uFF1A${error}`);
@@ -1651,9 +1651,9 @@ var init_yaml = __esm({
1651
1651
  * @param path - 路径,用点号分隔
1652
1652
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1653
1653
  */
1654
- has(path36, isSplit = true) {
1654
+ has(path37, isSplit = true) {
1655
1655
  try {
1656
- const _path = typeof path36 === "string" ? isSplit ? path36.split(".") : [path36] : path36;
1656
+ const _path = typeof path37 === "string" ? isSplit ? path37.split(".") : [path37] : path37;
1657
1657
  return this.document.hasIn(_path);
1658
1658
  } catch (error) {
1659
1659
  logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84\u662F\u5426\u5B58\u5728\u65F6\u51FA\u9519\uFF1A${error}`);
@@ -1666,9 +1666,9 @@ var init_yaml = __esm({
1666
1666
  * @param value - 要查询的值
1667
1667
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1668
1668
  */
1669
- hasval(path36, value, isSplit = true) {
1669
+ hasval(path37, value, isSplit = true) {
1670
1670
  try {
1671
- const _path = typeof path36 === "string" ? isSplit ? path36.split(".") : [path36] : path36;
1671
+ const _path = typeof path37 === "string" ? isSplit ? path37.split(".") : [path37] : path37;
1672
1672
  const current = this.document.getIn(_path);
1673
1673
  if (!current) return false;
1674
1674
  if (current instanceof YAML.YAMLSeq) {
@@ -1679,7 +1679,7 @@ var init_yaml = __esm({
1679
1679
  return lodash3.isEqual(current, value);
1680
1680
  }
1681
1681
  } catch (error) {
1682
- logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84 ${path36} \u662F\u5426\u5305\u542B\u503C\u65F6\u51FA\u9519\uFF1A${error}`);
1682
+ logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84 ${path37} \u662F\u5426\u5305\u542B\u503C\u65F6\u51FA\u9519\uFF1A${error}`);
1683
1683
  return false;
1684
1684
  }
1685
1685
  }
@@ -1689,8 +1689,8 @@ var init_yaml = __esm({
1689
1689
  * @param value - 要查询的值
1690
1690
  * @deprecated 请使用 `hasval` 代替
1691
1691
  */
1692
- hasVal(path36, value) {
1693
- return this.hasval(path36, value);
1692
+ hasVal(path37, value) {
1693
+ return this.hasval(path37, value);
1694
1694
  }
1695
1695
  /**
1696
1696
  * 向根节点新增元素,如果根节点不是数组,则将其转换为数组再新增元素
@@ -1735,9 +1735,9 @@ var init_yaml = __esm({
1735
1735
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
1736
1736
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1737
1737
  */
1738
- getpair(path36, isSplit = true) {
1739
- if (!path36) throw new Error("path is required");
1740
- const keys = typeof path36 === "string" ? isSplit ? path36.split(".") : [path36] : path36;
1738
+ getpair(path37, isSplit = true) {
1739
+ if (!path37) throw new Error("path is required");
1740
+ const keys = typeof path37 === "string" ? isSplit ? path37.split(".") : [path37] : path37;
1741
1741
  let pair = this.document.contents;
1742
1742
  keys.forEach((key) => {
1743
1743
  if (isMap(pair)) {
@@ -1757,10 +1757,10 @@ var init_yaml = __esm({
1757
1757
  * @param prepend - 如果为 true,则添加注释到开头,否则添加到同一行的末尾
1758
1758
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1759
1759
  */
1760
- comment(path36, comment2, prepend = true, isSplit = true) {
1761
- if (!path36) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
1762
- const pair = this.getpair(path36, isSplit);
1763
- if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path36}`);
1760
+ comment(path37, comment2, prepend = true, isSplit = true) {
1761
+ if (!path37) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
1762
+ const pair = this.getpair(path37, isSplit);
1763
+ if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path37}`);
1764
1764
  comment2 = ` ${comment2}`;
1765
1765
  if (prepend) {
1766
1766
  pair.key.commentBefore = comment2;
@@ -1774,10 +1774,10 @@ var init_yaml = __esm({
1774
1774
  * @param type - 要删除的注释类型,`before` 为注释前,`after` 为注释后,`all` 为全部
1775
1775
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1776
1776
  */
1777
- uncomment(path36, type = "all", isSplit = true) {
1778
- if (!path36) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
1779
- const pair = this.getpair(path36, isSplit);
1780
- if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path36}`);
1777
+ uncomment(path37, type = "all", isSplit = true) {
1778
+ if (!path37) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
1779
+ const pair = this.getpair(path37, isSplit);
1780
+ if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path37}`);
1781
1781
  if (type === "all") {
1782
1782
  delete pair.key.comment;
1783
1783
  delete pair.key.commentBefore;
@@ -1793,10 +1793,10 @@ var init_yaml = __esm({
1793
1793
  * @param type - 要检查的注释类型,`before` 为注释前,`after` 为注释后
1794
1794
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1795
1795
  */
1796
- hascomment(path36, type, isSplit = true) {
1797
- if (!path36) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
1798
- const pair = this.getpair(path36, isSplit);
1799
- if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path36}`);
1796
+ hascomment(path37, type, isSplit = true) {
1797
+ if (!path37) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
1798
+ const pair = this.getpair(path37, isSplit);
1799
+ if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path37}`);
1800
1800
  if (type === "before") {
1801
1801
  return !!pair.key.commentBefore;
1802
1802
  } else if (type === "after") {
@@ -1809,10 +1809,10 @@ var init_yaml = __esm({
1809
1809
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
1810
1810
  * @param isSplit - 是否使用分割路径路径,默认为 `true`
1811
1811
  */
1812
- getcomment(path36, isSplit = true) {
1813
- if (!path36) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
1814
- const pair = this.getpair(path36, isSplit);
1815
- if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path36}`);
1812
+ getcomment(path37, isSplit = true) {
1813
+ if (!path37) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
1814
+ const pair = this.getpair(path37, isSplit);
1815
+ if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path37}`);
1816
1816
  return pair.key.commentBefore || pair.key.comment;
1817
1817
  }
1818
1818
  /**
@@ -1824,11 +1824,11 @@ var init_yaml = __esm({
1824
1824
  logger.debug("[YamlEditor] \u6587\u4EF6\u5DF2\u4FDD\u5B58");
1825
1825
  }
1826
1826
  };
1827
- read = (path36) => {
1828
- const data = YAML.parse(fs5.readFileSync(path36, "utf-8"));
1827
+ read = (path37) => {
1828
+ const data = YAML.parse(fs5.readFileSync(path37, "utf-8"));
1829
1829
  read.save = (options) => {
1830
1830
  try {
1831
- save(path36, data, typeof options === "string" ? JSON.parse(options) : options);
1831
+ save(path37, data, typeof options === "string" ? JSON.parse(options) : options);
1832
1832
  return true;
1833
1833
  } catch (error) {
1834
1834
  logger.error("[YamlEditor] \u4FDD\u5B58\u6587\u4EF6\u65F6\u51FA\u9519");
@@ -1838,23 +1838,23 @@ var init_yaml = __esm({
1838
1838
  };
1839
1839
  return data;
1840
1840
  };
1841
- write = (path36, value) => {
1841
+ write = (path37, value) => {
1842
1842
  try {
1843
- fs5.writeFileSync(path36, YAML.stringify(value));
1843
+ fs5.writeFileSync(path37, YAML.stringify(value));
1844
1844
  return true;
1845
1845
  } catch {
1846
1846
  return false;
1847
1847
  }
1848
1848
  };
1849
- save = (path36, value, options) => {
1849
+ save = (path37, value, options) => {
1850
1850
  if (!options) {
1851
- fs5.writeFileSync(path36, YAML.stringify(value));
1851
+ fs5.writeFileSync(path37, YAML.stringify(value));
1852
1852
  return;
1853
1853
  }
1854
1854
  const editor = new YamlEditor(YAML.stringify(value));
1855
1855
  const comment2 = typeof options === "string" ? JSON.parse(fs5.readFileSync(options, "utf8")) : options;
1856
1856
  applyComments(editor, comment2);
1857
- fs5.writeFileSync(path36, editor.document.toString());
1857
+ fs5.writeFileSync(path37, editor.document.toString());
1858
1858
  };
1859
1859
  comment = (filePath, commentConfig) => {
1860
1860
  const editor = new YamlEditor(filePath);
@@ -10440,11 +10440,11 @@ var init_update = __esm({
10440
10440
  }
10441
10441
  };
10442
10442
  getCommit = async (options) => {
10443
- const { path: path36, count: count3 = 1, hash, branch } = options;
10443
+ const { path: path37, count: count3 = 1, hash, branch } = options;
10444
10444
  let cmd = `git log -${count3} --format="[%ad]%s %n" --date="format:%m-%d %H:%M"`;
10445
10445
  if (hash) cmd = `git log ${hash}..HEAD --format="[%ad] %s %n" --date="format:%m-%d %H:%M"`;
10446
10446
  if (branch) cmd = `git log -${count3} ${branch} --format="[%ad] %s %n" --date="format:%m-%d %H:%M"`;
10447
- const { stdout, error } = await exec(cmd, { cwd: path36 });
10447
+ const { stdout, error } = await exec(cmd, { cwd: path37 });
10448
10448
  if (error) {
10449
10449
  throw error;
10450
10450
  }
@@ -11540,8 +11540,8 @@ var init_github = __esm({
11540
11540
  const urlObj = new URL$1(url);
11541
11541
  const owner = urlObj.pathname.split("/")[1];
11542
11542
  const repo = urlObj.pathname.split("/")[2];
11543
- const path36 = urlObj.pathname.split("/").slice(3).join("/");
11544
- return { owner, repo, path: path36 };
11543
+ const path37 = urlObj.pathname.split("/").slice(3).join("/");
11544
+ return { owner, repo, path: path37 };
11545
11545
  };
11546
11546
  getFastGithub = async (type) => {
11547
11547
  const list2 = [
@@ -11561,8 +11561,8 @@ var init_github = __esm({
11561
11561
  isClone: false,
11562
11562
  isRaw: true,
11563
11563
  raw: function(url) {
11564
- const { owner, repo, path: path36 } = parseGithubUrl(url);
11565
- return `${this.proxy}/${owner}/${repo}/${path36}`;
11564
+ const { owner, repo, path: path37 } = parseGithubUrl(url);
11565
+ return `${this.proxy}/${owner}/${repo}/${path37}`;
11566
11566
  },
11567
11567
  clone: function(url) {
11568
11568
  const { owner, repo } = parseGithubUrl(url);
@@ -11574,8 +11574,8 @@ var init_github = __esm({
11574
11574
  isClone: false,
11575
11575
  isRaw: true,
11576
11576
  raw: function(url) {
11577
- const { owner, repo, path: path36 } = parseGithubUrl(url);
11578
- return `${this.proxy}/${owner}/${repo}/${path36}`;
11577
+ const { owner, repo, path: path37 } = parseGithubUrl(url);
11578
+ return `${this.proxy}/${owner}/${repo}/${path37}`;
11579
11579
  },
11580
11580
  clone: function(url) {
11581
11581
  const { owner, repo } = parseGithubUrl(url);
@@ -12052,7 +12052,7 @@ function requireDataStream() {
12052
12052
  hasRequiredDataStream = 1;
12053
12053
  var Buffer2 = requireSafeBuffer().Buffer;
12054
12054
  var Stream = require$$32;
12055
- var util6 = require$$5;
12055
+ var util7 = require$$5;
12056
12056
  function DataStream(data) {
12057
12057
  this.buffer = null;
12058
12058
  this.writable = true;
@@ -12078,7 +12078,7 @@ function requireDataStream() {
12078
12078
  }
12079
12079
  throw new TypeError("Unexpected data type (" + typeof data + ")");
12080
12080
  }
12081
- util6.inherits(DataStream, Stream);
12081
+ util7.inherits(DataStream, Stream);
12082
12082
  DataStream.prototype.write = function write2(data) {
12083
12083
  this.buffer = Buffer2.concat([this.buffer, Buffer2.from(data)]);
12084
12084
  this.emit("data", data);
@@ -12287,7 +12287,7 @@ function requireJwa() {
12287
12287
  var Buffer2 = requireSafeBuffer().Buffer;
12288
12288
  var crypto9 = require$$22;
12289
12289
  var formatEcdsa = requireEcdsaSigFormatter();
12290
- var util6 = require$$5;
12290
+ var util7 = require$$5;
12291
12291
  var MSG_INVALID_ALGORITHM = '"%s" is not a valid algorithm.\n Supported algorithms are:\n "HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512" and "none".';
12292
12292
  var MSG_INVALID_SECRET = "secret must be a string or buffer";
12293
12293
  var MSG_INVALID_VERIFIER_KEY = "key must be a string or a buffer";
@@ -12367,7 +12367,7 @@ function requireJwa() {
12367
12367
  }
12368
12368
  function typeError(template2) {
12369
12369
  var args = [].slice.call(arguments, 1);
12370
- var errMsg = util6.format.bind(util6, template2).apply(null, args);
12370
+ var errMsg = util7.format.bind(util7, template2).apply(null, args);
12371
12371
  return new TypeError(errMsg);
12372
12372
  }
12373
12373
  function bufferOrString(obj) {
@@ -12513,7 +12513,7 @@ function requireSignStream() {
12513
12513
  var jwa2 = requireJwa();
12514
12514
  var Stream = require$$32;
12515
12515
  var toString = requireTostring();
12516
- var util6 = require$$5;
12516
+ var util7 = require$$5;
12517
12517
  function base64url(string, encoding) {
12518
12518
  return Buffer2.from(string, encoding).toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
12519
12519
  }
@@ -12521,7 +12521,7 @@ function requireSignStream() {
12521
12521
  encoding = encoding || "utf8";
12522
12522
  var encodedHeader = base64url(toString(header), "binary");
12523
12523
  var encodedPayload = base64url(toString(payload), encoding);
12524
- return util6.format("%s.%s", encodedHeader, encodedPayload);
12524
+ return util7.format("%s.%s", encodedHeader, encodedPayload);
12525
12525
  }
12526
12526
  function jwsSign(opts) {
12527
12527
  var header = opts.header;
@@ -12531,7 +12531,7 @@ function requireSignStream() {
12531
12531
  var algo = jwa2(header.alg);
12532
12532
  var securedInput = jwsSecuredInput(header, payload, encoding);
12533
12533
  var signature = algo.sign(securedInput, secretOrKey);
12534
- return util6.format("%s.%s", securedInput, signature);
12534
+ return util7.format("%s.%s", securedInput, signature);
12535
12535
  }
12536
12536
  function SignStream(opts) {
12537
12537
  var secret = opts.secret || opts.privateKey || opts.key;
@@ -12550,7 +12550,7 @@ function requireSignStream() {
12550
12550
  this.sign();
12551
12551
  }.bind(this));
12552
12552
  }
12553
- util6.inherits(SignStream, Stream);
12553
+ util7.inherits(SignStream, Stream);
12554
12554
  SignStream.prototype.sign = function sign2() {
12555
12555
  try {
12556
12556
  var signature = jwsSign({
@@ -12582,7 +12582,7 @@ function requireVerifyStream() {
12582
12582
  var jwa2 = requireJwa();
12583
12583
  var Stream = require$$32;
12584
12584
  var toString = requireTostring();
12585
- var util6 = require$$5;
12585
+ var util7 = require$$5;
12586
12586
  var JWS_REGEX = /^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)?$/;
12587
12587
  function isObject(thing) {
12588
12588
  return Object.prototype.toString.call(thing) === "[object Object]";
@@ -12661,7 +12661,7 @@ function requireVerifyStream() {
12661
12661
  this.verify();
12662
12662
  }.bind(this));
12663
12663
  }
12664
- util6.inherits(VerifyStream, Stream);
12664
+ util7.inherits(VerifyStream, Stream);
12665
12665
  VerifyStream.prototype.verify = function verify2() {
12666
12666
  try {
12667
12667
  var valid2 = jwsVerify(this.signature.buffer, this.algorithm, this.key.buffer);
@@ -17794,35 +17794,35 @@ var init_check = __esm({
17794
17794
  headers: { Authorization: `Bearer ${process.env.HTTP_AUTH_KEY}` },
17795
17795
  validateStatus: () => true
17796
17796
  });
17797
- request = async (url, path36, method, timeout2, isPrint = true) => {
17797
+ request = async (url, path37, method, timeout2, isPrint = true) => {
17798
17798
  const client = createHttpClient(url, timeout2);
17799
17799
  try {
17800
- const result = await client[method](path36);
17801
- return handleResponse(result, method, path36, isPrint);
17800
+ const result = await client[method](path37);
17801
+ return handleResponse(result, method, path37, isPrint);
17802
17802
  } catch (error) {
17803
17803
  logger.debug(
17804
- tips(`${method.toUpperCase()} \u8BF7\u6C42\u5F02\u5E38:`, true) + ` ${path36} - ${error?.message || "\u672A\u77E5\u9519\u8BEF"}`
17804
+ tips(`${method.toUpperCase()} \u8BF7\u6C42\u5F02\u5E38:`, true) + ` ${path37} - ${error?.message || "\u672A\u77E5\u9519\u8BEF"}`
17805
17805
  );
17806
17806
  return { code: 500, success: false };
17807
17807
  }
17808
17808
  };
17809
- handleResponse = (result, method, path36, isPrint) => {
17809
+ handleResponse = (result, method, path37, isPrint) => {
17810
17810
  if (result.status === 200) {
17811
17811
  isPrint && logger.info(
17812
- tips(`${method.toUpperCase()} \u8BF7\u6C42\u6210\u529F:`, true) + ` ${path36} -> ${JSON.stringify(result.data)}`
17812
+ tips(`${method.toUpperCase()} \u8BF7\u6C42\u6210\u529F:`, true) + ` ${path37} -> ${JSON.stringify(result.data)}`
17813
17813
  );
17814
17814
  return { code: result.status, success: true, data: result.data };
17815
17815
  }
17816
17816
  if (result.status === 401) {
17817
17817
  logger.error(
17818
- tips(`${method.toUpperCase()} \u9274\u6743\u5931\u8D25:`, true) + ` ${path36} -> ${JSON.stringify(result.data)}`
17818
+ tips(`${method.toUpperCase()} \u9274\u6743\u5931\u8D25:`, true) + ` ${path37} -> ${JSON.stringify(result.data)}`
17819
17819
  );
17820
17820
  return { code: result.status, success: false };
17821
17821
  }
17822
- const logMethod = path36 === "/ping" ? logger.debug : logger.error;
17822
+ const logMethod = path37 === "/ping" ? logger.debug : logger.error;
17823
17823
  logMethod.call(
17824
17824
  logger,
17825
- tips(`${method.toUpperCase()} \u8BF7\u6C42\u5931\u8D25:`, true) + ` ${path36} -> ${JSON.stringify(result.data)}`
17825
+ tips(`${method.toUpperCase()} \u8BF7\u6C42\u5931\u8D25:`, true) + ` ${path37} -> ${JSON.stringify(result.data)}`
17826
17826
  );
17827
17827
  return { code: result.status, success: false };
17828
17828
  };
@@ -20750,12 +20750,14 @@ var init_getLog = __esm({
20750
20750
  activeConnections = 0;
20751
20751
  getLogRouter = async (req, res) => {
20752
20752
  const maxConnections = Number(process.env.LOG_API_MAX_CONNECTIONS) || 5;
20753
+ const MAX_CHUNK_SIZE = Number(process.env.LOG_API_MAX_CHUNK_SIZE) || 1024 * 1024;
20753
20754
  if (activeConnections >= maxConnections) {
20754
20755
  return createBadRequestResponse(res, "\u5F53\u524D\u8FDE\u63A5\u6570\u5DF2\u8FBE\u5230\u4E0A\u9650\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
20755
20756
  }
20756
20757
  activeConnections++;
20757
20758
  const date = moment();
20758
20759
  if (!date.isValid()) {
20760
+ activeConnections--;
20759
20761
  return createBadRequestResponse(res, "\u65E5\u671F\u683C\u5F0F\u9519\u8BEF");
20760
20762
  }
20761
20763
  const file = path4.join(logsPath, `logger.${date.format("YYYY-MM-DD")}.log`);
@@ -20764,6 +20766,7 @@ var init_getLog = __esm({
20764
20766
  res.setHeader("Connection", "keep-alive");
20765
20767
  res.setHeader("X-Accel-Buffering", "no");
20766
20768
  let position = 0;
20769
+ let isStreaming = false;
20767
20770
  const isEventSource = req.headers.accept === "text/event-stream";
20768
20771
  const heartbeat = setInterval(() => {
20769
20772
  if (isEventSource) {
@@ -20771,6 +20774,7 @@ var init_getLog = __esm({
20771
20774
  }
20772
20775
  }, 3e4);
20773
20776
  const tailFile = () => {
20777
+ if (isStreaming) return;
20774
20778
  fs5.stat(file, (err, stats) => {
20775
20779
  if (err) {
20776
20780
  logger.error("\u8BFB\u53D6\u65E5\u5FD7\u6587\u4EF6\u72B6\u6001\u9519\u8BEF:", err);
@@ -20780,25 +20784,37 @@ var init_getLog = __esm({
20780
20784
  position = 0;
20781
20785
  }
20782
20786
  if (position < stats.size) {
20783
- const stream3 = fs5.createReadStream(file, { start: position, encoding: "utf-8" });
20787
+ isStreaming = true;
20788
+ const endPosition = Math.min(position + MAX_CHUNK_SIZE, stats.size);
20789
+ const stream3 = fs5.createReadStream(file, {
20790
+ start: position,
20791
+ end: endPosition - 1,
20792
+ encoding: "utf-8",
20793
+ highWaterMark: 64 * 1024
20794
+ // 设置较小的缓冲区,减少内存使用
20795
+ });
20784
20796
  stream3.on("data", (data) => {
20785
20797
  const lines = data.toString().split("\n");
20786
20798
  for (const line of lines) {
20787
- if (isEventSource) {
20788
- res.write(`data: ${line}
20799
+ if (line) {
20800
+ if (isEventSource) {
20801
+ res.write(`data: ${line}
20789
20802
 
20790
20803
  `);
20791
- } else {
20792
- res.write(`${line}
20804
+ } else {
20805
+ res.write(`${line}
20793
20806
  `);
20807
+ }
20794
20808
  }
20795
20809
  }
20796
20810
  });
20797
20811
  stream3.on("end", () => {
20798
- position = stats.size;
20812
+ position = endPosition;
20813
+ isStreaming = false;
20799
20814
  });
20800
20815
  stream3.on("error", (error) => {
20801
20816
  logger.error("\u8BFB\u53D6\u65E5\u5FD7\u6587\u4EF6\u9519\u8BEF:", error.message);
20817
+ isStreaming = false;
20802
20818
  });
20803
20819
  }
20804
20820
  });
@@ -20810,6 +20826,11 @@ var init_getLog = __esm({
20810
20826
  clearInterval(heartbeat);
20811
20827
  activeConnections--;
20812
20828
  });
20829
+ req.on("error", () => {
20830
+ clearInterval(interval);
20831
+ clearInterval(heartbeat);
20832
+ activeConnections--;
20833
+ });
20813
20834
  };
20814
20835
  getLogFileListRouter = async (_, res) => {
20815
20836
  const files = fs5.readdirSync(logsPath);
@@ -20825,6 +20846,11 @@ var init_getLog = __esm({
20825
20846
  if (!fs5.existsSync(filePath)) {
20826
20847
  return createBadRequestResponse(res, "\u65E5\u5FD7\u6587\u4EF6\u4E0D\u5B58\u5728");
20827
20848
  }
20849
+ const stats = fs5.statSync(filePath);
20850
+ const FILE_SIZE_LIMIT = Number(process.env.LOG_FILE_SIZE_LIMIT) || 10 * 1024 * 1024;
20851
+ if (stats.size > FILE_SIZE_LIMIT) {
20852
+ return createBadRequestResponse(res, "\u65E5\u5FD7\u6587\u4EF6\u8FC7\u5927\uFF0C\u8BF7\u4F7F\u7528\u6D41\u5F0F\u63A5\u53E3\u83B7\u53D6\u6216\u4E0B\u8F7D\u6587\u4EF6");
20853
+ }
20828
20854
  const content = fs5.readFileSync(filePath, "utf-8");
20829
20855
  createSuccessResponse(res, content, "\u6210\u529F");
20830
20856
  };
@@ -22861,8 +22887,6 @@ var init_list2 = __esm({
22861
22887
  getRegistry();
22862
22888
  }
22863
22889
  });
22864
-
22865
- // src/server/dependencies/manage.ts
22866
22890
  var manageDependenciesRouter, installDependencies, removeDependencies, addDependencies;
22867
22891
  var init_manage2 = __esm({
22868
22892
  "src/server/dependencies/manage.ts"() {
@@ -22896,12 +22920,14 @@ var init_manage2 = __esm({
22896
22920
  const args = ["install", ...packagesToInstall.split(" ")];
22897
22921
  if (isWorkspace()) args.push("-w");
22898
22922
  await spawnProcess("pnpm", args, {}, emitLog);
22923
+ logger.mark(`\u5B89\u88C5\u4F9D\u8D56 ${logger.green(packagesToInstall)} \u5B8C\u6210`);
22899
22924
  return true;
22900
22925
  }
22901
22926
  );
22902
22927
  return handleReturn2(res, true, "\u5B89\u88C5\u4EFB\u52A1\u5DF2\u521B\u5EFA", id);
22903
22928
  } catch (error) {
22904
22929
  logger.error("[installDependencies]", error);
22930
+ logger.mark(`\u5B89\u88C5\u4F9D\u8D56 ${logger.red(dependencies.join(" "))} \u5931\u8D25`);
22905
22931
  return handleReturn2(res, false, `\u5B89\u88C5\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
22906
22932
  }
22907
22933
  };
@@ -22919,12 +22945,14 @@ var init_manage2 = __esm({
22919
22945
  const args = ["remove", ...packagesToRemove.split(" ")];
22920
22946
  if (isWorkspace()) args.push("-w");
22921
22947
  await spawnProcess("pnpm", args, {}, emitLog);
22948
+ logger.mark(`\u5220\u9664\u4F9D\u8D56 ${logger.yellow(packagesToRemove)} \u5B8C\u6210`);
22922
22949
  return true;
22923
22950
  }
22924
22951
  );
22925
22952
  return handleReturn2(res, true, "\u5220\u9664\u4EFB\u52A1\u5DF2\u521B\u5EFA", id);
22926
22953
  } catch (error) {
22927
22954
  logger.error("[removeDependencies]", error);
22955
+ logger.mark(`\u5220\u9664\u4F9D\u8D56 ${logger.red(dependencies.join(" "))} \u5931\u8D25`);
22928
22956
  return handleReturn2(res, false, `\u5220\u9664\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
22929
22957
  }
22930
22958
  };
@@ -22953,12 +22981,23 @@ var init_manage2 = __esm({
22953
22981
  }
22954
22982
  if (isWorkspace()) args.push("-w");
22955
22983
  await spawnProcess("pnpm", args, {}, emitLog);
22984
+ const depDir = path4.join(process.cwd(), "packages", dependencies.name, "package.json");
22985
+ try {
22986
+ const pkg2 = JSON.parse(fs5.readFileSync(depDir, "utf-8"));
22987
+ if (!pkg2.peerDependencies) return true;
22988
+ await spawnProcess("pnpm", ["install"], {}, emitLog);
22989
+ } catch (error) {
22990
+ logger.error("[addDependencies]", error);
22991
+ emitLog(util5.format(error));
22992
+ }
22993
+ logger.mark(`\u65B0\u589E\u4F9D\u8D56 ${logger.green(dependencies.name)} \u5B8C\u6210`);
22956
22994
  return true;
22957
22995
  }
22958
22996
  );
22959
22997
  return handleReturn2(res, true, "\u6DFB\u52A0\u4EFB\u52A1\u5DF2\u521B\u5EFA", id);
22960
22998
  } catch (error) {
22961
22999
  logger.error("[addDependencies]", error);
23000
+ logger.mark(`\u65B0\u589E\u4F9D\u8D56 ${logger.red(dependencies.name)} \u5931\u8D25`);
22962
23001
  return handleReturn2(res, false, `\u6DFB\u52A0\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
22963
23002
  }
22964
23003
  };
@@ -23253,12 +23292,12 @@ var init_config5 = __esm({
23253
23292
  };
23254
23293
  getNpmrcContentRouter = async (req, res) => {
23255
23294
  try {
23256
- const { path: path36 } = req.body;
23295
+ const { path: path37 } = req.body;
23257
23296
  const list2 = await getNpmConfigList();
23258
- if (!list2.find((item) => item.path === path36)) {
23297
+ if (!list2.find((item) => item.path === path37)) {
23259
23298
  return createBadRequestResponse(res, "\u6587\u4EF6\u4E0D\u5B58\u5728");
23260
23299
  }
23261
- const content = ini.read(path36);
23300
+ const content = ini.read(path37);
23262
23301
  return createSuccessResponse(res, content);
23263
23302
  } catch (error) {
23264
23303
  logger.error("[getNpmrcContentRouter]", error);
@@ -23285,7 +23324,7 @@ var init_config5 = __esm({
23285
23324
  };
23286
23325
  saveNpmrcRouter = async (req, res) => {
23287
23326
  try {
23288
- const { path: path36, content, baseConfig } = req.body;
23327
+ const { path: path37, content, baseConfig } = req.body;
23289
23328
  const list2 = await getNpmConfigList();
23290
23329
  const promises = [];
23291
23330
  if (baseConfig.registry) {
@@ -23298,11 +23337,11 @@ var init_config5 = __esm({
23298
23337
  promises.push(setNpmConfig("https-proxy", baseConfig["https-proxy"]));
23299
23338
  }
23300
23339
  await Promise.all(promises);
23301
- if (path36 && content) {
23302
- if (!list2.find((item) => item.path === path36)) {
23340
+ if (path37 && content) {
23341
+ if (!list2.find((item) => item.path === path37)) {
23303
23342
  return createBadRequestResponse(res, "\u6587\u4EF6\u4E0D\u5B58\u5728");
23304
23343
  }
23305
- ini.write(content, path36);
23344
+ ini.write(content, path37);
23306
23345
  }
23307
23346
  return createSuccessResponse(res, "\u4FDD\u5B58\u6210\u529F");
23308
23347
  } catch (error) {
@@ -24335,6 +24374,7 @@ init_check();
24335
24374
  init_exit();
24336
24375
  init_listeners();
24337
24376
  var processHandler = () => {
24377
+ process.title = `karin v${process.env.KARIN_VERSION} \xA9 ${(/* @__PURE__ */ new Date()).getFullYear()} - Karinjs`;
24338
24378
  process.once("SIGHUP", (code) => processExit(code));
24339
24379
  process.once("SIGINT", (code) => processExit(code));
24340
24380
  process.once("SIGTERM", (code) => processExit(code));
@@ -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 filePath = path.join(_dirname, import.meta.url.includes(".mjs") ? "app.mjs" : "app.ts");
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
- const { port, type, token } = JSON.parse(message) || {};
32
- if (type === "restart") {
33
- restart(port, token);
34
- return;
35
- }
36
- if (type === "stop") {
37
- process.exit(0);
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.on("error", (err) => {
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
- process.on("exit", () => {
105
- child.kill("SIGTERM");
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.9.8",
3
+ "version": "1.9.9",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",