plugin-updater 1.0.15 → 1.0.17

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/index.js +28 -23
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -19,6 +19,7 @@ function writeLog(message, isError = false) {
19
19
  try {
20
20
  const date = new Date();
21
21
  const dateStr = date.toISOString().split('T')[0];
22
+ const timeStr = date.toISOString().replace(/:/g, '-').split('.')[0];
22
23
  const isClaude = process.argv.join(' ').includes('claude');
23
24
  const appName = isClaude ? "claude" : "opencode";
24
25
  const configDir = getAppConfigDir(appName);
@@ -28,13 +29,12 @@ function writeLog(message, isError = false) {
28
29
  fs.mkdirSync(logsDir, { recursive: true });
29
30
  }
30
31
 
31
- const logFile = path.join(logsDir, `updater-${dateStr}.log`);
32
+ const logFile = path.join(logsDir, `updater-${timeStr}.log`);
32
33
  const prefix = isError ? "[ERROR]" : "[INFO]";
33
34
  const logMsg = `[${date.toISOString()}] ${prefix} ${message}\n`;
34
35
 
35
36
  fs.appendFileSync(logFile, logMsg);
36
37
  } catch (e) {
37
- // Silent fallback if logging fails
38
38
  }
39
39
  if (isError) console.error(message);
40
40
  else console.log(message);
@@ -86,6 +86,8 @@ function deployToExecutionDir(pluginName, executionPath) {
86
86
  if (!fs.existsSync(sourceDir)) return false;
87
87
 
88
88
  const packageJsonPath = path.join(sourceDir, "package.json");
89
+ let entryFile = "index.js";
90
+
89
91
  if (fs.existsSync(packageJsonPath)) {
90
92
  try {
91
93
  writeLog(`Running npm install for ${pluginName}`);
@@ -93,6 +95,10 @@ function deployToExecutionDir(pluginName, executionPath) {
93
95
  writeLog(`Finished npm install for ${pluginName}`);
94
96
 
95
97
  const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
98
+ if (pkg.main) {
99
+ entryFile = pkg.main;
100
+ }
101
+
96
102
  if (pkg.scripts && pkg.scripts.build) {
97
103
  execSync("npm run build", { cwd: sourceDir, stdio: "ignore" });
98
104
  writeLog(`Finished npm run build for ${pluginName}`);
@@ -105,32 +111,34 @@ function deployToExecutionDir(pluginName, executionPath) {
105
111
  }
106
112
 
107
113
  const distPath = path.join(sourceDir, "dist");
108
- const deploySource = fs.existsSync(distPath) ? distPath : sourceDir;
109
- const pluginExecutionPath = path.join(executionPath, pluginName);
114
+ let deploySource = path.join(sourceDir, entryFile);
115
+
116
+ if (fs.existsSync(path.join(distPath, entryFile))) {
117
+ deploySource = path.join(distPath, entryFile);
118
+ } else if (fs.existsSync(path.join(distPath, "index.js"))) {
119
+ deploySource = path.join(distPath, "index.js");
120
+ }
121
+
122
+ const pluginExecutionFile = path.join(executionPath, `${pluginName}.js`);
110
123
 
111
- if (!fs.existsSync(pluginExecutionPath)) {
112
- fs.mkdirSync(pluginExecutionPath, { recursive: true });
124
+ if (!fs.existsSync(executionPath)) {
125
+ fs.mkdirSync(executionPath, { recursive: true });
113
126
  }
114
127
 
115
128
  try {
116
- writeLog(`Running cpSync for ${pluginName}`);
117
- fs.cpSync(deploySource, pluginExecutionPath, { recursive: true, force: true });
118
- writeLog(`Finished cpSync for ${pluginName}`);
129
+ writeLog(`Running copy for ${pluginName}`);
130
+ fs.copyFileSync(deploySource, pluginExecutionFile);
131
+ writeLog(`Finished copy for ${pluginName}`);
119
132
  } catch (e) {
120
- writeLog(`cpSync failed for ${pluginName}: ${e.message}`, true);
133
+ writeLog(`Copy failed for ${pluginName}: ${e.message}`, true);
121
134
  }
122
135
  return true;
123
136
  }
124
137
 
125
- // OpenCode NPM plugin contract: export default must be a function.
126
- // opencode iterates Object.entries(mod) and calls each export as fn(input).
127
- // ONLY export a single default function — no named exports.
128
138
  async function pluginUpdaterEntry(input) {
129
- const configDir = (input && input.directory)
130
- ? path.dirname(input.directory)
131
- : path.dirname(getReposDir());
139
+ const isClaude = process.argv.join(' ').includes('claude');
140
+ const configDir = getAppConfigDir(isClaude ? "claude" : "opencode");
132
141
 
133
- // 1. GUARANTEE BASE DIRECTORIES EXIST ON LAUNCH
134
142
  const reposDir = path.join(configDir, "repos");
135
143
  const pluginsDir = path.join(configDir, "plugin");
136
144
  if (!fs.existsSync(reposDir)) fs.mkdirSync(reposDir, { recursive: true });
@@ -160,12 +168,9 @@ async function pluginUpdaterEntry(input) {
160
168
  }
161
169
  }
162
170
 
163
- // Return empty hooks object — required by opencode plugin contract
164
171
  return {};
165
172
  }
166
173
 
167
- // Attach API methods for hub access via: import('plugin-updater').then(m => m.default.earlyLaunch(...))
168
- // These are function properties, NOT module-level named exports — they won't appear in Object.entries(mod)
169
174
  pluginUpdaterEntry.earlyLaunch = function(configDir) {
170
175
  EARLY_LAUNCH_CONFIG_DIR = configDir;
171
176
  global.__PLUGIN_UPDATER_HANDLED_BY_HUB__ = true;
@@ -201,9 +206,9 @@ pluginUpdaterEntry.disable = function(plugin) {
201
206
  fs.writeFileSync(pluginsJsonPath, JSON.stringify(plugins, null, 2), "utf-8");
202
207
  }
203
208
  }
204
- const pluginExecutionPath = path.join(configDir, "plugin", plugin.name);
209
+ const pluginExecutionPath = path.join(configDir, "plugin", `${plugin.name}.js`);
205
210
  if (fs.existsSync(pluginExecutionPath)) {
206
- try { fs.rmSync(pluginExecutionPath, { recursive: true, force: true }); } catch (e) {}
211
+ try { fs.rmSync(pluginExecutionPath, { force: true }); } catch (e) {}
207
212
  }
208
213
  };
209
214
  pluginUpdaterEntry.uninstall = function(plugin) {
@@ -214,4 +219,4 @@ pluginUpdaterEntry.uninstall = function(plugin) {
214
219
  }
215
220
  };
216
221
 
217
- export default pluginUpdaterEntry;
222
+ export default pluginUpdaterEntry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plugin-updater",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Plugin lifecycle manager for OpenCode and Claude Code launchers",
5
5
  "type": "module",
6
6
  "main": "index.js",