Skip to content

Commit

Permalink
Merge pull request #2067 from zowe/fix/peer-dep-check
Browse files Browse the repository at this point in the history
Fix plug-in peerDep check
  • Loading branch information
zFernand0 authored Mar 6, 2024
2 parents 3c342af + 2e1d2d0 commit 9334d66
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the Imperative package will be documented in this file.
## Recent Changes

- V3 Breaking: Changed prompting logic to prompt for port if port provided is 0 [#2075](https://github.com/zowe/zowe-cli/issues/2075)
- BugFix: Fixed issue with peerDep warnings showing when a plug-in is installed and the version ranges satisfy the semver requirements. [#2067](https://github.com/zowe/zowe-cli/pull/2067)

## `8.0.0-next.202403041352`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ describe("Plugin Management Facility", () => {
describe("comparePluginVersionToCli function", () => {
beforeEach(() => {
PMF.currPluginName = pluginName;
PMF.semver.intersects = jest.fn();
PMF.semver.satisfies = jest.fn();

// impCfg.getCliCmdName is a getter of a property, so mock the property
Object.defineProperty(impCfg, "cliCmdName", {
Expand All @@ -1914,15 +1914,15 @@ describe("Plugin Management Facility", () => {
});

it("should record no issue when version is compatible", () => {
PMF.semver.intersects.mockReturnValueOnce(true);
PMF.semver.satisfies.mockReturnValueOnce(true);

PMF.comparePluginVersionToCli(pluginName, "pluginVerVal", "cliVerPropNm", "CliVerVal");

expect(pluginIssues.getIssueListForPlugin(pluginName).length).toBe(0);
});

it("should record issue when exception threw by semver", () => {
PMF.semver.intersects.mockImplementationOnce(() => {
PMF.semver.satisfies.mockImplementationOnce(() => {
throw new Error("dummy error");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,42 +520,36 @@ export class PluginManagementFacility {
* Compare the version of a plugin version property with a version property
* of its base CLI.
*
* If the versions do not intersect (according so semver rules), then a
* PluginIssue is recorded.
* If the versions do not satisfy the semver rules, then a PluginIssue is recorded.
*
* @param pluginName - The name of the plugin.
*
* @param pluginVerPropNm - The name of the plugin property containing a version.
*
* @param pluginVerVal - value of the plugin's version.
*
* @param pluginVerRange - value of the plugin's version.
* @param cliVerPropNm - The name of the base CLI property containing a version.
*
* @param cliVerVal - value of the base CLI's version.
*
* @param cliVerValue - value of the base CLI's version.
*/
private comparePluginVersionToCli(
pluginName: string,
pluginVerPropNm: string,
pluginVerVal: string,
pluginVerRange: string,
cliVerPropNm: string,
cliVerVal: string
cliVerValue: string
): void {
const cliCmdName = ImperativeConfig.instance.rootCommandName;
try {
if (!this.semver.intersects(cliVerVal, pluginVerVal, false)) {
if (!this.semver.satisfies(cliVerValue, pluginVerRange)) {
this.pluginIssues.recordIssue(pluginName, IssueSeverity.WARNING,
"The version value (" + pluginVerVal + ") of the plugin's '" +
"The version value (" + pluginVerRange + ") of the plugin's '" +
pluginVerPropNm + "' property is incompatible with the version value (" +
cliVerVal + ") of the " + cliCmdName + " command's '" +
cliVerValue + ") of the " + cliCmdName + " command's '" +
cliVerPropNm + "' property."
);
}
} catch (semverExcept) {
PluginIssues.instance.recordIssue(pluginName, IssueSeverity.WARNING,
"Failed to compare the version value (" +
pluginVerVal + ") of the plugin's '" + pluginVerPropNm +
"' property with the version value (" + cliVerVal +
pluginVerRange + ") of the plugin's '" + pluginVerPropNm +
"' property with the version value (" + cliVerValue +
") of the " + cliCmdName + " command's '" + cliVerPropNm + "' property.\n" +
"This can occur when one of the specified values is not a valid version string.\n" +
"Reported reason = " + semverExcept.message
Expand Down Expand Up @@ -936,8 +930,8 @@ export class PluginManagementFacility {
* with those specified in the host CLI.
*
* Both range strings come from the package.json files of the plugin and the
* hosting CLI. We consider the version ranges to be compatible if the two
* ranges intersect. This should allow npm to download one common version
* hosting CLI. We consider the version ranges to be compatible if they satisfy
* the CLI version range. This should allow npm to download one common version
* of core and of imperative to be owned by the base CLI and shared by the plugin.
*
* Any errors are recorded in PluginIssues.
Expand Down

0 comments on commit 9334d66

Please sign in to comment.