Skip to content

extend more hooks to include import attributes and add warnings#5700

Merged
lukastaegert merged 9 commits into
masterfrom
feat/different-import-attributes
Jan 27, 2026
Merged

extend more hooks to include import attributes and add warnings#5700
lukastaegert merged 9 commits into
masterfrom
feat/different-import-attributes

Conversation

@TrickyPi

Copy link
Copy Markdown
Member

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:
#5694

Description

Add the missing import attributes for the hooks load, transform and renderDynamicImport. For the upcoming breaking changes for complete resolving #5694, add a warning when returning attributes from load or transform with strictDeprecations enabled.
cc @sapphi-red , It would be appreciated to get your feedback on whether the API extensions are satisfactory for you.

@vercel

vercel Bot commented Oct 24, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
rollup Ready Ready Preview, Comment Jan 26, 2026 5:27am

Request Review

@github-actions

github-actions Bot commented Oct 24, 2024

Copy link
Copy Markdown

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#feat/different-import-attributes

Notice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust.

or load it into the REPL:
https://rollup-kypahsyxn-rollup-js.vercel.app/repl/?pr=5700

@github-actions

github-actions Bot commented Oct 24, 2024

Copy link
Copy Markdown

Performance report

  • BUILD: 6974ms, 836 MB
    • initialize: 0ms, 24.6 MB (+7%)
    • generate module graph: 2629ms, 634 MB
      • generate ast: 1386ms, 626 MB
    • sort and bind modules: 412ms, 692 MB
    • mark included statements: 3938ms, 836 MB
      • treeshaking pass 1: 2283ms, 832 MB
      • treeshaking pass 2: 467ms, 853 MB
      • treeshaking pass 3: 403ms, 834 MB
      • treeshaking pass 4: 388ms, 861 MB
      • treeshaking pass 5: 386ms, 836 MB
  • GENERATE: 697ms, 938 MB
    • initialize render: 0ms, 836 MB
    • generate chunks: 41ms, 852 MB
      • optimize chunks: 0ms, 844 MB
    • render chunks: 638ms, 911 MB
    • transform chunks: 17ms, 938 MB
    • generate bundle: 0ms, 938 MB

@codecov

codecov Bot commented Oct 24, 2024

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.83%. Comparing base (c519d82) to head (1697459).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5700   +/-   ##
=======================================
  Coverage   98.83%   98.83%           
=======================================
  Files         273      273           
  Lines       10692    10700    +8     
  Branches     2849     2854    +5     
=======================================
+ Hits        10567    10575    +8     
  Misses         82       82           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/rollup/types.d.ts Outdated
Comment thread src/rollup/types.d.ts
@lukastaegert

Copy link
Copy Markdown
Member

In ResolveIdHook, do we also want to add importerAttributes separately?

@TrickyPi

TrickyPi commented Oct 27, 2024

Copy link
Copy Markdown
Member Author

Yeah, I think it can be included in the options parameter, just like attributes.

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking through the code besides adding importerAttributes to ResolveIdHook, the only thing missing to release this from my side is to adapt the types on the website.

Comment thread test/function/samples/warn-for-load-and-transform/_config.js Outdated
@TrickyPi

Copy link
Copy Markdown
Member Author

the only thing missing to release this from my side is to adapt the types on the website

Yeah, I’ll update the website after adding importerAttributes.

Comment thread docs/plugin-development/index.md Outdated
Comment thread docs/plugin-development/index.md Outdated
Comment thread docs/plugin-development/index.md Outdated
Comment thread docs/plugin-development/index.md Outdated
Comment thread docs/plugin-development/index.md Outdated
Comment thread docs/plugin-development/index.md Outdated
@jogibear9988

Copy link
Copy Markdown

Is there anything holding this back?
I use json and css imports in all of my projects, and would really love to see a bundler support them.

@lukastaegert lukastaegert force-pushed the master branch 2 times, most recently from 5369863 to 96b5453 Compare November 7, 2025 21:32
Copilot AI review requested due to automatic review settings January 25, 2026 06:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the plugin API to include import attributes in the load, transform, and renderDynamicImport hooks, and adds deprecation warnings when plugins return attributes from load or transform hooks. This is part of the work towards supporting multiple modules with the same ID but different import attributes (#5694).

Changes:

  • Extended load, transform, shouldTransformCachedModule, resolveId, resolveDynamicImport, and renderDynamicImport hooks to include import attribute information
  • Added importerAttributes parameter to resolveId and resolveDynamicImport hooks to pass the import attributes of the importing module
  • Added deprecation warnings when attributes are returned from load or transform hooks with strictDeprecations enabled
  • Removed attributes field from SourceDescription return type in documentation (now passed as input parameter instead)

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/rollup/types.d.ts Updated type definitions for hooks to include attributes and importerAttributes parameters
src/utils/transform.ts Added attributes parameter to transform hook and deprecation warning for returning attributes
src/ModuleLoader.ts Extended load hook with attributes parameter, added deprecation warning, and threaded importerAttributes through resolution
src/utils/resolveIdViaPlugins.ts Added importerAttributes parameter to resolveId plugin calls
src/utils/resolveId.ts Threaded importerAttributes through resolveId function
src/utils/PluginContext.ts Added importerAttributes to this.resolve context function
src/ast/nodes/ImportExpression.ts Added targetModuleAttributes to renderDynamicImport hook options
src/utils/urls.ts Added URL constants for load and transform hook documentation
test/function/samples/extend-more-hooks-to-include-import-attributes/* Test coverage for new hook parameters including attributes and importerAttributes
test/function/samples/deprecated/warn-for-load-and-transform/* Test for deprecation warnings when returning attributes from load/transform
test/incremental/index.js Updated test expectations to include attributes in shouldTransformCachedModule
docs/plugin-development/index.md Updated documentation for all affected hooks, removed attributes from SourceDescription return types

Comment thread src/ModuleLoader.ts Outdated
Comment thread src/utils/transform.ts Outdated
…icts

Also, we needed to add the ssr attribute in the handlers that did not yet have
options at all.
The expectation is to revert this for Rollup 5.

Luckily, we removed skipLibCheck at last to detect those.

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for ignoring this for far too long. This weekend I did another review. There are some small things I changed:

  • I also added attributes fields for the current module to resolveFileUrl and resolveImportMeta
  • There is now a small dedicated section about import attributes in the docs. Not sure we want to keep it, but the AI suggested it and it did not feel completely bananas. I needed to slightly rework its examples, though.
  • Recently, I did some changes to get rid of skipLibCheck in the TypeScript config. As we now also have Vite and Vitepress as dependencies, this highlighted some type conflicts with the Vite types. In order to avoid friction, I did some temporary changes to the types that I hope we can revert again for Rollup 5:
    • Marked the provided "options" in the load and transform hook as optional even though they are always present.
    • Added a fake optional ssr attribute to options. Otherwise, the TypeScript compiler would complain that the existing Vite options had nothin in common with the Rollup options.

In general, I would like to merge this the next days in order to get the Rollup 5 release going soon.

@TrickyPi

TrickyPi commented Jan 27, 2026

Copy link
Copy Markdown
Member Author

Super excited that the Rollup 5 release is getting close!

Lukas, just to confirm — the implementation for supporting different import attributes follows the approach described in #5694 (comment), correct? If so, I’ll continue with the follow-up implementation once this PR is merged.

I’ve also submitted an MR to merge feat/use-with-by-default. As for feat/use-base36, my suggestion would be to land it last to minimize merge conflicts with master during the Rollup 5 release cycle.

@lukastaegert

Copy link
Copy Markdown
Member

Glad you are on board!

follows the approach described in #5694 (comment),

As there has been no other word, I think we should just implement it that way, yes.

I’ll continue with the follow-up implementation once this PR is merged

Please do so!

@lukastaegert lukastaegert added this pull request to the merge queue Jan 27, 2026
Merged via the queue into master with commit 74121c7 Jan 27, 2026
48 checks passed
@lukastaegert lukastaegert deleted the feat/different-import-attributes branch January 27, 2026 05:21
@github-actions

Copy link
Copy Markdown

This PR has been released as part of [email protected]. 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.

5 participants