-
-
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?
Changes from 1 commit
f097be1
3c6910d
84a3fc3
b684b01
c398bb5
ad0657b
1477416
4a27246
aec247b
43ec503
15399c6
563c6ac
831094e
213b01b
91309bf
c6767ff
d20a11f
b62b334
2046031
b5daf64
f0b3556
e299975
90472f8
babf240
8d31b66
dd75c40
417fea9
30ae157
fbaafa7
f90cc6e
6cd441a
82fcfb2
85858f6
c2019c3
c268246
0236599
02e93e9
034a8eb
65313c6
a9f661a
dfa531c
487ba3e
cbd3c88
8429fad
ac68a79
683bb8f
4a3cc04
9735e40
6be2a1a
35f67c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 4,7 @@ | |
*/ | ||
|
||
"use strict"; | ||
|
||
const path = require("path"); | ||
const ModuleNotFoundError = require("../ModuleNotFoundError"); | ||
const RuntimeGlobals = require("../RuntimeGlobals"); | ||
|
@@ -255,28 256,45 @@ class ConsumeSharedPlugin { | |
requiredVersion | ||
} | ||
); | ||
// Check if exclusion criteria is provided | ||
if (config.exclusionCriteria && config.exclusionCriteria.version) { | ||
const exclusionCriteriaWarning = details => { | ||
const error = new WebpackError( | ||
`Error while attempting to decide exclusion criteria with version: ${config.exclusionCriteria.version}. ${details}` | ||
); | ||
error.file = `shared module ${request}`; | ||
compilation.warnings.push(error); | ||
}; | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Here, we check if |
||
// If a fallback version is provided by the user, use that to check | ||
if (config.exclusionCriteria.fallbackVersion) { | ||
if ( | ||
satisfy( | ||
parseRange(config.exclusionCriteria.version), | ||
config.exclusionCriteria.fallbackVersion | ||
) | ||
) { | ||
return undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If user has supplied a |
||
} | ||
return consumedModule; | ||
} | ||
return new Promise(resolve => { | ||
// Get the closest package.json file corresponding to the resolved import. | ||
// This version will be used for checking whether the dependency must be | ||
// excluded from consumption (in a share context). If such a version does | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Find the closest |
||
compilation.inputFileSystem, | ||
path.dirname(importResolved), | ||
["package.json"], | ||
(err, result) => { | ||
if (err) { | ||
console.error(err); | ||
return resolve(consumedModule); | ||
} | ||
const { data } = result; | ||
if (!data) { | ||
exclusionCriteriaWarning( | ||
`Unable to find description file in ${importResolved}.` | ||
); | ||
if ( | ||
!data || | ||
(data && !data.version) || | ||
(data && data.name !== request) | ||
) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check that the |
||
// If we cannot determine exclusion, return the consumed module | ||
return resolve(consumedModule); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 8,7 @@ | |
const { parseOptions } = require("../container/options"); | ||
const ConsumeSharedPlugin = require("./ConsumeSharedPlugin"); | ||
const ProvideSharedPlugin = require("./ProvideSharedPlugin"); | ||
const { isRequiredVersion } = require("./utils"); | ||
const { isRequiredVersion, validateShareOptions } = require("./utils"); | ||
|
||
/** @typedef {import("../../declarations/plugins/sharing/ConsumeSharedPlugin").ConsumeSharedPluginOptions} ConsumeSharedPluginOptions */ | ||
/** @typedef {import("../../declarations/plugins/sharing/ConsumeSharedPlugin").ConsumesConfig} ConsumesConfig */ | ||
|
@@ -43,13 43,19 @@ class SharePlugin { | |
}, | ||
item => item | ||
); | ||
validateShareOptions(sharedOptions); | ||
/** @type {Record<string, ConsumesConfig>[]} */ | ||
const consumes = sharedOptions.map(([key, options]) => ({ | ||
[key]: { | ||
import: options.import, | ||
shareKey: options.shareKey || key, | ||
shareScope: options.shareScope, | ||
exclusionCriteria: options.exclusionCriteria, | ||
exclusionCriteria: options.exclusionCriteria | ||
? { | ||
...options.exclusionCriteria, | ||
fallbackVersion: options.version ? options.version : undefined | ||
} | ||
: undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass in |
||
requiredVersion: options.requiredVersion, | ||
strictVersion: options.strictVersion, | ||
singleton: options.singleton, | ||
|
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 toConsumeSharedPlugin
. It is not directly accessible toModuleFederationPlugin
consumers. The value of this property is the truthy value ofversion
property passed toModuleFederationPlugin
.