Skip to content

Commit

Permalink
Merge pull request #842 from forcedotcom/sm/aliases-without-config-file
Browse files Browse the repository at this point in the history
Sm/aliases-without-config-file
  • Loading branch information
shetzel authored Jun 1, 2023
2 parents 0b8ba43 + a6ff169 commit e2eda9d
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 361 deletions.
12 changes: 11 additions & 1 deletion MIGRATING_V3-V4.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ Both of these were empty wrappers around `SfProject` and `SfProjectJson`. Use th

## Connection.deployRecentValidation

Since this was moved to jsforce2, the sfdx-core implementation was an empty wrapper. Use jsforce's Connection.metadata#deployRecentValidation instead.
Since this was moved to jsforce2, the sfdx-core implementation was an empty wrapper. Use jsforce's ConnectionDeployRecentValidation instead.

## StateAggregator.aliases (aliasAccessor)

There are some deprecated methods (set, unset). They still exist, but you should use the newer async equivalent. They not only set/unset the value in memory, but immediately write to the filesystem.

`write` on aliases is now deprecated and a no-op.

AliasAccessor no longer inherits from the entire configFile family of classes, so those methods are no longer available.

This new version introduces file locks so parallel operations that write to Aliases should not cross-save each other.

## sfdc

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Mocking Aliases', () => {
const testData = new MockTestOrgData();
await $$.stubAliases({ myAlias: testData.username });
const alias = (await StateAggregator.getInstance()).aliases.get(testData.username);
strictEqual(alias, 'myAlais');
strictEqual(alias, 'myAlias');
});
});

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"js2xmlparser": "^4.0.1",
"jsforce": "^2.0.0-beta.23",
"jsonwebtoken": "9.0.0",
"proper-lockfile": "^4.1.2",
"ts-retry-promise": "^0.7.0"
},
"devDependencies": {
Expand All @@ -64,6 +65,7 @@
"@types/debug": "0.0.31",
"@types/jsonwebtoken": "9.0.2",
"@types/lodash": "^4.14.194",
"@types/proper-lockfile": "^4.1.2",
"@types/shelljs": "0.8.12",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
Expand Down
27 changes: 0 additions & 27 deletions src/config/aliasesConfig.ts

This file was deleted.

252 changes: 0 additions & 252 deletions src/config/configGroup.ts

This file was deleted.

49 changes: 23 additions & 26 deletions src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,36 +1211,33 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
this.logger.debug(`Removing users associate with org: ${this.getOrgId()}`);
const config = await this.retrieveOrgUsersConfig();
this.logger.debug(`using path for org users: ${config.getPath()}`);
const authInfos: AuthInfo[] = await this.readUserAuthFiles();

const usernames = (await this.readUserAuthFiles()).map((auth) => auth.getFields().username).filter(isString);

await Promise.all(
authInfos
.map((auth) => auth.getFields().username)
.map(async (username) => {
const aliasKeys = (username && stateAggregator.aliases.getAll(username)) ?? [];
stateAggregator.aliases.unsetAll(username as string);

const orgForUser =
username === this.getUsername()
? this
: await Org.create({
connection: await Connection.create({ authInfo: await AuthInfo.create({ username }) }),
});

const orgType = this.isDevHubOrg() ? OrgConfigProperties.TARGET_DEV_HUB : OrgConfigProperties.TARGET_ORG;
const configInfo = orgForUser.configAggregator.getInfo(orgType);
const needsConfigUpdate =
(configInfo.isGlobal() || configInfo.isLocal()) &&
(configInfo.value === username || aliasKeys.includes(configInfo.value as string));

return [
orgForUser.removeAuth(),
needsConfigUpdate ? Config.update(configInfo.isGlobal(), orgType, undefined) : undefined,
].filter(Boolean);
})
usernames.map(async (username) => {
const orgForUser =
username === this.getUsername()
? this
: await Org.create({
connection: await Connection.create({ authInfo: await AuthInfo.create({ username }) }),
});

const orgType = this.isDevHubOrg() ? OrgConfigProperties.TARGET_DEV_HUB : OrgConfigProperties.TARGET_ORG;
const configInfo = orgForUser.configAggregator.getInfo(orgType);
const needsConfigUpdate =
(configInfo.isGlobal() || configInfo.isLocal()) &&
(configInfo.value === username || stateAggregator.aliases.get(configInfo.value as string) === username);

return [
orgForUser.removeAuth(),
needsConfigUpdate ? Config.update(configInfo.isGlobal(), orgType, undefined) : undefined,
].filter(Boolean);
})
);

await stateAggregator.aliases.write();
// now that we're done with all the aliases, we can unset those
await stateAggregator.aliases.unsetValuesAndSave(usernames);
}

private async removeSandboxConfig(): Promise<void> {
Expand Down
Loading

0 comments on commit e2eda9d

Please sign in to comment.