Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into docs-default-profiles-zowe-config-set
Browse files Browse the repository at this point in the history
Signed-off-by: Amanda D'Errico <[email protected]>
  • Loading branch information
AmandaDErrico authored Aug 3, 2022
2 parents 4551f9c + 2ace4a5 commit 800ec9e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to the Imperative package will be documented in this file.

- Introduced examples for setting default profiles in `zowe config set` Examples section. [#1428](https://github.com/zowe/zowe-cli/issues/1428)

## `5.3.7`

- BugFix: Fixed error when installing plug-ins that do not define profiles. [#859](https://github.com/zowe/imperative/issues/859)

## `5.3.6`

- BugFix: Removed some extraneous dependencies. [#477](https://github.com/zowe/imperative/issues/477)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zowe/imperative",
"version": "5.3.6",
"version": "5.3.7",
"description": "framework for building configurable CLIs",
"author": "Zowe",
"license": "EPL-2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,7 @@ describe("Plugin Management Facility", () => {
PMF.currPluginName = "PluginWithConfigModule";

const moduleContent = PMF.requirePluginModuleCallback(PMF.currPluginName)(modulePath);
expect(moduleContent).toEqual({});
const issue = pluginIssues.getIssueListForPlugin(PMF.currPluginName)[0];
expect(issue.issueSev).toBe(IssueSeverity.CMD_ERROR);
expect(issue.issueText).toContain(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("PMF: Install Interface", () => {
mocks.resolve.mockReturnValue(packageName);
mocks.join.mockReturnValue("/fake/join/path");

mocks.ConfigurationLoader_load.mockReturnValue({ profiles: "fake" });
mocks.ConfigurationLoader_load.mockReturnValue({ profiles: ["fake"] });
});

/**
Expand All @@ -95,22 +95,27 @@ describe("PMF: Install Interface", () => {
* @param {string} expectedPackage The package that should be sent to npm install
* @param {string} expectedRegistry The registry that should be sent to npm install
*/
const wasNpmInstallCallValid = (expectedPackage: string, expectedRegistry: string) => {
const wasNpmInstallCallValid = (expectedPackage: string, expectedRegistry: string, updateSchema?: boolean) => {
expect(mocks.installPackages).toHaveBeenCalledWith(PMFConstants.instance.PLUGIN_INSTALL_LOCATION,
expectedRegistry, expectedPackage);
shouldUpdateSchema();
shouldUpdateSchema(updateSchema ?? true);
};

/**
* Validates that plugins install call updates the global schema.
*/
const shouldUpdateSchema = () => {
const shouldUpdateSchema = (shouldUpdate: boolean) => {
expect(mocks.PMF_requirePluginModuleCallback).toHaveBeenCalledTimes(1);
expect(mocks.ConfigurationLoader_load).toHaveBeenCalledTimes(1);
expect(mocks.UpdateImpConfig_addProfiles).toHaveBeenCalledTimes(1);

expect(mocks.ConfigSchema_updateSchema).toHaveBeenCalledTimes(1);
expect(mocks.ConfigSchema_updateSchema).toHaveBeenCalledWith({ layer: "global" });
if (shouldUpdate) {
expect(mocks.UpdateImpConfig_addProfiles).toHaveBeenCalledTimes(1);
expect(mocks.ConfigSchema_updateSchema).toHaveBeenCalledTimes(1);
expect(mocks.ConfigSchema_updateSchema).toHaveBeenCalledWith({ layer: "global" });
} else {
expect(mocks.UpdateImpConfig_addProfiles).not.toHaveBeenCalled();
expect(mocks.ConfigSchema_updateSchema).not.toHaveBeenCalled();
}
};

/**
Expand Down Expand Up @@ -218,6 +223,19 @@ describe("PMF: Install Interface", () => {
version: packageVersion
});
});

it("should install plugin that does not define profiles", async () => {
mocks.ConfigurationLoader_load.mockReturnValueOnce({});
await install(packageName, packageRegistry);

// Validate the install
wasNpmInstallCallValid(packageName, packageRegistry, false);
wasWriteFileSyncCallValid({}, packageName, {
package: packageName,
registry: packageRegistry,
version: packageVersion
});
});
});

describe("Advanced install", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class PluginManagementFacility {
pluginName + "' :\n" + pluginModuleRuntimePath + "\n" +
"Reason = " + requireError.message
);
return "{}";
return {};
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ export async function install(packageLocation: string, registry: string, install
// Update the Imperative Configuration to add the profiles introduced by the recently installed plugin
// This might be needed outside of PLUGIN_USING_CONFIG scenarios, but we haven't had issues with other APIs before
const requirerFunction = PluginManagementFacility.instance.requirePluginModuleCallback(packageInfo.name);
UpdateImpConfig.addProfiles(ConfigurationLoader.load(null, packageInfo, requirerFunction).profiles);

ConfigSchema.updateSchema({ layer: "global" });
const pluginImpConfig = ConfigurationLoader.load(null, packageInfo, requirerFunction);
if (Array.isArray(pluginImpConfig.profiles)) {
UpdateImpConfig.addProfiles(pluginImpConfig.profiles);
ConfigSchema.updateSchema({ layer: "global" });
}
}

iConsole.info("Plugin '" + packageName + "' successfully installed.");
Expand Down

0 comments on commit 800ec9e

Please sign in to comment.