@eggjs/watcher 5.0.0-beta.18 → 5.0.0-beta.20
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/agent.d.ts +1 -1
- package/dist/agent.js +4 -1
- package/dist/app.d.ts +1 -1
- package/dist/app.js +4 -1
- package/dist/base-C8f9YO9e.js +7 -0
- package/dist/base-DJbFfMBT.d.ts +9 -0
- package/dist/boot-0zKWMxhf.js +26 -0
- package/dist/boot-DG5R1PH_.d.ts +10 -0
- package/dist/config/config.default.d.ts +1 -22
- package/dist/config.default-Chl85mlX.d.ts +23 -0
- package/dist/default-GKOXgWps.js +19 -0
- package/dist/default-HrAUw2OK.d.ts +10 -0
- package/dist/development-Dxou8BHR.js +66 -0
- package/dist/development-x407-Xwn.d.ts +11 -0
- package/dist/event-sources-BjXjuNzX.js +1 -0
- package/dist/index-C9nY9t1j.d.ts +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +7 -5
- package/dist/lib/boot.d.ts +1 -9
- package/dist/lib/boot.js +4 -24
- package/dist/lib/event-sources/base.d.ts +1 -8
- package/dist/lib/event-sources/base.js +1 -5
- package/dist/lib/event-sources/default.d.ts +2 -9
- package/dist/lib/event-sources/default.js +2 -17
- package/dist/lib/event-sources/development.d.ts +2 -10
- package/dist/lib/event-sources/development.js +2 -64
- package/dist/lib/event-sources/index.d.ts +4 -3
- package/dist/lib/event-sources/index.js +4 -3
- package/dist/lib/utils.js +1 -7
- package/dist/lib/watcher.d.ts +1 -22
- package/dist/lib/watcher.js +3 -62
- package/dist/types-CQtQr8gw.js +1 -0
- package/dist/types-DWelR7br.d.ts +12 -0
- package/dist/types.d.ts +3 -12
- package/dist/types.js +2 -0
- package/dist/utils-BSqdCAAj.js +9 -0
- package/dist/watcher-BGaGRNx5.js +63 -0
- package/dist/watcher-J8AUQIOb.d.ts +23 -0
- package/package.json +8 -8
package/dist/agent.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Boot } from "./
|
|
1
|
+
import { Boot } from "./boot-DG5R1PH_.js";
|
|
2
2
|
export { Boot as default };
|
package/dist/agent.js
CHANGED
package/dist/app.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Boot } from "./
|
|
1
|
+
import { Boot } from "./boot-DG5R1PH_.js";
|
|
2
2
|
export { Boot as default };
|
package/dist/app.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Watcher } from "./watcher-BGaGRNx5.js";
|
|
2
|
+
import { debuglog } from "node:util";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/boot.ts
|
|
5
|
+
const debug = debuglog("egg/watcher/lib/boot");
|
|
6
|
+
var Boot = class {
|
|
7
|
+
#app;
|
|
8
|
+
constructor(appOrAgent) {
|
|
9
|
+
this.#app = appOrAgent;
|
|
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));
|
|
18
|
+
}
|
|
19
|
+
async didLoad() {
|
|
20
|
+
await this.#app.watcher.ready();
|
|
21
|
+
this.#app.coreLogger.info("[@eggjs/watcher:%s] watcher start success", this.#app.type);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Boot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EggApplicationCore, ILifecycleBoot } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/boot.d.ts
|
|
4
|
+
declare class Boot implements ILifecycleBoot {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(appOrAgent: EggApplicationCore);
|
|
7
|
+
didLoad(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Boot };
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
interface WatcherConfig {
|
|
3
|
-
/**
|
|
4
|
-
* event source type, default is `default`
|
|
5
|
-
* can be `default` or `development`
|
|
6
|
-
*/
|
|
7
|
-
type: string;
|
|
8
|
-
/**
|
|
9
|
-
* event sources
|
|
10
|
-
* key is event source type, value is event source module path
|
|
11
|
-
*/
|
|
12
|
-
eventSources: Record<string, string>;
|
|
13
|
-
}
|
|
14
|
-
declare const _default: {
|
|
15
|
-
/**
|
|
16
|
-
* watcher options
|
|
17
|
-
* @member Config#watcher
|
|
18
|
-
* @property {string} type - event source type
|
|
19
|
-
*/
|
|
20
|
-
watcher: WatcherConfig;
|
|
21
|
-
};
|
|
22
|
-
//#endregion
|
|
1
|
+
import { WatcherConfig, _default } from "../config.default-Chl85mlX.js";
|
|
23
2
|
export { WatcherConfig, _default as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/config/config.default.d.ts
|
|
2
|
+
interface WatcherConfig {
|
|
3
|
+
/**
|
|
4
|
+
* event source type, default is `default`
|
|
5
|
+
* can be `default` or `development`
|
|
6
|
+
*/
|
|
7
|
+
type: string;
|
|
8
|
+
/**
|
|
9
|
+
* event sources
|
|
10
|
+
* key is event source type, value is event source module path
|
|
11
|
+
*/
|
|
12
|
+
eventSources: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
declare const _default: {
|
|
15
|
+
/**
|
|
16
|
+
* watcher options
|
|
17
|
+
* @member Config#watcher
|
|
18
|
+
* @property {string} type - event source type
|
|
19
|
+
*/
|
|
20
|
+
watcher: WatcherConfig;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { WatcherConfig, _default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseEventSource } from "./base-C8f9YO9e.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/event-sources/default.ts
|
|
4
|
+
var DefaultEventSource = class extends BaseEventSource {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
setImmediate(() => this.emit("info", "[@eggjs/watcher] defaultEventSource watcher will NOT take effect"));
|
|
8
|
+
this.ready(true);
|
|
9
|
+
}
|
|
10
|
+
watch() {
|
|
11
|
+
this.emit("info", "[@eggjs/watcher] using defaultEventSource watcher.watch() does NOTHING");
|
|
12
|
+
}
|
|
13
|
+
unwatch() {
|
|
14
|
+
this.emit("info", "[@eggjs/watcher] using defaultEventSource watcher.unwatch() does NOTHING");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { DefaultEventSource };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseEventSource } from "./base-DJbFfMBT.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/event-sources/default.d.ts
|
|
4
|
+
declare class DefaultEventSource extends BaseEventSource {
|
|
5
|
+
constructor();
|
|
6
|
+
watch(): void;
|
|
7
|
+
unwatch(): void;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { DefaultEventSource };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { BaseEventSource } from "./base-C8f9YO9e.js";
|
|
2
|
+
import { debuglog } from "node:util";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/event-sources/development.ts
|
|
7
|
+
const debug = debuglog("egg-watcher/lib/event-sources/development");
|
|
8
|
+
var DevelopmentEventSource = class extends BaseEventSource {
|
|
9
|
+
#fileWatching = /* @__PURE__ */ new Map();
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.ready(true);
|
|
13
|
+
}
|
|
14
|
+
watch(file) {
|
|
15
|
+
try {
|
|
16
|
+
const stat = fs.statSync(file, { throwIfNoEntry: false });
|
|
17
|
+
if (!stat) {
|
|
18
|
+
debug("watch %o ignore, file not exists", file);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
debug("watch %o, isFile: %o", file, stat.isFile());
|
|
22
|
+
let recursive = true;
|
|
23
|
+
if (process.platform === "linux" && process.version.startsWith("v18.")) recursive = false;
|
|
24
|
+
const handler = fs.watch(file, {
|
|
25
|
+
persistent: true,
|
|
26
|
+
recursive
|
|
27
|
+
}, (event, filename) => {
|
|
28
|
+
debug("watch %o => event: %o, filename: %o", file, event, filename);
|
|
29
|
+
let changePath = file;
|
|
30
|
+
if (stat.isFile()) this.#onFsWatchChange(event, changePath);
|
|
31
|
+
else {
|
|
32
|
+
if (filename) changePath = path.join(file, filename);
|
|
33
|
+
this.#onFsWatchChange(event, changePath);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
this.#fileWatching.set(file, handler);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
this.emit("warn", "[@eggjs/watcher:DevelopmentEventSource] watch %o error: %s", file, e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
unwatch(file) {
|
|
42
|
+
if (!file) return;
|
|
43
|
+
const h = this.#fileWatching.get(file);
|
|
44
|
+
if (!h) return;
|
|
45
|
+
h.removeAllListeners();
|
|
46
|
+
h.close();
|
|
47
|
+
this.#fileWatching.delete(file);
|
|
48
|
+
}
|
|
49
|
+
#onFsWatchChange(event, file) {
|
|
50
|
+
if (!file) {
|
|
51
|
+
this.emit("warn", "[@eggjs/watcher:DevelopmentEventSource] event: %o", event);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const stat = fs.statSync(file, { throwIfNoEntry: false });
|
|
55
|
+
const info = {
|
|
56
|
+
path: file,
|
|
57
|
+
event,
|
|
58
|
+
stat,
|
|
59
|
+
isDirectory: stat?.isDirectory()
|
|
60
|
+
};
|
|
61
|
+
this.emit("change", info);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { DevelopmentEventSource };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseEventSource } from "./base-DJbFfMBT.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/event-sources/development.d.ts
|
|
4
|
+
declare class DevelopmentEventSource extends BaseEventSource {
|
|
5
|
+
#private;
|
|
6
|
+
constructor();
|
|
7
|
+
watch(file: string): void;
|
|
8
|
+
unwatch(file: string): void;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DevelopmentEventSource };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import "./config.default-Chl85mlX.js";
|
|
2
|
+
import { ChangeInfo, WatchListener, Watcher } from "./watcher-J8AUQIOb.js";
|
|
3
|
+
import "./types-DWelR7br.js";
|
|
4
|
+
import { BaseEventSource } from "./base-DJbFfMBT.js";
|
|
5
|
+
import { DefaultEventSource } from "./default-HrAUw2OK.js";
|
|
6
|
+
import { DevelopmentEventSource } from "./development-x407-Xwn.js";
|
|
7
|
+
import "./index-C9nY9t1j.js";
|
|
5
8
|
export { BaseEventSource, ChangeInfo, DefaultEventSource, DevelopmentEventSource, WatchListener, Watcher };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { BaseEventSource } from "./
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import "./
|
|
1
|
+
import { BaseEventSource } from "./base-C8f9YO9e.js";
|
|
2
|
+
import "./utils-BSqdCAAj.js";
|
|
3
|
+
import { Watcher } from "./watcher-BGaGRNx5.js";
|
|
4
|
+
import "./types-CQtQr8gw.js";
|
|
5
|
+
import { DefaultEventSource } from "./default-GKOXgWps.js";
|
|
6
|
+
import { DevelopmentEventSource } from "./development-Dxou8BHR.js";
|
|
7
|
+
import "./event-sources-BjXjuNzX.js";
|
|
6
8
|
|
|
7
9
|
export { BaseEventSource, DefaultEventSource, DevelopmentEventSource, Watcher };
|
package/dist/lib/boot.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/lib/boot.d.ts
|
|
4
|
-
declare class Boot implements ILifecycleBoot {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(appOrAgent: EggApplicationCore);
|
|
7
|
-
didLoad(): Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
1
|
+
import { Boot } from "../boot-DG5R1PH_.js";
|
|
10
2
|
export { Boot };
|
package/dist/lib/boot.js
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import "../base-C8f9YO9e.js";
|
|
2
|
+
import "../utils-BSqdCAAj.js";
|
|
3
|
+
import "../watcher-BGaGRNx5.js";
|
|
4
|
+
import { Boot } from "../boot-0zKWMxhf.js";
|
|
3
5
|
|
|
4
|
-
//#region src/lib/boot.ts
|
|
5
|
-
const debug = debuglog("egg/watcher/lib/boot");
|
|
6
|
-
var Boot = class {
|
|
7
|
-
#app;
|
|
8
|
-
constructor(appOrAgent) {
|
|
9
|
-
this.#app = appOrAgent;
|
|
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));
|
|
18
|
-
}
|
|
19
|
-
async didLoad() {
|
|
20
|
-
await this.#app.watcher.ready();
|
|
21
|
-
this.#app.coreLogger.info("[@eggjs/watcher:%s] watcher start success", this.#app.type);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
6
|
export { Boot };
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/lib/event-sources/base.d.ts
|
|
4
|
-
declare abstract class BaseEventSource extends Base {
|
|
5
|
-
abstract watch(file: string): void;
|
|
6
|
-
abstract unwatch(file: string): void;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
1
|
+
import { BaseEventSource } from "../../base-DJbFfMBT.js";
|
|
9
2
|
export { BaseEventSource };
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/lib/event-sources/default.d.ts
|
|
4
|
-
declare class DefaultEventSource extends BaseEventSource {
|
|
5
|
-
constructor();
|
|
6
|
-
watch(): void;
|
|
7
|
-
unwatch(): void;
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
1
|
+
import "../../base-DJbFfMBT.js";
|
|
2
|
+
import { DefaultEventSource } from "../../default-HrAUw2OK.js";
|
|
10
3
|
export { DefaultEventSource as default };
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../base-C8f9YO9e.js";
|
|
2
|
+
import { DefaultEventSource } from "../../default-GKOXgWps.js";
|
|
2
3
|
|
|
3
|
-
//#region src/lib/event-sources/default.ts
|
|
4
|
-
var DefaultEventSource = class extends BaseEventSource {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
setImmediate(() => this.emit("info", "[@eggjs/watcher] defaultEventSource watcher will NOT take effect"));
|
|
8
|
-
this.ready(true);
|
|
9
|
-
}
|
|
10
|
-
watch() {
|
|
11
|
-
this.emit("info", "[@eggjs/watcher] using defaultEventSource watcher.watch() does NOTHING");
|
|
12
|
-
}
|
|
13
|
-
unwatch() {
|
|
14
|
-
this.emit("info", "[@eggjs/watcher] using defaultEventSource watcher.unwatch() does NOTHING");
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
4
|
export { DefaultEventSource as default };
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/lib/event-sources/development.d.ts
|
|
4
|
-
declare class DevelopmentEventSource extends BaseEventSource {
|
|
5
|
-
#private;
|
|
6
|
-
constructor();
|
|
7
|
-
watch(file: string): void;
|
|
8
|
-
unwatch(file: string): void;
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
1
|
+
import "../../base-DJbFfMBT.js";
|
|
2
|
+
import { DevelopmentEventSource } from "../../development-x407-Xwn.js";
|
|
11
3
|
export { DevelopmentEventSource as default };
|
|
@@ -1,66 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import fs from "node:fs";
|
|
1
|
+
import "../../base-C8f9YO9e.js";
|
|
2
|
+
import { DevelopmentEventSource } from "../../development-Dxou8BHR.js";
|
|
5
3
|
|
|
6
|
-
//#region src/lib/event-sources/development.ts
|
|
7
|
-
const debug = debuglog("egg-watcher/lib/event-sources/development");
|
|
8
|
-
var DevelopmentEventSource = class extends BaseEventSource {
|
|
9
|
-
#fileWatching = /* @__PURE__ */ new Map();
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
this.ready(true);
|
|
13
|
-
}
|
|
14
|
-
watch(file) {
|
|
15
|
-
try {
|
|
16
|
-
const stat = fs.statSync(file, { throwIfNoEntry: false });
|
|
17
|
-
if (!stat) {
|
|
18
|
-
debug("watch %o ignore, file not exists", file);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
debug("watch %o, isFile: %o", file, stat.isFile());
|
|
22
|
-
let recursive = true;
|
|
23
|
-
if (process.platform === "linux" && process.version.startsWith("v18.")) recursive = false;
|
|
24
|
-
const handler = fs.watch(file, {
|
|
25
|
-
persistent: true,
|
|
26
|
-
recursive
|
|
27
|
-
}, (event, filename) => {
|
|
28
|
-
debug("watch %o => event: %o, filename: %o", file, event, filename);
|
|
29
|
-
let changePath = file;
|
|
30
|
-
if (stat.isFile()) this.#onFsWatchChange(event, changePath);
|
|
31
|
-
else {
|
|
32
|
-
if (filename) changePath = path.join(file, filename);
|
|
33
|
-
this.#onFsWatchChange(event, changePath);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
this.#fileWatching.set(file, handler);
|
|
37
|
-
} catch (e) {
|
|
38
|
-
this.emit("warn", "[@eggjs/watcher:DevelopmentEventSource] watch %o error: %s", file, e);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
unwatch(file) {
|
|
42
|
-
if (!file) return;
|
|
43
|
-
const h = this.#fileWatching.get(file);
|
|
44
|
-
if (!h) return;
|
|
45
|
-
h.removeAllListeners();
|
|
46
|
-
h.close();
|
|
47
|
-
this.#fileWatching.delete(file);
|
|
48
|
-
}
|
|
49
|
-
#onFsWatchChange(event, file) {
|
|
50
|
-
if (!file) {
|
|
51
|
-
this.emit("warn", "[@eggjs/watcher:DevelopmentEventSource] event: %o", event);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const stat = fs.statSync(file, { throwIfNoEntry: false });
|
|
55
|
-
const info = {
|
|
56
|
-
path: file,
|
|
57
|
-
event,
|
|
58
|
-
stat,
|
|
59
|
-
isDirectory: stat?.isDirectory()
|
|
60
|
-
};
|
|
61
|
-
this.emit("change", info);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
4
|
export { DevelopmentEventSource as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BaseEventSource } from "
|
|
2
|
-
import DefaultEventSource from "
|
|
3
|
-
import DevelopmentEventSource from "
|
|
1
|
+
import { BaseEventSource } from "../../base-DJbFfMBT.js";
|
|
2
|
+
import { DefaultEventSource } from "../../default-HrAUw2OK.js";
|
|
3
|
+
import { DevelopmentEventSource } from "../../development-x407-Xwn.js";
|
|
4
|
+
import "../../index-C9nY9t1j.js";
|
|
4
5
|
export { BaseEventSource, DefaultEventSource, DevelopmentEventSource };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BaseEventSource } from "
|
|
2
|
-
import DefaultEventSource from "
|
|
3
|
-
import DevelopmentEventSource from "
|
|
1
|
+
import { BaseEventSource } from "../../base-C8f9YO9e.js";
|
|
2
|
+
import { DefaultEventSource } from "../../default-GKOXgWps.js";
|
|
3
|
+
import { DevelopmentEventSource } from "../../development-Dxou8BHR.js";
|
|
4
|
+
import "../../event-sources-BjXjuNzX.js";
|
|
4
5
|
|
|
5
6
|
export { BaseEventSource, DefaultEventSource, DevelopmentEventSource };
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isEqualOrParentPath } from "../utils-BSqdCAAj.js";
|
|
2
2
|
|
|
3
|
-
//#region src/lib/utils.ts
|
|
4
|
-
function isEqualOrParentPath(parent, child) {
|
|
5
|
-
return !path.relative(parent, child).startsWith("..");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
//#endregion
|
|
9
3
|
export { isEqualOrParentPath };
|
package/dist/lib/watcher.d.ts
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Stats, WatchEventType } from "node:fs";
|
|
3
|
-
import { EggAppConfig } from "egg";
|
|
4
|
-
|
|
5
|
-
//#region src/lib/watcher.d.ts
|
|
6
|
-
interface ChangeInfo extends Record<string, any> {
|
|
7
|
-
event: WatchEventType;
|
|
8
|
-
/**
|
|
9
|
-
* file stat if path exists
|
|
10
|
-
*/
|
|
11
|
-
stat?: Stats;
|
|
12
|
-
path: string;
|
|
13
|
-
isDirectory?: boolean;
|
|
14
|
-
}
|
|
15
|
-
type WatchListener = (info: ChangeInfo) => void;
|
|
16
|
-
declare class Watcher extends Base {
|
|
17
|
-
#private;
|
|
18
|
-
constructor(config: EggAppConfig);
|
|
19
|
-
protected _init(): Promise<void>;
|
|
20
|
-
watch(path: string | string[], listener: WatchListener): void;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
1
|
+
import { ChangeInfo, WatchListener, Watcher } from "../watcher-J8AUQIOb.js";
|
|
23
2
|
export { ChangeInfo, WatchListener, Watcher };
|
package/dist/lib/watcher.js
CHANGED
|
@@ -1,64 +1,5 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { Base } from "sdk-base";
|
|
5
|
-
import camelcase from "camelcase";
|
|
6
|
-
import { importModule } from "@eggjs/utils";
|
|
1
|
+
import "../base-C8f9YO9e.js";
|
|
2
|
+
import "../utils-BSqdCAAj.js";
|
|
3
|
+
import { Watcher } from "../watcher-BGaGRNx5.js";
|
|
7
4
|
|
|
8
|
-
//#region src/lib/watcher.ts
|
|
9
|
-
const debug = debuglog("egg/watcher/lib/watcher");
|
|
10
|
-
var Watcher = class extends Base {
|
|
11
|
-
#config;
|
|
12
|
-
#eventSource;
|
|
13
|
-
constructor(config) {
|
|
14
|
-
super({ initMethod: "_init" });
|
|
15
|
-
this.#config = config;
|
|
16
|
-
}
|
|
17
|
-
async _init() {
|
|
18
|
-
const watcherType = this.#config.watcher?.type;
|
|
19
|
-
debug("init with watcherType %o", watcherType);
|
|
20
|
-
if (!watcherType) {
|
|
21
|
-
debug("watcherType is not defined, skip initialization");
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
let EventSource = this.#config.watcher?.eventSources[watcherType];
|
|
25
|
-
if (typeof EventSource === "string") EventSource = await importModule(EventSource, { importDefaultOnly: true });
|
|
26
|
-
const key = camelcase(["watcher", watcherType]);
|
|
27
|
-
const eventSourceOptions = this.#config[key] ?? {};
|
|
28
|
-
this.#eventSource = Reflect.construct(EventSource, [eventSourceOptions]);
|
|
29
|
-
this.#eventSource.on("change", this.#onChange.bind(this)).on("fuzzy-change", this.#onFuzzyChange.bind(this)).on("info", (...args) => this.emit("info", ...args)).on("warn", (...args) => this.emit("warn", ...args)).on("error", (...args) => this.emit("error", ...args));
|
|
30
|
-
await this.#eventSource.ready();
|
|
31
|
-
}
|
|
32
|
-
watch(path, listener) {
|
|
33
|
-
debug("watch %o", path);
|
|
34
|
-
this.emit("info", "[@eggjs/watcher] Start watching: %j", path);
|
|
35
|
-
if (!path) return;
|
|
36
|
-
if (Array.isArray(path)) {
|
|
37
|
-
path.forEach((p) => this.watch(p, listener));
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (!this.listenerCount(path)) this.#eventSource.watch(path);
|
|
41
|
-
this.on(path, listener);
|
|
42
|
-
}
|
|
43
|
-
#onChange(info) {
|
|
44
|
-
debug("onChange %o", info);
|
|
45
|
-
this.emit("info", "[@eggjs/watcher] Received a change event from eventSource: %j", info);
|
|
46
|
-
const path = info.path;
|
|
47
|
-
for (const p of this.eventNames()) {
|
|
48
|
-
if (typeof p !== "string") continue;
|
|
49
|
-
if (isEqualOrParentPath(p, path)) this.emit(p, info);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
#onFuzzyChange(info) {
|
|
53
|
-
debug("onFuzzyChange %o", info);
|
|
54
|
-
this.emit("info", "[@eggjs/watcher] Received a fuzzy-change event from eventSource: %j", info);
|
|
55
|
-
const path = info.path;
|
|
56
|
-
for (const p of this.eventNames()) {
|
|
57
|
-
if (typeof p !== "string") continue;
|
|
58
|
-
if (isEqualOrParentPath(path, p)) this.emit(p, info);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
5
|
export { Watcher };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WatcherConfig } from "./config.default-Chl85mlX.js";
|
|
2
|
+
import { Watcher } from "./watcher-J8AUQIOb.js";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
declare module 'egg' {
|
|
6
|
+
interface EggApplicationCore {
|
|
7
|
+
watcher: Watcher;
|
|
8
|
+
}
|
|
9
|
+
interface EggAppConfig {
|
|
10
|
+
watcher?: WatcherConfig;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
declare module 'egg' {
|
|
6
|
-
interface EggApplicationCore {
|
|
7
|
-
watcher: Watcher;
|
|
8
|
-
}
|
|
9
|
-
interface EggAppConfig {
|
|
10
|
-
watcher?: WatcherConfig;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
import "./config.default-Chl85mlX.js";
|
|
2
|
+
import "./watcher-J8AUQIOb.js";
|
|
3
|
+
import "./types-DWelR7br.js";
|
package/dist/types.js
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isEqualOrParentPath } from "./utils-BSqdCAAj.js";
|
|
2
|
+
import { debuglog } from "node:util";
|
|
3
|
+
import { Base } from "sdk-base";
|
|
4
|
+
import camelcase from "camelcase";
|
|
5
|
+
import { importModule } from "@eggjs/utils";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/watcher.ts
|
|
8
|
+
const debug = debuglog("egg/watcher/lib/watcher");
|
|
9
|
+
var Watcher = class extends Base {
|
|
10
|
+
#config;
|
|
11
|
+
#eventSource;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
super({ initMethod: "_init" });
|
|
14
|
+
this.#config = config;
|
|
15
|
+
}
|
|
16
|
+
async _init() {
|
|
17
|
+
const watcherType = this.#config.watcher?.type;
|
|
18
|
+
debug("init with watcherType %o", watcherType);
|
|
19
|
+
if (!watcherType) {
|
|
20
|
+
debug("watcherType is not defined, skip initialization");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let EventSource = this.#config.watcher?.eventSources[watcherType];
|
|
24
|
+
if (typeof EventSource === "string") EventSource = await importModule(EventSource, { importDefaultOnly: true });
|
|
25
|
+
const key = camelcase(["watcher", watcherType]);
|
|
26
|
+
const eventSourceOptions = this.#config[key] ?? {};
|
|
27
|
+
this.#eventSource = Reflect.construct(EventSource, [eventSourceOptions]);
|
|
28
|
+
this.#eventSource.on("change", this.#onChange.bind(this)).on("fuzzy-change", this.#onFuzzyChange.bind(this)).on("info", (...args) => this.emit("info", ...args)).on("warn", (...args) => this.emit("warn", ...args)).on("error", (...args) => this.emit("error", ...args));
|
|
29
|
+
await this.#eventSource.ready();
|
|
30
|
+
}
|
|
31
|
+
watch(path, listener) {
|
|
32
|
+
debug("watch %o", path);
|
|
33
|
+
this.emit("info", "[@eggjs/watcher] Start watching: %j", path);
|
|
34
|
+
if (!path) return;
|
|
35
|
+
if (Array.isArray(path)) {
|
|
36
|
+
path.forEach((p) => this.watch(p, listener));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!this.listenerCount(path)) this.#eventSource.watch(path);
|
|
40
|
+
this.on(path, listener);
|
|
41
|
+
}
|
|
42
|
+
#onChange(info) {
|
|
43
|
+
debug("onChange %o", info);
|
|
44
|
+
this.emit("info", "[@eggjs/watcher] Received a change event from eventSource: %j", info);
|
|
45
|
+
const path = info.path;
|
|
46
|
+
for (const p of this.eventNames()) {
|
|
47
|
+
if (typeof p !== "string") continue;
|
|
48
|
+
if (isEqualOrParentPath(p, path)) this.emit(p, info);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
#onFuzzyChange(info) {
|
|
52
|
+
debug("onFuzzyChange %o", info);
|
|
53
|
+
this.emit("info", "[@eggjs/watcher] Received a fuzzy-change event from eventSource: %j", info);
|
|
54
|
+
const path = info.path;
|
|
55
|
+
for (const p of this.eventNames()) {
|
|
56
|
+
if (typeof p !== "string") continue;
|
|
57
|
+
if (isEqualOrParentPath(path, p)) this.emit(p, info);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { Watcher };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Base } from "sdk-base";
|
|
2
|
+
import { Stats, WatchEventType } from "node:fs";
|
|
3
|
+
import { EggAppConfig } from "egg";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/watcher.d.ts
|
|
6
|
+
interface ChangeInfo extends Record<string, any> {
|
|
7
|
+
event: WatchEventType;
|
|
8
|
+
/**
|
|
9
|
+
* file stat if path exists
|
|
10
|
+
*/
|
|
11
|
+
stat?: Stats;
|
|
12
|
+
path: string;
|
|
13
|
+
isDirectory?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type WatchListener = (info: ChangeInfo) => void;
|
|
16
|
+
declare class Watcher extends Base {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(config: EggAppConfig);
|
|
19
|
+
protected _init(): Promise<void>;
|
|
20
|
+
watch(path: string | string[], listener: WatchListener): void;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ChangeInfo, WatchListener, Watcher };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/watcher",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.20",
|
|
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.
|
|
29
|
+
"@eggjs/utils": "5.0.0-beta.20"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"egg": "4.1.0-beta.
|
|
32
|
+
"egg": "4.1.0-beta.20"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"tsdown": "^0.15.4",
|
|
36
|
-
"typescript": "5.9.
|
|
37
|
-
"vitest": "4.0.0-beta.
|
|
38
|
-
"@eggjs/mock": "7.0.0-beta.
|
|
39
|
-
"@eggjs/tsconfig": "3.1.0-beta.
|
|
40
|
-
"@eggjs/utils": "5.0.0-beta.
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vitest": "4.0.0-beta.16",
|
|
38
|
+
"@eggjs/mock": "7.0.0-beta.20",
|
|
39
|
+
"@eggjs/tsconfig": "3.1.0-beta.20",
|
|
40
|
+
"@eggjs/utils": "5.0.0-beta.20"
|
|
41
41
|
},
|
|
42
42
|
"type": "module",
|
|
43
43
|
"exports": {
|