diff --git a/packaging/build/after-pack.cjs b/packaging/build/after-pack.cjs index 170731252..869b04c35 100644 --- a/packaging/build/after-pack.cjs +++ b/packaging/build/after-pack.cjs @@ -30,6 +30,20 @@ function copyPluginSdk(resourcesDir, sdkDir = path.join(repoRoot, "packages", "p exports.copyPluginSdk = copyPluginSdk; +/** Mac App Store builds report "mas", not "darwin", but are still .app bundles. */ +function resourcesDirFor({ electronPlatformName, appOutDir, packager }) { + return ["darwin", "mas"].includes(electronPlatformName) + ? path.join( + appOutDir, + `${packager.appInfo.productFilename}.app`, + "Contents", + "Resources", + ) + : path.join(appOutDir, "resources"); +} + +exports.resourcesDirFor = resourcesDirFor; + exports.default = async function afterPack(context) { const { targets, appOutDir } = context; @@ -39,15 +53,7 @@ exports.default = async function afterPack(context) { fs.writeFileSync(markerPath, ""); } - const resourcesDir = - context.electronPlatformName === "darwin" - ? path.join( - appOutDir, - `${context.packager.appInfo.productFilename}.app`, - "Contents", - "Resources", - ) - : path.join(appOutDir, "resources"); + const resourcesDir = resourcesDirFor(context); copyPluginSdk(resourcesDir); diff --git a/src/backend/tests/electron/after-pack.test.ts b/src/backend/tests/electron/after-pack.test.ts index 450bad0d7..bceb44609 100644 --- a/src/backend/tests/electron/after-pack.test.ts +++ b/src/backend/tests/electron/after-pack.test.ts @@ -5,9 +5,14 @@ import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; const require = createRequire(import.meta.url); -const { copyPluginSdk } = +const { copyPluginSdk, resourcesDirFor } = require("../../../../packaging/build/after-pack.cjs") as { copyPluginSdk: (resourcesDir: string, sdkDir?: string) => string; + resourcesDirFor: (context: { + electronPlatformName: string; + appOutDir: string; + packager: { appInfo: { productFilename: string } }; + }) => string; }; let dir: string; @@ -53,4 +58,30 @@ describe("afterPack plugin SDK copy", () => { "npm run build:sdk", ); }); + + it.each(["darwin", "mas"])( + "copies into the app bundle for %s builds", + (electronPlatformName) => { + const context = { + electronPlatformName, + appOutDir: "/out", + packager: { appInfo: { productFilename: "Termix" } }, + }; + expect(resourcesDirFor(context)).toBe( + path.join("/out", "Termix.app", "Contents", "Resources"), + ); + }, + ); + + it.each(["win32", "linux"])( + "copies into resources for %s builds", + (electronPlatformName) => { + const context = { + electronPlatformName, + appOutDir: "/out", + packager: { appInfo: { productFilename: "Termix" } }, + }; + expect(resourcesDirFor(context)).toBe(path.join("/out", "resources")); + }, + ); });