Skip to content

A local-first personal finance app

[AI] Fix loot-core backend build failing on Windows (#9194)

Dami Oyeniyi4f28d63ec27a
diff --git a/packages/desktop-client/vite.config.mts b/packages/desktop-client/vite.config.mts
index de0f6dd396..92a81dc347 100644
--- a/packages/desktop-client/vite.config.mts
+++ b/packages/desktop-client/vite.config.mts
@@ -1,6 +1,6 @@
import { spawn } from 'node:child_process';
import type { ChildProcess } from 'node:child_process';
-import { createReadStream } from 'node:fs';
+import { createReadStream, readFileSync } from 'node:fs';
import { cp, mkdir, readdir, rename, rm, writeFile } from 'node:fs/promises';
import * as path from 'path';
import { fileURLToPath } from 'url';
@@ -98,6 +98,23 @@ const pluginsServiceDistDir = path.resolve(
);
const serviceWorkerDir = path.resolve(__dirname, 'service-worker');
+const repoRoot = path.resolve(__dirname, '../..');
+
+// The repo pins the Yarn release it expects via `.yarnrc.yml`, so resolve that
+// path and launch it through Node directly. Spawning `yarn` by name does not
+// work on Windows, where it resolves to a `.cmd` shim that `spawn` cannot
+// execute without a shell.
+function resolveYarnCli(): string {
+ const yarnRc = readFileSync(path.resolve(repoRoot, '.yarnrc.yml'), 'utf8');
+ const yarnPath = /^yarnPath:\s*(.+?)\s*$/m.exec(yarnRc)?.[1];
+
+ if (!yarnPath) {
+ throw new Error('Could not resolve "yarnPath" from .yarnrc.yml');
+ }
+
+ return path.resolve(repoRoot, yarnPath);
+}
+
const WORKER_FILENAME_RE = /^kcab\.worker\.(.+)\.js$/;
async function extractWorkerHash(): Promise<string> {
@@ -165,8 +182,9 @@ const lootCoreBackend = (): Plugin => ({
name: 'loot-core-backend',
configureServer(server) {
const child: ChildProcess = spawn(
- 'yarn',
+ process.execPath,
[
+ resolveYarnCli(),
'vite',
'build',
'--config',
diff --git a/upcoming-release-notes/fix-windows-loot-core-backend-build.md b/upcoming-release-notes/fix-windows-loot-core-backend-build.md
new file mode 100644
index 0000000000..9b304c7dba
--- /dev/null
+++ b/upcoming-release-notes/fix-windows-loot-core-backend-build.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [grzdev]
+---
+
+Fix the dev server failing to build the loot-core backend on Windows because `yarn` cannot be spawned by name.