@fastcar/core 0.3.10 → 0.3.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastcar/core",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "homepage": "https://github.com/williamDazhangyu/fast-car",
5
5
  "main": "target/index.js",
6
6
  "author": "william_zhong",
@@ -32,6 +32,7 @@
32
32
  "node": ">=18"
33
33
  },
34
34
  "dependencies": {
35
+ "chokidar": "^4.0.3",
35
36
  "reflect-metadata": "^0.2.2",
36
37
  "winston": "^3.10.0",
37
38
  "yaml": "^2.6.1"
@@ -134,10 +134,10 @@ class FastCarApplication extends Events {
134
134
 
135
135
  reloadFiles() {
136
136
  this.delayHotIds.forEach(({ fp, loadType }) => {
137
+ this.sysLogger.info(`hot update----${fp}`);
137
138
  switch (loadType) {
138
139
  case HotReloadEnum.reload: {
139
140
  let moduleClass = ClassLoader.loadModule(fp, true);
140
- this.sysLogger.info("hot update---" + fp);
141
141
  if (moduleClass != null) {
142
142
  moduleClass.forEach((func) => {
143
143
  this.convertInstance(func, fp);
@@ -146,7 +146,6 @@ class FastCarApplication extends Events {
146
146
  break;
147
147
  }
148
148
  case HotReloadEnum.sysReload: {
149
- this.sysLogger.info("sysConfig hot update----" + fp);
150
149
  this.loadSysConfig();
151
150
  break;
152
151
  }
@@ -1,8 +1,7 @@
1
1
  import TypeUtil from "./TypeUtil";
2
2
  import FileUtil from "./FileUtil";
3
- import * as fs from "fs";
4
- import * as path from "path";
5
3
  import { HotReloadEnum } from "../type/FileHotterDesc";
4
+ import chokidar from "chokidar";
6
5
 
7
6
  export default class ClassLoader {
8
7
  /***
@@ -49,23 +48,37 @@ export default class ClassLoader {
49
48
  /**
50
49
  * @version 1.0 监听某个文件或者文件夹
51
50
  */
52
- static watchServices(fp: string, context: any, eventName: HotReloadEnum = HotReloadEnum.reload): boolean {
51
+ static watchServices(
52
+ fp: string,
53
+ context: {
54
+ emit: (eventName: string | symbol, ...args: any) => boolean;
55
+ },
56
+ eventName: HotReloadEnum = HotReloadEnum.reload
57
+ ): boolean {
53
58
  if (typeof context.emit != "function") {
54
59
  return false;
55
60
  }
56
61
 
57
- const currStats = fs.statSync(fp);
58
- let fileFlag = currStats.isFile();
59
-
60
62
  //添加热更方法
61
- fs.watch(fp, function (event, filename) {
62
- if (event === "change") {
63
- if (!fileFlag && filename) {
64
- context.emit(eventName, path.join(fp, filename));
65
- } else {
66
- context.emit(eventName, fp);
67
- }
68
- }
63
+ const watcher = chokidar.watch(fp, {
64
+ persistent: true,
65
+ ignoreInitial: true,
66
+ awaitWriteFinish: {
67
+ stabilityThreshold: 500,
68
+ pollInterval: 100,
69
+ },
70
+ usePolling: false,
71
+ atomic: true,
72
+ });
73
+
74
+ watcher.on("change", (path) => {
75
+ context.emit(eventName, path);
76
+ watcher.unwatch(path); //防止因为git等操作造成inotify失效
77
+ watcher.add(path);
78
+ });
79
+
80
+ watcher.on("unlink", (path) => {
81
+ watcher.unwatch(path);
69
82
  });
70
83
 
71
84
  return true;
@@ -121,10 +121,10 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
121
121
  }
122
122
  reloadFiles() {
123
123
  this.delayHotIds.forEach(({ fp, loadType }) => {
124
+ this.sysLogger.info(`hot update----${fp}`);
124
125
  switch (loadType) {
125
126
  case FileHotterDesc_1.HotReloadEnum.reload: {
126
127
  let moduleClass = ClassLoader_1.default.loadModule(fp, true);
127
- this.sysLogger.info("hot update---" + fp);
128
128
  if (moduleClass != null) {
129
129
  moduleClass.forEach((func) => {
130
130
  this.convertInstance(func, fp);
@@ -133,7 +133,6 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
133
133
  break;
134
134
  }
135
135
  case FileHotterDesc_1.HotReloadEnum.sysReload: {
136
- this.sysLogger.info("sysConfig hot update----" + fp);
137
136
  this.loadSysConfig();
138
137
  break;
139
138
  }
@@ -2,9 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const TypeUtil_1 = require("./TypeUtil");
4
4
  const FileUtil_1 = require("./FileUtil");
5
- const fs = require("fs");
6
- const path = require("path");
7
5
  const FileHotterDesc_1 = require("../type/FileHotterDesc");
6
+ const chokidar_1 = require("chokidar");
8
7
  class ClassLoader {
9
8
  /***
10
9
  * @version 1.0 加载模块
@@ -47,18 +46,24 @@ class ClassLoader {
47
46
  if (typeof context.emit != "function") {
48
47
  return false;
49
48
  }
50
- const currStats = fs.statSync(fp);
51
- let fileFlag = currStats.isFile();
52
49
  //添加热更方法
53
- fs.watch(fp, function (event, filename) {
54
- if (event === "change") {
55
- if (!fileFlag && filename) {
56
- context.emit(eventName, path.join(fp, filename));
57
- }
58
- else {
59
- context.emit(eventName, fp);
60
- }
61
- }
50
+ const watcher = chokidar_1.default.watch(fp, {
51
+ persistent: true,
52
+ ignoreInitial: true,
53
+ awaitWriteFinish: {
54
+ stabilityThreshold: 500,
55
+ pollInterval: 100,
56
+ },
57
+ usePolling: false,
58
+ atomic: true,
59
+ });
60
+ watcher.on("change", (path) => {
61
+ context.emit(eventName, path);
62
+ watcher.unwatch(path); //防止因为git等操作造成inotify失效
63
+ watcher.add(path);
64
+ });
65
+ watcher.on("unlink", (path) => {
66
+ watcher.unwatch(path);
62
67
  });
63
68
  return true;
64
69
  }
@@ -1,11 +1,5 @@
1
- {"timestamp":"2024-12-09 15:03:04.199","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2024-12-09 15:03:04.437","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2024-12-09 15:03:04.439","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2024-12-09 15:03:04.441","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
- {"timestamp":"2024-12-09 15:03:04.442","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
- {"timestamp":"2024-12-09 15:03:58.880","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
- {"timestamp":"2024-12-09 15:06:04.17","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
8
- {"timestamp":"2024-12-09 15:06:04.249","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
9
- {"timestamp":"2024-12-09 15:06:04.251","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
10
- {"timestamp":"2024-12-09 15:06:04.253","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
11
- {"timestamp":"2024-12-09 15:06:04.254","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
1
+ {"timestamp":"2025-08-25 15:08:20.393","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-08-25 15:08:20.821","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-08-25 15:08:20.824","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-08-25 15:08:20.828","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-08-25 15:08:20.829","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
package/utils.d.ts CHANGED
@@ -153,7 +153,13 @@ export class ClassLoader {
153
153
  * @version 1.0 监听某个文件或者文件夹
154
154
  * @params eventName default reload
155
155
  */
156
- static watchServices(fp: string, context: any, eventName?: string): boolean;
156
+ static watchServices(
157
+ fp: string,
158
+ context: {
159
+ emit: (eventName: string | symbol, ...args: any) => boolean;
160
+ },
161
+ eventName?: string
162
+ ): boolean;
157
163
  }
158
164
  interface MixClass<T> {
159
165
  new (): T;
@@ -1,3 +0,0 @@
1
- {"timestamp":"2024-12-10 12:19:26.805","level":"INFO","label":"fastcar-server.logger","message":"自定义的日志输出"}
2
- {"timestamp":"2024-12-10 12:19:26.806","level":"WARN","label":"fastcar-server.logger","message":"自定义警告"}
3
- {"timestamp":"2024-12-10 12:19:26.806","level":"ERROR","label":"fastcar-server.logger","message":"自定义报错"}
@@ -1,10 +0,0 @@
1
- {"timestamp":"2024-12-09 15:07:12.204","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2024-12-09 15:07:12.536","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2024-12-09 15:07:12.539","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2024-12-09 15:07:12.541","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
- {"timestamp":"2024-12-09 15:07:12.542","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
- {"timestamp":"2024-12-09 15:07:35.539","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
- {"timestamp":"2024-12-09 15:07:35.916","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
- {"timestamp":"2024-12-09 15:07:35.918","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
- {"timestamp":"2024-12-09 15:07:35.921","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
- {"timestamp":"2024-12-09 15:07:35.921","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
@@ -1,10 +0,0 @@
1
- {"timestamp":"2024-12-09 15:09:48.53","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2024-12-09 15:09:48.365","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2024-12-09 15:09:48.368","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2024-12-09 15:09:48.370","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
- {"timestamp":"2024-12-09 15:09:48.371","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
- {"timestamp":"2024-12-09 15:11:58.841","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
- {"timestamp":"2024-12-09 15:11:59.168","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
- {"timestamp":"2024-12-09 15:11:59.170","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
- {"timestamp":"2024-12-09 15:11:59.173","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
- {"timestamp":"2024-12-09 15:11:59.173","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
@@ -1,10 +0,0 @@
1
- {"timestamp":"2024-12-09 15:15:25.814","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2024-12-09 15:15:26.25","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2024-12-09 15:15:26.27","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2024-12-09 15:15:26.29","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
- {"timestamp":"2024-12-09 15:15:26.30","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
- {"timestamp":"2024-12-09 15:16:30.883","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
- {"timestamp":"2024-12-09 15:16:31.207","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
- {"timestamp":"2024-12-09 15:16:31.209","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
- {"timestamp":"2024-12-09 15:16:31.211","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
- {"timestamp":"2024-12-09 15:16:31.211","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
@@ -1,10 +0,0 @@
1
- {"timestamp":"2024-12-09 15:50:39.260","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2024-12-09 15:50:39.595","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2024-12-09 15:50:39.597","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2024-12-09 15:50:39.600","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
- {"timestamp":"2024-12-09 15:50:39.600","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
- {"timestamp":"2024-12-09 15:51:13.373","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
- {"timestamp":"2024-12-09 15:51:13.731","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
- {"timestamp":"2024-12-09 15:51:13.733","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
- {"timestamp":"2024-12-09 15:51:13.736","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
- {"timestamp":"2024-12-09 15:51:13.737","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
@@ -1,13 +0,0 @@
1
- {"timestamp":"2024-12-10 12:19:26.598","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2024-12-10 12:19:26.795","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2024-12-10 12:19:26.796","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2024-12-10 12:19:26.798","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
- {"timestamp":"2024-12-10 12:19:26.799","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
- {"timestamp":"2024-12-25 22:17:05.503","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
- {"timestamp":"2024-12-25 22:17:05.827","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
- {"timestamp":"2024-12-25 22:17:05.829","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
- {"timestamp":"2024-12-25 22:17:05.831","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
- {"timestamp":"2024-12-25 22:17:05.832","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
11
- {"timestamp":"2024-12-25 22:17:09.47","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
12
- {"timestamp":"2024-12-25 22:17:16.221","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
13
- {"timestamp":"2024-12-25 22:17:25.294","level":"ERROR","label":"fastcar-server.sys","message":"Caught exception: ⨯ Unable to compile TypeScript:\nfastcar-core/test/example/simple/service/HelloService.ts(7,2): error TS2564: Property 'hello' has no initializer and is not definitely assigned in the constructor.\r\n"}
@@ -1,9 +0,0 @@
1
- {"timestamp":"2024-12-25 22:18:03.14","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2024-12-25 22:18:03.378","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2024-12-25 22:18:03.380","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2024-12-25 22:18:03.383","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
- {"timestamp":"2024-12-25 22:18:03.383","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
- {"timestamp":"2024-12-25 22:18:13.857","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
7
- {"timestamp":"2024-12-25 22:18:27.205","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
8
- {"timestamp":"2024-12-25 22:18:47.545","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
9
- {"timestamp":"2024-12-25 22:19:03.334","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
@@ -1,13 +0,0 @@
1
- {"timestamp":"2024-12-25 22:21:34.898","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2024-12-25 22:21:35.252","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2024-12-25 22:21:35.255","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2024-12-25 22:21:35.257","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
- {"timestamp":"2024-12-25 22:21:35.258","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
- {"timestamp":"2024-12-25 22:21:39.105","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
7
- {"timestamp":"2024-12-25 22:21:46.811","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
8
- {"timestamp":"2024-12-25 22:48:23.291","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
9
- {"timestamp":"2024-12-25 22:48:23.536","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
10
- {"timestamp":"2024-12-25 22:48:23.538","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
11
- {"timestamp":"2024-12-25 22:48:23.539","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
12
- {"timestamp":"2024-12-25 22:48:23.540","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
13
- {"timestamp":"2024-12-25 22:48:29.09","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
@@ -1,11 +0,0 @@
1
- {"timestamp":"2024-12-25 22:48:35.213","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
2
- {"timestamp":"2024-12-25 22:48:41.354","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
3
- {"timestamp":"2024-12-25 22:48:53.438","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
4
- {"timestamp":"2024-12-25 22:49:05.829","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
5
- {"timestamp":"2024-12-25 22:50:26.222","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
6
- {"timestamp":"2024-12-25 22:50:26.701","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
7
- {"timestamp":"2024-12-25 22:50:26.704","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
8
- {"timestamp":"2024-12-25 22:50:26.706","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
9
- {"timestamp":"2024-12-25 22:50:26.707","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
10
- {"timestamp":"2024-12-25 22:50:29.663","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
11
- {"timestamp":"2024-12-25 22:50:32.698","level":"INFO","label":"fastcar-server.sys","message":"hot update---D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\HelloService.ts"}
File without changes
File without changes
File without changes