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

Commit

Permalink
fix: Add secrets SDK as dev. dep, remove resolve helper
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Aug 2, 2023
1 parent 3e4b030 commit fff54a3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 36 deletions.
2 changes: 1 addition & 1 deletion __tests__/__integration__/imperative/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@zowe/imperative": "../../..",
"@zowe/secrets-for-zowe-sdk": "7.18.0-next.1"
"@zowe/secrets-for-zowe-sdk": "7.18.0-next.4"
},
"engines": {
"node": ">=8.0.0"
Expand Down
29 changes: 4 additions & 25 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"dependencies": {
"@types/yargs": "13.0.4",
"@zowe/perf-timing": "1.0.7",
"@zowe/secrets-for-zowe-sdk": "7.18.0-next.4",
"chalk": "2.4.2",
"cli-table3": "0.6.2",
"comment-json": "4.1.1",
Expand Down Expand Up @@ -92,7 +91,6 @@
"yargs": "15.3.1"
},
"devDependencies": {
"@napi-rs/cli": "^2.16.1",
"@types/cross-spawn": "^6.0.2",
"@types/diff": "^5.0.2",
"@types/find-up": "^2.1.1",
Expand All @@ -113,6 +111,7 @@
"@types/which": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"@zowe/secrets-for-zowe-sdk": "^7.18.0-next.4",
"ansi-colors": "^4.1.1",
"clear-require": "^2.0.0",
"concurrently": "^7.5.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/security/__tests__/DefaultCredentialManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("DefaultCredentialManager", () => {
const fakeCliPath = "/root/fakeCli";
const mainModule = process.mainModule;
process.mainModule = { filename: fakeCliPath } as any;
const pathResolveSpy = jest.spyOn(DefaultCredentialManager.prototype, "resolveDep").mockReturnValue(fakeCliPath);
const resolveSpy = jest.spyOn(path, "resolve").mockReturnValue(fakeCliPath);

// Force enter the try catch
Object.defineProperty(manager, "keytar", {
Expand All @@ -92,11 +92,11 @@ describe("DefaultCredentialManager", () => {
expect(privateManager.loadError).toBeInstanceOf(ImperativeError);
const error: Error = privateManager.loadError.causeErrors;
expect(error).toBeDefined();
expect(error.message).toContain("Cannot find module");
expect(error.message).toContain("Cannot resolve module");
expect(error.message).toContain(fakeCliPath);
} finally {
process.mainModule = mainModule;
pathResolveSpy.mockRestore();
resolveSpy.mockRestore();
}
});

Expand Down
6 changes: 1 addition & 5 deletions packages/security/src/DefaultCredentialManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ export class DefaultCredentialManager extends AbstractCredentialManager {
}
}

public resolveDep(name: string, opts?: { paths: string[] }) {
return require.resolve(name, opts);
}

/**
* Called by {@link CredentialManagerFactory.initialize} before the freeze of the object. This
* gives us a chance to load keytar into the class before we are locked down. If a load failure
Expand All @@ -128,7 +124,7 @@ export class DefaultCredentialManager extends AbstractCredentialManager {
requireOpts.paths = [process.mainModule.filename, ...require.resolve.paths("@zowe/secrets-for-zowe-sdk")];
}
// use helper function for require.resolve so it can be mocked in jest tests
const keytarPath = this.resolveDep("@zowe/secrets-for-zowe-sdk", requireOpts);
const keytarPath = require.resolve("@zowe/secrets-for-zowe-sdk", requireOpts);
Logger.getImperativeLogger().debug("Loading Keytar module from", keytarPath);
this.keytar = (await import(keytarPath)).keyring;
} catch (error) {
Expand Down

0 comments on commit fff54a3

Please sign in to comment.