Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.2k
feat: expose importAttributes to loaders via _importAttributes#20232
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 ourterms of service andprivacy 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?
feat: expose importAttributes to loaders via _importAttributes#20232
Conversation
changeset-botbot commentedDec 12, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
|
codspeed-hqbot commentedDec 12, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#20232 willnot alter performanceComparing Summary
Footnotes
|
snitin315 commentedDec 12, 2025
@samarthsinh2660 Could you please check the lint failure? |
samarthsinh2660 commentedDec 12, 2025
Thanks for the heads-up. |
aa878d8 to9e3eaa7Comparehai-x commentedDec 13, 2025
We also need to handle |
samarthsinh2660 commentedDec 13, 2025
okay i will do it |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
…tAttributes, revert generate-types-config.js
Summary
This PR exposes
importAttributesto the loader interface so loaders can react to metadata onimport/import()statements, as requested in#20228.Today, the parser already understands import attributes, and they are used for things like rule matching, but loaders cannot see them. This change threads the parsed
ImportAttributesfrom the dependency/resolve data into NormalModule and then into the loader context as_importAttributes, so loaders can read them viathis._importAttributes.High-level implementation:
importAttributesin thecreateDatapassed to NormalModule.importAttributeson NormalModule instances._importAttributes, following the pattern of other internal context fields like_module,_compilation, etc._importAttributes?: Record<string, unknown>.configCasestest case undertest/configCases/loaders/import-attributes-loader-context:this._importAttributesand exports it.undefinedis produced when no attributes are present.What kind of change does this PR introduce?
Feature.
It adds a new capability for loaders to inspect the import attributes of the module they are processing (via
_importAttributeson the loader context).Did you add tests for your changes?
Yes.
node node_modules/jest/bin/jest.js test/ConfigTestCases.basictest.js --no-coverage --runInBand --testNamePattern=import-attributes-loader-context--testNamePattern="loaders import-attributes"to ensure existing cases still pass.On my Windows environment, running the full Jest suite surfaces unrelated snapshot differences (absolute paths vs
<cwd>) and missing optional dependencies like@swc/core/esbuild, which appear to be environment-specific and not related to this change.Does this PR introduce a breaking change?
No.
_importAttributeson the loader context.If relevant, what needs to be documented once your changes are merged or what have you already documented?
_importAttributes(an object of import attributes when present, otherwiseundefined) for modules that were imported with attributes._importAttributes(e.g., treating assets differently whenwith { type: "image", preload: true }is used).undefined.