From 25d4131f149a9e6272417b35d42a8e69abab8d22 Mon Sep 17 00:00:00 2001 From: Mike Maietta Date: Fri, 11 Oct 2024 17:31:16 -0700 Subject: [PATCH] moving fuses logic outside of signing function --- .../app-builder-lib/src/platformPackager.ts | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/packages/app-builder-lib/src/platformPackager.ts b/packages/app-builder-lib/src/platformPackager.ts index 3792e287c12..3e87a06637f 100644 --- a/packages/app-builder-lib/src/platformPackager.ts +++ b/packages/app-builder-lib/src/platformPackager.ts @@ -330,35 +330,14 @@ export abstract class PlatformPackager const isAsar = asarOptions != null await this.sanityCheckPackage(appOutDir, isAsar, framework, !!this.config.disableSanityCheckAsar) - if (sign) { - await this.doSignAfterPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets) - } - } - protected async doSignAfterPack(outDir: string, appOutDir: string, platformName: ElectronPlatformName, arch: Arch, platformSpecificBuildOptions: DC, targets: Array) { - const asarOptions = await this.computeAsarOptions(platformSpecificBuildOptions) - const isAsar = asarOptions != null - const packContext = { - appOutDir, - outDir, - arch, - targets, - packager: this, - electronPlatformName: platformName, - } // the fuses MUST be flipped right before signing if (this.config.electronFuses != null) { const fuseConfig = this.generateFuseConfig(this.config.electronFuses) await this.addElectronFuses(packContext, fuseConfig) } - const didSign = await this.signApp(packContext, isAsar) - const afterSign = await resolveFunction(this.appInfo.type, this.config.afterSign, "afterSign") - if (afterSign != null) { - if (didSign) { - await Promise.resolve(afterSign(packContext)) - } else { - log.warn(null, `skipping "afterSign" hook as no signing occurred, perhaps you intended "afterPack"?`) - } + if (sign) { + await this.doSignAfterPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets) } } @@ -395,8 +374,18 @@ export abstract class PlatformPackager return config } + /** + * Use `AfterPackContext` here to keep available for public API + * @param {AfterPackContext} context + * @param {FuseConfig} fuses + * + * Can be used in `afterPack` hook for custom fuse logic like below. It's an alternative approach if one wants to override electron-builder's @electron/fuses version + * ``` + * await context.packager.addElectronFuses(context, { ... }) + * ``` + */ public async addElectronFuses(context: AfterPackContext, fuses: FuseConfig) { - const { appOutDir, electronPlatformName, packager } = context + const { appOutDir, electronPlatformName } = context const ext = { darwin: ".app", @@ -404,13 +393,35 @@ export abstract class PlatformPackager linux: "", }[electronPlatformName] - const executableName = packager instanceof LinuxPackager ? packager.executableName : packager.appInfo.productFilename + const executableName = this instanceof LinuxPackager ? this.executableName : this.appInfo.productFilename const electronBinaryPath = path.join(appOutDir, `${executableName}${ext}`) log.info({ electronPath: log.filePath(electronBinaryPath) }, "executing @electron/fuses") return flipFuses(electronBinaryPath, fuses) } + protected async doSignAfterPack(outDir: string, appOutDir: string, platformName: ElectronPlatformName, arch: Arch, platformSpecificBuildOptions: DC, targets: Array) { + const asarOptions = await this.computeAsarOptions(platformSpecificBuildOptions) + const isAsar = asarOptions != null + const packContext = { + appOutDir, + outDir, + arch, + targets, + packager: this, + electronPlatformName: platformName, + } + const didSign = await this.signApp(packContext, isAsar) + const afterSign = await resolveFunction(this.appInfo.type, this.config.afterSign, "afterSign") + if (afterSign != null) { + if (didSign) { + await Promise.resolve(afterSign(packContext)) + } else { + log.warn(null, `skipping "afterSign" hook as no signing occurred, perhaps you intended "afterPack"?`) + } + } + } + // eslint-disable-next-line protected createTransformerForExtraFiles(packContext: AfterPackContext): FileTransformer | null { return null