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
Open
samarthsinh2660 wants to merge6 commits intowebpack:mainChoose a base branch fromsamarthsinh2660:feat/loader-import-attributes
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+51 −3
Open
Changes from1 commit
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
ba2c0ba feat: expose importAttributes to loaders via _importAttributes
samarthsinh2660f7731f5 chore: update generated types.d.ts
samarthsinh26609e3eaa7 fix: add _importAttributes to NormalModuleLoaderContext in types.d.ts
samarthsinh2660e15bea9 fix lint error
samarthsinh26602aa6267 fix: add serialization/deserialization for importAttributes
samarthsinh26607ce0722 refactor: address author feedback - rename _importAttributes to impor…
samarthsinh2660File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
feat: expose importAttributes to loaders via _importAttributes
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commitba2c0bab62a76d84ec8c35d4d25ccad84f199302
There are no files selected for viewing
1 change: 1 addition & 0 deletionsdeclarations/LoaderContext.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -63,6 +63,7 @@ export interface NormalModuleLoaderContext<OptionsType> { | ||
| _module?: NormalModule; | ||
| _compilation?: Compilation; | ||
| _compiler?: Compiler; | ||
| _importAttributes?: Record<string, unknown>; | ||
samarthsinh2660 marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| /** These properties are added by the HotModuleReplacementPlugin */ | ||
10 changes: 8 additions & 2 deletionslib/NormalModule.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -97,6 +97,7 @@ const memoize = require("./util/memoize"); | ||
| /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ | ||
| /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */ | ||
| /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */ | ||
| /** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */ | ||
| /** | ||
| * @template T | ||
| * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook | ||
| @@ -256,6 +257,7 @@ makeSerializable( | ||
| * @property {GeneratorOptions=} generatorOptions the options of the generator used | ||
| * @property {ResolveOptions=} resolveOptions options used for resolving requests from this module | ||
| * @property {boolean} extractSourceMap enable/disable extracting source map | ||
| * @property {ImportAttributes=} importAttributes import attributes from the import statement | ||
| */ | ||
| /** | ||
| @@ -348,7 +350,8 @@ class NormalModule extends Module { | ||
| generator, | ||
| generatorOptions, | ||
| resolveOptions, | ||
| extractSourceMap, | ||
| importAttributes | ||
| }) { | ||
| super(type, context || getContext(resource), layer); | ||
| @@ -384,6 +387,8 @@ class NormalModule extends Module { | ||
| } | ||
| /** @type {NormalModuleCreateData['extractSourceMap']} */ | ||
| this.extractSourceMap = extractSourceMap; | ||
| /** @type {NormalModuleCreateData['importAttributes']} */ | ||
| this.importAttributes = importAttributes; | ||
samarthsinh2660 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| // Info from Build | ||
| /** @type {WebpackError | null} */ | ||
| @@ -836,7 +841,8 @@ class NormalModule extends Module { | ||
| _module: this, | ||
| _compilation: compilation, | ||
| _compiler: compilation.compiler, | ||
| fs, | ||
| _importAttributes: this.importAttributes | ||
| }; | ||
| Object.assign(loaderContext, options.loader); | ||
3 changes: 2 additions & 1 deletionlib/NormalModuleFactory.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionstest/configCases/loaders/import-attributes-loader-context/data.data.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // This file will be processed by the loader | ||
| // The content doesn't matter - the loader will replace it with the import attributes |
1 change: 1 addition & 0 deletionstest/configCases/loaders/import-attributes-loader-context/data2.data.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // This file will be processed by the loader without import attributes |
10 changes: 10 additions & 0 deletionstest/configCases/loaders/import-attributes-loader-context/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import attributesWithType from "./data.data.js" with { type: "custom", preload: "true" }; | ||
| import attributesEmpty from "./data2.data.js"; | ||
| it("should expose import attributes to loaders via _importAttributes", function() { | ||
| expect(attributesWithType).toEqual({ type: "custom", preload: "true" }); | ||
| }); | ||
| it("should return undefined when no import attributes are present", function() { | ||
| expect(attributesEmpty).toBeUndefined(); | ||
| }); |
5 changes: 5 additions & 0 deletionstest/configCases/loaders/import-attributes-loader-context/loader.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /**@type {import("../../../../").LoaderDefinition} */ | ||
| module.exports=function(source){ | ||
| constattributes=this._importAttributes; | ||
| return`module.exports =${JSON.stringify(attributes)};`; | ||
| }; |
13 changes: 13 additions & 0 deletionstest/configCases/loaders/import-attributes-loader-context/webpack.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| "use strict"; | ||
| /** @type {import("../../../../").Configuration} */ | ||
| module.exports = { | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.data\.js$/, | ||
| loader: require.resolve("./loader.js") | ||
| } | ||
| ] | ||
| } | ||
| }; |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.