@qqbrowser/qbot-claw-launcher 0.9.32

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 (90) hide show
  1. package/README.md +1 -0
  2. package/debug.html +440 -0
  3. package/dist/config.d.ts +15 -0
  4. package/dist/config.d.ts.map +1 -0
  5. package/dist/config.js +23 -0
  6. package/dist/config.js.map +1 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +128 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/installer.d.ts +20 -0
  12. package/dist/installer.d.ts.map +1 -0
  13. package/dist/installer.js +335 -0
  14. package/dist/installer.js.map +1 -0
  15. package/dist/quarantine.d.ts +37 -0
  16. package/dist/quarantine.d.ts.map +1 -0
  17. package/dist/quarantine.js +315 -0
  18. package/dist/quarantine.js.map +1 -0
  19. package/dist/reportLog.d.ts +28 -0
  20. package/dist/reportLog.d.ts.map +1 -0
  21. package/dist/reportLog.js +262 -0
  22. package/dist/reportLog.js.map +1 -0
  23. package/dist/server.d.ts +4 -0
  24. package/dist/server.d.ts.map +1 -0
  25. package/dist/server.js +425 -0
  26. package/dist/server.js.map +1 -0
  27. package/dist/service.d.ts +11 -0
  28. package/dist/service.d.ts.map +1 -0
  29. package/dist/service.js +197 -0
  30. package/dist/service.js.map +1 -0
  31. package/dist/state.d.ts +21 -0
  32. package/dist/state.d.ts.map +1 -0
  33. package/dist/state.js +62 -0
  34. package/dist/state.js.map +1 -0
  35. package/dist/utils.d.ts +25 -0
  36. package/dist/utils.d.ts.map +1 -0
  37. package/dist/utils.js +101 -0
  38. package/dist/utils.js.map +1 -0
  39. package/node_modules/@parcel/watcher/LICENSE +21 -0
  40. package/node_modules/@parcel/watcher/README.md +136 -0
  41. package/node_modules/@parcel/watcher/index.d.ts +49 -0
  42. package/node_modules/@parcel/watcher/index.js +42 -0
  43. package/node_modules/@parcel/watcher/index.js.flow +48 -0
  44. package/node_modules/@parcel/watcher/node_modules/picomatch/LICENSE +21 -0
  45. package/node_modules/@parcel/watcher/node_modules/picomatch/README.md +738 -0
  46. package/node_modules/@parcel/watcher/node_modules/picomatch/index.js +17 -0
  47. package/node_modules/@parcel/watcher/node_modules/picomatch/lib/constants.js +180 -0
  48. package/node_modules/@parcel/watcher/node_modules/picomatch/lib/parse.js +1085 -0
  49. package/node_modules/@parcel/watcher/node_modules/picomatch/lib/picomatch.js +341 -0
  50. package/node_modules/@parcel/watcher/node_modules/picomatch/lib/scan.js +391 -0
  51. package/node_modules/@parcel/watcher/node_modules/picomatch/lib/utils.js +72 -0
  52. package/node_modules/@parcel/watcher/node_modules/picomatch/package.json +83 -0
  53. package/node_modules/@parcel/watcher/node_modules/picomatch/posix.js +3 -0
  54. package/node_modules/@parcel/watcher/package.json +39 -0
  55. package/node_modules/@parcel/watcher/wrapper.js +74 -0
  56. package/node_modules/@parcel/watcher-darwin-arm64/LICENSE +21 -0
  57. package/node_modules/@parcel/watcher-darwin-arm64/README.md +1 -0
  58. package/node_modules/@parcel/watcher-darwin-arm64/package.json +30 -0
  59. package/node_modules/@parcel/watcher-darwin-arm64/watcher.node +0 -0
  60. package/node_modules/fs-xattr/LICENSE +21 -0
  61. package/node_modules/fs-xattr/build/Makefile +347 -0
  62. package/node_modules/fs-xattr/build/Release/.deps/Release/obj.target/xattr/src/async.o.d +15 -0
  63. package/node_modules/fs-xattr/build/Release/.deps/Release/obj.target/xattr/src/error.o.d +12 -0
  64. package/node_modules/fs-xattr/build/Release/.deps/Release/obj.target/xattr/src/sync.o.d +15 -0
  65. package/node_modules/fs-xattr/build/Release/.deps/Release/obj.target/xattr/src/util.o.d +12 -0
  66. package/node_modules/fs-xattr/build/Release/.deps/Release/obj.target/xattr/src/xattr.o.d +14 -0
  67. package/node_modules/fs-xattr/build/Release/.deps/Release/xattr.node.d +1 -0
  68. package/node_modules/fs-xattr/build/Release/obj.target/xattr/src/async.o +0 -0
  69. package/node_modules/fs-xattr/build/Release/obj.target/xattr/src/error.o +0 -0
  70. package/node_modules/fs-xattr/build/Release/obj.target/xattr/src/sync.o +0 -0
  71. package/node_modules/fs-xattr/build/Release/obj.target/xattr/src/util.o +0 -0
  72. package/node_modules/fs-xattr/build/Release/obj.target/xattr/src/xattr.o +0 -0
  73. package/node_modules/fs-xattr/build/Release/xattr.node +0 -0
  74. package/node_modules/fs-xattr/build/binding.Makefile +6 -0
  75. package/node_modules/fs-xattr/build/config.gypi +530 -0
  76. package/node_modules/fs-xattr/build/gyp-mac-tool +772 -0
  77. package/node_modules/fs-xattr/build/xattr.target.mk +185 -0
  78. package/node_modules/fs-xattr/index.d.ts +47 -0
  79. package/node_modules/fs-xattr/index.js +80 -0
  80. package/node_modules/fs-xattr/package.json +29 -0
  81. package/node_modules/fs-xattr/readme.md +101 -0
  82. package/node_modules/is-extglob/LICENSE +21 -0
  83. package/node_modules/is-extglob/README.md +107 -0
  84. package/node_modules/is-extglob/index.js +20 -0
  85. package/node_modules/is-extglob/package.json +69 -0
  86. package/node_modules/is-glob/LICENSE +21 -0
  87. package/node_modules/is-glob/README.md +206 -0
  88. package/node_modules/is-glob/index.js +150 -0
  89. package/node_modules/is-glob/package.json +81 -0
  90. package/package.json +45 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;AAsGA,oCAoEC;AAKD,kCAsBC;AArMD,4CAAoB;AACpB,gDAAwB;AACxB,gDAAwB;AACxB,qCAAoD;AACpD,mCAA8F;AAC9F,qCAAsC;AAEtC,2CAAiD;AACjD,mCAA2C;AAC3C,2CAA2C;AAE3C,0BAA0B;AAC1B,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,OAAO,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AO,GAAQ,EAAE,CAAC;QAClB,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACzB,IAAA,kBAAU,GAAE,CAAC;QACf,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QAC7E,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ export interface LauncherState {
2
+ pid?: number;
3
+ port?: number;
4
+ ppid?: number;
5
+ gatewayPid?: number;
6
+ gatewayPort?: number;
7
+ mcpHttpPort?: number;
8
+ mcpWsPort?: number;
9
+ }
10
+ export declare function readState(): LauncherState;
11
+ export declare function writeState(state: LauncherState): void;
12
+ export declare function clearState(): void;
13
+ /**
14
+ * 检测指定端口是否可用
15
+ */
16
+ export declare function isPortAvailable(port: number): Promise<boolean>;
17
+ /**
18
+ * 随机生成一个可用端口(范围 10000~60000)
19
+ */
20
+ export declare function findAvailablePort(): Promise<number>;
21
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,SAAS,IAAI,aAAa,CASzC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAMrD;AAED,wBAAgB,UAAU,IAAI,IAAI,CAIjC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAS9D;AAED;;GAEG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAOzD"}
package/dist/state.js ADDED
@@ -0,0 +1,62 @@
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
+ exports.readState = readState;
7
+ exports.writeState = writeState;
8
+ exports.clearState = clearState;
9
+ exports.isPortAvailable = isPortAvailable;
10
+ exports.findAvailablePort = findAvailablePort;
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const path_1 = __importDefault(require("path"));
13
+ const net_1 = __importDefault(require("net"));
14
+ const config_1 = require("./config");
15
+ function readState() {
16
+ try {
17
+ if (fs_1.default.existsSync(config_1.STATE_FILE)) {
18
+ return JSON.parse(fs_1.default.readFileSync(config_1.STATE_FILE, 'utf-8'));
19
+ }
20
+ }
21
+ catch {
22
+ // 文件损坏时忽略
23
+ }
24
+ return {};
25
+ }
26
+ function writeState(state) {
27
+ const dir = path_1.default.dirname(config_1.STATE_FILE);
28
+ if (!fs_1.default.existsSync(dir)) {
29
+ fs_1.default.mkdirSync(dir, { recursive: true });
30
+ }
31
+ fs_1.default.writeFileSync(config_1.STATE_FILE, JSON.stringify(state, null, 2));
32
+ }
33
+ function clearState() {
34
+ if (fs_1.default.existsSync(config_1.STATE_FILE)) {
35
+ fs_1.default.unlinkSync(config_1.STATE_FILE);
36
+ }
37
+ }
38
+ /**
39
+ * 检测指定端口是否可用
40
+ */
41
+ function isPortAvailable(port) {
42
+ return new Promise((resolve) => {
43
+ const tester = net_1.default.createServer();
44
+ tester.once('error', () => resolve(false));
45
+ tester.once('listening', () => {
46
+ tester.close(() => resolve(true));
47
+ });
48
+ tester.listen(port, '127.0.0.1');
49
+ });
50
+ }
51
+ /**
52
+ * 随机生成一个可用端口(范围 10000~60000)
53
+ */
54
+ async function findAvailablePort() {
55
+ while (true) {
56
+ const port = Math.floor(Math.random() * 50000) + 10000;
57
+ if (await isPortAvailable(port)) {
58
+ return port;
59
+ }
60
+ }
61
+ }
62
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":";;;;;AAeA,8BASC;AAED,gCAMC;AAED,gCAIC;AAKD,0CASC;AAKD,8CAOC;AAhED,4CAAoB;AACpB,gDAAwB;AACxB,8CAAsB;AACtB,qCAAsC;AAYtC,SAAgB,SAAS;IACvB,IAAI,CAAC;QACH,IAAI,YAAE,CAAC,UAAU,CAAC,mBAAU,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,mBAAU,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,UAAU;IACZ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAgB,UAAU,CAAC,KAAoB;IAC7C,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,mBAAU,CAAC,CAAC;IACrC,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,YAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,YAAE,CAAC,aAAa,CAAC,mBAAU,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,SAAgB,UAAU;IACxB,IAAI,YAAE,CAAC,UAAU,CAAC,mBAAU,CAAC,EAAE,CAAC;QAC9B,YAAE,CAAC,UAAU,CAAC,mBAAU,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,aAAG,CAAC,YAAY,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;YAC5B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,iBAAiB;IACrC,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;QACvD,IAAI,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import http from 'http';
2
+ /**
3
+ * 执行命令并返回输出
4
+ */
5
+ export declare function execCommand(cmd: string): Promise<string>;
6
+ /**
7
+ * 发送 JSON 响应
8
+ */
9
+ export declare function sendJSON(res: http.ServerResponse, statusCode: number, data: object): void;
10
+ /**
11
+ * 获取本地已安装的 qbotclaw 版本号,未安装或失败返回 null
12
+ * 若返回内容不符合语义化版本格式(如 x.y.z),则返回 '0.0.0'
13
+ */
14
+ export declare function getQBotClawVersion(): Promise<string | null>;
15
+ /**
16
+ * 比较两个语义化版本号
17
+ * 返回负数表示 a < b,0 表示相等,正数表示 a > b
18
+ */
19
+ export declare function compareVersion(a: string, b: string): number;
20
+ /**
21
+ * 随机找一个可用的 TCP 端口
22
+ * 通过让系统分配端口(绑定到 0)后立即释放来获取可用端口号
23
+ */
24
+ export declare function findAvailablePort(): Promise<number>;
25
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAUxD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAUlF;AAGD;;;GAGG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAcjE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAS3D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAgBnD"}
package/dist/utils.js ADDED
@@ -0,0 +1,101 @@
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
+ exports.execCommand = execCommand;
7
+ exports.sendJSON = sendJSON;
8
+ exports.getQBotClawVersion = getQBotClawVersion;
9
+ exports.compareVersion = compareVersion;
10
+ exports.findAvailablePort = findAvailablePort;
11
+ const http_1 = __importDefault(require("http"));
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const child_process_1 = require("child_process");
14
+ const config_1 = require("./config");
15
+ /**
16
+ * 执行命令并返回输出
17
+ */
18
+ function execCommand(cmd) {
19
+ return new Promise((resolve, reject) => {
20
+ (0, child_process_1.exec)(cmd, (error, stdout, stderr) => {
21
+ if (error) {
22
+ reject(new Error(stderr || error.message));
23
+ return;
24
+ }
25
+ resolve(stdout.trim());
26
+ });
27
+ });
28
+ }
29
+ /**
30
+ * 发送 JSON 响应
31
+ */
32
+ function sendJSON(res, statusCode, data) {
33
+ const body = JSON.stringify(data);
34
+ res.writeHead(statusCode, {
35
+ 'Content-Type': 'application/json',
36
+ 'Content-Length': Buffer.byteLength(body),
37
+ 'Access-Control-Allow-Origin': '*',
38
+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
39
+ 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With',
40
+ });
41
+ res.end(body);
42
+ }
43
+ /**
44
+ * 获取本地已安装的 qbotclaw 版本号,未安装或失败返回 null
45
+ * 若返回内容不符合语义化版本格式(如 x.y.z),则返回 '0.0.0'
46
+ */
47
+ async function getQBotClawVersion() {
48
+ if (!fs_1.default.existsSync(config_1.QBOTCLAW_BIN)) {
49
+ return null;
50
+ }
51
+ try {
52
+ // 使用 NODE_BIN 直接执行,避免依赖 PATH 中的 node(从 GUI 应用启动时 PATH 可能不含 node)
53
+ const raw = (await execCommand(`"${config_1.NODE_BIN}" "${config_1.QBOTCLAW_BIN}" --version`)).trim();
54
+ if (!raw)
55
+ return null;
56
+ // 校验是否为合法的语义化版本号(x.y.z 格式)
57
+ const semverReg = /^\d+\.\d+\.\d+$/;
58
+ return semverReg.test(raw) ? raw : '0.0.0';
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ }
64
+ /**
65
+ * 比较两个语义化版本号
66
+ * 返回负数表示 a < b,0 表示相等,正数表示 a > b
67
+ */
68
+ function compareVersion(a, b) {
69
+ const pa = a.split('.').map(Number);
70
+ const pb = b.split('.').map(Number);
71
+ const len = Math.max(pa.length, pb.length);
72
+ for (let i = 0; i < len; i++) {
73
+ const diff = (pa[i] || 0) - (pb[i] || 0);
74
+ if (diff !== 0)
75
+ return diff;
76
+ }
77
+ return 0;
78
+ }
79
+ /**
80
+ * 随机找一个可用的 TCP 端口
81
+ * 通过让系统分配端口(绑定到 0)后立即释放来获取可用端口号
82
+ */
83
+ function findAvailablePort() {
84
+ return new Promise((resolve, reject) => {
85
+ const srv = http_1.default.createServer();
86
+ srv.listen(0, '127.0.0.1', () => {
87
+ const addr = srv.address();
88
+ const port = addr && typeof addr === 'object' ? addr.port : null;
89
+ srv.close((err) => {
90
+ if (err || port === null) {
91
+ reject(err || new Error('无法获取可用端口'));
92
+ }
93
+ else {
94
+ resolve(port);
95
+ }
96
+ });
97
+ });
98
+ srv.on('error', reject);
99
+ });
100
+ }
101
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;AAQA,kCAUC;AAKD,4BAUC;AAOD,gDAcC;AAMD,wCASC;AAMD,8CAgBC;AA3FD,gDAAwB;AACxB,4CAAoB;AACpB,iDAAqC;AACrC,qCAAkD;AAElD;;GAEG;AACH,SAAgB,WAAW,CAAC,GAAW;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAA,oBAAI,EAAC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAClC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC3C,OAAO;YACT,CAAC;YACD,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,GAAwB,EAAE,UAAkB,EAAE,IAAY;IACjF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,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copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,136 @@
1
+ # @parcel/watcher
2
+
3
+ A native C++ Node module for querying and subscribing to filesystem events. Used by [Parcel 2](https://github.com/parcel-bundler/parcel).
4
+
5
+ ## Features
6
+
7
+ - **Watch** - subscribe to realtime recursive directory change notifications when files or directories are created, updated, or deleted.
8
+ - **Query** - performantly query for historical change events in a directory, even when your program is not running.
9
+ - **Native** - implemented in C++ for performance and low-level integration with the operating system.
10
+ - **Cross platform** - includes backends for macOS, Linux, Windows, FreeBSD, and Watchman.
11
+ - **Performant** - events are throttled in C++ so the JavaScript thread is not overwhelmed during large filesystem changes (e.g. `git checkout` or `npm install`).
12
+ - **Scalable** - tens of thousands of files can be watched or queried at once with good performance.
13
+
14
+ ## Example
15
+
16
+ ```javascript
17
+ const watcher = require('@parcel/watcher');
18
+ const path = require('path');
19
+
20
+ // Subscribe to events
21
+ let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
22
+ console.log(events);
23
+ });
24
+
25
+ // later on...
26
+ await subscription.unsubscribe();
27
+
28
+ // Get events since some saved snapshot in the past
29
+ let snapshotPath = path.join(process.cwd(), 'snapshot.txt');
30
+ let events = await watcher.getEventsSince(process.cwd(), snapshotPath);
31
+
32
+ // Save a snapshot for later
33
+ await watcher.writeSnapshot(process.cwd(), snapshotPath);
34
+ ```
35
+
36
+ ## Watching
37
+
38
+ `@parcel/watcher` supports subscribing to realtime notifications of changes in a directory. It works recursively, so changes in sub-directories will also be emitted.
39
+
40
+ Events are throttled and coalesced for performance during large changes like `git checkout` or `npm install`, and a single notification will be emitted with all of the events at the end.
41
+
42
+ Only one notification will be emitted per file. For example, if a file was both created and updated since the last event, you'll get only a `create` event. If a file is both created and deleted, you will not be notifed of that file. Renames cause two events: a `delete` for the old name, and a `create` for the new name.
43
+
44
+ ```javascript
45
+ let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
46
+ console.log(events);
47
+ });
48
+ ```
49
+
50
+ Events have two properties:
51
+
52
+ - `type` - the event type: `create`, `update`, or `delete`.
53
+ - `path` - the absolute path to the file or directory.
54
+
55
+ To unsubscribe from change notifications, call the `unsubscribe` method on the returned subscription object.
56
+
57
+ ```javascript
58
+ await subscription.unsubscribe();
59
+ ```
60
+
61
+ `@parcel/watcher` has the following watcher backends, listed in priority order:
62
+
63
+ - [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) on macOS
64
+ - [Watchman](https://facebook.github.io/watchman/) if installed
65
+ - [inotify](http://man7.org/linux/man-pages/man7/inotify.7.html) on Linux
66
+ - [ReadDirectoryChangesW](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v%3Dvs.85%29.aspx) on Windows
67
+ - [kqueue](https://man.freebsd.org/cgi/man.cgi?kqueue) on FreeBSD, or as an alternative to FSEvents on macOS
68
+
69
+ You can specify the exact backend you wish to use by passing the `backend` option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
70
+
71
+ ## Querying
72
+
73
+ `@parcel/watcher` also supports querying for historical changes made in a directory, even when your program is not running. This makes it easy to invalidate a cache and re-build only the files that have changed, for example. It can be **significantly** faster than traversing the entire filesystem to determine what files changed, depending on the platform.
74
+
75
+ In order to query for historical changes, you first need a previous snapshot to compare to. This can be saved to a file with the `writeSnapshot` function, e.g. just before your program exits.
76
+
77
+ ```javascript
78
+ await watcher.writeSnapshot(dirPath, snapshotPath);
79
+ ```
80
+
81
+ When your program starts up, you can query for changes that have occurred since that snapshot using the `getEventsSince` function.
82
+
83
+ ```javascript
84
+ let events = await watcher.getEventsSince(dirPath, snapshotPath);
85
+ ```
86
+
87
+ The events returned are exactly the same as the events that would be passed to the `subscribe` callback (see above).
88
+
89
+ `@parcel/watcher` has the following watcher backends, listed in priority order:
90
+
91
+ - [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) on macOS
92
+ - [Watchman](https://facebook.github.io/watchman/) if installed
93
+ - [fts](http://man7.org/linux/man-pages/man3/fts.3.html) (brute force) on Linux and FreeBSD
94
+ - [FindFirstFile](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea) (brute force) on Windows
95
+
96
+ The FSEvents (macOS) and Watchman backends are significantly more performant than the brute force backends used by default on Linux and Windows, for example returning results in miliseconds instead of seconds for large directory trees. This is because a background daemon monitoring filesystem changes on those platforms allows us to query cached data rather than traversing the filesystem manually (brute force).
97
+
98
+ macOS has good performance with FSEvents by default. For the best performance on other platforms, install [Watchman](https://facebook.github.io/watchman/) and it will be used by `@parcel/watcher` automatically.
99
+
100
+ You can specify the exact backend you wish to use by passing the `backend` option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
101
+
102
+ ## Options
103
+
104
+ All of the APIs in `@parcel/watcher` support the following options, which are passed as an object as the last function argument.
105
+
106
+ - `ignore` - an array of paths or glob patterns to ignore. uses [`is-glob`](https://github.com/micromatch/is-glob) to distinguish paths from globs. glob patterns are parsed with [`picomatch`](https://github.com/micromatch/picomatch) (see [features](https://github.com/micromatch/picomatch#globbing-features)).
107
+ - paths can be relative or absolute and can either be files or directories. No events will be emitted about these files or directories or their children.
108
+ - glob patterns match on relative paths from the root that is watched. No events will be emitted for matching paths.
109
+ - `backend` - the name of an explicitly chosen backend to use. Allowed options are `"fs-events"`, `"watchman"`, `"inotify"`, `"kqueue"`, `"windows"`, or `"brute-force"` (only for querying). If the specified backend is not available on the current platform, the default backend will be used instead.
110
+
111
+ ## WASM
112
+
113
+ The `@parcel/watcher-wasm` package can be used in place of `@parcel/watcher` on unsupported platforms. It relies on the Node `fs` module, so in non-Node environments such as browsers, an `fs` polyfill will be needed.
114
+
115
+ **Note**: the WASM implementation is significantly less efficient than the native implementations because it must crawl the file system to watch each directory individually. Use the native `@parcel/watcher` package wherever possible.
116
+
117
+ ```js
118
+ import {subscribe} from '@parcel/watcher-wasm';
119
+
120
+ // Use the module as documented above.
121
+ subscribe(/* ... */);
122
+ ```
123
+
124
+ ## Who is using this?
125
+
126
+ - [Parcel 2](https://parceljs.org/)
127
+ - [VSCode](https://code.visualstudio.com/updates/v1_62#_file-watching-changes)
128
+ - [Tailwind CSS Intellisense](https://github.com/tailwindlabs/tailwindcss-intellisense)
129
+ - [Gatsby Cloud](https://twitter.com/chatsidhartha/status/1435647412828196867)
130
+ - [Nx](https://nx.dev)
131
+ - [Nuxt](https://nuxt.com)
132
+ - [Meteor](https://github.com/meteor/meteor)
133
+
134
+ ## License
135
+
136
+ MIT
@@ -0,0 +1,49 @@
1
+ declare type FilePath = string;
2
+ declare type GlobPattern = string;
3
+
4
+ declare namespace ParcelWatcher {
5
+ export type BackendType =
6
+ | 'fs-events'
7
+ | 'watchman'
8
+ | 'inotify'
9
+ | 'windows'
10
+ | 'brute-force';
11
+ export type EventType = 'create' | 'update' | 'delete';
12
+ export interface Options {
13
+ ignore?: (FilePath|GlobPattern)[];
14
+ backend?: BackendType;
15
+ }
16
+ export type SubscribeCallback = (
17
+ err: Error | null,
18
+ events: Event[]
19
+ ) => unknown;
20
+ export interface AsyncSubscription {
21
+ unsubscribe(): Promise<void>;
22
+ }
23
+ export interface Event {
24
+ path: FilePath;
25
+ type: EventType;
26
+ }
27
+ export function getEventsSince(
28
+ dir: FilePath,
29
+ snapshot: FilePath,
30
+ opts?: Options
31
+ ): Promise<Event[]>;
32
+ export function subscribe(
33
+ dir: FilePath,
34
+ fn: SubscribeCallback,
35
+ opts?: Options
36
+ ): Promise<AsyncSubscription>;
37
+ export function unsubscribe(
38
+ dir: FilePath,
39
+ fn: SubscribeCallback,
40
+ opts?: Options
41
+ ): Promise<void>;
42
+ export function writeSnapshot(
43
+ dir: FilePath,
44
+ snapshot: FilePath,
45
+ opts?: Options
46
+ ): Promise<FilePath>;
47
+ }
48
+
49
+ export = ParcelWatcher;
@@ -0,0 +1,42 @@
1
+ const {createWrapper} = require('./wrapper');
2
+
3
+ let name = `@parcel/watcher-${process.platform}-${process.arch}`;
4
+ if (process.platform === 'linux') {
5
+ const { MUSL, familySync } = require('detect-libc');
6
+ const family = familySync();
7
+ if (family === MUSL) {
8
+ name += '-musl';
9
+ } else {
10
+ name += '-glibc';
11
+ }
12
+ }
13
+
14
+ let binding;
15
+ try {
16
+ binding = require(name);
17
+ } catch (err) {
18
+ handleError(err);
19
+ try {
20
+ binding = require('./build/Release/watcher.node');
21
+ } catch (err) {
22
+ handleError(err);
23
+ try {
24
+ binding = require('./build/Debug/watcher.node');
25
+ } catch (err) {
26
+ handleError(err);
27
+ throw new Error(`No prebuild or local build of @parcel/watcher found. Tried ${name}. Please ensure it is installed (don't use --no-optional when installing with npm). Otherwise it is possible we don't support your platform yet. If this is the case, please report an issue to https://github.com/parcel-bundler/watcher.`);
28
+ }
29
+ }
30
+ }
31
+
32
+ function handleError(err) {
33
+ if (err?.code !== 'MODULE_NOT_FOUND') {
34
+ throw err;
35
+ }
36
+ }
37
+
38
+ const wrapper = createWrapper(binding);
39
+ exports.writeSnapshot = wrapper.writeSnapshot;
40
+ exports.getEventsSince = wrapper.getEventsSince;
41
+ exports.subscribe = wrapper.subscribe;
42
+ exports.unsubscribe = wrapper.unsubscribe;
@@ -0,0 +1,48 @@
1
+ // @flow
2
+ declare type FilePath = string;
3
+ declare type GlobPattern = string;
4
+
5
+ export type BackendType =
6
+ | 'fs-events'
7
+ | 'watchman'
8
+ | 'inotify'
9
+ | 'windows'
10
+ | 'brute-force';
11
+ export type EventType = 'create' | 'update' | 'delete';
12
+ export interface Options {
13
+ ignore?: Array<FilePath | GlobPattern>,
14
+ backend?: BackendType
15
+ }
16
+ export type SubscribeCallback = (
17
+ err: ?Error,
18
+ events: Array<Event>
19
+ ) => mixed;
20
+ export interface AsyncSubscription {
21
+ unsubscribe(): Promise<void>
22
+ }
23
+ export interface Event {
24
+ path: FilePath,
25
+ type: EventType
26
+ }
27
+ declare module.exports: {
28
+ getEventsSince(
29
+ dir: FilePath,
30
+ snapshot: FilePath,
31
+ opts?: Options
32
+ ): Promise<Array<Event>>,
33
+ subscribe(
34
+ dir: FilePath,
35
+ fn: SubscribeCallback,
36
+ opts?: Options
37
+ ): Promise<AsyncSubscription>,
38
+ unsubscribe(
39
+ dir: FilePath,
40
+ fn: SubscribeCallback,
41
+ opts?: Options
42
+ ): Promise<void>,
43
+ writeSnapshot(
44
+ dir: FilePath,
45
+ snapshot: FilePath,
46
+ opts?: Options
47
+ ): Promise<FilePath>
48
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017-present, Jon Schlinkert.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.