Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sm/new-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 29, 2023
2 parents bd83d3e + 3e49d42 commit 210f380
Show file tree
Hide file tree
Showing 8 changed files with 1,068 additions and 3,332 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: perf-tests
on:
push:
branches-ignore: [main]
branches-ignore: [main, gh-pages]
workflow_dispatch:

# linux will finish ahead of windows, but prevent other branches/commits from hitting simultaneously
Expand All @@ -22,7 +22,6 @@ jobs:
with:
cache: yarn
- run: yarn install
# build is necessary because transport references /lib
- run: yarn build
- run: npm run test:perf | tee test/perf/output.txt

Expand Down
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"watch-files": ["src", "test"],
"recursive": true,
"reporter": "spec",
"timeout": 10000
"timeout": 20000
}
4,316 changes: 997 additions & 3,319 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/core",
"version": "4.3.3",
"version": "4.3.5",
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
"main": "lib/exported",
"types": "lib/exported.d.ts",
Expand Down Expand Up @@ -48,7 +48,7 @@
"faye": "^1.4.0",
"form-data": "^4.0.0",
"js2xmlparser": "^4.0.1",
"jsforce": "^2.0.0-beta.25",
"jsforce": "^2.0.0-beta.27",
"jsonwebtoken": "9.0.0",
"jszip": "3.10.1",
"pino": "^8.14.1",
Expand Down
20 changes: 16 additions & 4 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Op

// Initialized in loadProperties
private allowedProperties!: ConfigPropertyMeta[];
private localConfig?: Config;
private globalConfig: Config;
private readonly localConfig?: Config;
private readonly globalConfig: Config;
private envVars: Dictionary<string> = {};

/**
Expand Down Expand Up @@ -334,6 +334,19 @@ export class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Op
return this.config;
}

public async unsetByValue(key: string): Promise<void> {
const hasLocalWrites = this.localConfig
?.getKeysByValue(key)
.map((k) => this.localConfig?.unset(k))
.some(Boolean);
if (hasLocalWrites) await this.localConfig?.write();
const hasGlobalWrites = this.globalConfig
?.getKeysByValue(key)
.map((k) => this.globalConfig?.unset(k))
.some(Boolean);
if (hasGlobalWrites) await this.globalConfig?.write();
}

/**
* Get the config properties that are environment variables.
*/
Expand Down Expand Up @@ -412,8 +425,7 @@ export class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Op
configs.push(this.envVars);

const json: JsonMap = {};
const reduced = configs.filter(isJsonMap).reduce((acc: JsonMap, el: AnyJson) => merge(acc, el), json);
return reduced;
return configs.filter(isJsonMap).reduce((acc: JsonMap, el: AnyJson) => merge(acc, el), json);
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,16 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
* Will delete 'this' instance remotely and any files locally
*/
public async delete(): Promise<void> {
const username = ensureString(this.getUsername());

// unset any aliases referencing this org
const stateAgg = await StateAggregator.getInstance();
const existingAliases = stateAgg.aliases.getAll(username);
await stateAgg.aliases.unsetValuesAndSave(existingAliases);

// unset any configs referencing this org
[...existingAliases, username].flatMap((name) => this.configAggregator.unsetByValue(name));

if (await this.isSandbox()) {
await this.deleteSandbox();
} else {
Expand Down Expand Up @@ -1132,6 +1142,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
try {
const devHubConn = devHub.getConnection();
const username = this.getUsername();

const activeScratchOrgRecordId = (
await devHubConn.singleRecordQuery<{ Id: string }>(
`SELECT Id FROM ActiveScratchOrg WHERE SignupUsername='${username}'`
Expand Down
36 changes: 36 additions & 0 deletions test/unit/org/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,42 @@ describe('Org Tests', () => {
}
});

it('should unset the alias and any configs', async () => {
const dev = await createOrgViaAuthInfo(testData.username);
const configAgg = await ConfigAggregator.create();

const orgTestData = new MockTestOrgData();
const org = await createOrgViaAuthInfo(orgTestData.username, orgTestData);
const username = ensureString(org.getUsername());
$$.setConfigStubContents('Config', { contents: { [OrgConfigProperties.TARGET_ORG]: username } });

await configAgg.reload();
const stateAggregator = await StateAggregator.getInstance();

expect(configAgg.getConfig()['target-org']).to.equal(username);

await stateAggregator.aliases.setAndSave('deleteThisAlias', username);
expect(stateAggregator.aliases.getUsername('deleteThisAlias')).to.equal(username);

const devHubQuery = stubMethod($$.SANDBOX, Connection.prototype, 'singleRecordQuery').resolves({
Id: orgTestData.orgId,
});
const devHubDelete = stubMethod($$.SANDBOX, Org.prototype, 'destroyScratchOrg').resolves();
$$.SANDBOX.stub(org, 'getDevHubOrg').resolves(dev);

await org.delete();
expect(configAgg.getConfig()['target-org']).to.equal(undefined);

expect(stateAggregator.aliases.get(username)).to.be.null;
expect(devHubQuery.calledOnce).to.be.true;
expect(devHubQuery.firstCall.args[0]).to.equal(
`SELECT Id FROM ActiveScratchOrg WHERE SignupUsername='${orgTestData.username}'`
);

expect(devHubDelete.calledOnce).to.be.true;
expect(devHubDelete.firstCall.args[1]).to.equal(orgTestData.orgId);
});

it('should handle SingleRecordQueryErrors.NoRecords errors', async () => {
const dev = await createOrgViaAuthInfo();

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3021,10 +3021,10 @@ jsesc@^2.5.1:
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4"
integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==

jsforce@^2.0.0-beta.25:
version "2.0.0-beta.25"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.25.tgz#120a3999babf96ae18ab8f1232003d56588a9ca5"
integrity sha512-ZtzwJErI4SSJYWrGAw0mHEHPZRB4Idz0RiXHakCtEgEjEWt6JIDR4sNbWRHUzWHdEO4O61z2YSBvdOuag1hkWg==
jsforce@^2.0.0-beta.27:
version "2.0.0-beta.27"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.27.tgz#ba822b18b77bea4529491060a9b07bc1009735ac"
integrity sha512-d9dDWWeHwayRKPo8FJBAIUyk8sNXGSHwdUjR6al3yK0YKci27Jc1XfNaQTxEAuymHQJVaCb1gxTKqmA4uznFdQ==
dependencies:
"@babel/runtime" "^7.12.5"
"@babel/runtime-corejs3" "^7.12.5"
Expand Down

4 comments on commit 210f380

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 210f380 Previous: 3e49d42 Ratio
Child logger creation 409857 ops/sec (±1.51%) 16974 ops/sec (±0.52%) 0.041414444550172375
Logging a string on root logger 568032 ops/sec (±22.62%) 68919 ops/sec (±0.25%) 0.12
Logging an object on root logger 490783 ops/sec (±7.46%) 58769 ops/sec (±0.59%) 0.12
Logging an object with a message on root logger 8837 ops/sec (±190.97%) 28577 ops/sec (±0.21%) 3.23
Logging an object with a redacted prop on root logger 314601 ops/sec (±18.31%) 53184 ops/sec (±0.45%) 0.17
Logging a nested 3-level object on root logger 277309 ops/sec (±10.74%) 48902 ops/sec (±0.23%) 0.18

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 210f380 Previous: 3e49d42 Ratio
Logging an object with a message on root logger 8837 ops/sec (±190.97%) 28577 ops/sec (±0.21%) 3.23

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 210f380 Previous: 3e49d42 Ratio
Child logger creation 299792 ops/sec (±1.15%) 3326 ops/sec (±0.99%) 0.011094358755403747
Logging a string on root logger 610896 ops/sec (±10.65%) 49551 ops/sec (±1.00%) 0.08111200597155653
Logging an object on root logger 419550 ops/sec (±13.10%) 36566 ops/sec (±0.99%) 0.08715528542485997
Logging an object with a message on root logger 213593 ops/sec (±22.33%) 15768 ops/sec (±2.90%) 0.07382264400050563
Logging an object with a redacted prop on root logger 3757 ops/sec (±205.78%) 33293 ops/sec (±1.15%) 8.86
Logging a nested 3-level object on root logger 267433 ops/sec (±9.80%) 28685 ops/sec (±1.62%) 0.11

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - windows-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 210f380 Previous: 3e49d42 Ratio
Logging an object with a redacted prop on root logger 3757 ops/sec (±205.78%) 33293 ops/sec (±1.15%) 8.86

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.