Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/few-zebras-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix: remove Promise ability from AsyncEventEmitter as it's impossible to filter listeners by without being async
20 changes: 10 additions & 10 deletions packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,18 @@ export class Packager {
log.info({ version: PACKAGE_VERSION, os: getOsRelease() }, "electron-builder")
}

addPackagerEventHandlers() {
async addPackagerEventHandlers() {
const { type } = this.appInfo
this.eventEmitter.on("artifactBuildStarted", resolveFunction(type, this.config.artifactBuildStarted, "artifactBuildStarted"), "user")
this.eventEmitter.on("artifactBuildCompleted", resolveFunction(type, this.config.artifactBuildCompleted, "artifactBuildCompleted"), "user")
this.eventEmitter.on("artifactBuildStarted", await resolveFunction(type, this.config.artifactBuildStarted, "artifactBuildStarted"), "user")
this.eventEmitter.on("artifactBuildCompleted", await resolveFunction(type, this.config.artifactBuildCompleted, "artifactBuildCompleted"), "user")

this.eventEmitter.on("appxManifestCreated", resolveFunction(type, this.config.appxManifestCreated, "appxManifestCreated"), "user")
this.eventEmitter.on("msiProjectCreated", resolveFunction(type, this.config.msiProjectCreated, "msiProjectCreated"), "user")
this.eventEmitter.on("appxManifestCreated", await resolveFunction(type, this.config.appxManifestCreated, "appxManifestCreated"), "user")
this.eventEmitter.on("msiProjectCreated", await resolveFunction(type, this.config.msiProjectCreated, "msiProjectCreated"), "user")

this.eventEmitter.on("beforePack", resolveFunction(type, this.config.beforePack, "beforePack"), "user")
this.eventEmitter.on("afterExtract", resolveFunction(type, this.config.afterExtract, "afterExtract"), "user")
this.eventEmitter.on("afterPack", resolveFunction(type, this.config.afterPack, "afterPack"), "user")
this.eventEmitter.on("afterSign", resolveFunction(type, this.config.afterSign, "afterSign"), "user")
this.eventEmitter.on("beforePack", await resolveFunction(type, this.config.beforePack, "beforePack"), "user")
this.eventEmitter.on("afterExtract", await resolveFunction(type, this.config.afterExtract, "afterExtract"), "user")
this.eventEmitter.on("afterPack", await resolveFunction(type, this.config.afterPack, "afterPack"), "user")
this.eventEmitter.on("afterSign", await resolveFunction(type, this.config.afterSign, "afterSign"), "user")
}

onAfterPack(handler: PackagerEvents["afterPack"]): Packager {
Expand Down Expand Up @@ -396,7 +396,7 @@ export class Packager {
}

this._appInfo = new AppInfo(this, null)
this.addPackagerEventHandlers()
await this.addPackagerEventHandlers()

this._framework = await createFrameworkInfo(this.config, this)

Expand Down
9 changes: 3 additions & 6 deletions packages/app-builder-lib/src/util/asyncEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Handler = (...args: any[]) => Promise<void> | void

export type HandlerType = "system" | "user"

type Handle = { handler: Handler | Promise<Handler | Nullish>; type: HandlerType }
type Handle = { handler: Handler; type: HandlerType }

export type EventMap = {
[key: string]: Handler
Expand All @@ -23,7 +23,7 @@ export class AsyncEventEmitter<T extends EventMap> implements TypedEventEmitter<
private readonly listeners: Map<keyof T, Handle[] | undefined> = new Map()
private readonly cancellationToken = new CancellationToken()

on<E extends keyof T>(event: E, listener: T[E] | Promise<T[E] | Nullish> | Nullish, type: HandlerType = "system"): this {
on<E extends keyof T>(event: E, listener: T[E] | Nullish, type: HandlerType = "system"): this {
if (!listener) {
return this
}
Expand Down Expand Up @@ -72,10 +72,7 @@ export class AsyncEventEmitter<T extends EventMap> implements TypedEventEmitter<

filterListeners<E extends keyof T>(event: E, type: HandlerType | undefined): Handle[] {
const listeners = this.listeners.get(event) ?? []
if (type) {
return listeners.filter(l => l.type === type)
}
return listeners
return type ? listeners.filter(l => l.type === type) : listeners
}

clear() {
Expand Down
Loading