Skip to content

Allow shouldTransformCachedModule to return null#4932

Merged
lukastaegert merged 3 commits intorollup:masterfrom
bluwy:shouldTransformCachedModule-null
Apr 11, 2023
Merged

Allow shouldTransformCachedModule to return null#4932
lukastaegert merged 3 commits intorollup:masterfrom
bluwy:shouldTransformCachedModule-null

Conversation

@bluwy
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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
@bluwy bluwy deleted the shouldTransformCachedModule-null branch April 12, 2023 02:01
@rollup-bot
Copy link
Copy Markdown
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
Copy Markdown
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.

3 participants