Skip to content

Commit 4d3fdfc

Browse files
authored
fix(packager): report the correct status result when doSign exits early
1 parent b7c10f5 commit 4d3fdfc

File tree

6 files changed

+38
-29
lines changed

6 files changed

+38
-29
lines changed

Diff for: .changeset/stale-dots-build.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"app-builder-lib": patch
3+
"builder-util": patch
4+
---
5+
6+
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

Diff for: packages/app-builder-lib/src/codeSign/windowsCodeSign.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface CustomWindowsSignTaskConfiguration extends WindowsSignTaskConfi
3939
computeSignToolArgs(isWin: boolean): Array<string>
4040
}
4141

42-
export async function sign(options: WindowsSignOptions, packager: WinPackager) {
42+
export async function sign(options: WindowsSignOptions, packager: WinPackager): Promise<boolean> {
4343
let hashes = options.options.signingHashAlgorithms
4444
// msi does not support dual-signing
4545
if (options.path.endsWith(".msi")) {
@@ -70,6 +70,8 @@ export async function sign(options: WindowsSignOptions, packager: WinPackager) {
7070
await rename(taskConfiguration.resultOutputPath, options.path)
7171
}
7272
}
73+
74+
return true
7375
}
7476

7577
export interface FileCodeSigningInfo {

Diff for: packages/app-builder-lib/src/macPackager.ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
153153
}
154154
}
155155

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

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

447-
protected async signApp(packContext: AfterPackContext, isAsar: boolean): Promise<any> {
448-
const appFileName = `${this.appInfo.productFilename}.app`
447+
protected async signApp(packContext: AfterPackContext, isAsar: boolean): Promise<boolean> {
448+
const readDirectoryAndSign = async (sourceDirectory: string, directories: string[], filter: (file: string) => boolean): Promise<boolean> => {
449+
await BluebirdPromise.map(directories, async (file: string): Promise<null> => {
450+
if (filter(file)) {
451+
await this.sign(path.join(sourceDirectory, file), null, null, null)
452+
}
453+
return null
454+
})
455+
return true
456+
}
449457

450-
await BluebirdPromise.map(readdir(packContext.appOutDir), async (file: string): Promise<any> => {
451-
if (file === appFileName) {
452-
const appPath = path.join(packContext.appOutDir, file)
453-
await this.sign(appPath, null, null, null)
454-
}
455-
return null
456-
})
458+
const appFileName = `${this.appInfo.productFilename}.app`
459+
await readDirectoryAndSign(packContext.appOutDir, await readdir(packContext.appOutDir), file => file === appFileName)
457460

458461
if (!isAsar) {
459-
return
462+
return true
460463
}
461464

462465
const outResourcesDir = path.join(packContext.appOutDir, "resources", "app.asar.unpacked")
463-
await BluebirdPromise.map(orIfFileNotExist(readdir(outResourcesDir), []), (file: string): any => {
464-
if (file.endsWith(".app")) {
465-
return this.sign(path.join(outResourcesDir, file), null, null, null)
466-
} else {
467-
return null
468-
}
469-
})
466+
await readDirectoryAndSign(outResourcesDir, await orIfFileNotExist(readdir(outResourcesDir), []), file => file.endsWith(".app"))
467+
468+
return true
470469
}
471470

472471
private async notarizeIfProvided(appPath: string) {

Diff for: packages/app-builder-lib/src/platformPackager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
429429
}
430430

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

Diff for: packages/app-builder-lib/src/winPackager.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
199199
return this._iconPath.value
200200
}
201201

202-
async sign(file: string, logMessagePrefix?: string): Promise<void> {
202+
async sign(file: string, logMessagePrefix?: string): Promise<boolean> {
203203
const signOptions: WindowsSignOptions = {
204204
path: file,
205205
name: this.appInfo.productName,
@@ -216,7 +216,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
216216
`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`
217217
)
218218
}
219-
return
219+
return true
220220
}
221221

222222
if (logMessagePrefix == null) {
@@ -245,7 +245,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
245245
)
246246
}
247247

248-
await this.doSign({
248+
return this.doSign({
249249
...signOptions,
250250
cscInfo,
251251
options: {
@@ -258,7 +258,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
258258
for (let i = 0; i < 3; i++) {
259259
try {
260260
await sign(options, this)
261-
break
261+
return true
262262
} catch (e: any) {
263263
// https://github.com/electron-userland/electron-builder/issues/1414
264264
const message = e.message
@@ -269,6 +269,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
269269
throw e
270270
}
271271
}
272+
return false
272273
}
273274

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

397398
if (!isAsar) {
398-
return false
399+
return true
399400
}
400401

401-
const signPromise = (filepath: string[]) => {
402+
const filesPromise = (filepath: string[]) => {
402403
const outDir = path.join(packContext.appOutDir, ...filepath)
403404
return walk(outDir, (file, stat) => stat.isDirectory() || this.shouldSignFile(file))
404405
}
405-
const filesToSign = await Promise.all([signPromise(["resources", "app.asar.unpacked"]), signPromise(["swiftshader"])])
406+
const filesToSign = await Promise.all([filesPromise(["resources", "app.asar.unpacked"]), filesPromise(["swiftshader"])])
406407
await BluebirdPromise.map(filesToSign.flat(1), file => this.sign(file), { concurrency: 4 })
408+
407409
return true
408410
}
409411
}

Diff for: packages/builder-util/src/fs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as isCI from "is-ci"
1212
export const MAX_FILE_REQUESTS = 8
1313
export const CONCURRENCY = { concurrency: MAX_FILE_REQUESTS }
1414

15-
export type AfterCopyFileTransformer = (file: string) => Promise<void>
15+
export type AfterCopyFileTransformer = (file: string) => Promise<boolean>
1616

1717
export class CopyFileTransformer {
1818
constructor(public readonly afterCopyTransformer: AfterCopyFileTransformer) {}
@@ -220,7 +220,7 @@ export class FileCopier {
220220
}
221221
}
222222

223-
async copy(src: string, dest: string, stat: Stats | undefined) {
223+
async copy(src: string, dest: string, stat: Stats | undefined): Promise<void> {
224224
let afterCopyTransformer: AfterCopyFileTransformer | null = null
225225
if (this.transformer != null && stat != null && stat.isFile()) {
226226
let data = this.transformer(src)

0 commit comments

Comments
 (0)