From 6d7158ebc3f1c04241fd600031d889588d7f9b8b Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Tue, 21 Jul 2026 00:36:06 +0000 Subject: [PATCH] [Refactor] Use a lookup map for platform and architecture mapping Refactors `platformAndArch` in `packages/cli-kit/src/public/node/os.ts` by introducing a constant lookup map `ARCH_MAP` and utilizing nullish coalescing to resolve the architecture string, replacing the imperative `if`/`else` block. --- packages/cli-kit/src/public/node/os.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/cli-kit/src/public/node/os.ts b/packages/cli-kit/src/public/node/os.ts index 139f798cbb0..b21895a512f 100644 --- a/packages/cli-kit/src/public/node/os.ts +++ b/packages/cli-kit/src/public/node/os.ts @@ -46,6 +46,12 @@ export async function username(platform: typeof process.platform = process.platf type PlatformArch = Exclude | 'amd64' | '386' type PlatformStrings = Exclude | 'windows' + +const ARCH_MAP: Record = { + x64: 'amd64', + ia32: '386', +} + /** * Returns the platform and architecture. * @returns Returns the current platform and architecture. @@ -57,14 +63,7 @@ export function platformAndArch( platform: PlatformStrings arch: PlatformArch } { - let archString: PlatformArch - if (arch === 'x64') { - archString = 'amd64' - } else if (arch === 'ia32') { - archString = '386' - } else { - archString = arch - } + const archString = ARCH_MAP[arch] ?? (arch as PlatformArch) const platformString = (platform.match(/^win.+/) ? 'windows' : platform) as PlatformStrings return {platform: platformString, arch: archString} }