plugin-updater 1.0.16 → 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 +26 -20
  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,31 +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
139
  const isClaude = process.argv.join(' ').includes('claude');
130
140
  const configDir = getAppConfigDir(isClaude ? "claude" : "opencode");
131
141
 
132
- // 1. GUARANTEE BASE DIRECTORIES EXIST ON LAUNCH
133
142
  const reposDir = path.join(configDir, "repos");
134
143
  const pluginsDir = path.join(configDir, "plugin");
135
144
  if (!fs.existsSync(reposDir)) fs.mkdirSync(reposDir, { recursive: true });
@@ -159,12 +168,9 @@ async function pluginUpdaterEntry(input) {
159
168
  }
160
169
  }
161
170
 
162
- // Return empty hooks object — required by opencode plugin contract
163
171
  return {};
164
172
  }
165
173
 
166
- // Attach API methods for hub access via: import('plugin-updater').then(m => m.default.earlyLaunch(...))
167
- // These are function properties, NOT module-level named exports — they won't appear in Object.entries(mod)
168
174
  pluginUpdaterEntry.earlyLaunch = function(configDir) {
169
175
  EARLY_LAUNCH_CONFIG_DIR = configDir;
170
176
  global.__PLUGIN_UPDATER_HANDLED_BY_HUB__ = true;
@@ -200,9 +206,9 @@ pluginUpdaterEntry.disable = function(plugin) {
200
206
  fs.writeFileSync(pluginsJsonPath, JSON.stringify(plugins, null, 2), "utf-8");
201
207
  }
202
208
  }
203
- const pluginExecutionPath = path.join(configDir, "plugin", plugin.name);
209
+ const pluginExecutionPath = path.join(configDir, "plugin", `${plugin.name}.js`);
204
210
  if (fs.existsSync(pluginExecutionPath)) {
205
- try { fs.rmSync(pluginExecutionPath, { recursive: true, force: true }); } catch (e) {}
211
+ try { fs.rmSync(pluginExecutionPath, { force: true }); } catch (e) {}
206
212
  }
207
213
  };
208
214
  pluginUpdaterEntry.uninstall = function(plugin) {
@@ -213,4 +219,4 @@ pluginUpdaterEntry.uninstall = function(plugin) {
213
219
  }
214
220
  };
215
221
 
216
- 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.16",
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",