diff --git a/apps/server/compile.ts b/apps/server/compile.ts index 1704ae2..55b3e10 100644 --- a/apps/server/compile.ts +++ b/apps/server/compile.ts @@ -4,14 +4,17 @@ import process from 'node:process' const ENTRYPOINT = '.output/server/index.mjs' const OUTDIR = 'out' -const VALID_TARGETS = [ - 'bun-windows-x64', - 'bun-darwin-arm64', - 'bun-linux-x64', - 'bun-linux-arm64', -] as const +const TARGETS = { + 'bun-windows-x64': true, + 'bun-darwin-arm64': true, + 'bun-linux-x64': true, + 'bun-linux-arm64': true, +} as const -type Target = (typeof VALID_TARGETS)[number] +type Target = keyof typeof TARGETS + +const isTarget = (value: unknown): value is Target => + typeof value === 'string' && value in TARGETS const HOST_MAP: Record = { 'win32-x64': 'bun-windows-x64', @@ -24,12 +27,12 @@ const resolveTarget = (): Target => { const idx = process.argv.indexOf('--target') if (idx !== -1) { const value = process.argv[idx + 1] - if (!value || !VALID_TARGETS.includes(value as Target)) { + if (!isTarget(value)) { throw new Error( - `Invalid target: ${value}\nAllowed: ${VALID_TARGETS.join(', ')}`, + `Invalid target: ${value}\nAllowed: ${Object.keys(TARGETS).join(', ')}`, ) } - return value as Target + return value } const key = `${process.platform}-${process.arch}`