Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: infer EventEmitter extensions from API #259

Merged
merged 2 commits into from
Mar 19, 2024
Merged

Conversation

MarshallOfSound
Copy link
Member

Instead of hard-coding a list of modules, we now infer if a module/class is an eventemitter with the following heuristic:

  • If the module / class has any events it's an emitter
  • If the module / class exposes on, once and removeListener it's an emitter (e.g. ipcMain)

This correctly identifies several exposed interfaces as not being emitters and improves the type safety of newly added modules

@MarshallOfSound MarshallOfSound requested review from a team as code owners February 23, 2024 07:43
@erickzhao erickzhao self-requested a review March 5, 2024 18:36
Copy link
Member

@erickzhao erickzhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool change, just one type comment

'messagechannelmain',
];
return !nonEventEmitters.includes(module.name.toLowerCase());
export const isEmitter = (doc: ParsedDocumentationResult[0]) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we make this type cleaner by giving ParsedDocumentationResult[0] a type and making type ParsedDocumentationResult = MyNewType[]? Personally find that working backward from index access types makes this harder to grok at first glance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do that, but ParsedDocumentationResult comes from @electron/docs-parser not this module. So here we are.

@MarshallOfSound MarshallOfSound merged commit 478d24b into main Mar 19, 2024
3 checks passed
@MarshallOfSound MarshallOfSound deleted the infer-emitter branch March 19, 2024 19:53
Copy link

🎉 This PR is included in version 8.15.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Comment on lines +66 to +68
if (module.name.toLowerCase() === 'session' && isStaticVersion) {
console.log({ isStaticVersion, instanceModuleForStaticVersion, extendsInfo });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarshallOfSound, was this debug code that got left in accidentally? Seeing the output on e/e now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants