Skip to content

Commit

Permalink
fix: event emitter on extended Process (#264)
Browse files Browse the repository at this point in the history
* fix: event emitter on extended Process

* Review feedback
  • Loading branch information
mxschmitt authored Apr 17, 2024
1 parent 75942f3 commit 0fc0420
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/module-declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const generateModuleDeclaration = (
...parentModules.map(m => m.instanceEvents || []),
)
.sort((a, b) => a.name.localeCompare(b.name))
.forEach(moduleEvent => {
.forEach((moduleEvent, i, events) => {
utils.extendArray(
moduleAPI,
utils.wrapComment(moduleEvent.description, moduleEvent.additionalTags),
Expand Down Expand Up @@ -198,6 +198,15 @@ export const generateModuleDeclaration = (
}
moduleAPI.push(`${method}(event: '${moduleEvent.name}', listener: ${listener}): this;`);
}

// EventEmitter methods get overriden above. In order to not break untyped usage, we need to add them back after the last event.
if (module.name === 'process' && i === events.length - 1) {
for (const method of methods) {
moduleAPI.push(
`${method}(eventName: string | symbol, listener: (...args: any[]) => void): this;`,
);
}
}
});
}

Expand Down

0 comments on commit 0fc0420

Please sign in to comment.