evolclaw 2.0.0 → 2.0.1
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/utils/init.js +28 -4
- package/package.json +1 -1
package/dist/utils/init.js
CHANGED
|
@@ -26,12 +26,22 @@ async function npmInstallGlobal(pkg) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
async function sudoExec(cmd, args) {
|
|
29
|
+
// 让 n 安装到当前 node 所在的 prefix 目录
|
|
30
|
+
const env = { ...process.env };
|
|
31
|
+
if (cmd === 'n' && !env.N_PREFIX) {
|
|
32
|
+
try {
|
|
33
|
+
const nodePrefix = execFileSync('node', ['-e', 'process.stdout.write(process.config.variables.node_prefix)'], { encoding: 'utf-8' });
|
|
34
|
+
if (nodePrefix)
|
|
35
|
+
env.N_PREFIX = nodePrefix;
|
|
36
|
+
}
|
|
37
|
+
catch { }
|
|
38
|
+
}
|
|
29
39
|
try {
|
|
30
|
-
await execFileAsync(cmd, args, { timeout: 120000 });
|
|
40
|
+
await execFileAsync(cmd, args, { timeout: 120000, env });
|
|
31
41
|
}
|
|
32
42
|
catch (e) {
|
|
33
43
|
if (e.stderr?.includes('EACCES') || e.message?.includes('EACCES') || e.code === 'EACCES') {
|
|
34
|
-
await execFileAsync('sudo', [cmd, ...args], { timeout: 120000 });
|
|
44
|
+
await execFileAsync('sudo', [cmd, ...args], { timeout: 120000, env });
|
|
35
45
|
}
|
|
36
46
|
else {
|
|
37
47
|
throw e;
|
|
@@ -49,6 +59,18 @@ async function checkEnvironment(rl) {
|
|
|
49
59
|
else {
|
|
50
60
|
console.log(` ✗ Node.js v${process.versions.node} — 需要 >= 22(node:sqlite 依赖)`);
|
|
51
61
|
// 检测 nvm
|
|
62
|
+
// 检测 bash 是否存在(nvm 和 n 都依赖 bash)
|
|
63
|
+
let hasBash = false;
|
|
64
|
+
try {
|
|
65
|
+
execFileSync('which', ['bash'], { encoding: 'utf-8' });
|
|
66
|
+
hasBash = true;
|
|
67
|
+
}
|
|
68
|
+
catch { }
|
|
69
|
+
if (!hasBash) {
|
|
70
|
+
console.log(' ⚠ 当前环境没有 bash(Alpine 容器?),无法自动升级 Node.js');
|
|
71
|
+
console.log(' → 请手动升级: apk add nodejs-current 或重建容器使用 node:22-alpine');
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
52
74
|
const hasNvm = !!process.env.NVM_DIR && fs.existsSync(process.env.NVM_DIR);
|
|
53
75
|
if (hasNvm) {
|
|
54
76
|
const answer = (await ask(rl, ' → 是否通过 nvm 升级到 Node.js 22?[Y/n] ')).trim().toLowerCase();
|
|
@@ -61,7 +83,8 @@ async function checkEnvironment(rl) {
|
|
|
61
83
|
const nvmDir = process.env.NVM_DIR;
|
|
62
84
|
const { stdout } = await execFileAsync('bash', ['-c', `source "${nvmDir}/nvm.sh" && nvm install 22 && nvm alias default 22`], { timeout: 120000 });
|
|
63
85
|
console.log(stdout.trim().split('\n').map(l => ` ${l}`).join('\n'));
|
|
64
|
-
console.log(' ✓ Node.js
|
|
86
|
+
console.log(' ✓ Node.js 升级完成');
|
|
87
|
+
console.log(' → 请打开新终端后重新运行 evolclaw init');
|
|
65
88
|
return false;
|
|
66
89
|
}
|
|
67
90
|
catch (e) {
|
|
@@ -86,7 +109,8 @@ async function checkEnvironment(rl) {
|
|
|
86
109
|
console.log(' 正在升级 Node.js...');
|
|
87
110
|
try {
|
|
88
111
|
await sudoExec('n', ['22']);
|
|
89
|
-
console.log(' ✓ Node.js
|
|
112
|
+
console.log(' ✓ Node.js 升级完成');
|
|
113
|
+
console.log(' → 请打开新终端后重新运行 evolclaw init');
|
|
90
114
|
return false;
|
|
91
115
|
}
|
|
92
116
|
catch (e) {
|
package/package.json
CHANGED