Skip to content

Commit 365831f

Browse files
authored
fix: support multiple plugin-config versions (#78)
1 parent e17b491 commit 365831f

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "attach",
10+
"name": "Attach",
11+
"port": 9229,
12+
"skipFiles": ["<node_internals>/**"]
13+
},
14+
]
15+
}

src/testkit.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as fg from 'fast-glob';
1414
import { exec, find, mv, rm, which } from 'shelljs';
1515
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
1616
import { AsyncCreatable, Env, set, parseJsonMap } from '@salesforce/kit';
17-
import { AnyJson, Dictionary, ensureString, get, JsonMap, Nullable } from '@salesforce/ts-types';
17+
import { AnyJson, Dictionary, ensureString, JsonMap, Nullable } from '@salesforce/ts-types';
1818
import { AuthInfo, SfdxPropertyKeys, Connection, NamedPackageDir, SfdxProject } from '@salesforce/core';
1919
import { debug, Debugger } from 'debug';
2020
import { MetadataResolver } from '@salesforce/source-deploy-retrieve';
@@ -382,7 +382,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
382382
}
383383

384384
/**
385-
* Returns true if the executable being used belongs to a local pacakage
385+
* Returns true if the executable being used belongs to a local package
386386
*/
387387
public isLocalExecutable(): boolean {
388388
return (
@@ -537,11 +537,17 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
537537
}
538538

539539
private async getDefaultUsername(): Promise<string> {
540-
const configVar = this.executableName === Executable.SF ? 'target-org' : SfdxPropertyKeys.DEFAULT_USERNAME;
541-
const configResult = execCmd(`config:get ${configVar} --json`).jsonOutput!;
542-
const results = get(configResult, 'result', configResult) as Array<{ key?: string; name?: string; value: string }>;
543-
const username = results.find((r) => r.key === configVar || r.name === configVar)!.value;
544-
return username;
540+
const configVar = 'target-org';
541+
const configResult = execCmd<Array<{ key?: string; name?: string; value: string }>>(
542+
`config:get ${configVar} --json`
543+
).jsonOutput?.result;
544+
// depending on which version of config:get the user has available, there may be a name or key
545+
// eventually, drop the `key` option and the deprecated SfdxPropertyKeys
546+
const possibleKeys = [configVar, SfdxPropertyKeys.DEFAULT_USERNAME];
547+
const username = configResult?.find(
548+
(r) => (r.key && possibleKeys.includes(r.key)) || (r.name && possibleKeys.includes(r.name))
549+
)?.value;
550+
return username!;
545551
}
546552

547553
private async createConnection(): Promise<Nullable<Connection>> {

0 commit comments

Comments
 (0)