extend more hooks to include import attributes and add warnings#5700
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#feat/different-import-attributesNotice: 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: |
Performance report
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
In |
|
Yeah, I think it can be included in the |
lukastaegert
left a comment
There was a problem hiding this comment.
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.
Yeah, I’ll update the website after adding |
62cb213 to
f026169
Compare
bc9900b to
1652147
Compare
1652147 to
8e51d95
Compare
8e51d95 to
196d1e1
Compare
|
Is there anything holding this back? |
5369863 to
96b5453
Compare
196d1e1 to
05a379f
Compare
There was a problem hiding this comment.
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, andrenderDynamicImporthooks to include import attribute information - Added
importerAttributesparameter toresolveIdandresolveDynamicImporthooks to pass the import attributes of the importing module - Added deprecation warnings when
attributesare returned fromloadortransformhooks withstrictDeprecationsenabled - Removed
attributesfield fromSourceDescriptionreturn 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 |
…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.
300a3a5 to
72f0f92
Compare
lukastaegert
left a comment
There was a problem hiding this comment.
Sorry for ignoring this for far too long. This weekend I did another review. There are some small things I changed:
- I also added
attributesfields for the current module toresolveFileUrlandresolveImportMeta - 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
skipLibCheckin 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
loadandtransformhook as optional even though they are always present. - Added a fake optional
ssrattribute to options. Otherwise, the TypeScript compiler would complain that the existing Vite options had nothin in common with the Rollup options.
- Marked the provided "options" in the
In general, I would like to merge this the next days in order to get the Rollup 5 release going soon.
|
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 |
|
Glad you are on board!
As there has been no other word, I think we should just implement it that way, yes.
Please do so! |
|
This PR has been released as part of [email protected]. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
#5694
Description
Add the missing import attributes for the hooks
load,transformandrenderDynamicImport. For the upcoming breaking changes for complete resolving #5694, add a warning when returning attributes fromloadortransformwithstrictDeprecationsenabled.cc @sapphi-red , It would be appreciated to get your feedback on whether the API extensions are satisfactory for you.