@mingxy/opencode-mascot 0.2.1 → 0.2.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/opencode-mascot",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "OpenCode TUI mascot plugin framework - customizable ASCII mascots for your terminal",
5
5
  "author": "mingxy",
6
6
  "license": "MIT",
@@ -3,7 +3,7 @@ import { promisify } from "node:util";
3
3
  import { createRequire } from "node:module";
4
4
  import { join, dirname } from "node:path";
5
5
  import { homedir, tmpdir } from "node:os";
6
- import { openSync, closeSync, unlinkSync, statSync, writeSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
6
+ import { openSync, closeSync, unlinkSync, statSync, writeSync, mkdtempSync, readdirSync, rmSync, readFileSync, writeFileSync } from "node:fs";
7
7
 
8
8
  const execFileAsync = promisify(execFile);
9
9
  const require = createRequire(import.meta.url);
@@ -41,7 +41,7 @@ function getInstallDir(): string {
41
41
  }
42
42
  }
43
43
 
44
- async function installUpdate(targetDir: string): Promise<boolean> {
44
+ async function installUpdate(targetDir: string, newVersion: string): Promise<boolean> {
45
45
  const tmpDir = mkdtempSync(join(tmpdir(), "mascot-update-"));
46
46
  try {
47
47
  await execFileAsync("npm", ["pack", `${PKG_NAME}@latest`, "--pack-destination", tmpDir], { timeout: 60000 });
@@ -53,6 +53,22 @@ async function installUpdate(targetDir: string): Promise<boolean> {
53
53
  ["-xzf", join(tmpDir, tgz), "-C", targetDir, "--strip-components=1", "--no-same-owner", "--no-same-permissions"],
54
54
  { timeout: 30000 },
55
55
  );
56
+
57
+ // 更新 opencode 插件管理清单的版本号,防止重启时回滚
58
+ let dir = targetDir;
59
+ for (let i = 0; i < 5; i++) {
60
+ dir = dirname(dir);
61
+ const manifestPath = join(dir, "package.json");
62
+ try {
63
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
64
+ if (manifest.dependencies && PKG_NAME in manifest.dependencies) {
65
+ manifest.dependencies[PKG_NAME] = newVersion;
66
+ writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
67
+ break;
68
+ }
69
+ } catch {}
70
+ }
71
+
56
72
  return true;
57
73
  } catch {
58
74
  return false;
@@ -99,7 +115,7 @@ export async function checkAndUpdate(
99
115
 
100
116
  try {
101
117
  const targetDir = getInstallDir();
102
- const success = await installUpdate(targetDir);
118
+ const success = await installUpdate(targetDir, latest);
103
119
  if (success) {
104
120
  onSuccess(latest);
105
121
  }