Skip to content

Commit ce6f202

Browse files
authored
Merge pull request #5 from salesforcecli/sm/pr-feedback-as-pr
Sm/pr feedback as pr
2 parents 406d042 + 574140d commit ce6f202

File tree

7 files changed

+418
-355
lines changed

7 files changed

+418
-355
lines changed

.github/dependabot.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "npm"
4-
directory: "/"
3+
- package-ecosystem: 'npm'
4+
directory: '/'
55
schedule:
6-
interval: "weekly"
7-
day: "saturday"
8-
versioning-strategy: "increase"
6+
interval: 'weekly'
7+
day: 'saturday'
8+
versioning-strategy: 'increase'
99
labels:
10-
- "dependencies"
10+
- 'dependencies'
1111
open-pull-requests-limit: 5
1212
pull-request-branch-name:
13-
separator: "-"
13+
separator: '-'
1414
commit-message:
1515
# cause a release for non-dev-deps
1616
prefix: fix(deps)
1717
# no release for dev-deps
1818
prefix-development: chore(dev-deps)
1919
ignore:
20-
- dependency-name: "*"
21-
update-types: ["version-update:semver-major"]
20+
- dependency-name: '*'
21+
update-types: ['version-update:semver-major']

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@
1515
"@oclif/test": "^2.1.1",
1616
"@salesforce/cli-plugins-testkit": "^2.3.10",
1717
"@salesforce/dev-config": "^3.1.0",
18-
"@salesforce/dev-scripts": "^2.0.4",
18+
"@salesforce/dev-scripts": "^3.0.0",
1919
"@salesforce/kit": "^1.5.45",
2020
"@salesforce/plugin-command-reference": "^2.2.8",
2121
"@salesforce/prettier-config": "^0.0.2",
2222
"@salesforce/ts-sinon": "^1.3.21",
2323
"@salesforce/ts-types": "^1.5.20",
2424
"@types/fs-extra": "^9.0.13",
2525
"@types/shelljs": "^0.8.11",
26-
"@typescript-eslint/eslint-plugin": "^4.33.0",
27-
"@typescript-eslint/parser": "^4.33.0",
26+
"@typescript-eslint/eslint-plugin": "^5.33.0",
27+
"@typescript-eslint/parser": "^5.33.0",
2828
"chai": "^4.3.6",
29-
"eslint": "^7.32.0",
29+
"eslint": "^8.21.0",
3030
"eslint-config-prettier": "^8.5.0",
31-
"eslint-config-salesforce": "^0.1.6",
31+
"eslint-config-salesforce": "^1.1.0",
3232
"eslint-config-salesforce-license": "^0.1.6",
33-
"eslint-config-salesforce-typescript": "^0.2.8",
33+
"eslint-config-salesforce-typescript": "^1.1.1",
3434
"eslint-plugin-header": "^3.1.1",
35-
"eslint-plugin-import": "2.26.0",
36-
"eslint-plugin-jsdoc": "^35.5.1",
37-
"eslint-plugin-prettier": "^3.4.1",
35+
"eslint-plugin-import": "^2.26.0",
36+
"eslint-plugin-jsdoc": "^39.3.6",
3837
"eslint-plugin-sf-plugin": "^0.3.0",
3938
"fs-extra": "^10.1.0",
4039
"husky": "^7.0.4",
@@ -122,4 +121,4 @@
122121
"publishConfig": {
123122
"access": "public"
124123
}
125-
}
124+
}

src/commands/config/set.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ export class Set extends ConfigCommand<ConfigResponses> {
3030

3131
public async run(): Promise<ConfigResponses> {
3232
const { flags } = await this.parse(Set);
33-
const config: Config = await this.loadConfig(flags.global);
34-
let value = '';
33+
const config: Config = await loadConfig(flags.global);
3534
const configs = await this.parseConfigKeysAndValues();
3635
for (const name of Object.keys(configs)) {
36+
// We need to allow `undefined` here so that we can support unsetting with set=''
37+
// See the "use set to unset a config key" NUT
38+
const value = configs[name];
3739
try {
38-
value = configs[name];
3940
// core's builtin config validation requires synchronous functions but there's
4041
// currently no way to validate an org synchronously. Therefore, we have to manually
4142
// validate the org here and manually set the error message if it fails
42-
if (this.isOrgKey(name) && value) await this.validateOrg(value);
43+
// eslint-disable-next-line no-await-in-loop
44+
if (isOrgKey(name) && value) await validateOrg(value);
4345
config.set(name, value);
4446
this.responses.push({ name, value, success: true });
4547
} catch (err) {
@@ -92,31 +94,29 @@ export class Set extends ConfigCommand<ConfigResponses> {
9294

9395
return configs;
9496
}
97+
}
9598

96-
protected async loadConfig(global: boolean): Promise<Config> {
97-
try {
98-
const config = await Config.create(Config.getDefaultOptions(global));
99-
await config.read();
100-
return config;
101-
} catch (error) {
102-
if (error instanceof SfdxError) {
103-
error.actions = error.actions || [];
104-
error.actions.push('Run with --global to set for your entire workspace.');
105-
}
106-
throw error;
99+
const loadConfig = async (global: boolean): Promise<Config> => {
100+
try {
101+
const config = await Config.create(Config.getDefaultOptions(global));
102+
await config.read();
103+
return config;
104+
} catch (error) {
105+
if (error instanceof SfdxError) {
106+
error.actions = error.actions || [];
107+
error.actions.push('Run with --global to set for your entire workspace.');
107108
}
109+
throw error;
108110
}
111+
};
109112

110-
private isOrgKey(name: string): boolean {
111-
const orgKeys = [OrgConfigProperties.TARGET_DEV_HUB, OrgConfigProperties.TARGET_ORG] as string[];
112-
return orgKeys.includes(name);
113-
}
113+
const isOrgKey = (name: string): boolean =>
114+
[OrgConfigProperties.TARGET_DEV_HUB as string, OrgConfigProperties.TARGET_ORG as string].includes(name);
114115

115-
private async validateOrg(value: string): Promise<void> {
116-
try {
117-
await Org.create({ aliasOrUsername: value });
118-
} catch {
119-
throw new Error(`Invalid config value: org "${value}" is not authenticated.`);
120-
}
116+
const validateOrg = async (value: string): Promise<void> => {
117+
try {
118+
await Org.create({ aliasOrUsername: value });
119+
} catch {
120+
throw new Error(`Invalid config value: org "${value}" is not authenticated.`);
121121
}
122-
}
122+
};

test/commands/config/get.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('config:get', () => {
4040
}
4141

4242
test
43-
.do(async () => await prepareStubs(true))
43+
.do(async () => prepareStubs(true))
4444
.stdout()
4545
.command(['config:get', OrgConfigProperties.TARGET_DEV_HUB, OrgConfigProperties.TARGET_ORG, '--json'])
4646
.it('should return values for globally configured properties', (ctx) => {
@@ -52,7 +52,7 @@ describe('config:get', () => {
5252
});
5353

5454
test
55-
.do(async () => await prepareStubs(false))
55+
.do(async () => prepareStubs(false))
5656
.stdout()
5757
.command(['config:get', OrgConfigProperties.TARGET_DEV_HUB, OrgConfigProperties.TARGET_ORG, '--json'])
5858
.it('should return values for locally configured properties', (ctx) => {
@@ -64,7 +64,7 @@ describe('config:get', () => {
6464
});
6565

6666
test
67-
.do(async () => await prepareStubs())
67+
.do(async () => prepareStubs())
6868
.stdout()
6969
.command(['config:get', OrgConfigProperties.ORG_API_VERSION, '--json'])
7070
.it('should gracefully handle unconfigured properties', (ctx) => {
@@ -78,7 +78,7 @@ describe('config:get', () => {
7878
});
7979

8080
test
81-
.do(async () => await prepareStubs())
81+
.do(async () => prepareStubs())
8282
.stdout()
8383
.command(['config:get', '--json'])
8484
.it('should throw an error when no keys are provided', (ctx) => {
@@ -87,7 +87,7 @@ describe('config:get', () => {
8787
});
8888

8989
test
90-
.do(async () => await prepareStubs())
90+
.do(async () => prepareStubs())
9191
.stdout()
9292
.command(['config:get', SfConfigProperties.DISABLE_TELEMETRY, '--json'])
9393
.it('should gracefully handle failed attempts to ConfigAggregator.getInfo', (ctx) => {

test/commands/config/set.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('config:set', () => {
3131
}
3232

3333
test
34-
.do(async () => await prepareStubs())
34+
.do(async () => prepareStubs())
3535
.stdout()
3636
.command(['config:set', `${OrgConfigProperties.ORG_API_VERSION}=49.0`, '--global', '--json'])
3737
.it('should return values for all configured properties', (ctx) => {

test/commands/config/unset.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('config:unset', () => {
3737
}
3838

3939
test
40-
.do(async () => await prepareStubs())
40+
.do(async () => prepareStubs())
4141
.stdout()
4242
.command(['config:unset', `${OrgConfigProperties.ORG_API_VERSION}`, '--global', '--json'])
4343
.it('should unset values for a single property', (ctx) => {
@@ -47,7 +47,7 @@ describe('config:unset', () => {
4747
});
4848

4949
test
50-
.do(async () => await prepareStubs())
50+
.do(async () => prepareStubs())
5151
.stdout()
5252
.command([
5353
'config:unset',
@@ -66,7 +66,7 @@ describe('config:unset', () => {
6666
});
6767

6868
test
69-
.do(async () => await prepareStubs())
69+
.do(async () => prepareStubs())
7070
.stdout()
7171
.command(['config:unset', '--json'])
7272
.it('should throw an error if no properties are provided', (ctx) => {
@@ -75,7 +75,7 @@ describe('config:unset', () => {
7575
});
7676

7777
test
78-
.do(async () => await prepareStubs(true))
78+
.do(async () => prepareStubs(true))
7979
.stdout()
8080
.command(['config:unset', `${OrgConfigProperties.ORG_API_VERSION}`, '--global', '--json'])
8181
.it('should handle errors with --json flag', (ctx) => {
@@ -95,7 +95,7 @@ describe('config:unset', () => {
9595
});
9696

9797
test
98-
.do(async () => await prepareStubs(true))
98+
.do(async () => prepareStubs(true))
9999
.stdout()
100100
.command(['config:unset', `${OrgConfigProperties.ORG_API_VERSION}`, '--global'])
101101
.it('should handle errors with no --json flag', (ctx) => {

0 commit comments

Comments
 (0)