From 5e9ec8b3e3e7be84b03ec23c282043fc244d7060 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 2 Apr 2024 11:08:29 -0500 Subject: [PATCH] fix: remove deprecated core aliasAccessor methods --- src/commands/alias/set.ts | 42 ++++++++++++++++++------------------- src/commands/alias/unset.ts | 38 +++++++++++++++++---------------- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/commands/alias/set.ts b/src/commands/alias/set.ts index 6d98a04d..0c32fbd9 100644 --- a/src/commands/alias/set.ts +++ b/src/commands/alias/set.ts @@ -31,28 +31,28 @@ export default class AliasSet extends AliasCommand { const parsed = parseVarArgs(args, argv as string[]); - const results = Object.entries(parsed).map(([alias, value]) => { - try { - // to support plugin-settings in sfdx, which allowed setting an alias to undefined, when that happens we'll unset the alias - // which is what the user wants - if (!value) { - stateAggregator.aliases.unset(alias); - } else { - stateAggregator.aliases.set(alias, value); + const results = await Promise.all( + Object.entries(parsed).map(async ([alias, value]) => { + try { + // to support plugin-settings in sfdx, which allowed setting an alias to undefined, when that happens we'll unset the alias + // which is what the user wants + if (!value) { + await stateAggregator.aliases.unsetAndSave(alias); + } else { + await stateAggregator.aliases.setAndSave(alias, value); + } + return { alias, success: true, value }; + } catch (err) { + const { name, message } = + err instanceof Error + ? err + : typeof err === 'string' + ? new Error(err) + : { name: 'UnknownError', message: 'Unknown Error' }; + return { alias, success: false, error: { name, message }, value }; } - return { alias, success: true, value }; - } catch (err) { - const { name, message } = - err instanceof Error - ? err - : typeof err === 'string' - ? new Error(err) - : { name: 'UnknownError', message: 'Unknown Error' }; - return { alias, success: false, error: { name, message }, value }; - } - }); - - await stateAggregator.aliases.write(); + }) + ); this.output('Alias Set', results); diff --git a/src/commands/alias/unset.ts b/src/commands/alias/unset.ts index e8170835..03c37873 100644 --- a/src/commands/alias/unset.ts +++ b/src/commands/alias/unset.ts @@ -57,24 +57,26 @@ export default class AliasUnset extends AliasCommand { return []; } - const results = toRemove.map((alias) => { - // We will log the value in the output in case an alias was unset by mistake. - const value = aliases[alias]; - try { - stateAggregator.aliases.unset(alias); - return { alias, value, success: true }; - } catch (err) { - const { name, message } = - err instanceof Error - ? err - : typeof err === 'string' - ? new Error(err) - : { name: 'UnknownError', message: 'Unknown Error' }; - return { alias, value, success: false, error: { name, message } }; - } - }); - - await stateAggregator.aliases.write(); + const results = await Promise.all( + toRemove + // We will log the value in the output in case an alias was unset by mistake. + .map((alias) => ({ alias, value: aliases[alias] })) + .map(async ({ alias, value }) => { + try { + // safe to parallelize because of file locking + await stateAggregator.aliases.unsetAndSave(alias); + return { alias, value, success: true }; + } catch (err) { + const { name, message } = + err instanceof Error + ? err + : typeof err === 'string' + ? new Error(err) + : { name: 'UnknownError', message: 'Unknown Error' }; + return { alias, value, success: false, error: { name, message } }; + } + }) + ); this.output('Alias Unset', results);