@yeaft/webchat-agent 0.1.237 → 0.1.240
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/connection/upgrade.js +10 -8
- package/package.json +1 -1
package/connection/upgrade.js
CHANGED
|
@@ -19,6 +19,12 @@ const npmPath = join(nodeBinDir, isWin ? 'npm.cmd' : 'npm');
|
|
|
19
19
|
const pm2Path = join(nodeBinDir, isWin ? 'pm2.cmd' : 'pm2');
|
|
20
20
|
const shellOpt = isWin ? { shell: true } : {};
|
|
21
21
|
|
|
22
|
+
// Ensure PATH includes nodeBinDir so that `#!/usr/bin/env node` shebangs
|
|
23
|
+
// can locate node in launchd/systemd environments with minimal PATH.
|
|
24
|
+
const currentPath = process.env.PATH || '/usr/bin:/bin:/usr/sbin:/sbin';
|
|
25
|
+
const safePath = currentPath.includes(nodeBinDir) ? currentPath : `${nodeBinDir}:${currentPath}`;
|
|
26
|
+
const safeEnv = { ...process.env, PATH: safePath };
|
|
27
|
+
|
|
22
28
|
// Shared cleanup logic for restart/upgrade
|
|
23
29
|
function cleanupAndExit(exitCode) {
|
|
24
30
|
setTimeout(() => {
|
|
@@ -55,7 +61,7 @@ export async function handleUpgradeAgent() {
|
|
|
55
61
|
const pkgName = ctx.pkgName || '@yeaft/webchat-agent';
|
|
56
62
|
// Check latest version (async to avoid blocking heartbeat)
|
|
57
63
|
const latestVersion = await new Promise((resolve, reject) => {
|
|
58
|
-
execFile(npmPath, ['view', pkgName, 'version'], { stdio: 'pipe', ...shellOpt }, (err, stdout) => {
|
|
64
|
+
execFile(npmPath, ['view', pkgName, 'version'], { stdio: 'pipe', env: safeEnv, ...shellOpt }, (err, stdout) => {
|
|
59
65
|
if (err) reject(err); else resolve(stdout.toString().trim());
|
|
60
66
|
});
|
|
61
67
|
});
|
|
@@ -83,7 +89,7 @@ export async function handleUpgradeAgent() {
|
|
|
83
89
|
|
|
84
90
|
// 判断全局安装 vs 局部安装
|
|
85
91
|
const isGlobalInstall = await new Promise((resolve) => {
|
|
86
|
-
execFile(npmPath, ['prefix', '-g'], { ...shellOpt }, (err, stdout) => {
|
|
92
|
+
execFile(npmPath, ['prefix', '-g'], { env: safeEnv, ...shellOpt }, (err, stdout) => {
|
|
87
93
|
if (err) { resolve(false); return; }
|
|
88
94
|
const globalPrefix = stdout.toString().trim().replace(/\\/g, '/');
|
|
89
95
|
resolve(installDir === globalPrefix || installDir === globalPrefix + '/lib');
|
|
@@ -103,7 +109,7 @@ export async function handleUpgradeAgent() {
|
|
|
103
109
|
const isPm2 = !!process.env.pm_id;
|
|
104
110
|
if (isPm2) {
|
|
105
111
|
try {
|
|
106
|
-
execFileSync(pm2Path, ['delete', PM2_APP_NAME], { stdio: 'pipe', ...shellOpt });
|
|
112
|
+
execFileSync(pm2Path, ['delete', PM2_APP_NAME], { stdio: 'pipe', env: safeEnv, ...shellOpt });
|
|
107
113
|
console.log(`[Agent] PM2 app deleted to prevent auto-restart during upgrade`);
|
|
108
114
|
} catch {
|
|
109
115
|
console.log(`[Agent] PM2 delete skipped (app may not be registered)`);
|
|
@@ -252,17 +258,13 @@ function spawnUnixUpgradeScript(pkgName, installDir, isGlobalInstall, latestVers
|
|
|
252
258
|
const isLaunchd = platform() === 'darwin' && existsSync(join(process.env.HOME || '', 'Library', 'LaunchAgents', 'com.yeaft.agent.plist'));
|
|
253
259
|
const cwd = isGlobalInstall ? undefined : installDir;
|
|
254
260
|
|
|
255
|
-
// Ensure PATH includes the node bin dir (critical for launchd which has minimal PATH)
|
|
256
|
-
const currentPath = process.env.PATH || '/usr/bin:/bin:/usr/sbin:/sbin';
|
|
257
|
-
const exportPath = currentPath.includes(nodeBinDir) ? currentPath : `${nodeBinDir}:${currentPath}`;
|
|
258
|
-
|
|
259
261
|
const shLines = [
|
|
260
262
|
'#!/bin/bash',
|
|
261
263
|
`PID=${pid}`,
|
|
262
264
|
`PKG="${pkgName}@latest"`,
|
|
263
265
|
`NPM="${npmPath}"`,
|
|
264
266
|
`LOGFILE="${join(configDir, 'logs', 'upgrade.log')}"`,
|
|
265
|
-
`export PATH="${
|
|
267
|
+
`export PATH="${safePath}"`,
|
|
266
268
|
'',
|
|
267
269
|
'# Redirect all output to log file',
|
|
268
270
|
'exec > "$LOGFILE" 2>&1',
|