From 08e6520b8d2ac6d147a41bdf05de6381a529555c Mon Sep 17 00:00:00 2001 From: Thada Wangthammang Date: Mon, 6 May 2024 21:48:48 +0700 Subject: [PATCH] fix(cli): when buildOptions.target is undefined, it should load the host target on default config load --- infra/azure-functions/src/test-os.ts | 2 +- packages/main/src/command/build/build.ts | 19 ++++++++----------- packages/main/src/command/nammatham-config.ts | 4 +++- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/infra/azure-functions/src/test-os.ts b/infra/azure-functions/src/test-os.ts index 15a249a..9a5a049 100644 --- a/infra/azure-functions/src/test-os.ts +++ b/infra/azure-functions/src/test-os.ts @@ -1,3 +1,3 @@ console.log('the current platform is ', process.platform); console.log('the current architecture is ', process.arch); -console.log('the current version is ', process.version); \ No newline at end of file +console.log('the current version is ', process.version); diff --git a/packages/main/src/command/build/build.ts b/packages/main/src/command/build/build.ts index 1dc9395..8a794fd 100644 --- a/packages/main/src/command/build/build.ts +++ b/packages/main/src/command/build/build.ts @@ -200,19 +200,16 @@ export async function buildExecutable(options: NammathamConfigs, result: BuildNo if (options.buildOption?.nodeToolChain?.package !== 'pkg') { throw new Error(`Unsupported package tool: ${options.buildOption?.nodeToolChain?.package}`); } - const target = options.buildOption?.target ?? 'host'; - let targetOptions: TargetOptions; - if (target === 'host') { - targetOptions = getHostTarget(); - } else { - targetOptions = target; + const target = options.buildOption?.target; + if (!target) { + throw new Error(`Target should be set at the default configuration when the cli loaded`); } - debug?.(`Building executable for target: ${targetOptions.runtime}-${targetOptions.platform}-${targetOptions.arch}`); - if (targetOptions.runtime === 'bun') { - throw new Error(`Conflict target build runtime: ${targetOptions.runtime} with ${options.runtime}`); + debug?.(`Building executable for target: ${target.runtime}-${target.platform}-${target.arch}`); + if (target.runtime === 'bun') { + throw new Error(`Conflict target build runtime: ${target.runtime} with ${options.runtime}`); } - const targetString = `${targetOptions.runtime}-${targetOptions.platform}-${targetOptions.arch}`; - const executablePath = targetOptions.platform === 'win' ? 'main.exe' : 'main'; + const targetString = `${target.runtime}-${target.platform}-${target.arch}`; + const executablePath = target.platform === 'win' ? 'main.exe' : 'main'; const pkgArgs = [ result.filePath, '--target', diff --git a/packages/main/src/command/nammatham-config.ts b/packages/main/src/command/nammatham-config.ts index a0fcef2..e777eb6 100644 --- a/packages/main/src/command/nammatham-config.ts +++ b/packages/main/src/command/nammatham-config.ts @@ -1,6 +1,7 @@ -import type { BuildOptions } from './build'; import type { EnvVariablesConfig, HostConfigV2, LocalSettings } from './config-loader'; +import { getHostTarget, type BuildOptions } from './build'; + export interface NammathamConfigs { /** * The path to the build directory. @@ -47,6 +48,7 @@ export const defaultNammathamConfigs: NammathamConfigs = { buildPath: '.nmt', runtime: 'bun', buildOption: { + target: getHostTarget(), nodeToolChain: { dev: 'tsx', bundle: 'esbuild',