@eggjs/watcher 5.0.0-beta.17 → 5.0.0-beta.18

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/lib/boot.js CHANGED
@@ -1,16 +1,23 @@
1
1
  import { Watcher } from "./watcher.js";
2
+ import { debuglog } from "node:util";
2
3
 
3
4
  //#region src/lib/boot.ts
5
+ const debug = debuglog("egg/watcher/lib/boot");
4
6
  var Boot = class {
5
7
  #app;
6
- #watcher;
7
8
  constructor(appOrAgent) {
8
9
  this.#app = appOrAgent;
9
- this.#watcher = this.#app.watcher = this.#app.cluster(Watcher, {}).delegate("watch", "subscribe").create(appOrAgent.config);
10
- this.#watcher.on("info", (msg, ...args) => this.#app.coreLogger.info(msg, ...args)).on("warn", (msg, ...args) => this.#app.coreLogger.warn(msg, ...args)).on("error", (msg, ...args) => this.#app.coreLogger.error(msg, ...args));
10
+ if (this.#app.options.mode === "all-in-one-process") {
11
+ debug("init watcher in all-in-one-process mode");
12
+ this.#app.watcher = new Watcher(appOrAgent.config);
13
+ } else {
14
+ debug("init watcher in cluster mode");
15
+ this.#app.watcher = this.#app.clusterWrapper(Watcher, {}).delegate("watch", "subscribe").create(appOrAgent.config);
16
+ }
17
+ this.#app.watcher.on("info", (msg, ...args) => this.#app.coreLogger.info(msg, ...args)).on("warn", (msg, ...args) => this.#app.coreLogger.warn(msg, ...args)).on("error", (msg, ...args) => this.#app.coreLogger.error(msg, ...args));
11
18
  }
12
19
  async didLoad() {
13
- await this.#watcher.ready();
20
+ await this.#app.watcher.ready();
14
21
  this.#app.coreLogger.info("[@eggjs/watcher:%s] watcher start success", this.#app.type);
15
22
  }
16
23
  };
@@ -6,7 +6,7 @@ import camelcase from "camelcase";
6
6
  import { importModule } from "@eggjs/utils";
7
7
 
8
8
  //#region src/lib/watcher.ts
9
- const debug = debuglog("egg-watcher/lib/watcher");
9
+ const debug = debuglog("egg/watcher/lib/watcher");
10
10
  var Watcher = class extends Base {
11
11
  #config;
12
12
  #eventSource;
@@ -16,7 +16,11 @@ var Watcher = class extends Base {
16
16
  }
17
17
  async _init() {
18
18
  const watcherType = this.#config.watcher?.type;
19
- if (!watcherType) return;
19
+ debug("init with watcherType %o", watcherType);
20
+ if (!watcherType) {
21
+ debug("watcherType is not defined, skip initialization");
22
+ return;
23
+ }
20
24
  let EventSource = this.#config.watcher?.eventSources[watcherType];
21
25
  if (typeof EventSource === "string") EventSource = await importModule(EventSource, { importDefaultOnly: true });
22
26
  const key = camelcase(["watcher", watcherType]);
@@ -26,6 +30,7 @@ var Watcher = class extends Base {
26
30
  await this.#eventSource.ready();
27
31
  }
28
32
  watch(path, listener) {
33
+ debug("watch %o", path);
29
34
  this.emit("info", "[@eggjs/watcher] Start watching: %j", path);
30
35
  if (!path) return;
31
36
  if (Array.isArray(path)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/watcher",
3
- "version": "5.0.0-beta.17",
3
+ "version": "5.0.0-beta.18",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -26,18 +26,18 @@
26
26
  "dependencies": {
27
27
  "camelcase": "^8.0.0",
28
28
  "sdk-base": "^5.0.1",
29
- "@eggjs/utils": "5.0.0-beta.17"
29
+ "@eggjs/utils": "5.0.0-beta.18"
30
30
  },
31
31
  "peerDependencies": {
32
- "egg": "4.1.0-beta.17"
32
+ "egg": "4.1.0-beta.18"
33
33
  },
34
34
  "devDependencies": {
35
35
  "tsdown": "^0.15.4",
36
36
  "typescript": "5.9.2",
37
37
  "vitest": "4.0.0-beta.13",
38
- "@eggjs/tsconfig": "3.1.0-beta.17",
39
- "@eggjs/mock": "7.0.0-beta.17",
40
- "@eggjs/utils": "5.0.0-beta.17"
38
+ "@eggjs/mock": "7.0.0-beta.18",
39
+ "@eggjs/tsconfig": "3.1.0-beta.18",
40
+ "@eggjs/utils": "5.0.0-beta.18"
41
41
  },
42
42
  "type": "module",
43
43
  "exports": {