@qqbrowser/qbot-claw-launcher 0.9.53 → 0.9.54
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/config.js +1 -1
- package/dist/installer.js +6 -5
- package/dist/server.js +3 -3
- package/dist/service.js +1 -1
- package/dist/version.js +1 -1
- package/node_modules/@parcel/watcher/build/Release/watcher.node +0 -0
- package/node_modules/@parcel/watcher/package.json +3 -1
- package/node_modules/fs-xattr/build/Release/xattr.node +0 -0
- package/node_modules/fs-xattr/package.json +1 -0
- package/package.json +2 -2
- package/node_modules/@parcel/watcher/LICENSE +0 -21
- package/node_modules/@parcel/watcher/README.md +0 -136
- package/node_modules/@parcel/watcher/index.js.flow +0 -48
- package/node_modules/fs-xattr/LICENSE +0 -21
- package/node_modules/fs-xattr/readme.md +0 -101
package/dist/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_MCP_HTTP_PORT=exports.STATE_FILE=exports.MCPORTER_BIN=exports.OPENCLAW_BIN=exports.QBOTCLAW_BIN=exports.NPM_GLOBAL_MODULES=exports.NPM_PACKAGE_NAME=exports.QBOT_CLAW_CONFIG_PATH=exports.NODE_BIN_DIR=exports.NPM_RC=exports.NPM_BIN=exports.PYTHON_BIN=exports.NODE_BIN=exports.QBOT_CLAW_DIR=void 0;const _=n(require("path")),o=n(require("os"));exports.QBOT_CLAW_DIR=_.default.join(o.default.homedir(),".qbotclaw"),exports.NODE_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","node"),exports.PYTHON_BIN=_.default.join(exports.QBOT_CLAW_DIR,"python","bin","python3"),exports.NPM_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","npm"),exports.NPM_RC=_.default.join(exports.QBOT_CLAW_DIR,"node",".npmrc"),exports.NODE_BIN_DIR=_.default.dirname(exports.NODE_BIN),exports.QBOT_CLAW_CONFIG_PATH=_.default.join(exports.QBOT_CLAW_DIR,".openclaw-qbot.json"),exports.NPM_PACKAGE_NAME="@qqbrowser/openclaw-qbot",exports.NPM_GLOBAL_MODULES=_.default.join(exports.QBOT_CLAW_DIR,"node","lib","node_modules"),exports.QBOTCLAW_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","qb-qbot-claw"),exports.OPENCLAW_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","openclaw"),exports.MCPORTER_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","mcporter"),exports.STATE_FILE=_.default.join(exports.QBOT_CLAW_DIR,"launcher.json"),exports.DEFAULT_MCP_HTTP_PORT=38789;
|
|
1
|
+
"use strict";var n=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_MCP_HTTP_PORT=exports.SESSIONS_FILE=exports.STATE_FILE=exports.MCPORTER_BIN=exports.OPENCLAW_BIN=exports.QBOTCLAW_BIN=exports.NPM_GLOBAL_MODULES=exports.NPM_PACKAGE_NAME=exports.QBOT_CLAW_CONFIG_PATH=exports.NODE_BIN_DIR=exports.NPM_RC=exports.NPM_BIN=exports.PYTHON_BIN=exports.NODE_BIN=exports.QBOT_CLAW_DIR=void 0;const _=n(require("path")),o=n(require("os"));exports.QBOT_CLAW_DIR=_.default.join(o.default.homedir(),".qbotclaw"),exports.NODE_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","node"),exports.PYTHON_BIN=_.default.join(exports.QBOT_CLAW_DIR,"python","bin","python3"),exports.NPM_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","npm"),exports.NPM_RC=_.default.join(exports.QBOT_CLAW_DIR,"node",".npmrc"),exports.NODE_BIN_DIR=_.default.dirname(exports.NODE_BIN),exports.QBOT_CLAW_CONFIG_PATH=_.default.join(exports.QBOT_CLAW_DIR,".openclaw-qbot.json"),exports.NPM_PACKAGE_NAME="@qqbrowser/openclaw-qbot",exports.NPM_GLOBAL_MODULES=_.default.join(exports.QBOT_CLAW_DIR,"node","lib","node_modules"),exports.QBOTCLAW_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","qb-qbot-claw"),exports.OPENCLAW_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","openclaw"),exports.MCPORTER_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","mcporter"),exports.STATE_FILE=_.default.join(exports.QBOT_CLAW_DIR,"launcher.json"),exports.SESSIONS_FILE=_.default.join(exports.QBOT_CLAW_DIR,"agents","main","sessions","sessions.json"),exports.DEFAULT_MCP_HTTP_PORT=38789;
|
package/dist/installer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
"use strict";var d=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PYTHON_DIR=exports.installState=void 0,exports.runQBotClaw=
|
|
2
|
-
`)}catch{}}}exports.installState={status:"idle",message:"\u672A\u5F00\u59CB"},exports.PYTHON_DIR=u.default.join(
|
|
3
|
-
`);
|
|
4
|
-
`)}catch{}}catch(
|
|
5
|
-
`)}catch{}}})()}
|
|
1
|
+
"use strict";var d=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PYTHON_DIR=exports.isInstalling=exports.installState=void 0,exports.runQBotClaw=A,exports.configAndRunQBotClaw=N,exports.runInstall=$;const c=d(require("fs")),u=d(require("path")),_=require("child_process"),s=require("./config"),w=require("./utils"),p=require("./state"),f=require("./quarantine"),a=require("./reportLog");function g(t,o,r,i){if(t&&t.writable){const e=o>0?Math.round(r/o*1e4)/100:0;try{t.write(JSON.stringify({status:"downloading",progress:e,totalSteps:o,currentStep:r,message:i})+`
|
|
2
|
+
`)}catch{}}}exports.installState={status:"idle",message:"\u672A\u5F00\u59CB"},exports.isInstalling=!1,exports.PYTHON_DIR=u.default.join(s.QBOT_CLAW_DIR,"python");function A(t,o){return new Promise(r=>{const i=(0,_.spawn)(s.QBOTCLAW_BIN,t,{stdio:["ignore","pipe","pipe"],env:{PATH:s.NODE_BIN_DIR,HOME:process.env.HOME,OPENCLAW_TELEMETRY_GALIELO_GUID:process.env.QB_GUID||"",OPENCLAW_TELEMETRY_GALIELO_QIEMI36:process.env.QB_QIMEI36||""}});(0,a.log)(`[QBotClaw] \u6267\u884C: QBotClaw ${t.join(" ")}`),i.stdout.on("data",e=>{const n=e.toString();if(o&&o.writable)try{o.write(n)}catch{}}),i.stderr.on("data",e=>{const n=e.toString();if(o&&o.writable)try{o.write(n)}catch{}}),i.on("close",e=>{(0,a.log)(`[QBotClaw] \u6267\u884C\u5B8C\u6210\uFF0C\u9000\u51FA\u7801: ${e}`),r()}),i.on("error",e=>{(0,a.log)(`[QBotClaw] \u542F\u52A8\u5931\u8D25: ${e.message}`),r()})})}function I(){c.default.existsSync(s.QBOT_CLAW_DIR)||c.default.mkdirSync(s.QBOT_CLAW_DIR,{recursive:!0})}function m(){const t=u.default.join(exports.PYTHON_DIR,"pip.conf");if(c.default.existsSync(t)){(0,a.log)("pip.conf \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");return}const o=["[global]","index-url = https://mirrors.tencent.com/pypi/simple/",`cache-dir = ${u.default.join(exports.PYTHON_DIR,".pip-cache")}`,"","[install]",`prefix = ${exports.PYTHON_DIR}`,""].join(`
|
|
3
|
+
`);c.default.writeFileSync(t,o,"utf-8"),(0,a.log)(`\u5DF2\u5199\u5165 pip.conf: ${t}`)}async function C(t){if(c.default.existsSync(s.MCPORTER_BIN)){(0,a.log)("mcporter \u5DF2\u5B89\u88C5\uFF0C\u8DF3\u8FC7");return}(0,a.log)("\u5F00\u59CB\u5B89\u88C5 mcporter..."),await new Promise((o,r)=>{const i=(0,_.spawn)(s.NPM_BIN,["--userconfig",s.NPM_RC,"install","-g","mcporter"],{stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:`${u.default.dirname(s.NPM_BIN)}:${process.env.PATH}`}});i.stdout.on("data",e=>{const n=`[mcporter] ${e.toString().trim()}`;(0,a.log)(n),g(t,0,0,n)}),i.stderr.on("data",e=>{const n=`[mcporter] ${e.toString().trim()}`;(0,a.log)(n),g(t,0,0,n)}),i.on("close",e=>{e===0?((0,a.log)("mcporter \u5B89\u88C5\u6210\u529F"),o()):r(new Error(`mcporter \u5B89\u88C5\u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${e}`))}),i.on("error",r)})}function P(t,o){return new Promise((r,i)=>{const e=(0,_.spawn)(s.NPM_BIN,["--userconfig",s.NPM_RC,...t],{stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:`${u.default.dirname(s.NPM_BIN)}:${process.env.PATH}`}});e.stdout.on("data",n=>{const l=`[npm] ${n.toString().trim()}`;(0,a.log)(l)}),e.stderr.on("data",n=>{const l=`[npm] ${n.toString().trim()}`;(0,a.log)(l)}),e.on("close",n=>{n===0?((0,a.log)(`${o} \u6210\u529F`),r()):i(new Error(`${o} \u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${n}`))}),e.on("error",i)})}async function E(t){const o=`${s.NPM_PACKAGE_NAME}@${t}`;(0,a.log)(`\u5F00\u59CB\u5B89\u88C5 ${o}\uFF08--ignore-scripts\uFF0C\u4EC5\u4E0B\u8F7D\u89E3\u538B\uFF09...`),await P(["install","-g","--ignore-scripts",o],`${o} \u4E0B\u8F7D\u89E3\u538B`)}async function O(t){const o=`${s.NPM_PACKAGE_NAME}@${t}`;(0,a.log)("\u5F00\u59CB npm rebuild\uFF08\u6267\u884C postinstall \u811A\u672C\uFF09..."),await P(["rebuild","-g",s.NPM_PACKAGE_NAME],`${o} rebuild`),(0,a.log)(`${o} \u5B89\u88C5\u6210\u529F`)}async function y(t,o,r,i){let e;if((0,a.log)(`\u8986\u76D6\u7528\u6237\u5DF2\u6709\u914D\u7F6E: ${i}`),!i&&c.default.existsSync(s.QBOT_CLAW_CONFIG_PATH))e=s.QBOT_CLAW_CONFIG_PATH,(0,a.log)(`\u4F7F\u7528\u5DF2\u6709\u914D\u7F6E\u6587\u4EF6: ${e}`);else{const l=u.default.join(s.NPM_GLOBAL_MODULES,s.NPM_PACKAGE_NAME,"preset-config.json");if(!c.default.existsSync(l)){(0,a.log)(`npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u4E2D\u7684\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u5199\u5165: ${l}`);return}e=l,(0,a.log)(`\u4F7F\u7528 npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u4E2D\u7684\u914D\u7F6E: ${e}`)}let n;try{n=JSON.parse(c.default.readFileSync(e,"utf-8")),(0,a.log)(`\u5DF2\u8BFB\u53D6\u914D\u7F6E: ${e}`)}catch(l){(0,a.log)(`\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25: ${e}\uFF0C${l.message}\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u5199\u5165`);return}t!==void 0&&(n.gateway={...n.gateway??{},port:t},(0,a.log)(`\u5DF2\u5C06 gateway.port=${t} \u5199\u5165\u914D\u7F6E`)),n.plugins=n.plugins??{},n.plugins.entries=n.plugins.entries??{},n.plugins.entries["x5use-browser-control"]=n.plugins.entries["x5use-browser-control"]??{},n.plugins.entries["x5use-browser-control"].config={...n.plugins.entries["x5use-browser-control"].config??{},wsPort:r,httpPort:o},(0,a.log)(`\u5DF2\u5C06 x5use-browser-control wsPort=${r}, httpPort=${o} \u5199\u5165\u914D\u7F6E`),c.default.writeFileSync(s.QBOT_CLAW_CONFIG_PATH,JSON.stringify(n,null,2),"utf-8"),(0,a.log)(`\u914D\u7F6E\u6587\u4EF6\u5DF2\u5199\u5165: ${s.QBOT_CLAW_CONFIG_PATH}`)}async function N(t){const o=(0,p.readState)();let r;o.gatewayPort&&!await(0,p.isPortAvailable)(o.gatewayPort)?(r=o.gatewayPort,(0,a.log)(`\u68C0\u6D4B\u5230 QBotClaw gateway \u5DF2\u5728\u7AEF\u53E3 ${r} \u8FD0\u884C\uFF0C\u590D\u7528\u539F\u7AEF\u53E3`)):r=await(0,w.findAvailablePort)(),(0,a.log)(`\u540E\u53F0\u542F\u52A8 QBotClaw gateway run --port ${r} --force`);const i=await(0,w.findAvailablePort)(s.DEFAULT_MCP_HTTP_PORT),e=await(0,w.findAvailablePort)();await y(r,i,e,t);const n=(0,_.spawn)(s.QBOTCLAW_BIN,["gateway","run","--port",String(r),"--force"],{stdio:"ignore",env:{PATH:s.NODE_BIN_DIR,HOME:process.env.HOME,OPENCLAW_NO_RESPAWN:"true",VENUS_API_KEY:"E9isWWfAr4VIFuIa5RbJaPxD@2040",OPENCLAW_TELEMETRY_GALIELO_GUID:process.env.QB_GUID||"",OPENCLAW_TELEMETRY_GALIELO_QIEMI36:process.env.QB_QIMEI36||""}});n.unref();const l=n.pid;(0,a.log)(`QBotClaw gateway \u5DF2\u5728\u540E\u53F0\u542F\u52A8\uFF0CPID: ${l}\uFF0C\u7AEF\u53E3: ${r}`),(0,p.writeState)({...(0,p.readState)(),gatewayPid:l,gatewayPort:r,mcpHttpPort:i,mcpWsPort:e})}function $(t,o,r){if(exports.isInstalling){if((0,a.log)("[runInstall] \u5B89\u88C5\u6B63\u5728\u8FDB\u884C\u4E2D\uFF0C\u62D2\u7EDD\u91CD\u590D\u6267\u884C"),t&&t.writable)try{t.end(JSON.stringify({status:"failed",progress:0,message:"\u5B89\u88C5\u6B63\u5728\u8FDB\u884C\u4E2D\uFF0C\u8BF7\u52FF\u91CD\u590D\u64CD\u4F5C"})+`
|
|
4
|
+
`)}catch{}return}exports.isInstalling=!0,exports.installState={status:"downloading",message:"\u6B63\u5728\u5B89\u88C5...",startTime:new Date().toISOString()},(0,a.log)(`\u5F00\u59CB\u5B89\u88C5 ${s.NPM_PACKAGE_NAME}@${o}`),(async()=>{try{(0,p.stopGateway)(),I(),m();const i=5;let e=0;g(t,i,e,"\u5F00\u59CB\u5B89\u88C5 mcporter..."),await C(t),e++,g(t,i,e,"\u5F00\u59CB\u4E0B\u8F7D\u89E3\u538B QBotClaw..."),await E(o),e++,g(t,i,e,"npmDownloadQBotClaw \u5B8C\u6210"),await(0,f.fullScanClearQuarantine)("npm install --ignore-scripts \u5B8C\u6210\u540E\uFF0Crebuild \u524D"),e++,await(0,f.watchWorkspaceQuarantine)().catch(n=>{(0,a.log)(`[quarantine] watchWorkspaceQuarantine \u542F\u52A8\u5F02\u5E38: ${n.message}`)}),g(t,i,e,"\u5F00\u59CB npm rebuild..."),await O(o),e++,g(t,i,e,"npmRebuildQBotClaw \u5B8C\u6210");try{c.default.existsSync(s.OPENCLAW_BIN)||(c.default.symlinkSync(s.QBOTCLAW_BIN,s.OPENCLAW_BIN),(0,a.log)(`\u5DF2\u521B\u5EFA\u8F6F\u94FE\u63A5: ${s.OPENCLAW_BIN} -> ${s.QBOTCLAW_BIN}`))}catch(n){(0,a.log)(`\u521B\u5EFA openclaw \u8F6F\u94FE\u63A5\u5931\u8D25: ${n.message}`)}if(await(0,f.stopWatchWorkspaceQuarantine)().catch(n=>{(0,a.log)(`[quarantine] stopWatchWorkspaceQuarantine \u5F02\u5E38: ${n.message}`)}),exports.installState={status:"success",message:"\u5B89\u88C5\u6210\u529F",endTime:new Date().toISOString()},(0,a.log)("\u5B89\u88C5\u6210\u529F"),(0,a.refreshClawVersion)(o),g(t,i,e,"\u5F00\u59CB\u914D\u7F6E\u5E76\u542F\u52A8 QBotClaw gateway..."),await N(r),e++,t.writable)try{t.end(JSON.stringify({status:"done",progress:100,message:"\u5B89\u88C5\u6210\u529F"})+`
|
|
5
|
+
`)}catch{}}catch(i){if(await(0,f.stopWatchWorkspaceQuarantine)().catch(()=>{}),exports.installState={status:"failed",message:i.message,endTime:new Date().toISOString()},(0,a.log)(`\u5B89\u88C5\u5931\u8D25: ${i.message}`),t&&t.writable)try{t.end(JSON.stringify({status:"failed",progress:0,message:i.message})+`
|
|
6
|
+
`)}catch{}}finally{exports.isInstalling=!1}})()}
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var _=exports&&exports.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.watchParentProcess=O;const N=_(require("http")),w=_(require("fs")),C=_(require("path")),n=require("./config"),c=require("./utils"),s=require("./reportLog"),P=require("./installer"),T=require("./version"),f=require("./state"),$=require("child_process"),y={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization, X-Requested-With","Access-Control-Max-Age":"86400"};function A(u){for(const[e,g]of Object.entries(y))u.setHeader(e,g)}exports.server=N.default.createServer(async(u,e)=>{const g=u.url||"";if(A(e),u.method==="OPTIONS"){e.writeHead(204,y),e.end();return}if(g==="/api/version"){let a="unknown";try{a=(await(0,c.execCommand)(`"${n.NODE_BIN}" -v`)).trim(),(0,s.log)(`[version] node \u7248\u672C: ${a}`)}catch(l){(0,s.log)(`[version] \u83B7\u53D6 node \u7248\u672C\u5931\u8D25: ${l.message}`),a=`error: ${l.message}`}const r=await(0,c.getQBotClawVersion)()??"0.0.0";(0,s.log)(`[version] qbotclaw \u7248\u672C: ${r}`);let t="0.0.0";if(w.default.existsSync(n.MCPORTER_BIN))try{t=(await(0,c.execCommand)(`"${n.NODE_BIN}" "${n.MCPORTER_BIN}" --version`)).trim(),(0,s.log)(`[version] mcporter \u7248\u672C: ${t}`)}catch(l){(0,s.log)(`[version] \u83B7\u53D6 mcporter \u7248\u672C\u5931\u8D25: ${l.message}`),t=`error: ${l.message}`}let o="0.0.0";if(w.default.existsSync(n.PYTHON_BIN))try{o=(await(0,c.execCommand)(`"${n.PYTHON_BIN}" --version`)).trim(),(0,s.log)(`[version] python \u7248\u672C: ${o}`)}catch(l){(0,s.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${l.message}`),o=`error: ${l.message}`}(0,c.sendJSON)(e,200,{status:"\u6210\u529F",launcher:T.LAUNCHER_VERSION,node:a,qbotclaw:r,mcporter:t,python:o});return}if(g==="/api/port"){const a=exports.server.address(),r=a&&typeof a=="object"?a.port:null,t=(0,f.readState)();(0,c.sendJSON)(e,200,{status:"\u6210\u529F",launcher:r,qbotclaw:t.gatewayPort??2e3,mcpHttp:t.mcpHttpPort??n.DEFAULT_MCP_HTTP_PORT,mcpWs:t.mcpWsPort??8765});return}if(g==="/api/status"){const a=(0,f.readState)(),r=[];if(a.gatewayPid)try{process.kill(a.gatewayPid,0)}catch{r.push(`gateway \u8FDB\u7A0B (pid: ${a.gatewayPid}) \u5DF2\u9000\u51FA`)}else r.push("gateway \u8FDB\u7A0B\u672A\u542F\u52A8\uFF08\u72B6\u6001\u4E2D\u65E0 gatewayPid\uFF09");const t=[{name:"gateway",port:a.gatewayPort},{name:"mcpHttp",port:a.mcpHttpPort},{name:"mcpWs",port:a.mcpWsPort}];for(const{name:o,port:l}of t){if(!l){r.push(`${o} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,f.isPortAvailable)(l)&&r.push(`${o} \u7AEF\u53E3 (${l}) \u65E0\u670D\u52A1\u76D1\u542C`)}r.length===0?(0,c.sendJSON)(e,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,c.sendJSON)(e,200,{ok:!1,message:r.join("\uFF1B")});return}if(g==="/api/restart"){try{const a=(0,f.readState)();if(a.gatewayPid)try{process.kill(a.gatewayPid,"SIGTERM"),(0,s.log)(`[restart] \u5DF2\u53D1\u9001 SIGTERM \u7ED9\u65E7 gateway \u8FDB\u7A0B pid: ${a.gatewayPid}`)}catch{(0,s.log)(`[restart] \u65E7 gateway \u8FDB\u7A0B ${a.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}const{gatewayPid:r,gatewayPort:t,mcpHttpPort:o,mcpWsPort:l,...m}=a;(0,f.writeState)(m),(0,s.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpHttpPort, mcpWsPort"),await(0,P.configAndRunQBotClaw)(),(0,s.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const d=(0,f.readState)(),i=exports.server.address(),p=i&&typeof i=="object"?i.port:null;(0,c.sendJSON)(e,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:p,qbotclaw:d.gatewayPort??2e3,mcpHttp:d.mcpHttpPort??n.DEFAULT_MCP_HTTP_PORT,mcpWs:d.mcpWsPort??8765})}catch(a){(0,s.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${a.message}`),(0,c.sendJSON)(e,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${a.message}`})}return}if(g==="/api/wechat/history"){try{if(!w.default.existsSync(n.SESSIONS_FILE)){(0,c.sendJSON)(e,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(w.default.readFileSync(n.SESSIONS_FILE,"utf-8"));let r=null,t=0;for(const[m,d]of Object.entries(a))if(m.includes("openclaw-weixin")){const p=d.updatedAt??0;p>t&&(t=p,r=m)}if(!r){(0,c.sendJSON)(e,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const l=r.split(":").slice(4).join(":");(0,c.sendJSON)(e,200,{ok:!0,sessionKey:l,message:"\u83B7\u53D6\u6210\u529F"})}catch(a){(0,s.log)(`[wechat/history] \u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${a.message}`),(0,c.sendJSON)(e,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(g==="/api/installing"){(0,c.sendJSON)(e,200,{installing:P.isInstalling});return}if(g==="/api/install"||g.startsWith("/api/install?")){if(P.installState.status==="downloading"){(0,c.sendJSON)(e,200,{ok:"downloading",message:"\u6B63\u5728\u5B89\u88C5\u4E2D..."});return}const a=new URL(g,"http://localhost"),r=a.searchParams.get("version")||void 0,t=a.searchParams.get("overrideConfig")==="true";if(!r){(0,c.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 version\uFF0C\u7528\u6CD5: GET /api/install?version=x.x.x"});return}e.writeHead(200,{...y,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,P.runInstall)(e,r,t);return}if(g.startsWith("/api/watch")){const r=new URL(g,"http://localhost").searchParams.get("ppid");if(!r||isNaN(Number(r))){(0,c.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u6709\u6548\u7684 ppid \u53C2\u6570\uFF0C\u7528\u6CD5: GET /api/watch?ppid=12345"});return}const t=parseInt(r,10);try{process.kill(t,0)}catch{(0,c.sendJSON)(e,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${t} \u4E0D\u5B58\u5728`});return}const o=(0,f.readState)();(0,f.writeState)({...o,ppid:t}),O(t),(0,c.sendJSON)(e,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${t}`});return}if(g==="/api/qbotclaw"&&u.method==="POST"){let a="";u.on("data",r=>{a+=r.toString()}),u.on("end",()=>{let r;try{const t=JSON.parse(a);if(!Array.isArray(t.args)||t.args.length===0){(0,c.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u53C2\u6570 args \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"});return}r=t.args.map(o=>String(o))}catch{(0,c.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(!w.default.existsSync(n.QBOTCLAW_BIN)){(0,c.sendJSON)(e,404,{status:"\u5931\u8D25",message:`qbotclaw \u53EF\u6267\u884C\u6587\u4EF6\u4E0D\u5B58\u5728: ${n.QBOTCLAW_BIN}`});return}e.writeHead(200,{...y,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,P.runQBotClaw)(r,e).then(()=>{e.end(`
|
|
2
2
|
[\u6267\u884C\u6210\u529F]
|
|
3
3
|
`)}).catch(t=>{e.end(`
|
|
4
4
|
[\u542F\u52A8\u5931\u8D25: ${t.message}]
|
|
5
|
-
`)})});return}if(g.startsWith("/api/uninstall")){const
|
|
6
|
-
`)}catch{}};try{t("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const
|
|
5
|
+
`)})});return}if(g.startsWith("/api/uninstall")){const r=new URL(g,"http://localhost").searchParams.get("keepWorkspace")==="true";e.writeHead(200,{...y,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const t=(o,l,m)=>{if(e.writable)try{e.write(JSON.stringify({status:o,file:l,msg:m})+`
|
|
6
|
+
`)}catch{}};try{t("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const o=(0,f.readState)();if(o.gatewayPid)try{process.kill(o.gatewayPid,"SIGTERM"),(0,s.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${o.gatewayPid}`),t("\u6210\u529F","",`\u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${o.gatewayPid}`)}catch{(0,s.log)(`[uninstall] QBotClaw gateway \u8FDB\u7A0B ${o.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`),t("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${o.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`)}else t("\u6210\u529F","","QBotClaw \u672A\u5728\u8FD0\u884C");t("\u6210\u529F","",`\u6B63\u5728\u6267\u884C npm uninstall -g ${n.NPM_PACKAGE_NAME}...`);try{await new Promise((m,d)=>{const i=(0,$.spawn)(n.NPM_BIN,["--userconfig",n.NPM_RC,"uninstall","-g",n.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${n.NODE_BIN_DIR}:${process.env.PATH}`}});i.stdout?.on("data",p=>{(0,s.log)(`[uninstall] npm: ${p.toString().trim()}`)}),i.stderr?.on("data",p=>{(0,s.log)(`[uninstall] npm stderr: ${p.toString().trim()}`)}),i.on("close",p=>{p===0?m():d(new Error(`npm uninstall \u9000\u51FA\u7801: ${p}`))}),i.on("error",p=>d(p))}),(0,s.log)(`[uninstall] npm uninstall -g ${n.NPM_PACKAGE_NAME} \u6210\u529F`),t("\u6210\u529F","",`npm uninstall -g ${n.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(m){(0,s.log)(`[uninstall] npm uninstall \u5931\u8D25: ${m.message}`),t("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${m.message}`)}t("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${n.QBOT_CLAW_DIR}...`);const l=[];if(w.default.existsSync(n.QBOT_CLAW_DIR)){const m=w.default.readdirSync(n.QBOT_CLAW_DIR);for(const d of m){const i=C.default.join(n.QBOT_CLAW_DIR,d);if(r&&d==="workspace"){t("\u6210\u529F",i,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{w.default.statSync(i).isDirectory()?w.default.rmSync(i,{recursive:!0,force:!0}):w.default.unlinkSync(i),t("\u6210\u529F",i,"\u5DF2\u5220\u9664")}catch(p){(0,s.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${i} - ${p.message}`),t("\u5931\u8D25",i,`\u5220\u9664\u5931\u8D25: ${p.message}`),l.push(i)}}if(l.length>0){t("\u6210\u529F","",`${l.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const d of l)try{(0,$.execSync)(`rm -rf "${d}"`),(0,s.log)(`[uninstall] rm -rf \u91CD\u8BD5\u6210\u529F: ${d}`),t("\u6210\u529F",d,"rm \u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(i){(0,s.log)(`[uninstall] rm -rf \u91CD\u8BD5\u4E5F\u5931\u8D25: ${d} - ${i.message}`),t("\u5931\u8D25",d,`rm \u91CD\u8BD5\u4E5F\u5931\u8D25: ${i.message}`)}}if(r)t("\u6210\u529F",n.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{w.default.rmSync(n.QBOT_CLAW_DIR,{recursive:!0,force:!0}),t("\u6210\u529F",n.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(d){(0,s.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${d.message}`);try{(0,$.execSync)(`rm -rf "${n.QBOT_CLAW_DIR}"`),t("\u6210\u529F",n.QBOT_CLAW_DIR,"rm \u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(i){t("\u5931\u8D25",n.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${i.message}`)}}}else t("\u6210\u529F",n.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");t("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(o){(0,s.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${o.message}`),t("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${o.message}`)}e.end(),setTimeout(()=>{(0,s.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}(0,c.sendJSON)(e,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})});let h=null,S=null;function O(u){if(!u)return;if(h&&S===u){(0,s.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${u}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}h?((0,s.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${S}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${u}`),clearInterval(h),h=null,S=null):(0,s.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${u}`);const e=setInterval(()=>{try{process.kill(u,0)}catch{(0,s.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${u} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(e),h=null,S=null;const g=(0,f.readState)();if(g.gatewayPid)try{process.kill(g.gatewayPid,"SIGTERM"),(0,s.log)(`[watchParentProcess] \u5DF2\u53D1\u9001 SIGTERM \u7ED9 qbotclaw \u8FDB\u7A0B pid: ${g.gatewayPid}`)}catch{(0,s.log)(`[watchParentProcess] qbotclaw \u8FDB\u7A0B ${g.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}(0,f.clearState)(),(0,s.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,s.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,s.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);e.unref(),h=e,S=u}
|
package/dist/service.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";var l=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.startService=q,exports.stopService=h;const f=l(require("fs")),S=l(require("http")),g=require("crypto"),p=require("./server"),e=require("./state"),w=require("./config"),u=require("./version"),y=require("./installer"),_=require("./utils"),o=require("./reportLog");let c=null;function v(t){return new Promise(r=>{const s=S.default.get(`http://127.0.0.1:${t}/api/version`,a=>{let n="";a.on("data",i=>{n+=i.toString()}),a.on("end",()=>{try{const i=JSON.parse(n);r(i.launcher??null)}catch{r(null)}})});s.on("error",()=>r(null)),s.setTimeout(3e3,()=>{s.destroy(),r(null)})})}async function k(){const t=(0,e.readState)();if(!t.pid||!t.port)return null;try{process.kill(t.pid,0)}catch{return(0,e.clearState)(),null}if(await(0,e.isPortAvailable)(t.port))return(0,o.log)("\u7AEF\u53E3\u672A\u88AB\u5360\u7528\uFF0C\u8BF4\u660E\u72B6\u6001\u6587\u4EF6\u8FC7\u671F"),(0,e.clearState)(),null;const s=await v(t.port);if((0,o.log)(`[service] \u68C0\u6D4B\u5230\u6B63\u5728\u8FD0\u884C\u7684\u670D\u52A1\u7248\u672C: ${s??"unknown"}\uFF0C\u5F53\u524D\u7248\u672C: ${u.LAUNCHER_VERSION}`),s===u.LAUNCHER_VERSION)return(0,o.log)(`[service] \u7248\u672C\u4E00\u81F4\uFF0C\u590D\u7528\u5DF2\u6709\u670D\u52A1 (pid: ${t.pid}, port: ${t.port})`),!1;(0,o.log)(`[service] \u7248\u672C\u4E0D\u4E00\u81F4 (\u8FD0\u884C\u4E2D: ${s??"unknown"}, \u5F53\u524D: ${u.LAUNCHER_VERSION})\uFF0C\u6740\u6389\u65E7\u8FDB\u7A0B pid: ${t.pid}\uFF0C\u91CD\u65B0\u542F\u52A8`);try{process.kill(t.pid,"SIGTERM")}catch{}return(0,e.clearState)(),!0}async function q(t,r){if(await k()===!1){const n=(0,e.readState)();c=n.token??null,process.stdout.write(JSON.stringify({state:"success",pid:n.pid,port:n.port,token:c})+`
|
|
2
2
|
`),process.stdout.uncork();return}const a=await(0,e.findAvailablePort)();c=(0,g.randomUUID)(),p.server.listen(a,"127.0.0.1",()=>{if((0,e.writeState)({pid:process.pid,port:a,token:c,...t?{ppid:t}:{}}),process.stdout.write(JSON.stringify({state:"success",pid:process.pid,port:a,token:c})+`
|
|
3
|
-
`),process.stdout.uncork(),(0,p.watchParentProcess)(t),!f.default.existsSync(w.QBOTCLAW_BIN)){(0,o.log)("[service] qbotclaw \u672A\u5B89\u88C5\uFF0C\u4E0D\u81EA\u52A8\u542F\u52A8");return}(0,_.getQBotClawVersion)().then(n=>{const i=(0,e.readState)();if(n!==r){(0,o.log)(`[service] qbotclaw \u672C\u5730\u7248\u672C (${n??"unknown"}) \u4E0E\u671F\u671B\u7248\u672C (${r}) \u4E0D\u4E00\u81F4\uFF0C\u505C\u6B62\u5F53\u524D qbotclaw \u8FDB\u7A0B`),(0,e.stopGateway)();return}else i.gatewayPid&&i.gatewayPort?(0,o.log)(`[service] qbotclaw \u5DF2\u5728\u8FD0\u884C\uFF0Cpid: ${i.gatewayPid}, port: ${i.gatewayPort}`):((0,o.log)("[service] \u68C0\u6D4B\u5230 qbotclaw\uFF0C\u7248\u672C\u5339\u914D\uFF0C\u81EA\u52A8\u542F\u52A8 gateway..."),(0,y.configAndRunQBotClaw)().catch(d=>{(0,o.log)(`[service] \u81EA\u52A8\u542F\u52A8 gateway \u5931\u8D25: ${d.message}`)}))})}),process.on("SIGTERM",()=>{(0,e.clearState)(),(0,o.flushLogs)().finally(()=>{process.exit(0)})})}function h(){const t=(0,e.readState)();if(!t.pid){process.stdout.write(JSON.stringify({state:"err",pid:0,port:0})+`
|
|
3
|
+
`),process.stdout.uncork(),(0,p.watchParentProcess)(t),!f.default.existsSync(w.QBOTCLAW_BIN)){(0,o.log)("[service] qbotclaw \u672A\u5B89\u88C5\uFF0C\u4E0D\u81EA\u52A8\u542F\u52A8");return}(0,_.getQBotClawVersion)().then(n=>{const i=(0,e.readState)();if(n!==r){(0,o.log)(`[service] qbotclaw \u672C\u5730\u7248\u672C (${n??"unknown"}) \u4E0E\u671F\u671B\u7248\u672C (${r}) \u4E0D\u4E00\u81F4\uFF0C\u505C\u6B62\u5F53\u524D qbotclaw \u8FDB\u7A0B`),(0,e.stopGateway)();return}else i.gatewayPid&&i.gatewayPort?(0,o.log)(`[service] qbotclaw \u5DF2\u5728\u8FD0\u884C\uFF0Cpid: ${i.gatewayPid}, port: ${i.gatewayPort}`):((0,o.log)("[service] \u68C0\u6D4B\u5230 qbotclaw\uFF0C\u7248\u672C\u5339\u914D\uFF0C\u81EA\u52A8\u542F\u52A8 gateway..."),(0,y.configAndRunQBotClaw)().catch(d=>{(0,o.log)(`[service] \u81EA\u52A8\u542F\u52A8 gateway \u5931\u8D25: ${d.message}`)}))})}),process.on("SIGTERM",()=>{(0,e.stopGateway)(),(0,e.clearState)(),(0,o.flushLogs)().finally(()=>{process.exit(0)})})}function h(){const t=(0,e.readState)();if(!t.pid){process.stdout.write(JSON.stringify({state:"err",pid:0,port:0})+`
|
|
4
4
|
`),process.stdout.uncork();return}try{process.kill(t.pid,"SIGTERM");const r=t.pid,s=t.port??0;(0,e.clearState)(),process.stdout.write(JSON.stringify({state:"success",pid:r,port:s})+`
|
|
5
5
|
`),process.stdout.uncork()}catch(r){r.code==="ESRCH"&&(0,e.clearState)(),process.stdout.write(JSON.stringify({state:"err",pid:0,port:0})+`
|
|
6
6
|
`),process.stdout.uncork()}}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.9.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.9.54";
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qqbrowser/qbot-claw-launcher",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.54",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "node scripts/inject-version.js && tsc && node scripts/obfuscate.js && chmod +x dist/index.js",
|
|
19
|
-
"prepack": "bash scripts/build-fs-xattr.sh && bash scripts/build-parcel-watcher.sh && rm -rf node_modules/fs-xattr && cp -r fs-xattr node_modules/fs-xattr && rm -rf node_modules/@parcel/watcher && mkdir -p node_modules/@parcel && cp -r parcel-watcher node_modules/@parcel/watcher && bash scripts/verify-universal-binary.sh",
|
|
19
|
+
"prepack": "bash scripts/build-fs-xattr.sh && bash scripts/build-parcel-watcher.sh && rm -rf node_modules/fs-xattr && cp -r fs-xattr node_modules/fs-xattr && rm -rf node_modules/@parcel/watcher && mkdir -p node_modules/@parcel && cp -r parcel-watcher node_modules/@parcel/watcher && bash scripts/clean-native-sources.sh && bash scripts/verify-universal-binary.sh",
|
|
20
20
|
"start": "node dist/index.js",
|
|
21
21
|
"dev": "ts-node src/index.ts",
|
|
22
22
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017-present Devon Govett
|
|
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 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.
|
|
@@ -1,136 +0,0 @@
|
|
|
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
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2013-2020 Linus Unnebäck
|
|
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 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.
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# fs-xattr
|
|
2
|
-
|
|
3
|
-
Node.js module for manipulating extended attributes.
|
|
4
|
-
|
|
5
|
-
There are already some libraries for this, why use `fs-xattr`?
|
|
6
|
-
|
|
7
|
-
- Very useful errors
|
|
8
|
-
- No limits on value size
|
|
9
|
-
- Clean and easy api
|
|
10
|
-
- Proper asynchronous implementation
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
```sh
|
|
15
|
-
npm install --save fs-xattr
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
import { getAttribute, setAttribute } from 'fs-xattr'
|
|
22
|
-
|
|
23
|
-
await setAttribute('index.js', 'user.linusu.test', 'Hello, World!')
|
|
24
|
-
|
|
25
|
-
console.log(await getAttribute('index.js', 'user.linusu.test'))
|
|
26
|
-
//=> Hello, World!
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## API
|
|
30
|
-
|
|
31
|
-
### `getAttribute(path, attr)`
|
|
32
|
-
|
|
33
|
-
- `path` (`string`, required)
|
|
34
|
-
- `attr` (`string`, required)
|
|
35
|
-
- returns `Promise<Buffer>` - a `Promise` that will resolve with the value of the attribute.
|
|
36
|
-
|
|
37
|
-
Get extended attribute `attr` from file at `path`.
|
|
38
|
-
|
|
39
|
-
### `getAttributeSync(path, attr)`
|
|
40
|
-
|
|
41
|
-
- `path` (`string`, required)
|
|
42
|
-
- `attr` (`string`, required)
|
|
43
|
-
- returns `Buffer`
|
|
44
|
-
|
|
45
|
-
Synchronous version of `getAttribute`.
|
|
46
|
-
|
|
47
|
-
### `setAttribute(path, attr, value)`
|
|
48
|
-
|
|
49
|
-
- `path` (`string`, required)
|
|
50
|
-
- `attr` (`string`, required)
|
|
51
|
-
- `value` (`Buffer` or `string`, required)
|
|
52
|
-
- returns `Promise<void>` - a `Promise` that will resolve when the value has been set.
|
|
53
|
-
|
|
54
|
-
Set extended attribute `attr` to `value` on file at `path`.
|
|
55
|
-
|
|
56
|
-
### `setAttributeSync(path, attr, value)`
|
|
57
|
-
|
|
58
|
-
- `path` (`string`, required)
|
|
59
|
-
- `attr` (`string`, required)
|
|
60
|
-
- `value` (`Buffer` or `string`, required)
|
|
61
|
-
|
|
62
|
-
Synchronous version of `setAttribute`.
|
|
63
|
-
|
|
64
|
-
### `removeAttribute(path, attr)`
|
|
65
|
-
|
|
66
|
-
- `path` (`string`, required)
|
|
67
|
-
- `attr` (`string`, required)
|
|
68
|
-
- returns `Promise<void>` - a `Promise` that will resolve when the value has been removed.
|
|
69
|
-
|
|
70
|
-
Remove extended attribute `attr` on file at `path`.
|
|
71
|
-
|
|
72
|
-
### `removeAttributeSync(path, attr)`
|
|
73
|
-
|
|
74
|
-
- `path` (`string`, required)
|
|
75
|
-
- `attr` (`string`, required)
|
|
76
|
-
|
|
77
|
-
Synchronous version of `removeAttribute`.
|
|
78
|
-
|
|
79
|
-
### `listAttributes(path)`
|
|
80
|
-
|
|
81
|
-
- `path` (`string`, required)
|
|
82
|
-
- returns `Promise<Array<string>>` - a `Promise` that will resolve with an array of strings, e.g. `['user.linusu.test', 'com.apple.FinderInfo']`.
|
|
83
|
-
|
|
84
|
-
List all attributes on file at `path`.
|
|
85
|
-
|
|
86
|
-
### `listAttributesSync(path)`
|
|
87
|
-
|
|
88
|
-
- `path` (`string`, required)
|
|
89
|
-
- returns `Array<string>`
|
|
90
|
-
|
|
91
|
-
Synchronous version of `listAttributes`.
|
|
92
|
-
|
|
93
|
-
## Namespaces
|
|
94
|
-
|
|
95
|
-
For the large majority of Linux filesystem there are currently 4 supported namespaces (`user`, `trusted`, `security`, and `system`) you can use. Some other systems, like FreeBSD have only 2 (`user` and `system`).
|
|
96
|
-
|
|
97
|
-
Be sure to use a namespace that is appropriate for your supported platforms. You can read more about this in [the "Extended File Attributes" Wikipedia article](https://en.wikipedia.org/wiki/Extended_file_attributes#Implementations).
|
|
98
|
-
|
|
99
|
-
Using a namespace like `com.linusu.test` would work on macOS, but would give you the following error on Debian Linux:
|
|
100
|
-
|
|
101
|
-
> Error \[ENOTSUP]: The file system does not support extended attributes or has the feature disabled.
|