opencode-immune 1.0.26 → 1.0.27
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/plugin.js +30 -3
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -13,12 +13,39 @@ const child_process_1 = require("child_process");
|
|
|
13
13
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
14
14
|
const PLUGIN_VERSION = "1.0.26";
|
|
15
15
|
const PLUGIN_PACKAGE_NAME = "opencode-immune";
|
|
16
|
+
/**
|
|
17
|
+
* Read plugin version from package.json at runtime.
|
|
18
|
+
* Falls back to PLUGIN_VERSION constant if read fails.
|
|
19
|
+
*/
|
|
20
|
+
async function getPluginVersion() {
|
|
21
|
+
try {
|
|
22
|
+
// Try to find package.json relative to the compiled plugin location.
|
|
23
|
+
// dist/plugin.js → ../package.json
|
|
24
|
+
// Also try direct path for when loaded from npm cache.
|
|
25
|
+
const candidates = [
|
|
26
|
+
(0, path_1.join)(__dirname, "..", "package.json"),
|
|
27
|
+
(0, path_1.join)(__dirname, "package.json"),
|
|
28
|
+
];
|
|
29
|
+
for (const pkgPath of candidates) {
|
|
30
|
+
try {
|
|
31
|
+
const content = await (0, promises_1.readFile)(pkgPath, "utf-8");
|
|
32
|
+
const pkg = JSON.parse(content);
|
|
33
|
+
if (pkg.version)
|
|
34
|
+
return pkg.version;
|
|
35
|
+
}
|
|
36
|
+
catch { /* try next */ }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch { /* fallback */ }
|
|
40
|
+
return PLUGIN_VERSION;
|
|
41
|
+
}
|
|
16
42
|
/**
|
|
17
43
|
* Check npm registry for latest version. Warn if current is outdated.
|
|
18
44
|
* Non-blocking, fire-and-forget — never delays plugin startup.
|
|
19
45
|
*/
|
|
20
46
|
async function checkPluginUpdate() {
|
|
21
47
|
try {
|
|
48
|
+
const currentVersion = await getPluginVersion();
|
|
22
49
|
const controller = new AbortController();
|
|
23
50
|
const timeout = setTimeout(() => controller.abort(), 5_000);
|
|
24
51
|
const res = await fetch(`https://registry.npmjs.org/${PLUGIN_PACKAGE_NAME}/latest`, { signal: controller.signal });
|
|
@@ -27,12 +54,12 @@ async function checkPluginUpdate() {
|
|
|
27
54
|
return;
|
|
28
55
|
const data = (await res.json());
|
|
29
56
|
const latest = data.version;
|
|
30
|
-
if (latest && latest !==
|
|
31
|
-
console.warn(`[opencode-immune] Plugin update available: ${
|
|
57
|
+
if (latest && latest !== currentVersion) {
|
|
58
|
+
console.warn(`[opencode-immune] Plugin update available: ${currentVersion} → ${latest}. ` +
|
|
32
59
|
`Restart opencode to pick up the new version.`);
|
|
33
60
|
}
|
|
34
61
|
else if (latest) {
|
|
35
|
-
console.log(`[opencode-immune] Plugin version ${
|
|
62
|
+
console.log(`[opencode-immune] Plugin version ${currentVersion} is up to date.`);
|
|
36
63
|
}
|
|
37
64
|
}
|
|
38
65
|
catch {
|