@eggjs/watcher 4.0.4 → 4.0.5-beta.2

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.
Files changed (102) hide show
  1. package/README.md +1 -5
  2. package/dist/agent.d.ts +2 -0
  3. package/dist/agent.js +7 -0
  4. package/dist/app.d.ts +2 -0
  5. package/dist/app.js +7 -0
  6. package/dist/config/config.default.d.ts +13 -0
  7. package/dist/config/config.default.js +14 -0
  8. package/dist/config/config.local.d.ts +8 -0
  9. package/dist/config/config.local.js +5 -0
  10. package/dist/config/config.unittest.d.ts +8 -0
  11. package/dist/config/config.unittest.js +5 -0
  12. package/dist/index.d.ts +6 -0
  13. package/dist/index.js +7 -0
  14. package/dist/lib/boot.d.ts +10 -0
  15. package/dist/lib/boot.js +19 -0
  16. package/dist/lib/event-sources/base.d.ts +9 -0
  17. package/dist/lib/event-sources/base.js +7 -0
  18. package/dist/lib/event-sources/default.d.ts +10 -0
  19. package/dist/lib/event-sources/default.js +19 -0
  20. package/dist/lib/event-sources/development.d.ts +11 -0
  21. package/dist/lib/event-sources/development.js +66 -0
  22. package/dist/lib/event-sources/index.d.ts +4 -0
  23. package/dist/lib/event-sources/index.js +5 -0
  24. package/{src/lib/types.ts → dist/lib/types.d.ts} +10 -12
  25. package/dist/lib/types.js +1 -0
  26. package/dist/lib/utils.d.ts +5 -0
  27. package/dist/lib/utils.js +15 -0
  28. package/dist/lib/watcher.d.ts +14 -0
  29. package/dist/lib/watcher.js +59 -0
  30. package/package.json +49 -59
  31. package/dist/commonjs/agent.d.ts +0 -2
  32. package/dist/commonjs/agent.js +0 -5
  33. package/dist/commonjs/app.d.ts +0 -2
  34. package/dist/commonjs/app.js +0 -5
  35. package/dist/commonjs/config/config.default.d.ts +0 -10
  36. package/dist/commonjs/config/config.default.js +0 -22
  37. package/dist/commonjs/config/config.local.d.ts +0 -5
  38. package/dist/commonjs/config/config.local.js +0 -8
  39. package/dist/commonjs/config/config.unittest.d.ts +0 -5
  40. package/dist/commonjs/config/config.unittest.js +0 -8
  41. package/dist/commonjs/index.d.ts +0 -3
  42. package/dist/commonjs/index.js +0 -20
  43. package/dist/commonjs/lib/boot.d.ts +0 -6
  44. package/dist/commonjs/lib/boot.js +0 -23
  45. package/dist/commonjs/lib/event-sources/base.d.ts +0 -5
  46. package/dist/commonjs/lib/event-sources/base.js +0 -8
  47. package/dist/commonjs/lib/event-sources/default.d.ts +0 -6
  48. package/dist/commonjs/lib/event-sources/default.js +0 -19
  49. package/dist/commonjs/lib/event-sources/development.d.ts +0 -7
  50. package/dist/commonjs/lib/event-sources/development.js +0 -103
  51. package/dist/commonjs/lib/event-sources/index.d.ts +0 -4
  52. package/dist/commonjs/lib/event-sources/index.js +0 -13
  53. package/dist/commonjs/lib/types.d.ts +0 -31
  54. package/dist/commonjs/lib/types.js +0 -3
  55. package/dist/commonjs/lib/utils.d.ts +0 -2
  56. package/dist/commonjs/lib/utils.js +0 -25
  57. package/dist/commonjs/lib/watcher.d.ts +0 -10
  58. package/dist/commonjs/lib/watcher.js +0 -113
  59. package/dist/commonjs/package.json +0 -3
  60. package/dist/esm/agent.d.ts +0 -2
  61. package/dist/esm/agent.js +0 -3
  62. package/dist/esm/app.d.ts +0 -2
  63. package/dist/esm/app.js +0 -3
  64. package/dist/esm/config/config.default.d.ts +0 -10
  65. package/dist/esm/config/config.default.js +0 -17
  66. package/dist/esm/config/config.local.d.ts +0 -5
  67. package/dist/esm/config/config.local.js +0 -6
  68. package/dist/esm/config/config.unittest.d.ts +0 -5
  69. package/dist/esm/config/config.unittest.js +0 -6
  70. package/dist/esm/index.d.ts +0 -3
  71. package/dist/esm/index.js +0 -4
  72. package/dist/esm/lib/boot.d.ts +0 -6
  73. package/dist/esm/lib/boot.js +0 -19
  74. package/dist/esm/lib/event-sources/base.d.ts +0 -5
  75. package/dist/esm/lib/event-sources/base.js +0 -4
  76. package/dist/esm/lib/event-sources/default.d.ts +0 -6
  77. package/dist/esm/lib/event-sources/default.js +0 -16
  78. package/dist/esm/lib/event-sources/development.d.ts +0 -7
  79. package/dist/esm/lib/event-sources/development.js +0 -97
  80. package/dist/esm/lib/event-sources/index.d.ts +0 -4
  81. package/dist/esm/lib/event-sources/index.js +0 -5
  82. package/dist/esm/lib/types.d.ts +0 -31
  83. package/dist/esm/lib/types.js +0 -2
  84. package/dist/esm/lib/utils.d.ts +0 -2
  85. package/dist/esm/lib/utils.js +0 -18
  86. package/dist/esm/lib/watcher.d.ts +0 -10
  87. package/dist/esm/lib/watcher.js +0 -106
  88. package/dist/esm/package.json +0 -3
  89. package/dist/package.json +0 -4
  90. package/src/agent.ts +0 -3
  91. package/src/app.ts +0 -3
  92. package/src/config/config.default.ts +0 -18
  93. package/src/config/config.local.ts +0 -7
  94. package/src/config/config.unittest.ts +0 -7
  95. package/src/index.ts +0 -3
  96. package/src/lib/boot.ts +0 -22
  97. package/src/lib/event-sources/base.ts +0 -6
  98. package/src/lib/event-sources/default.ts +0 -18
  99. package/src/lib/event-sources/development.ts +0 -101
  100. package/src/lib/event-sources/index.ts +0 -9
  101. package/src/lib/utils.ts +0 -20
  102. package/src/lib/watcher.ts +0 -120
package/README.md CHANGED
@@ -1,16 +1,12 @@
1
1
  # @eggjs/watcher
2
2
 
3
3
  [![NPM version][npm-image]][npm-url]
4
- [![Node.js CI](https://github.com/eggjs/watcher/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/watcher/actions/workflows/nodejs.yml)
5
- [![Test coverage][codecov-image]][codecov-url]
6
4
  [![Known Vulnerabilities][snyk-image]][snyk-url]
7
5
  [![npm download][download-image]][download-url]
8
6
  [![Node.js Version](https://img.shields.io/node/v/@eggjs/watcher.svg?style=flat)](https://nodejs.org/en/download/)
9
7
 
10
8
  [npm-image]: https://img.shields.io/npm/v/@eggjs/watcher.svg?style=flat-square
11
9
  [npm-url]: https://npmjs.org/package/@eggjs/watcher
12
- [codecov-image]: https://codecov.io/github/eggjs/watcher/coverage.svg?branch=master
13
- [codecov-url]: https://codecov.io/github/eggjs/watcher?branch=master
14
10
  [snyk-image]: https://snyk.io/test/npm/@eggjs/watcher/badge.svg?style=flat-square
15
11
  [snyk-url]: https://snyk.io/test/npm/@eggjs/watcher
16
12
  [download-image]: https://img.shields.io/npm/dm/@eggjs/watcher.svg?style=flat-square
@@ -142,6 +138,6 @@ Please open an issue [here](https://github.com/eggjs/egg/issues).
142
138
 
143
139
  ## Contributors
144
140
 
145
- [![Contributors](https://contrib.rocks/image?repo=eggjs/watcher)](https://github.com/eggjs/watcher/graphs/contributors)
141
+ [![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)
146
142
 
147
143
  Made with [contributors-img](https://contrib.rocks).
@@ -0,0 +1,2 @@
1
+ import { Boot } from "./lib/boot.js";
2
+ export { Boot as default };
package/dist/agent.js ADDED
@@ -0,0 +1,7 @@
1
+ import { Boot } from "./lib/boot.js";
2
+
3
+ //#region src/agent.ts
4
+ var agent_default = Boot;
5
+
6
+ //#endregion
7
+ export { agent_default as default };
package/dist/app.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { Boot } from "./lib/boot.js";
2
+ export { Boot as default };
package/dist/app.js ADDED
@@ -0,0 +1,7 @@
1
+ import { Boot } from "./lib/boot.js";
2
+
3
+ //#region src/app.ts
4
+ var app_default = Boot;
5
+
6
+ //#endregion
7
+ export { app_default as default };
@@ -0,0 +1,13 @@
1
+ import { WatcherConfig } from "../lib/types.js";
2
+
3
+ //#region src/config/config.default.d.ts
4
+ declare const _default: {
5
+ /**
6
+ * watcher options
7
+ * @member Config#watcher
8
+ * @property {string} type - event source type
9
+ */
10
+ watcher: WatcherConfig;
11
+ };
12
+ //#endregion
13
+ export { _default as default };
@@ -0,0 +1,14 @@
1
+ import { getSourceDirname } from "../lib/utils.js";
2
+ import path from "node:path";
3
+
4
+ //#region src/config/config.default.ts
5
+ var config_default_default = { watcher: {
6
+ type: "default",
7
+ eventSources: {
8
+ default: path.join(getSourceDirname(), "lib", "event-sources", "default"),
9
+ development: path.join(getSourceDirname(), "lib", "event-sources", "development")
10
+ }
11
+ } };
12
+
13
+ //#endregion
14
+ export { config_default_default as default };
@@ -0,0 +1,8 @@
1
+ import { WatcherConfig } from "../lib/types.js";
2
+
3
+ //#region src/config/config.local.d.ts
4
+ declare const _default: {
5
+ watcher: WatcherConfig;
6
+ };
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,5 @@
1
+ //#region src/config/config.local.ts
2
+ var config_local_default = { watcher: { type: "development" } };
3
+
4
+ //#endregion
5
+ export { config_local_default as default };
@@ -0,0 +1,8 @@
1
+ import { WatcherConfig } from "../lib/types.js";
2
+
3
+ //#region src/config/config.unittest.d.ts
4
+ declare const _default: {
5
+ watcher: WatcherConfig;
6
+ };
7
+ //#endregion
8
+ export { _default as default };
@@ -0,0 +1,5 @@
1
+ //#region src/config/config.unittest.ts
2
+ var config_unittest_default = { watcher: { type: "development" } };
3
+
4
+ //#endregion
5
+ export { config_unittest_default as default };
@@ -0,0 +1,6 @@
1
+ import { WatchListener, Watcher } from "./lib/watcher.js";
2
+ import { ChangeInfo, WatcherConfig } from "./lib/types.js";
3
+ import { BaseEventSource } from "./lib/event-sources/base.js";
4
+ import DefaultEventSource from "./lib/event-sources/default.js";
5
+ import DevelopmentEventSource from "./lib/event-sources/development.js";
6
+ export { BaseEventSource, ChangeInfo, DefaultEventSource, DevelopmentEventSource, WatchListener, Watcher, WatcherConfig };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { BaseEventSource } from "./lib/event-sources/base.js";
2
+ import { Watcher } from "./lib/watcher.js";
3
+ import DefaultEventSource from "./lib/event-sources/default.js";
4
+ import DevelopmentEventSource from "./lib/event-sources/development.js";
5
+ import "./lib/event-sources/index.js";
6
+
7
+ export { BaseEventSource, DefaultEventSource, DevelopmentEventSource, Watcher };
@@ -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 };
@@ -0,0 +1,19 @@
1
+ import { Watcher } from "./watcher.js";
2
+
3
+ //#region src/lib/boot.ts
4
+ var Boot = class {
5
+ #app;
6
+ #watcher;
7
+ constructor(appOrAgent) {
8
+ 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));
11
+ }
12
+ async didLoad() {
13
+ await this.#watcher.ready();
14
+ this.#app.coreLogger.info("[@eggjs/watcher:%s] watcher start success", this.#app.type);
15
+ }
16
+ };
17
+
18
+ //#endregion
19
+ export { Boot };
@@ -0,0 +1,9 @@
1
+ import { Base } from "sdk-base";
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
9
+ export { BaseEventSource };
@@ -0,0 +1,7 @@
1
+ import { Base } from "sdk-base";
2
+
3
+ //#region src/lib/event-sources/base.ts
4
+ var BaseEventSource = class extends Base {};
5
+
6
+ //#endregion
7
+ export { BaseEventSource };
@@ -0,0 +1,10 @@
1
+ import { BaseEventSource } from "./base.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 as default };
@@ -0,0 +1,19 @@
1
+ import { BaseEventSource } from "./base.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 as default };
@@ -0,0 +1,11 @@
1
+ import { BaseEventSource } from "./base.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 as default };
@@ -0,0 +1,66 @@
1
+ import { BaseEventSource } from "./base.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 as default };
@@ -0,0 +1,4 @@
1
+ import { BaseEventSource } from "./base.js";
2
+ import DefaultEventSource from "./default.js";
3
+ import DevelopmentEventSource from "./development.js";
4
+ export { BaseEventSource, DefaultEventSource, DevelopmentEventSource };
@@ -0,0 +1,5 @@
1
+ import { BaseEventSource } from "./base.js";
2
+ import DefaultEventSource from "./default.js";
3
+ import DevelopmentEventSource from "./development.js";
4
+
5
+ export { BaseEventSource, DefaultEventSource, DevelopmentEventSource };
@@ -1,7 +1,8 @@
1
- import type { WatchEventType, Stats } from 'node:fs';
2
- import type { Watcher } from './watcher.js';
1
+ import { Watcher } from "./watcher.js";
2
+ import { Stats, WatchEventType } from "node:fs";
3
3
 
4
- export interface WatcherConfig {
4
+ //#region src/lib/types.d.ts
5
+ interface WatcherConfig {
5
6
  /**
6
7
  * event source type, default is `default`
7
8
  * can be `default` or `development`
@@ -13,8 +14,7 @@ export interface WatcherConfig {
13
14
  */
14
15
  eventSources: Record<string, string>;
15
16
  }
16
-
17
- export interface ChangeInfo extends Record<string, any> {
17
+ interface ChangeInfo extends Record<string, any> {
18
18
  event: WatchEventType;
19
19
  /**
20
20
  * file stat if path exists
@@ -23,15 +23,13 @@ export interface ChangeInfo extends Record<string, any> {
23
23
  path: string;
24
24
  isDirectory?: boolean;
25
25
  }
26
-
27
- declare module '@eggjs/core' {
28
- interface EggCore {
29
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
30
- // @ts-ignore
26
+ declare module 'egg' {
27
+ interface EggApplicationCore {
31
28
  watcher: Watcher;
32
29
  }
33
-
34
30
  interface EggAppConfig {
35
- watcher: WatcherConfig;
31
+ watcher?: WatcherConfig;
36
32
  }
37
33
  }
34
+ //#endregion
35
+ export { ChangeInfo, WatcherConfig };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,5 @@
1
+ //#region src/lib/utils.d.ts
2
+ declare function isEqualOrParentPath(parent: string, child: string): boolean;
3
+ declare function getSourceDirname(): string;
4
+ //#endregion
5
+ export { getSourceDirname, isEqualOrParentPath };
@@ -0,0 +1,15 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ //#region src/lib/utils.ts
5
+ function isEqualOrParentPath(parent, child) {
6
+ return !path.relative(parent, child).startsWith("..");
7
+ }
8
+ function getSourceDirname() {
9
+ if (typeof __dirname === "string") return path.dirname(__dirname);
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ return path.dirname(path.dirname(__filename));
12
+ }
13
+
14
+ //#endregion
15
+ export { getSourceDirname, isEqualOrParentPath };
@@ -0,0 +1,14 @@
1
+ import { ChangeInfo } from "./types.js";
2
+ import { Base } from "sdk-base";
3
+ import { EggAppConfig } from "egg";
4
+
5
+ //#region src/lib/watcher.d.ts
6
+ type WatchListener = (info: ChangeInfo) => void;
7
+ declare class Watcher extends Base {
8
+ #private;
9
+ constructor(config: EggAppConfig);
10
+ protected _init(): Promise<void>;
11
+ watch(path: string | string[], listener: WatchListener): void;
12
+ }
13
+ //#endregion
14
+ export { WatchListener, Watcher };
@@ -0,0 +1,59 @@
1
+ import "./event-sources/base.js";
2
+ import { isEqualOrParentPath } from "./utils.js";
3
+ import { debuglog } from "node:util";
4
+ import { Base } from "sdk-base";
5
+ import camelcase from "camelcase";
6
+ import { importModule } from "@eggjs/utils";
7
+
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
+ if (!watcherType) return;
20
+ let EventSource = this.#config.watcher?.eventSources[watcherType];
21
+ if (typeof EventSource === "string") EventSource = await importModule(EventSource, { importDefaultOnly: true });
22
+ const key = camelcase(["watcher", watcherType]);
23
+ const eventSourceOptions = this.#config[key] ?? {};
24
+ this.#eventSource = Reflect.construct(EventSource, [eventSourceOptions]);
25
+ 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));
26
+ await this.#eventSource.ready();
27
+ }
28
+ watch(path, listener) {
29
+ this.emit("info", "[@eggjs/watcher] Start watching: %j", path);
30
+ if (!path) return;
31
+ if (Array.isArray(path)) {
32
+ path.forEach((p) => this.watch(p, listener));
33
+ return;
34
+ }
35
+ if (!this.listenerCount(path)) this.#eventSource.watch(path);
36
+ this.on(path, listener);
37
+ }
38
+ #onChange(info) {
39
+ debug("onChange %o", info);
40
+ this.emit("info", "[@eggjs/watcher] Received a change event from eventSource: %j", info);
41
+ const path = info.path;
42
+ for (const p of this.eventNames()) {
43
+ if (typeof p !== "string") continue;
44
+ if (isEqualOrParentPath(p, path)) this.emit(p, info);
45
+ }
46
+ }
47
+ #onFuzzyChange(info) {
48
+ debug("onFuzzyChange %o", info);
49
+ this.emit("info", "[@eggjs/watcher] Received a fuzzy-change event from eventSource: %j", info);
50
+ const path = info.path;
51
+ for (const p of this.eventNames()) {
52
+ if (typeof p !== "string") continue;
53
+ if (isEqualOrParentPath(path, p)) this.emit(p, info);
54
+ }
55
+ }
56
+ };
57
+
58
+ //#endregion
59
+ export { Watcher };
package/package.json CHANGED
@@ -1,32 +1,18 @@
1
1
  {
2
2
  "name": "@eggjs/watcher",
3
- "version": "4.0.4",
3
+ "version": "4.0.5-beta.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "file watcher plugin for egg",
8
8
  "eggPlugin": {
9
- "name": "watcher",
10
- "exports": {
11
- "import": "./dist/esm",
12
- "require": "./dist/commonjs",
13
- "typescript": "./src"
14
- }
9
+ "name": "watcher"
15
10
  },
16
- "scripts": {
17
- "lint": "eslint --cache src test --ext .ts",
18
- "pretest": "npm run clean && npm run lint -- --fix",
19
- "test": "egg-bin test",
20
- "preci": "npm run clean && npm run lint",
21
- "ci": "egg-bin cov",
22
- "postci": "npm run prepublishOnly && attw --pack && npm run clean",
23
- "prepublishOnly": "tshy && tshy-after",
24
- "clean": "rimraf dist"
25
- },
26
- "homepage": "https://github.com/eggjs/watcher",
11
+ "homepage": "https://github.com/eggjs/egg/tree/master/plugins/watcher#readme",
27
12
  "repository": {
28
13
  "type": "git",
29
- "url": "git@github.com:eggjs/watcher.git"
14
+ "url": "git://github.com/eggjs/egg.git",
15
+ "directory": "plugins/watcher"
30
16
  },
31
17
  "keywords": [
32
18
  "egg-watcher",
@@ -35,54 +21,58 @@
35
21
  "watch"
36
22
  ],
37
23
  "engines": {
38
- "node": ">= 18.19.0"
24
+ "node": ">= 20.19.0"
39
25
  },
40
26
  "dependencies": {
41
- "@eggjs/core": "^6.2.13",
42
- "@eggjs/utils": "^4.2.3",
43
- "camelcase": "^5.0.0",
44
- "sdk-base": "^5.0.0"
27
+ "camelcase": "^8.0.0",
28
+ "sdk-base": "^5.0.1",
29
+ "@eggjs/utils": "4.5.0-beta.8"
30
+ },
31
+ "peerDependencies": {
32
+ "egg": "4.1.0-beta.8"
45
33
  },
46
34
  "devDependencies": {
47
- "@arethetypeswrong/cli": "^0.17.1",
48
- "@eggjs/tsconfig": "1",
49
- "@types/node": "22",
50
- "@types/mocha": "10",
51
- "egg": "beta",
52
- "@eggjs/bin": "7",
53
- "@eggjs/mock": "6",
54
- "rimraf": "6",
55
- "eslint": "8",
56
- "eslint-config-egg": "14",
57
- "tshy": "3",
58
- "tshy-after": "1",
59
- "typescript": "5"
35
+ "@types/node": "24",
36
+ "rimraf": "^6.0.1",
37
+ "tsdown": "^0.15.0",
38
+ "typescript": "5.9.2",
39
+ "vitest": "4.0.0-beta.11",
40
+ "@eggjs/mock": "6.1.0-beta.8",
41
+ "@eggjs/bin": "7.3.1-beta.6",
42
+ "@eggjs/supertest": "8.3.0-beta.8",
43
+ "@eggjs/utils": "4.5.0-beta.8",
44
+ "@eggjs/tsconfig": "3.1.0-beta.8"
60
45
  },
61
46
  "type": "module",
62
- "tshy": {
63
- "exports": {
64
- ".": "./src/index.ts",
65
- "./package.json": "./package.json"
66
- }
67
- },
68
47
  "exports": {
69
- ".": {
70
- "import": {
71
- "types": "./dist/esm/index.d.ts",
72
- "default": "./dist/esm/index.js"
73
- },
74
- "require": {
75
- "types": "./dist/commonjs/index.d.ts",
76
- "default": "./dist/commonjs/index.js"
77
- }
78
- },
48
+ ".": "./dist/index.js",
49
+ "./agent": "./dist/agent.js",
50
+ "./app": "./dist/app.js",
51
+ "./config/config.default": "./dist/config/config.default.js",
52
+ "./config/config.local": "./dist/config/config.local.js",
53
+ "./config/config.unittest": "./dist/config/config.unittest.js",
54
+ "./lib/boot": "./dist/lib/boot.js",
55
+ "./lib/event-sources": "./dist/lib/event-sources/index.js",
56
+ "./lib/event-sources/base": "./dist/lib/event-sources/base.js",
57
+ "./lib/event-sources/default": "./dist/lib/event-sources/default.js",
58
+ "./lib/event-sources/development": "./dist/lib/event-sources/development.js",
59
+ "./lib/types": "./dist/lib/types.js",
60
+ "./lib/utils": "./dist/lib/utils.js",
61
+ "./lib/watcher": "./dist/lib/watcher.js",
79
62
  "./package.json": "./package.json"
80
63
  },
81
64
  "files": [
82
- "dist",
83
- "src"
65
+ "dist"
84
66
  ],
85
- "types": "./dist/commonjs/index.d.ts",
86
- "main": "./dist/commonjs/index.js",
87
- "module": "./dist/esm/index.js"
88
- }
67
+ "types": "./dist/index.d.ts",
68
+ "main": "./dist/index.js",
69
+ "module": "./dist/index.js",
70
+ "scripts": {
71
+ "lint": "oxlint --type-aware",
72
+ "typecheck": "tsc --noEmit",
73
+ "pretest": "pnpm run clean",
74
+ "test": "vitest run",
75
+ "clean": "rimraf dist",
76
+ "build": "tsdown"
77
+ }
78
+ }
@@ -1,2 +0,0 @@
1
- import { Boot } from './lib/boot.js';
2
- export default Boot;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const boot_js_1 = require("./lib/boot.js");
4
- exports.default = boot_js_1.Boot;
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYWdlbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwyQ0FBcUM7QUFFckMsa0JBQWUsY0FBSSxDQUFDIn0=
@@ -1,2 +0,0 @@
1
- import { Boot } from './lib/boot.js';
2
- export default Boot;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const boot_js_1 = require("./lib/boot.js");
4
- exports.default = boot_js_1.Boot;
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FwcC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDJDQUFxQztBQUVyQyxrQkFBZSxjQUFJLENBQUMifQ==
@@ -1,10 +0,0 @@
1
- import type { WatcherConfig } from '../lib/types.js';
2
- declare const _default: {
3
- /**
4
- * watcher options
5
- * @member Config#watcher
6
- * @property {string} type - event source type
7
- */
8
- watcher: WatcherConfig;
9
- };
10
- export default _default;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_path_1 = __importDefault(require("node:path"));
7
- const utils_js_1 = require("../lib/utils.js");
8
- exports.default = {
9
- /**
10
- * watcher options
11
- * @member Config#watcher
12
- * @property {string} type - event source type
13
- */
14
- watcher: {
15
- type: 'default', // default event source
16
- eventSources: {
17
- default: node_path_1.default.join((0, utils_js_1.getSourceDirname)(), 'lib', 'event-sources', 'default'),
18
- development: node_path_1.default.join((0, utils_js_1.getSourceDirname)(), 'lib', 'event-sources', 'development'),
19
- },
20
- },
21
- };
22
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmRlZmF1bHQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY29uZmlnL2NvbmZpZy5kZWZhdWx0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsMERBQTZCO0FBQzdCLDhDQUFtRDtBQUduRCxrQkFBZTtJQUNiOzs7O09BSUc7SUFDSCxPQUFPLEVBQUU7UUFDUCxJQUFJLEVBQUUsU0FBUyxFQUFFLHVCQUF1QjtRQUN4QyxZQUFZLEVBQUU7WUFDWixPQUFPLEVBQUUsbUJBQUksQ0FBQyxJQUFJLENBQUMsSUFBQSwyQkFBZ0IsR0FBRSxFQUFFLEtBQUssRUFBRSxlQUFlLEVBQUUsU0FBUyxDQUFDO1lBQ3pFLFdBQVcsRUFBRSxtQkFBSSxDQUFDLElBQUksQ0FBQyxJQUFBLDJCQUFnQixHQUFFLEVBQUUsS0FBSyxFQUFFLGVBQWUsRUFBRSxhQUFhLENBQUM7U0FDbEY7S0FDZTtDQUNuQixDQUFDIn0=