From e06e7157ac79b437bbc5d61f2e67a0c393ebbdb8 Mon Sep 17 00:00:00 2001 From: Kfir Amar Date: Sun, 15 Mar 2026 12:26:23 +0200 Subject: [PATCH] fix(electron): sanitize staged bundle paths cross-platform Match both slash styles when removing build-machine paths from the staged standalone bundle so the sanitization step works on Windows and POSIX builds. While touching the helper, replace the custom basename logic with Node's built-in `path.basename` for clarity. --- scripts/prepare-electron-standalone.mjs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/prepare-electron-standalone.mjs b/scripts/prepare-electron-standalone.mjs index 4d26be012b..4f8c5e5d11 100644 --- a/scripts/prepare-electron-standalone.mjs +++ b/scripts/prepare-electron-standalone.mjs @@ -9,7 +9,7 @@ import { rmSync, writeFileSync, } from "node:fs"; -import { dirname, join, relative } from "node:path"; +import { basename, dirname, join, relative } from "node:path"; import { fileURLToPath } from "node:url"; const __filename = fileURLToPath(import.meta.url); @@ -45,8 +45,11 @@ function resolveStandaloneBundleDir() { ); } -function basename(filePath) { - return filePath.split(/[\\/]/).filter(Boolean).at(-1) || filePath; +function createPathPattern(filePath) { + return filePath + .replace(/\\/g, "/") + .replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + .replace(/\//g, "[\\\\/]"); } function sanitizeBuildPaths(bundleDir) { @@ -65,8 +68,7 @@ function sanitizeBuildPaths(bundleDir) { let updated = content; for (const original of replacements) { - const escaped = original.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); - updated = updated.replace(new RegExp(escaped, "g"), "."); + updated = updated.replace(new RegExp(createPathPattern(original), "g"), "."); } if (updated !== content) {