feat: expose importAttributes to loaders via _importAttributes#20232
feat: expose importAttributes to loaders via _importAttributes#20232samarthsinh2660 wants to merge 6 commits intowebpack:mainfrom
Conversation
|
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
|
|
@samarthsinh2660 Could you please check the lint failure? |
Thanks for the heads-up. |
aa878d8 to
9e3eaa7
Compare
|
We also need to handle |
okay i will do it |
7ce0722 to
a7bb93d
Compare
…tAttributes, revert generate-types-config.js
a7bb93d to
c5ad681
Compare
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.