-
Notifications
You must be signed in to change notification settings - Fork 4
Add tap support for hookMap #24
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
base: main
Are you sure you want to change the base?
Add tap support for hookMap #24
Conversation
Add tap(), tapAsync(), and tapPromise() methods to HookMap and QueriedHookMap classes for webpack compatibility. These methods delegate to for(key).tap/tapAsync/tapPromise, matching the API provided by webpack's tapable library. This enables webpack plugins that use patterns like hookMap.tap(key, "name", fn) to work correctly with rspack.
Summary of ChangesHello @martinjlowm, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds tap, tapAsync, and tapPromise convenience methods to HookMap and QueriedHookMap to improve compatibility with webpack plugins. The changes to HookMap are well-implemented and include a comprehensive new test suite. However, the implementation of these methods on QueriedHookMap introduces a design inconsistency by bypassing the class's stageRange logic. My review includes a comment to address this issue by suggesting the removal of these methods from QueriedHookMap.
src/index.ts
Outdated
| tap( | ||
| key: HookMapKey, | ||
| options: Options<ExtractHookAdditionalOptions<H>>, | ||
| fn: Fn<ExtractHookArgs<H>, ExtractHookReturn<H>>, | ||
| ) { | ||
| return this.hookMap.for(key).tap(options, fn); | ||
| } | ||
|
|
||
| tapAsync( | ||
| key: HookMapKey, | ||
| options: Options<ExtractHookAdditionalOptions<H>>, | ||
| fn: FnAsync<ExtractHookArgs<H>, ExtractHookReturn<H>>, | ||
| ) { | ||
| return this.hookMap.for(key).tapAsync(options, fn); | ||
| } | ||
|
|
||
| tapPromise( | ||
| key: HookMapKey, | ||
| options: Options<ExtractHookAdditionalOptions<H>>, | ||
| fn: FnPromise<ExtractHookArgs<H>, ExtractHookReturn<H>>, | ||
| ) { | ||
| return this.hookMap.for(key).tapPromise(options, fn); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new tap, tapAsync, and tapPromise methods on QueriedHookMap are implemented inconsistently with the class's design.
QueriedHookMap is designed as a "view" over a HookMap for a specific stageRange. Its get(key) and for(key) methods correctly return a QueriedHook that is constrained by this stageRange.
However, the new tap methods delegate directly to the underlying this.hookMap:
return this.hookMap.for(key).tap(options, fn);This bypasses the stageRange logic entirely, breaking the abstraction of QueriedHookMap. A developer using a QueriedHookMap instance would not expect tap() to ignore the query context.
The PR description focuses on adding these methods to HookMap for webpack compatibility. It's unclear if they are also needed on QueriedHookMap.
Given that QueriedHook (returned by for(key)) does not have tap methods, and adding them would be complex, I recommend removing tap, tapAsync, and tapPromise from QueriedHookMap to avoid this design inconsistency. If these methods are strictly required, their interaction with stageRange needs to be clarified and implemented correctly.
Remove tap(), tapAsync(), tapPromise() from QueriedHookMap as they bypass the stageRange constraint by delegating directly to the underlying hookMap. This breaks the abstraction since QueriedHook doesn't have tap methods and the query context should be respected. The HookMap convenience methods are kept as they correctly delegate to for(key).tap() without any stage filtering concerns.
|
These methods already deprecated by tapable, is there any plugin that still using these methods? |
Add
tap(),tapAsync(), andtapPromise()methods to HookMap and QueriedHookMap classes for webpack compatibility. These methods delegate tofor(key).tap/tapAsync/tapPromise, matching the API provided by webpack's tapable library.This enables webpack plugins that use patterns like
hookMap.tap(key, "name", fn)to work correctly with rspack.