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

Allow shouldTransformCachedModule to return null #4932

Merged
merged 3 commits into from Apr 11, 2023
Merged

Allow shouldTransformCachedModule to return null #4932

merged 3 commits into from Apr 11, 2023

Conversation

bluwy
Copy link
Contributor

@bluwy bluwy commented Apr 9, 2023

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Allow shouldTransformCachedModule to return null. The hook uses the hookFirst approach, which only delegates other plugins if the return value is null.

// chains, first non-null result stops and returns result and last plugin
async hookFirstAndGetPlugin<H extends AsyncPluginHooks & FirstPluginHooks>(
hookName: H,
parameters: Parameters<FunctionPluginHooks[H]>,
replaceContext?: ReplaceContext | null,
skipped?: ReadonlySet<Plugin> | null
): Promise<[NonNullable<ReturnType<FunctionPluginHooks[H]>>, Plugin] | null> {
for (const plugin of this.getSortedPlugins(hookName)) {
if (skipped?.has(plugin)) continue;
const result = await this.runHook(hookName, parameters, plugin, replaceContext);
if (result != null) return [result, plugin];
}
return null;
}

Since the types only restricts returning a boolean, it makes it that the first plugin that implements this will take precedence over everything. Allowing to return null should fix this.

Perhaps there could be discussion if this was intentional.

@vercel
Copy link

vercel bot commented Apr 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2023 8:00pm

@codecov
Copy link

codecov bot commented Apr 9, 2023

Codecov Report

Merging #4932 (ea8f249) into master (6868eb4) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #4932   +/-   ##
=======================================
  Coverage   99.01%   99.01%           
=======================================
  Files         221      221           
  Lines        8052     8052           
  Branches     2216     2216           
=======================================
  Hits         7973     7973           
  Misses         26       26           
  Partials       53       53           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Good catch!

@lukastaegert lukastaegert enabled auto-merge (squash) April 11, 2023 19:54
@lukastaegert lukastaegert merged commit c4cb264 into rollup:master Apr 11, 2023
16 checks passed
@bluwy bluwy deleted the shouldTransformCachedModule-null branch April 12, 2023 02:01
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.20.3-0. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.20.3-0 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.20.3. You can test it via npm install rollup.

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

Successfully merging this pull request may close these issues.

None yet

3 participants