fix: prepend install-time node bin dir to menubar plugin PATH

SwiftBar/xbar launch plugins with a minimal environment. If an older
system Node (e.g. v18.x from Homebrew) appears earlier on PATH than the
NVM-managed Node used to install codeburn, the plugin silently fails
because string-width uses the /v regex flag (requires Node >= 20.11).

Resolve the node binary directory at install time via process.execPath
and prepend it to PATH in the generated plugin script. Also explicitly
set HOME, which SwiftBar does not always inherit.

Fixes #63
This commit is contained in:
Jonathan 2026-04-17 07:29:14 +01:00
parent f2d1753d3a
commit 276b14adea

View file

@ -71,6 +71,11 @@ function getCodeburnBin(): string {
function generatePlugin(bin: string): string {
const home = homedir()
// Resolve the directory of the node binary used at install time so the
// plugin uses the same Node version codeburn was installed with — even
// when SwiftBar/xbar launch with a minimal PATH that finds an older
// system Node first. Fixes #63.
const nodeBinDir = join(process.execPath, '..')
return `#!/bin/bash
# <xbar.title>CodeBurn</xbar.title>
# <xbar.version>v0.1.0</xbar.version>
@ -81,7 +86,8 @@ function generatePlugin(bin: string): string {
# <xbar.abouturl>https://github.com/agentseal/codeburn</xbar.abouturl>
# <xbar.dependencies>node</xbar.dependencies>
export PATH="/usr/local/bin:/opt/homebrew/bin:$HOME/.local/bin:$HOME/.npm-global/bin:$PATH"
export HOME="${home}"
export PATH="${nodeBinDir}:$HOME/.local/bin:$HOME/.npm-global/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"
${bin} status --format menubar 2>/dev/null || echo "-- | sfimage=flame.fill"
`