-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: exclude version ranges from federation #17425
base: main
Are you sure you want to change the base?
Conversation
Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 27.2.1 to 27.2.2. - [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases) - [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md) - [Commits](jest-community/eslint-plugin-jest@v27.2.1...v27.2.2) --- updated-dependencies: - dependency-name: eslint-plugin-jest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]>
Merge branch 'main' of github.com:tmpaul/webpack into feat/version-exclude
For maintainers only:
|
/** | ||
* Version of the package provided by the fallback if there is one. | ||
*/ | ||
fallbackVersion?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds a new property called fallbackVersion
, which is only exposed to ConsumeSharedPlugin
. It is not directly accessible to ModuleFederationPlugin
consumers. The value of this property is the truthy value of version
property passed to ModuleFederationPlugin
.
// Without a resolved import, we cannot proceed with exclusion check | ||
if (!importResolved) { | ||
return consumedModule; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we check if importResolved
can be mapped out. If there is no resolved import path for a request, we cannot decide whether to exclude it from sharing, so by default include
it.
config.exclusionCriteria.fallbackVersion | ||
) | ||
) { | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user has supplied a version
property to ModuleFed plugin, use that to check against the exclusionCriteria.version
range
// not exist in the package.json file, then we use the "version" property | ||
// set by users in the share config, which is passed here as fallbackVersion | ||
// a.k.a the version used to register the package in the scope. | ||
getDescriptionFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find the closest package.json
for the resolved import. This gives us the version of the package/module that corresponds to the request. Note that there are shared modules that do not have a corresponding package.json
file, and for these, we do not exclude them from sharing unless the user supplies a version
property. If that is the case, the check in line 269 will activate
!data || | ||
(data && !data.version) || | ||
(data && data.name !== request) | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that the package.json
name matches the requested module. Otherwise it can resolve to the root package.json
of the project.
...options.exclusionCriteria, | ||
fallbackVersion: options.version ? options.version : undefined | ||
} | ||
: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass in version
as fallbackVersion
to exclusionCriteria. As far a consumed module is concerned, the version
property represents the version of the fallback
.
Merge branch 'main' of github.com:tmpaul/webpack into feat/version-exclude
@alexander-akait Friendly bump |
@tmpaul Sorry for long delay (long store), is it still valid? |
@alexander-akait Yes. Due to the time gap, I assumed that it would not be reviewed. I have merged the latest changes. Please take a look when you can |
@ScriptedAlchemy Hello, what do you think about this PR? |
Summary
🤖 Generated by Copilot at 4a3cc04
No summary available (Limit exceeded: required to process 50446 tokens, but only 50000 are allowed per call)
Details
🤖 Generated by Copilot at 4a3cc04
SharedExclusionCriteria
type and schema, which has aversion
property that represents a version or semver range of the dependency to exclude from sharing (link, link, link, link, link, link)exclusionCriteria
property to theSharedConfig
type and schema, which references theSharedExclusionCriteria
type and schema (link, link, link, link, link)exclusionCriteria
property to the config object and the item object for theConsumeSharedPlugin
and theProvideSharedPlugin
(link, link, link, link, link, link)fallbackVersion
property to theexclusionCriteria
property for theConsumeSharedPlugin
, which is set to theversion
property of the config object if it exists (link, link)path
,semver
, andutils
modules as dependencies for theConsumeSharedPlugin
and theProvideSharedPlugin
(link, link, link, link, link)validateShareOptions
function to theutils
module, which performs additional validation logic for the share options and throws an error if any of the options have bothexclusionCriteria
andsingleton
set to true (link)exclusionCriteria
property to theConsumeSharedFallbackDependency
class, which holds the criteria used to exclude modules or version ranges from sharing for the dependency (link)consumedModule
, which is an instance of theConsumeSharedModule
class, representing a module that consumes a shared module (link)exclusionCriteria
is provided for theconsumedModule
, and if so, performs a check against the resolved import and the fallback version to determine if the consumption should be excluded (link)exclusionCriteria
is provided for the shared module in theProvideSharedPlugin
, and if so, performs a check against the version of the module using thesatisfy
andparseRange
functions from thesemver
module (link)validateShareOptions
function in theSharePlugin
, passing thesharedOptions
array, which contains the options for each shared module (link)ModuleFederationPlugin
, theConsumeSharedPlugin
, theProvideSharedPlugin
, and theSharePlugin
to reflect the changes in the JSON schema files (link, link, link, link)test/configCases/container/container-exclude-sharing
to test the feature with theModuleFederationPlugin
(link, link, link, link)test/configCases/sharing/consume-module
to test the feature with theSharePlugin
(link, link)First PR based on the discussion here: #17404 (comment)
New property
exclusionCriteria
This new property is a object that in the current PR accepts a version range object using the
version
property.The following logic is used for excluding a module/package from sharing
ProvideSharedPlugin
exclusionCriteria.version
is defined.version
is defined. Ifversion
is not provided, attempt to find version from closestpackage.json
.ConsumeSharedPlugin
This plugin is more involved since there is no "inherent" version, but there is only
requiredVersion
. While it is possible to do range intersection ofrequiredVersion
andexclusionCriteria.version
, the current semver util lib in webpack makes this difficult to do. Instead, we pass theversion
property from ModuleFederationPlugin asexclusionCriteria.fallbackVersion
, and use that version to check. If this property is missing, use the nearestpackage.json
file corresponding to the resolved import.If neither conditions match, it will be shared.
I've added inline comments to the PR to explain what I'm doing. Open to feedback/suggestions, thank you.