@teamvibe/poller 0.1.36 → 0.1.37
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/cli/update.js +47 -5
- package/package.json +1 -1
package/dist/cli/update.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import { execSync } from 'child_process';
|
|
3
|
-
import { PLIST_PATH, SERVICE_LABEL } from './plist.js';
|
|
3
|
+
import { generatePlist, PLIST_PATH, SERVICE_LABEL } from './plist.js';
|
|
4
4
|
export function update() {
|
|
5
5
|
console.log('TeamVibe Poller - Update\n');
|
|
6
6
|
console.log('Updating @teamvibe/poller...');
|
|
@@ -11,15 +11,57 @@ export function update() {
|
|
|
11
11
|
console.error('Failed to update. Try running: npm install -g @teamvibe/poller@latest');
|
|
12
12
|
process.exit(1);
|
|
13
13
|
}
|
|
14
|
-
//
|
|
14
|
+
// Fix plist if it points to a stale npx cache path
|
|
15
15
|
if (process.platform === 'darwin' && fs.existsSync(PLIST_PATH)) {
|
|
16
|
+
const plistContent = fs.readFileSync(PLIST_PATH, 'utf-8');
|
|
17
|
+
if (plistContent.includes('/_npx/')) {
|
|
18
|
+
console.log('\nDetected stale npx path in service plist, fixing...');
|
|
19
|
+
// Resolve the globally installed poller path
|
|
20
|
+
let globalPollerPath = '';
|
|
21
|
+
try {
|
|
22
|
+
const binPath = execSync('which poller', { encoding: 'utf-8' }).trim();
|
|
23
|
+
if (binPath) {
|
|
24
|
+
globalPollerPath = fs.realpathSync(binPath);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Fall back to current process
|
|
29
|
+
}
|
|
30
|
+
if (globalPollerPath) {
|
|
31
|
+
// Extract existing env vars from plist
|
|
32
|
+
const envVars = {};
|
|
33
|
+
const envMatch = plistContent.match(/<key>EnvironmentVariables<\/key>\s*<dict>([\s\S]*?)<\/dict>/);
|
|
34
|
+
if (envMatch) {
|
|
35
|
+
const pairs = envMatch[1].matchAll(/<key>(.*?)<\/key>\s*<string>(.*?)<\/string>/g);
|
|
36
|
+
for (const pair of pairs) {
|
|
37
|
+
envVars[pair[1]] = pair[2];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const nodePath = process.execPath;
|
|
41
|
+
const newPlist = generatePlist(nodePath, globalPollerPath, envVars);
|
|
42
|
+
// Unload, write, reload
|
|
43
|
+
try {
|
|
44
|
+
execSync(`launchctl unload "${PLIST_PATH}" 2>/dev/null`, { stdio: 'ignore' });
|
|
45
|
+
}
|
|
46
|
+
catch { /* ignore */ }
|
|
47
|
+
fs.writeFileSync(PLIST_PATH, newPlist);
|
|
48
|
+
console.log(`Updated plist to use: ${globalPollerPath}`);
|
|
49
|
+
try {
|
|
50
|
+
execSync(`launchctl load "${PLIST_PATH}"`);
|
|
51
|
+
console.log('Service restarted.');
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(`Failed to restart: ${error instanceof Error ? error.message : error}`);
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Normal restart (no npx fix needed)
|
|
16
60
|
console.log(`\nRestarting service '${SERVICE_LABEL}'...`);
|
|
17
61
|
try {
|
|
18
62
|
execSync(`launchctl unload "${PLIST_PATH}" 2>/dev/null`, { stdio: 'ignore' });
|
|
19
63
|
}
|
|
20
|
-
catch {
|
|
21
|
-
// Ignore
|
|
22
|
-
}
|
|
64
|
+
catch { /* ignore */ }
|
|
23
65
|
try {
|
|
24
66
|
execSync(`launchctl load "${PLIST_PATH}"`);
|
|
25
67
|
console.log('Service restarted.');
|