Skip to content

Commit

Permalink
modified location testing type to be a function
Browse files Browse the repository at this point in the history
Signed-off-by: jace-roell <[email protected]>
  • Loading branch information
jace-roell committed Jul 10, 2024
1 parent 60240e2 commit 1ed51d7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,23 +397,6 @@ describe("Plugin Management Facility install handler", () => {

expect(mocks.install).toHaveBeenCalledWith("@public/sample1","publicRegistryUrl");
});
it("should handle installed plugins via private scope", async () => {
const handler = new InstallHandler();

const params = getIHandlerParametersObject();
params.arguments.plugin = ["@private/sample1"];

mocks.getScopeRegistry.mockReturnValueOnce("privateRegistryUrl" as any);

try{
await handler.process(params);
}
catch(e){
expect(e).toBeUndefined();
}

expect(mocks.install).toHaveBeenCalledWith("@private/sample1","privateRegistryUrl");
});
it("should handle installed plugins via project/directory", async () => {
const handler = new InstallHandler();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

import { ICommandHandler, IHandlerParameters } from "../../../../../cmd";
import { Logger } from "../../../../../logger/";
Expand Down Expand Up @@ -72,6 +72,29 @@ import { IO } from "../../../../../io";
*
* @throws {ImperativeError}
*/

private locationTypeTest(plugin: string){
let isDirTest: boolean;
let installRegistry = getRegistry();
try {
isDirTest = IO.isDir(plugin);
} catch (e) {
isDirTest = false;
}

if (plugin.startsWith("@")) {
installRegistry = getScopeRegistry(
plugin.split("/")[0].substring(1)
).replace("\n", "");
} else if (
plugin.substring(plugin.lastIndexOf(".") + 1) === "tgz" ||
isDirTest
) {
installRegistry = plugin;
}
return installRegistry;
}

public async process(params: IHandlerParameters): Promise<void> {
const chalk = TextUtils.chalk;
this.console.debug(
Expand All @@ -93,7 +116,9 @@ import { IO } from "../../../../../io";
});
} else {
try {
let installRegistry = params.arguments.registry ?? getRegistry().replace("\n", "");
let installRegistry =
params.arguments.registry ??
getRegistry().replace("\n", "");

// This section determines which npm logic needs to take place
if (
Expand Down Expand Up @@ -138,26 +163,7 @@ import { IO } from "../../../../../io";
packageInfo.location = installRegistry;
}

let isDirTest: boolean;

try{
isDirTest = IO.isDir(packageInfo.package);
}
catch(e){
isDirTest = false;
}

if (packageInfo.package.startsWith("@")) {
installRegistry = getScopeRegistry(
packageInfo.package.split("/")[0].substring(1)
).replace("\n", "");
} else if (
packageInfo.package.substring(packageInfo.package.lastIndexOf(".") + 1) ===
"tgz" ||
isDirTest
) {
installRegistry = packageInfo.package;
}
installRegistry = this.locationTypeTest(packageInfo.location);

this.console.debug(
`Installing plugin: ${packageName}`
Expand Down Expand Up @@ -212,27 +218,7 @@ import { IO } from "../../../../../io";
for (const plugin of params.arguments.plugin ?? []) {
// Get the registry to install to
if (typeof params.arguments.registry === "undefined") {

let isDirTest: boolean;

try{
isDirTest = IO.isDir(plugin);
}
catch(e){
isDirTest = false;
}

if (plugin.startsWith("@")) {
installRegistry = getScopeRegistry(
plugin.split("/")[0].substring(1)
).replace("\n", "");
} else if (
plugin.substring(plugin.lastIndexOf(".") + 1) ===
"tgz" ||
isDirTest
) {
installRegistry = plugin;
}
installRegistry = this.locationTypeTest(plugin);
} else {
installRegistry = params.arguments.registry;
if (params.arguments.login) {
Expand Down

0 comments on commit 1ed51d7

Please sign in to comment.