Fix so ripgrep works in a built version of the app

Add ripgrep to electron-builder's asarUnpack config so that the ripgrep binary gets unpacked from the built *.asar file, and can be spawned.

#build
This commit is contained in:
Jonatan Heyman 2026-01-20 21:13:15 +01:00
parent 0222c805bf
commit d8a3418e74
2 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,9 @@
{
"appId": "com.heynote.app",
"asar": true,
"asarUnpack": [
"**/node_modules/@vscode/ripgrep/bin/**"
],
//"icon": "public/favicon.ico",
"directories": {
"output": "release/${version}",

View File

@ -8,14 +8,14 @@ import { parseImagesFromString } from "@/src/editor/image/image-parsing.js"
// If @vscode/ripgrep is in an .asar file, then the binary is unpacked.
//const rgDiskPath = rgPath.replace(/\bnode_modules\.asar\b/, 'node_modules.asar.unpacked');
const rgDiskPath = rgPath.replace(/app\.asar/, "app.asar.unpacked")
export async function runRipgrep(args, cwd, onLine) {
//console.log("cwd:", process.cwd(), "args:", args)
let stdout = ""
let stderr = ""
const rg = spawn(rgPath, args, {stdio: ["ignore", "pipe", "pipe"], cwd:cwd})
const rg = spawn(rgDiskPath, args, {stdio: ["ignore", "pipe", "pipe"], cwd:cwd})
rg.stdout.setEncoding("utf8")
rg.stderr.setEncoding("utf8")
const rl = readline.createInterface({ input: rg.stdout })
@ -38,7 +38,7 @@ export async function runRipgrep(args, cwd, onLine) {
const [code, signal] = await once(rg, "close")
// ripgrep exits with code 1 if there were not hits
if (code !== 0 && code !== 1) {
const err = new Error(`Command failed: ${rgPath}}`)
const err = new Error(`Command failed: ${rgDiskPath}}`)
err.code = code
err.signal = signal
err.stdout = stdout