agent-notify 0.1.1 → 0.2.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/package.json +1 -1
- package/scripts/install.js +23 -3
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -15,6 +15,11 @@ function getBinaryDir() {
|
|
|
15
15
|
// npm bin -g is deprecated, use npm prefix -g instead
|
|
16
16
|
try {
|
|
17
17
|
const prefix = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
|
|
18
|
+
// On Windows, npm prefix -g returns the bin directory directly
|
|
19
|
+
// On Unix, it returns the parent and bin is in {prefix}/bin
|
|
20
|
+
if (os.platform() === 'win32') {
|
|
21
|
+
return prefix;
|
|
22
|
+
}
|
|
18
23
|
return path.join(prefix, 'bin');
|
|
19
24
|
} catch (e) {
|
|
20
25
|
// Fallback to ~/.local/bin
|
|
@@ -24,6 +29,17 @@ function getBinaryDir() {
|
|
|
24
29
|
|
|
25
30
|
const BINARY_DIR = getBinaryDir();
|
|
26
31
|
|
|
32
|
+
function getInstalledVersion(binaryPath) {
|
|
33
|
+
try {
|
|
34
|
+
const version = execSync(`"${binaryPath}" --version`, { encoding: 'utf8', timeout: 5000 }).trim();
|
|
35
|
+
// version output like: agent-notify version 0.1.0
|
|
36
|
+
const match = version.match(/(\d+\.\d+\.\d+)/);
|
|
37
|
+
return match ? match[1] : null;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
27
43
|
function getRemoteBinaryName(version) {
|
|
28
44
|
const platform = os.platform();
|
|
29
45
|
const arch = os.arch();
|
|
@@ -121,10 +137,14 @@ async function install() {
|
|
|
121
137
|
const localBinaryName = getLocalBinaryName();
|
|
122
138
|
const binaryPath = path.join(BINARY_DIR, localBinaryName);
|
|
123
139
|
|
|
124
|
-
// Check if binary already exists
|
|
140
|
+
// Check if binary already exists with correct version
|
|
125
141
|
if (fs.existsSync(binaryPath)) {
|
|
126
|
-
|
|
127
|
-
|
|
142
|
+
const installedVersion = getInstalledVersion(binaryPath);
|
|
143
|
+
if (installedVersion === PACKAGE_VERSION) {
|
|
144
|
+
console.log(`Binary already exists at ${binaryPath} (v${PACKAGE_VERSION})`);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
console.log(`Updating binary from v${installedVersion || 'unknown'} to v${PACKAGE_VERSION}...`);
|
|
128
148
|
}
|
|
129
149
|
|
|
130
150
|
// Create binary directory
|