plugin-updater 1.0.26 → 1.0.28

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.
Files changed (2) hide show
  1. package/dist/index.js +27 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ function writeLog(message, isError = false) {
53
53
  else if (loggingEnabled)
54
54
  console.log(message);
55
55
  }
56
+ let NPM_GLOBAL_ROOT = null;
56
57
  function getReposDir() {
57
58
  const isClaude = process.argv.join(" ").includes("claude");
58
59
  const appName = isClaude ? "claude" : "opencode";
@@ -75,17 +76,38 @@ function executeGit(command, cwd) {
75
76
  return false;
76
77
  }
77
78
  }
79
+ function getNpmGlobalRoot() {
80
+ if (NPM_GLOBAL_ROOT !== null)
81
+ return NPM_GLOBAL_ROOT;
82
+ try {
83
+ NPM_GLOBAL_ROOT = execSync("npm root -g", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
84
+ }
85
+ catch {
86
+ NPM_GLOBAL_ROOT = "";
87
+ }
88
+ return NPM_GLOBAL_ROOT;
89
+ }
78
90
  function resolveNpmPluginVersion(name, configDir) {
79
91
  try {
92
+ // opencode installs npm plugins into ~/.cache/opencode/packages/<name>@<spec>/
93
+ const packageCache = path.join(os.homedir(), ".cache", "opencode", "packages");
94
+ if (fs.existsSync(packageCache)) {
95
+ for (const entry of fs.readdirSync(packageCache)) {
96
+ if (entry !== name && !entry.startsWith(`${name}@`))
97
+ continue;
98
+ const cachedPkg = path.join(packageCache, entry, "node_modules", name, "package.json");
99
+ if (fs.existsSync(cachedPkg)) {
100
+ return JSON.parse(fs.readFileSync(cachedPkg, "utf8")).version || "";
101
+ }
102
+ }
103
+ }
80
104
  const cacheDir = path.join(configDir, "cache", "node_modules");
81
- const globalNpm = process.platform === "win32"
82
- ? path.join(os.homedir(), "AppData", "Roaming", "npm", "node_modules")
83
- : path.join("/usr", "lib", "node_modules");
105
+ const globalNpm = getNpmGlobalRoot();
84
106
  const candidates = [
85
107
  path.join(cacheDir, name, "package.json"),
86
108
  path.join(configDir, "node_modules", name, "package.json"),
87
- path.join(globalNpm, name, "package.json"),
88
- ];
109
+ globalNpm ? path.join(globalNpm, name, "package.json") : "",
110
+ ].filter((p) => p !== "");
89
111
  for (const p of candidates) {
90
112
  if (fs.existsSync(p)) {
91
113
  return JSON.parse(fs.readFileSync(p, "utf8")).version || "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plugin-updater",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Plugin lifecycle manager for OpenCode and Claude Code launchers",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",