fix: preserve architecture in unpacked ASAR path (#1094)

This commit is contained in:
ZacharyZcR
2026-07-28 01:47:33 +08:00
committed by GitHub
parent fdeb79e9e9
commit 7c397e3f8a
3 changed files with 43 additions and 4 deletions
+8
View File
@@ -0,0 +1,8 @@
function getUnpackedAppRoot(appRoot) {
return appRoot.replace(
/app(-[a-z0-9]+)?\.asar(?!\.unpacked)/,
"app$1.asar.unpacked",
);
}
module.exports = { getUnpackedAppRoot };
+2 -4
View File
@@ -12,6 +12,7 @@ const {
nativeImage, nativeImage,
} = require("electron"); } = require("electron");
const path = require("path"); const path = require("path");
const { getUnpackedAppRoot } = require("./backend-paths.cjs");
const fs = require("fs"); const fs = require("fs");
const os = require("os"); const os = require("os");
const https = require("https"); const https = require("https");
@@ -800,10 +801,7 @@ function getBackendPaths() {
// fork() does not go through Electron's asar redirector — use the unpacked path. // fork() does not go through Electron's asar redirector — use the unpacked path.
// On macOS multi-arch builds (mergeASARs: false), electron-builder names the ASAR // On macOS multi-arch builds (mergeASARs: false), electron-builder names the ASAR
// app-arm64.asar / app-x64.asar instead of app.asar, so match all variants. // app-arm64.asar / app-x64.asar instead of app.asar, so match all variants.
const unpackedRoot = appRoot.replace( const unpackedRoot = getUnpackedAppRoot(appRoot);
/app(-[a-z0-9]+)?\.asar(?!\.unpacked)/,
"app.asar.unpacked",
);
const backendDir = path.join(unpackedRoot, "dist", "backend", "backend"); const backendDir = path.join(unpackedRoot, "dist", "backend", "backend");
return { return {
entryPath: path.join(backendDir, "starter.js"), entryPath: path.join(backendDir, "starter.js"),
@@ -0,0 +1,33 @@
import { createRequire } from "node:module";
import { describe, expect, it } from "vitest";
const require = createRequire(import.meta.url);
const { getUnpackedAppRoot } =
require("../../../../electron/backend-paths.cjs") as {
getUnpackedAppRoot: (appRoot: string) => string;
};
describe("getUnpackedAppRoot", () => {
it.each([
[
"/Applications/Termix.app/Contents/Resources/app.asar",
"/Applications/Termix.app/Contents/Resources/app.asar.unpacked",
],
[
"/Applications/Termix.app/Contents/Resources/app-arm64.asar",
"/Applications/Termix.app/Contents/Resources/app-arm64.asar.unpacked",
],
[
"/Applications/Termix.app/Contents/Resources/app-x64.asar",
"/Applications/Termix.app/Contents/Resources/app-x64.asar.unpacked",
],
])("maps %s to its matching unpacked directory", (appRoot, expected) => {
expect(getUnpackedAppRoot(appRoot)).toBe(expected);
});
it("does not append the suffix twice", () => {
const appRoot =
"/Applications/Termix.app/Contents/Resources/app-arm64.asar.unpacked";
expect(getUnpackedAppRoot(appRoot)).toBe(appRoot);
});
});