codeburn/app/scripts/after-pack.cjs
Resham Joshi ee5cf7c38f
Some checks are pending
CI / semgrep (push) Waiting to run
macOS Menubar CI / test (push) Waiting to run
Tests / desktop (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.15.0) (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / vscode (push) Waiting to run
Windows Menubar CI / check (ubuntu-latest) (push) Waiting to run
Windows Menubar CI / check (windows-latest) (push) Waiting to run
fix(menubar): find the desktop app's bundled CLI when no CLI is on PATH (#1871)
With only the desktop app installed from the Homebrew cask, the menu bar
failed to load Today with "nonZeroExit (code: 127, stderr: env: codeburn:
No such file or directory)". The menu bar looked for a codeburn in the
path recorded for it and in package-manager folders, then fell back to the
bare name. A desktop-only machine has nothing in those folders, so when the
record was missing or no longer ran, nothing was found and the error named
nothing.

The packaged desktop app now carries a plain launcher at
CodeBurn.app/Contents/Resources/cli/codeburn that runs its bundled CLI
through its own executable and finds its own bundle. The menu bar checks
it, in /Applications and ~/Applications, after the recorded path and the
package-manager folders. When none of them runs, Today says which paths
were tried. The CLI's menubar installer records the same launcher instead
of refusing the install when nothing named codeburn is on PATH.
2026-11-05 05:59:42 +01:00

44 lines
2 KiB
JavaScript

// Copy the staged self-contained CLI (app/build/cli, produced by stage-cli.mjs)
// into the packaged app's resources/cli directory.
//
// This is done here rather than via `extraResources` because electron-builder
// routes every `node_modules` directory it copies through its production-
// dependency filter, which keeps only the *app's* own deps — so the bundled
// CLI's dependency tree gets stripped out of an `extraResources` copy. afterPack
// runs after packaging but before code signing, so the files we add land inside
// the app's signature. The CLI's deps are pure JS (no native bindings), so the
// same tree is valid for every arch.
const { join } = require('node:path')
const { cpSync, existsSync, writeFileSync } = require('node:fs')
// A codeburn the menubar can run straight out of the bundle, so a desktop-only install has one
// even when nothing was recorded for it (#1825). It finds its own bundle, so ~/Applications works.
function writeMacCliLauncher(cliDir, executableName) {
writeFileSync(join(cliDir, 'codeburn'), [
'#!/bin/sh',
'here=$(cd "$(dirname "$0")" && pwd -P)',
`ELECTRON_RUN_AS_NODE=1 exec "$here/../../MacOS/${executableName}" "$here/dist/launch.js" "$@"`,
'',
].join('\n'), { mode: 0o755 })
}
exports.writeMacCliLauncher = writeMacCliLauncher
exports.default = async function afterPack(context) {
const { appOutDir, electronPlatformName, packager } = context
const src = join(__dirname, '..', 'build', 'cli')
if (!existsSync(join(src, 'node_modules'))) {
throw new Error(`after-pack: ${src}/node_modules is missing — run "npm run stage-cli" first`)
}
const resources =
electronPlatformName === 'darwin'
? join(appOutDir, `${packager.appInfo.productFilename}.app`, 'Contents', 'Resources')
: join(appOutDir, 'resources')
const dest = join(resources, 'cli')
cpSync(src, dest, { recursive: true, dereference: true })
if (electronPlatformName === 'darwin') writeMacCliLauncher(dest, packager.appInfo.productFilename)
console.log(`after-pack: bundled CLI copied -> ${dest}`)
}