claw-subagent-service 0.0.13 → 0.0.14
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/package.json +1 -1
- package/scripts/post-install.js +27 -6
- package/version.json +2 -2
package/package.json
CHANGED
package/scripts/post-install.js
CHANGED
|
@@ -4,16 +4,31 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const { exec, execFile, execSync } = require('child_process');
|
|
6
6
|
const path = require('path');
|
|
7
|
-
const fs = require('fs');
|
|
8
7
|
|
|
9
8
|
const SERVICE_NAME = 'claw-subagent-service';
|
|
10
9
|
const DAEMON_PATH = path.join(__dirname, '..', 'service', 'daemon.js');
|
|
11
10
|
|
|
12
11
|
function isGlobalInstall() {
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
// 方法1: npm 全局安装时会设置此环境变量
|
|
13
|
+
if (process.env.npm_config_global === 'true') {
|
|
14
|
+
console.log('[postinstall] 通过 npm_config_global 检测到全局安装');
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 方法2: 检查包路径是否在全局 node_modules 下
|
|
19
|
+
try {
|
|
20
|
+
const globalPrefix = execSync('npm prefix -g', { encoding: 'utf8', timeout: 5000 }).trim();
|
|
21
|
+
const globalModules = path.join(globalPrefix, 'node_modules');
|
|
22
|
+
const pkgPath = path.join(__dirname, '..');
|
|
23
|
+
const normalizedPkg = path.normalize(pkgPath).toLowerCase();
|
|
24
|
+
const normalizedGlobal = path.normalize(globalModules).toLowerCase();
|
|
25
|
+
const isGlobal = normalizedPkg.startsWith(normalizedGlobal);
|
|
26
|
+
console.log(`[postinstall] 全局安装检测: pkgPath=${normalizedPkg}, globalModules=${normalizedGlobal}, result=${isGlobal}`);
|
|
27
|
+
return isGlobal;
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.log(`[postinstall] 全局安装检测失败(${e.message}),默认按全局安装处理`);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
17
32
|
}
|
|
18
33
|
|
|
19
34
|
function isWindowsAdmin() {
|
|
@@ -46,7 +61,7 @@ function installAndStartService() {
|
|
|
46
61
|
try { execSync(`net stop "${SERVICE_NAME}" 2>nul`, { stdio: 'ignore', timeout: 10000 }); } catch (e) {}
|
|
47
62
|
try { execSync(`sc delete "${SERVICE_NAME}" 2>nul`, { stdio: 'ignore', timeout: 10000 }); } catch (e) {}
|
|
48
63
|
|
|
49
|
-
// 使用 execFile 直接传参数数组,避免 cmd
|
|
64
|
+
// 使用 execFile 直接传参数数组,避免 cmd 引号解析问题
|
|
50
65
|
execFile('sc.exe', [
|
|
51
66
|
'create', SERVICE_NAME,
|
|
52
67
|
'binPath=', binPath,
|
|
@@ -76,6 +91,12 @@ function installAndStartService() {
|
|
|
76
91
|
}
|
|
77
92
|
|
|
78
93
|
// 主逻辑
|
|
94
|
+
console.log('[postinstall] 脚本开始执行...');
|
|
95
|
+
console.log(`[postinstall] __dirname=${__dirname}`);
|
|
96
|
+
console.log(`[postinstall] cwd=${process.cwd()}`);
|
|
97
|
+
console.log(`[postinstall] npm_config_global=${process.env.npm_config_global}`);
|
|
98
|
+
console.log(`[postinstall] npm_config_prefix=${process.env.npm_config_prefix}`);
|
|
99
|
+
|
|
79
100
|
if (isGlobalInstall()) {
|
|
80
101
|
console.log('[postinstall] 检测到全局安装,准备自动注册服务...');
|
|
81
102
|
installAndStartService();
|
package/version.json
CHANGED