Skip to content

Commit

Permalink
fix(packager): report the correct status result when doSign exits e…
Browse files Browse the repository at this point in the history
…arly
  • Loading branch information
mmaietta authored Feb 21, 2023
1 parent b7c10f5 commit 4d3fdfc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .changeset/stale-dots-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"builder-util": patch
---

fix: report the correct status result when `doSign` exits early from macPackager and winPackager. Updated function definition to return `Promise<boolean>` to properly flag intellisense
4 changes: 3 additions & 1 deletion packages/app-builder-lib/src/codeSign/windowsCodeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface CustomWindowsSignTaskConfiguration extends WindowsSignTaskConfi
computeSignToolArgs(isWin: boolean): Array<string>
}

export async function sign(options: WindowsSignOptions, packager: WinPackager) {
export async function sign(options: WindowsSignOptions, packager: WinPackager): Promise<boolean> {
let hashes = options.options.signingHashAlgorithms
// msi does not support dual-signing
if (options.path.endsWith(".msi")) {
Expand Down Expand Up @@ -70,6 +70,8 @@ export async function sign(options: WindowsSignOptions, packager: WinPackager) {
await rename(taskConfiguration.resultOutputPath, options.path)
}
}

return true
}

export interface FileCodeSigningInfo {
Expand Down
35 changes: 17 additions & 18 deletions packages/app-builder-lib/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
}
}

async pack(outDir: string, arch: Arch, targets: Array<Target>, taskManager: AsyncTaskManager): Promise<any> {
async pack(outDir: string, arch: Arch, targets: Array<Target>, taskManager: AsyncTaskManager): Promise<void> {
let nonMasPromise: Promise<any> | null = null

const hasMas = targets.length !== 0 && targets.some(it => it.name === "mas" || it.name === "mas-dev")
Expand Down Expand Up @@ -444,29 +444,28 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
}
}

protected async signApp(packContext: AfterPackContext, isAsar: boolean): Promise<any> {
const appFileName = `${this.appInfo.productFilename}.app`
protected async signApp(packContext: AfterPackContext, isAsar: boolean): Promise<boolean> {
const readDirectoryAndSign = async (sourceDirectory: string, directories: string[], filter: (file: string) => boolean): Promise<boolean> => {
await BluebirdPromise.map(directories, async (file: string): Promise<null> => {
if (filter(file)) {
await this.sign(path.join(sourceDirectory, file), null, null, null)
}
return null
})
return true
}

await BluebirdPromise.map(readdir(packContext.appOutDir), async (file: string): Promise<any> => {
if (file === appFileName) {
const appPath = path.join(packContext.appOutDir, file)
await this.sign(appPath, null, null, null)
}
return null
})
const appFileName = `${this.appInfo.productFilename}.app`
await readDirectoryAndSign(packContext.appOutDir, await readdir(packContext.appOutDir), file => file === appFileName)

if (!isAsar) {
return
return true
}

const outResourcesDir = path.join(packContext.appOutDir, "resources", "app.asar.unpacked")
await BluebirdPromise.map(orIfFileNotExist(readdir(outResourcesDir), []), (file: string): any => {
if (file.endsWith(".app")) {
return this.sign(path.join(outResourcesDir, file), null, null, null)
} else {
return null
}
})
await readDirectoryAndSign(outResourcesDir, await orIfFileNotExist(readdir(outResourcesDir), []), file => file.endsWith(".app"))

return true
}

private async notarizeIfProvided(appPath: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected signApp(packContext: AfterPackContext, isAsar: boolean): Promise<any> {
protected signApp(packContext: AfterPackContext, isAsar: boolean): Promise<boolean> {
return Promise.resolve(false)
}

Expand Down
16 changes: 9 additions & 7 deletions packages/app-builder-lib/src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
return this._iconPath.value
}

async sign(file: string, logMessagePrefix?: string): Promise<void> {
async sign(file: string, logMessagePrefix?: string): Promise<boolean> {
const signOptions: WindowsSignOptions = {
path: file,
name: this.appInfo.productName,
Expand All @@ -216,7 +216,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
`App is not signed and "forceCodeSigning" is set to true, please ensure that code signing configuration is correct, please see https://electron.build/code-signing`
)
}
return
return true
}

if (logMessagePrefix == null) {
Expand Down Expand Up @@ -245,7 +245,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
)
}

await this.doSign({
return this.doSign({
...signOptions,
cscInfo,
options: {
Expand All @@ -258,7 +258,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
for (let i = 0; i < 3; i++) {
try {
await sign(options, this)
break
return true
} catch (e: any) {
// https://github.com/electron-userland/electron-builder/issues/1414
const message = e.message
Expand All @@ -269,6 +269,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
throw e
}
}
return false
}

async signAndEditResources(file: string, arch: Arch, outDir: string, internalName?: string | null, requestedExecutionLevel?: RequestedExecutionLevel | null) {
Expand Down Expand Up @@ -395,15 +396,16 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
})

if (!isAsar) {
return false
return true
}

const signPromise = (filepath: string[]) => {
const filesPromise = (filepath: string[]) => {
const outDir = path.join(packContext.appOutDir, ...filepath)
return walk(outDir, (file, stat) => stat.isDirectory() || this.shouldSignFile(file))
}
const filesToSign = await Promise.all([signPromise(["resources", "app.asar.unpacked"]), signPromise(["swiftshader"])])
const filesToSign = await Promise.all([filesPromise(["resources", "app.asar.unpacked"]), filesPromise(["swiftshader"])])
await BluebirdPromise.map(filesToSign.flat(1), file => this.sign(file), { concurrency: 4 })

return true
}
}
4 changes: 2 additions & 2 deletions packages/builder-util/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as isCI from "is-ci"
export const MAX_FILE_REQUESTS = 8
export const CONCURRENCY = { concurrency: MAX_FILE_REQUESTS }

export type AfterCopyFileTransformer = (file: string) => Promise<void>
export type AfterCopyFileTransformer = (file: string) => Promise<boolean>

export class CopyFileTransformer {
constructor(public readonly afterCopyTransformer: AfterCopyFileTransformer) {}
Expand Down Expand Up @@ -220,7 +220,7 @@ export class FileCopier {
}
}

async copy(src: string, dest: string, stat: Stats | undefined) {
async copy(src: string, dest: string, stat: Stats | undefined): Promise<void> {
let afterCopyTransformer: AfterCopyFileTransformer | null = null
if (this.transformer != null && stat != null && stat.isFile()) {
let data = this.transformer(src)
Expand Down

0 comments on commit 4d3fdfc

Please sign in to comment.