Skip to content

Commit

Permalink
moving fuses logic outside of signing function
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaietta committed Oct 12, 2024
1 parent f5cc9ed commit 25d4131
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,35 +330,14 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

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<Target>) {
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)
}
}

Expand Down Expand Up @@ -395,22 +374,54 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
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",
win32: ".exe",
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<Target>) {
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
Expand Down

0 comments on commit 25d4131

Please sign in to comment.