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.
This commit is contained in:
Kfir Amar
2026-03-15 12:26:23 +02:00
parent 22f9e6f4c0
commit e06e7157ac

View File

@@ -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) {