@ulthon/ul-opencode-event 0.1.25 → 0.1.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/updater.d.ts CHANGED
@@ -39,8 +39,8 @@ export declare function syncCachePackageJsonToIntent(pluginInfo: PluginInfo): {
39
39
  message?: string;
40
40
  };
41
41
  /**
42
- * Execute `bun install` in the given workspace directory.
43
- * Uses Bun.spawn if available, otherwise falls back to child_process.spawn.
42
+ * Execute package install in the given workspace directory.
43
+ * Tries `bun install` first, falls back to `npm install` if bun is not available.
44
44
  */
45
45
  export declare function runBunInstall(workspaceDir: string): Promise<boolean>;
46
46
  /**
package/dist/updater.js CHANGED
@@ -291,19 +291,23 @@ function resolveWorkspaceDir() {
291
291
  // Exported: bun install
292
292
  // ---------------------------------------------------------------------------
293
293
  /**
294
- * Execute `bun install` in the given workspace directory.
295
- * Uses Bun.spawn if available, otherwise falls back to child_process.spawn.
294
+ * Execute package install in the given workspace directory.
295
+ * Tries `bun install` first, falls back to `npm install` if bun is not available.
296
296
  */
297
297
  export async function runBunInstall(workspaceDir) {
298
298
  try {
299
299
  const { spawn } = await import('child_process');
300
+ // Detect which package manager is available
301
+ const pm = await detectPackageManager();
302
+ logger.info(`[updater] Using package manager: ${pm}`);
300
303
  return await new Promise((resolve) => {
301
304
  const spawnOptions = {
302
305
  cwd: workspaceDir,
303
306
  windowsHide: true,
304
307
  shell: true,
305
308
  };
306
- const child = spawn('bun', ['install'], spawnOptions);
309
+ const args = pm === 'bun' ? ['install'] : ['install', '--no-fund', '--no-audit'];
310
+ const child = spawn(pm, args, spawnOptions);
307
311
  let stdout = '';
308
312
  let stderr = '';
309
313
  child.stdout?.on('data', (data) => {
@@ -315,7 +319,7 @@ export async function runBunInstall(workspaceDir) {
315
319
  // Timeout guard
316
320
  const timer = setTimeout(() => {
317
321
  child.kill('SIGKILL');
318
- logger.warn('[updater] bun install timed out after 60s');
322
+ logger.warn(`[updater] ${pm} install timed out after 60s`);
319
323
  resolve(false);
320
324
  }, BUN_INSTALL_TIMEOUT);
321
325
  child.on('close', (code) => {
@@ -324,26 +328,63 @@ export async function runBunInstall(workspaceDir) {
324
328
  resolve(true);
325
329
  }
326
330
  else {
327
- logger.warn(`[updater] bun install exited with code ${code}`);
331
+ logger.warn(`[updater] ${pm} install exited with code ${code}`);
328
332
  if (stderr)
329
- logger.debug(`[updater] bun install stderr: ${stderr}`);
333
+ logger.debug(`[updater] ${pm} install stderr: ${stderr}`);
330
334
  if (stdout)
331
- logger.debug(`[updater] bun install stdout: ${stdout}`);
335
+ logger.debug(`[updater] ${pm} install stdout: ${stdout}`);
332
336
  resolve(false);
333
337
  }
334
338
  });
335
339
  child.on('error', (err) => {
336
340
  clearTimeout(timer);
337
- logger.error(`[updater] bun install spawn error: ${err}`);
341
+ logger.error(`[updater] ${pm} install spawn error: ${err}`);
338
342
  resolve(false);
339
343
  });
340
344
  });
341
345
  }
342
346
  catch (err) {
343
- logger.error(`[updater] bun install failed: ${err}`);
347
+ logger.error(`[updater] Package install failed: ${err}`);
344
348
  return false;
345
349
  }
346
350
  }
351
+ /**
352
+ * Detect which package manager is available.
353
+ * Prefers bun (matches OpenCode's native package manager), falls back to npm.
354
+ */
355
+ async function detectPackageManager() {
356
+ const { execFileSync } = await import('child_process');
357
+ // Check for existing lock file as a hint
358
+ const packagesDir = path.join(getCacheDir(), 'packages');
359
+ const scopedDir = path.join(packagesDir, `${PACKAGE_NAME}@latest`);
360
+ for (const dir of [scopedDir, packagesDir]) {
361
+ if (fs.existsSync(path.join(dir, 'bun.lock')) || fs.existsSync(path.join(dir, 'bun.lockb'))) {
362
+ return 'bun';
363
+ }
364
+ if (fs.existsSync(path.join(dir, 'package-lock.json'))) {
365
+ return 'npm';
366
+ }
367
+ }
368
+ // Try bun first
369
+ try {
370
+ execFileSync('bun', ['--version'], { timeout: 3000, windowsHide: true });
371
+ return 'bun';
372
+ }
373
+ catch {
374
+ // bun not available
375
+ }
376
+ // Fall back to npm
377
+ try {
378
+ execFileSync('npm', ['--version'], { timeout: 3000, windowsHide: true });
379
+ return 'npm';
380
+ }
381
+ catch {
382
+ // npm not available either
383
+ }
384
+ // Last resort: assume npm
385
+ logger.warn('[updater] Neither bun nor npm detected, defaulting to npm');
386
+ return 'npm';
387
+ }
347
388
  // ---------------------------------------------------------------------------
348
389
  // Helper: toast notification
349
390
  // ---------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulthon/ul-opencode-event",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "OpenCode notification plugin - sends notifications via email or DingTalk when session events occur",
5
5
  "author": "augushong",
6
6
  "license": "MIT",