diff --git a/apps/ui/scripts/prepare-server.mjs b/apps/ui/scripts/prepare-server.mjs index 182ab20c..db92b385 100644 --- a/apps/ui/scripts/prepare-server.mjs +++ b/apps/ui/scripts/prepare-server.mjs @@ -119,11 +119,19 @@ const nodeModulesAutomaker = join(BUNDLE_DIR, 'node_modules', '@automaker'); for (const pkgName of LOCAL_PACKAGES) { const pkgDir = pkgName.replace('@automaker/', ''); const nmPkgPath = join(nodeModulesAutomaker, pkgDir); - if (existsSync(nmPkgPath) && lstatSync(nmPkgPath).isSymbolicLink()) { - const realPath = resolve(BUNDLE_DIR, 'libs', pkgDir); - rmSync(nmPkgPath); - cpSync(realPath, nmPkgPath, { recursive: true }); - console.log(` ✓ Replaced symlink: ${pkgName}`); + try { + // lstatSync does not follow symlinks, allowing us to check for broken ones + if (lstatSync(nmPkgPath).isSymbolicLink()) { + const realPath = resolve(BUNDLE_DIR, 'libs', pkgDir); + rmSync(nmPkgPath); + cpSync(realPath, nmPkgPath, { recursive: true }); + console.log(` ✓ Replaced symlink: ${pkgName}`); + } + } catch (error) { + // If the path doesn't exist, lstatSync throws ENOENT. We can safely ignore this. + if (error.code !== 'ENOENT') { + throw error; + } } } diff --git a/libs/platform/src/system-paths.ts b/libs/platform/src/system-paths.ts index 676f8ee0..0d900dfa 100644 --- a/libs/platform/src/system-paths.ts +++ b/libs/platform/src/system-paths.ts @@ -752,9 +752,7 @@ export function electronUserDataWriteFileSync( const fullPath = path.join(electronUserDataPath, relativePath); // Ensure parent directory exists (may not exist on first launch) const dir = path.dirname(fullPath); - if (!fsSync.existsSync(dir)) { - fsSync.mkdirSync(dir, { recursive: true }); - } + fsSync.mkdirSync(dir, { recursive: true }); fsSync.writeFileSync(fullPath, data, options); }