From 5c1db51864d5d34d7d71a2dd347f1b0d28cbc9ec Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 14 Nov 2026 19:40:22 -0800 Subject: [PATCH 1/2] fix(builds): read the macOS update floor from the packaged app The update manifest's minimumSystemVersion was the literal 22.0.0, right for Electron 45 (macOS 13) and tied to nothing. Dependabot now proposes Electron upgrades, and the next one that drops a macOS release would leave the literal behind: installs on the dropped release would auto-update into an app that cannot launch, with no test or build step to say so. afterPack now reads LSMinimumSystemVersion from the packaged app's Info.plist, which is what macOS itself enforces at launch, and writes it as the Darwin version electron-updater compares against os.release(). macOS and Darwin numbers do not track each other (13 is Darwin 22, 26 is Darwin 25, 27 is Darwin 27), so the mapping is an explicit table. An Info.plist without the key, or a macOS release missing from the table, fails the build instead of shipping a manifest with no floor. Validation: macUpdateFloor.test.ts runs the hook on a packaged-app fixture; against the previous hook three of its four cases fail. A real unsigned `electron-builder --mac zip` on this branch logged "updates require macOS 13.0 (Darwin 22.0.0)" and wrote `minimumSystemVersion: 22.0.0` to latest-mac.yml, the same value as before. Not run through a ToDesktop build. --- scripts/afterPack.mjs | 53 +++++++++++-- src/main/lib/macUpdateFloor.test.ts | 114 ++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 src/main/lib/macUpdateFloor.test.ts diff --git a/scripts/afterPack.mjs b/scripts/afterPack.mjs index 48719ba9a..19ee452b0 100644 --- a/scripts/afterPack.mjs +++ b/scripts/afterPack.mjs @@ -91,14 +91,55 @@ function unpackedNodeModulesDir(context) { return path.join(resourcesDir, 'app.asar.unpacked', 'node_modules') } +const DARWIN_MAJOR_BY_MACOS_MAJOR = new Map([ + [11, 20], + [12, 21], + [13, 22], + [14, 23], + [15, 24], + [26, 25], + [27, 27] +]) + +export function darwinVersionForMacOS(macOSVersion) { + const darwinMajor = DARWIN_MAJOR_BY_MACOS_MAJOR.get(Number.parseInt(macOSVersion, 10)) + if (darwinMajor === undefined) { + throw new Error( + `afterPack: no Darwin version known for macOS ${macOSVersion}; add it to DARWIN_MAJOR_BY_MACOS_MAJOR` + ) + } + return `${darwinMajor}.0.0` +} + +export function minimumMacOSVersionOfApp(appContentsDir) { + const infoPlistPath = path.join(appContentsDir, 'Info.plist') + const match = /LSMinimumSystemVersion<\/key>\s*([^<]+)<\/string>/.exec( + fs.readFileSync(infoPlistPath, 'utf8') + ) + if (!match) { + throw new Error(`afterPack: LSMinimumSystemVersion not found in ${infoPlistPath}`) + } + return match[1] +} + +function requireTheAppsMinimumMacOSToUpdate(context) { + const { packager } = context + const appContentsDir = path.dirname(packager.getResourcesDir(context.appOutDir)) + const minimumMacOSVersion = minimumMacOSVersionOfApp(appContentsDir) + const minimumSystemVersion = darwinVersionForMacOS(minimumMacOSVersion) + packager.platformSpecificBuildOptions.releaseInfo = { + ...packager.config.releaseInfo, + ...packager.platformSpecificBuildOptions.releaseInfo, + minimumSystemVersion + } + console.log( + `afterPack: updates require macOS ${minimumMacOSVersion} (Darwin ${minimumSystemVersion})` + ) +} + export default async function afterPack(context) { if (context.electronPlatformName === 'darwin') { - const { packager } = context - packager.platformSpecificBuildOptions.releaseInfo = { - ...packager.config.releaseInfo, - ...packager.platformSpecificBuildOptions.releaseInfo, - minimumSystemVersion: '22.0.0' - } + requireTheAppsMinimumMacOSToUpdate(context) } if (context.electronPlatformName === 'win32') { diff --git a/src/main/lib/macUpdateFloor.test.ts b/src/main/lib/macUpdateFloor.test.ts new file mode 100644 index 000000000..0b1ed2f83 --- /dev/null +++ b/src/main/lib/macUpdateFloor.test.ts @@ -0,0 +1,114 @@ +import fs from 'fs' +import os from 'os' +import path from 'path' +import { pathToFileURL } from 'url' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +interface ReleaseInfo { + releaseNotes?: string + minimumSystemVersion?: string +} + +interface PackContext { + electronPlatformName: string + appOutDir: string + packager: { + config: { releaseInfo?: ReleaseInfo } + platformSpecificBuildOptions: { releaseInfo?: ReleaseInfo } + getResourcesDir: (appOutDir: string) => string + } +} + +interface AfterPackModule { + default: (context: PackContext) => Promise +} + +const APP_BUNDLE = 'Comfy Desktop.app' +const afterPackUrl = pathToFileURL(path.join(process.cwd(), 'scripts', 'afterPack.mjs')).href +const packedApps: string[] = [] + +function packedMacApp(minimumMacOS: string | null): string { + const appOutDir = fs.mkdtempSync(path.join(os.tmpdir(), 'packed-mac-app-')) + packedApps.push(appOutDir) + const contentsDir = path.join(appOutDir, APP_BUNDLE, 'Contents') + fs.mkdirSync(contentsDir, { recursive: true }) + const minimumSystemEntry = + minimumMacOS === null + ? '' + : `\tLSMinimumSystemVersion\n\t${minimumMacOS}\n` + fs.writeFileSync( + path.join(contentsDir, 'Info.plist'), + [ + '', + '', + '', + '\tCFBundleName', + '\tComfy Desktop', + `${minimumSystemEntry}`, + '', + '' + ].join('\n') + ) + return appOutDir +} + +function macPackContext(appOutDir: string, releaseInfo?: ReleaseInfo): PackContext { + return { + electronPlatformName: 'darwin', + appOutDir, + packager: { + config: { releaseInfo }, + platformSpecificBuildOptions: {}, + getResourcesDir: (dir) => path.join(dir, APP_BUNDLE, 'Contents', 'Resources') + } + } +} + +async function runAfterPack(context: PackContext): Promise { + const hook = (await import(afterPackUrl)) as AfterPackModule + await hook.default(context) +} + +describe('the macOS update manifest', () => { + beforeEach(() => { + vi.spyOn(console, 'log').mockImplementation(() => {}) + }) + + afterEach(() => { + vi.restoreAllMocks() + for (const dir of packedApps.splice(0)) fs.rmSync(dir, { recursive: true, force: true }) + }) + + it('holds an update back from a Mac older than the packaged app itself supports', async () => { + const context = macPackContext(packedMacApp('13.0'), { releaseNotes: 'What changed' }) + + await runAfterPack(context) + + expect(context.packager.platformSpecificBuildOptions.releaseInfo).toEqual({ + releaseNotes: 'What changed', + minimumSystemVersion: '22.0.0' + }) + }) + + it('follows the app when a later Electron raises the macOS it needs', async () => { + const context = macPackContext(packedMacApp('26.0')) + + await runAfterPack(context) + + expect(context.packager.platformSpecificBuildOptions.releaseInfo?.minimumSystemVersion).toBe( + '25.0.0' + ) + }) + + it('fails the build when the app needs a macOS whose Darwin version is not known', async () => { + const context = macPackContext(packedMacApp('99.0')) + + await expect(runAfterPack(context)).rejects.toThrow('no Darwin version known for macOS 99.0') + }) + + it('fails the build when the app does not say which macOS it needs', async () => { + const context = macPackContext(packedMacApp(null)) + + await expect(runAfterPack(context)).rejects.toThrow('LSMinimumSystemVersion not found') + }) +}) From 1ce9e451497bfee4dc3bbc5b5f31cf50af7fb77d Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 14 Nov 2026 19:41:00 -0800 Subject: [PATCH 2/2] chore(deps): drop electron from pnpm's build-script allowlist Electron 42 removed the package's postinstall, and this repository's own postinstall now fetches the binary. The allowlist entry no longer allows anything, and leaving it would let an install script run unreviewed if a later electron release added one. `pnpm install --frozen-lockfile` passes with the entry gone and the 45.3.2 binary is in place afterwards. --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 493df309b..d0630729a 100644 --- a/package.json +++ b/package.json @@ -132,7 +132,6 @@ }, "pnpm": { "onlyBuiltDependencies": [ - "electron", "electron-winstaller", "esbuild", "node-pty"