Skip to content

Commit

Permalink
fix(cli): when buildOptions.target is undefined, it should load the h…
Browse files Browse the repository at this point in the history
…ost target on default config load
  • Loading branch information
mildronize committed May 6, 2024
1 parent d876e3c commit 08e6520
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion infra/azure-functions/src/test-os.ts
Original file line number Diff line number Diff line change
@@ -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);
console.log('the current version is ', process.version);
19 changes: 8 additions & 11 deletions packages/main/src/command/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion packages/main/src/command/nammatham-config.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -47,6 +48,7 @@ export const defaultNammathamConfigs: NammathamConfigs = {
buildPath: '.nmt',
runtime: 'bun',
buildOption: {
target: getHostTarget(),
nodeToolChain: {
dev: 'tsx',
bundle: 'esbuild',
Expand Down

0 comments on commit 08e6520

Please sign in to comment.