Skip to content

Commit

Permalink
chore: move it so that it works when deleting sandboxes as well
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jun 26, 2023
1 parent 0436795 commit 56b3ea1
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,18 @@ 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
const config = await Config.create();
[...existingAliases, username].flatMap((name) => config.getKeysByValue(name)).map((key) => config.unset(key));
await config.write();

if (await this.isSandbox()) {
await this.deleteSandbox();
} else {
Expand Down Expand Up @@ -1131,17 +1143,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {

try {
const devHubConn = devHub.getConnection();
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
const config = await Config.create();
[...existingAliases, username].flatMap((name) => config.getKeysByValue(name)).map((key) => config.unset(key));
await config.write();
const username = this.getUsername();

const activeScratchOrgRecordId = (
await devHubConn.singleRecordQuery<{ Id: string }>(
Expand Down

0 comments on commit 56b3ea1

Please sign in to comment.