🐛 Fix pnpm packaging errors and refactor

This commit is contained in:
Tw93
2025-08-26 19:32:54 +08:00
parent 02463a72f6
commit 88690b15ea
6 changed files with 311 additions and 324 deletions

View File

@@ -187,26 +187,88 @@ export default abstract class BaseBuilder {
abstract getFileName(): string;
protected getBuildCommand(packageManager: string = 'pnpm'): string {
// 架构映射配置
protected static readonly ARCH_MAPPINGS: Record<
string,
Record<string, string>
> = {
darwin: {
arm64: 'aarch64-apple-darwin',
x64: 'x86_64-apple-darwin',
universal: 'universal-apple-darwin',
},
win32: {
arm64: 'aarch64-pc-windows-msvc',
x64: 'x86_64-pc-windows-msvc',
},
linux: {
arm64: 'aarch64-unknown-linux-gnu',
x64: 'x86_64-unknown-linux-gnu',
},
};
// 架构名称映射(用于文件名生成)
protected static readonly ARCH_DISPLAY_NAMES: Record<string, string> = {
arm64: 'aarch64',
x64: 'x64',
universal: 'universal',
};
/**
* 解析目标架构
*/
protected resolveTargetArch(requestedArch?: string): string {
if (requestedArch === 'auto' || !requestedArch) {
return process.arch;
}
return requestedArch;
}
/**
* 获取Tauri构建目标
*/
protected getTauriTarget(
arch: string,
platform: NodeJS.Platform = process.platform,
): string | null {
const platformMappings = BaseBuilder.ARCH_MAPPINGS[platform];
if (!platformMappings) return null;
return platformMappings[arch] || null;
}
/**
* 获取架构显示名称(用于文件名)
*/
protected getArchDisplayName(arch: string): string {
return BaseBuilder.ARCH_DISPLAY_NAMES[arch] || arch;
}
/**
* 构建基础构建命令
*/
protected buildBaseCommand(
packageManager: string,
configPath: string,
target?: string,
): string {
const baseCommand = this.options.debug
? `${packageManager} run build:debug`
: `${packageManager} run build`;
// Use temporary config directory to avoid modifying source files
const configPath = path.join(
npmDirectory,
'src-tauri',
'.pake',
'tauri.conf.json',
);
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
const argSeparator = packageManager === 'npm' ? ' --' : '';
let fullCommand = `${baseCommand}${argSeparator} -c "${configPath}"`;
// For macOS, use app bundles by default unless DMG is explicitly requested
if (IS_MAC && this.options.targets === 'app') {
fullCommand += ' --bundles app';
if (target) {
fullCommand += ` --target ${target}`;
}
// Add features
return fullCommand;
}
/**
* 获取构建特性列表
*/
protected getBuildFeatures(): string[] {
const features = ['cli-build'];
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
@@ -217,6 +279,27 @@ export default abstract class BaseBuilder {
}
}
return features;
}
protected getBuildCommand(packageManager: string = 'pnpm'): string {
// Use temporary config directory to avoid modifying source files
const configPath = path.join(
npmDirectory,
'src-tauri',
'.pake',
'tauri.conf.json',
);
let fullCommand = this.buildBaseCommand(packageManager, configPath);
// For macOS, use app bundles by default unless DMG is explicitly requested
if (IS_MAC && this.options.targets === 'app') {
fullCommand += ' --bundles app';
}
// Add features
const features = this.getBuildFeatures();
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}

View File

@@ -17,7 +17,7 @@ export default class LinuxBuilder extends BaseBuilder {
this.buildArch = 'arm64';
} else {
this.buildFormat = target;
this.buildArch = 'auto';
this.buildArch = this.resolveTargetArch('auto');
}
// Set targets to format for Tauri
@@ -28,14 +28,18 @@ export default class LinuxBuilder extends BaseBuilder {
const { name, targets } = this.options;
const version = tauriConfig.version;
// Determine architecture based on explicit target or auto-detect
// Determine architecture display name
let arch: string;
if (this.buildArch === 'arm64') {
arch = targets === 'rpm' || targets === 'appimage' ? 'aarch64' : 'arm64';
} else {
// Auto-detect or default to current architecture
arch = process.arch === 'x64' ? 'amd64' : process.arch;
if (arch === 'arm64' && (targets === 'rpm' || targets === 'appimage')) {
const resolvedArch = this.buildArch === 'x64' ? 'amd64' : this.buildArch;
arch = resolvedArch;
if (
resolvedArch === 'arm64' &&
(targets === 'rpm' || targets === 'appimage')
) {
arch = 'aarch64';
}
}
@@ -59,21 +63,22 @@ export default class LinuxBuilder extends BaseBuilder {
}
protected getBuildCommand(packageManager: string = 'pnpm'): string {
const baseCommand = this.options.debug
? `${packageManager} run build:debug`
: `${packageManager} run build`;
// Use temporary config directory to avoid modifying source files
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
// Add ARM64 target if explicitly specified
if (this.buildArch === 'arm64') {
fullCommand += ' --target aarch64-unknown-linux-gnu';
}
// Only add target if it's ARM64
const buildTarget =
this.buildArch === 'arm64'
? this.getTauriTarget(this.buildArch, 'linux')
: undefined;
let fullCommand = this.buildBaseCommand(
packageManager,
configPath,
buildTarget,
);
// Add features
const features = ['cli-build'];
const features = this.getBuildFeatures();
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
@@ -85,7 +90,8 @@ export default class LinuxBuilder extends BaseBuilder {
const basePath = this.options.debug ? 'debug' : 'release';
if (this.buildArch === 'arm64') {
return `src-tauri/target/aarch64-unknown-linux-gnu/${basePath}/bundle/`;
const target = this.getTauriTarget(this.buildArch, 'linux');
return `src-tauri/target/${target}/${basePath}/bundle/`;
}
return super.getBasePath();

View File

@@ -11,7 +11,12 @@ export default class MacBuilder extends BaseBuilder {
super(options);
// Store the original targets value for architecture selection
this.buildArch = options.targets || 'auto';
// For macOS, targets can be architecture names or format names
// Filter out non-architecture values
const validArchs = ['intel', 'apple', 'universal', 'auto', 'x64', 'arm64'];
this.buildArch = validArchs.includes(options.targets || '')
? options.targets
: 'auto';
// Use DMG by default for distribution
// Only create app bundles for testing to avoid user interaction
@@ -43,95 +48,51 @@ export default class MacBuilder extends BaseBuilder {
arch = 'x64';
} else {
// Auto-detect based on current architecture
arch = process.arch === 'arm64' ? 'aarch64' : process.arch;
arch = this.getArchDisplayName(this.resolveTargetArch(this.buildArch));
}
return `${name}_${tauriConfig.version}_${arch}`;
}
protected getBuildCommand(packageManager: string = 'pnpm'): string {
// Determine if we need universal build
const needsUniversal =
this.buildArch === 'universal' || this.options.multiArch;
if (needsUniversal) {
const baseCommand = this.options.debug
? `${packageManager} run tauri build -- --debug`
: `${packageManager} run tauri build --`;
// Use temporary config directory to avoid modifying source files
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} --target universal-apple-darwin -c "${configPath}"`;
// Add features
const features = ['cli-build'];
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
const macOSVersion = this.getMacOSMajorVersion();
if (macOSVersion >= 23) {
features.push('macos-proxy');
}
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
return fullCommand;
private getActualArch(): string {
if (this.buildArch === 'universal' || this.options.multiArch) {
return 'universal';
} else if (this.buildArch === 'apple') {
// Build for Apple Silicon only
const baseCommand = this.options.debug
? `${packageManager} run tauri build -- --debug`
: `${packageManager} run tauri build --`;
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} --target aarch64-apple-darwin -c "${configPath}"`;
// Add features
const features = ['cli-build'];
const macOSVersion = this.getMacOSMajorVersion();
if (macOSVersion >= 23) {
features.push('macos-proxy');
}
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
return fullCommand;
return 'arm64';
} else if (this.buildArch === 'intel') {
// Build for Intel only
const baseCommand = this.options.debug
? `${packageManager} run tauri build -- --debug`
: `${packageManager} run tauri build --`;
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} --target x86_64-apple-darwin -c "${configPath}"`;
return 'x64';
}
return this.resolveTargetArch(this.buildArch);
}
// Add features
const features = ['cli-build'];
const macOSVersion = this.getMacOSMajorVersion();
if (macOSVersion >= 23) {
features.push('macos-proxy');
}
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
protected getBuildCommand(packageManager: string = 'pnpm'): string {
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
const actualArch = this.getActualArch();
return fullCommand;
const buildTarget = this.getTauriTarget(actualArch, 'darwin');
if (!buildTarget) {
throw new Error(`Unsupported architecture: ${actualArch} for macOS`);
}
return super.getBuildCommand();
let fullCommand = this.buildBaseCommand(
packageManager,
configPath,
buildTarget,
);
// Add features
const features = this.getBuildFeatures();
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
return fullCommand;
}
protected getBasePath(): string {
const needsUniversal =
this.buildArch === 'universal' || this.options.multiArch;
const basePath = this.options.debug ? 'debug' : 'release';
const actualArch = this.getActualArch();
const target = this.getTauriTarget(actualArch, 'darwin');
if (needsUniversal) {
return `src-tauri/target/universal-apple-darwin/${basePath}/bundle`;
} else if (this.buildArch === 'apple') {
return `src-tauri/target/aarch64-apple-darwin/${basePath}/bundle`;
} else if (this.buildArch === 'intel') {
return `src-tauri/target/x86_64-apple-darwin/${basePath}/bundle`;
}
return super.getBasePath();
return `src-tauri/target/${target}/${basePath}/bundle`;
}
}

View File

@@ -9,61 +9,35 @@ export default class WinBuilder extends BaseBuilder {
constructor(options: PakeAppOptions) {
super(options);
// Store the original targets value for architecture selection
this.buildArch = options.targets || 'auto';
// Set targets to msi format for Tauri
this.buildArch = this.resolveTargetArch(options.targets);
this.options.targets = this.buildFormat;
}
getFileName(): string {
const { name } = this.options;
const language = tauriConfig.bundle.windows.wix.language[0];
// Determine architecture name based on explicit targets option or auto-detect
let targetArch: string;
if (this.buildArch === 'arm64') {
targetArch = 'aarch64';
} else if (this.buildArch === 'x64') {
targetArch = 'x64';
} else {
// Auto-detect based on current architecture if no explicit target
const archMap: { [key: string]: string } = {
x64: 'x64',
arm64: 'aarch64',
};
targetArch = archMap[process.arch] || process.arch;
}
const targetArch = this.getArchDisplayName(this.buildArch);
return `${name}_${tauriConfig.version}_${targetArch}_${language}`;
}
protected getBuildCommand(packageManager: string = 'pnpm'): string {
const baseCommand = this.options.debug
? `${packageManager} run build:debug`
: `${packageManager} run build`;
// Use temporary config directory to avoid modifying source files
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
const buildTarget = this.getTauriTarget(this.buildArch, 'win32');
// Determine build target based on explicit targets option or auto-detect
let buildTarget: string;
if (this.buildArch === 'arm64') {
buildTarget = 'aarch64-pc-windows-msvc';
} else if (this.buildArch === 'x64') {
buildTarget = 'x86_64-pc-windows-msvc';
} else {
// Auto-detect based on current architecture if no explicit target
buildTarget =
process.arch === 'arm64'
? 'aarch64-pc-windows-msvc'
: 'x86_64-pc-windows-msvc';
if (!buildTarget) {
throw new Error(
`Unsupported architecture: ${this.buildArch} for Windows`,
);
}
fullCommand += ` --target ${buildTarget}`;
let fullCommand = this.buildBaseCommand(
packageManager,
configPath,
buildTarget,
);
// Add features
const features = ['cli-build'];
const features = this.getBuildFeatures();
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
@@ -73,21 +47,7 @@ export default class WinBuilder extends BaseBuilder {
protected getBasePath(): string {
const basePath = this.options.debug ? 'debug' : 'release';
// Determine target based on explicit targets option or auto-detect
let target: string;
if (this.buildArch === 'arm64') {
target = 'aarch64-pc-windows-msvc';
} else if (this.buildArch === 'x64') {
target = 'x86_64-pc-windows-msvc';
} else {
// Auto-detect based on current architecture if no explicit target
target =
process.arch === 'arm64'
? 'aarch64-pc-windows-msvc'
: 'x86_64-pc-windows-msvc';
}
const target = this.getTauriTarget(this.buildArch, 'win32');
return `src-tauri/target/${target}/${basePath}/bundle/`;
}
}

301
dist/cli.js vendored
View File

@@ -54,9 +54,9 @@ var files = [
var scripts = {
start: "pnpm run dev",
dev: "pnpm run tauri dev",
build: "pnpm run tauri build --",
"build:debug": "pnpm run tauri build -- --debug",
"build:mac": "pnpm run tauri build -- --target universal-apple-darwin",
build: "tauri build",
"build:debug": "tauri build --debug",
"build:mac": "tauri build --target universal-apple-darwin",
"build:config": "chmod +x scripts/configure-tauri.mjs && node scripts/configure-tauri.mjs",
analyze: "cd src-tauri && cargo bloat --release --crates",
tauri: "tauri",
@@ -710,18 +710,48 @@ class BaseBuilder {
getFileType(target) {
return target;
}
getBuildCommand(packageManager = 'pnpm') {
/**
* 解析目标架构
*/
resolveTargetArch(requestedArch) {
if (requestedArch === 'auto' || !requestedArch) {
return process.arch;
}
return requestedArch;
}
/**
* 获取Tauri构建目标
*/
getTauriTarget(arch, platform = process.platform) {
const platformMappings = BaseBuilder.ARCH_MAPPINGS[platform];
if (!platformMappings)
return null;
return platformMappings[arch] || null;
}
/**
* 获取架构显示名称(用于文件名)
*/
getArchDisplayName(arch) {
return BaseBuilder.ARCH_DISPLAY_NAMES[arch] || arch;
}
/**
* 构建基础构建命令
*/
buildBaseCommand(packageManager, configPath, target) {
const baseCommand = this.options.debug
? `${packageManager} run build:debug`
: `${packageManager} run build`;
// Use temporary config directory to avoid modifying source files
const configPath = path.join(npmDirectory, 'src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
// For macOS, use app bundles by default unless DMG is explicitly requested
if (IS_MAC && this.options.targets === 'app') {
fullCommand += ' --bundles app';
const argSeparator = packageManager === 'npm' ? ' --' : '';
let fullCommand = `${baseCommand}${argSeparator} -c "${configPath}"`;
if (target) {
fullCommand += ` --target ${target}`;
}
// Add features
return fullCommand;
}
/**
* 获取构建特性列表
*/
getBuildFeatures() {
const features = ['cli-build'];
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
if (IS_MAC) {
@@ -730,6 +760,18 @@ class BaseBuilder {
features.push('macos-proxy');
}
}
return features;
}
getBuildCommand(packageManager = 'pnpm') {
// Use temporary config directory to avoid modifying source files
const configPath = path.join(npmDirectory, 'src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = this.buildBaseCommand(packageManager, configPath);
// For macOS, use app bundles by default unless DMG is explicitly requested
if (IS_MAC && this.options.targets === 'app') {
fullCommand += ' --bundles app';
}
// Add features
const features = this.getBuildFeatures();
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
@@ -757,12 +799,37 @@ class BaseBuilder {
}
}
BaseBuilder.packageManagerCache = null;
// 架构映射配置
BaseBuilder.ARCH_MAPPINGS = {
darwin: {
arm64: 'aarch64-apple-darwin',
x64: 'x86_64-apple-darwin',
universal: 'universal-apple-darwin'
},
win32: {
arm64: 'aarch64-pc-windows-msvc',
x64: 'x86_64-pc-windows-msvc'
},
linux: {
arm64: 'aarch64-unknown-linux-gnu',
x64: 'x86_64-unknown-linux-gnu'
}
};
// 架构名称映射(用于文件名生成)
BaseBuilder.ARCH_DISPLAY_NAMES = {
arm64: 'aarch64',
x64: 'x64',
universal: 'universal'
};
class MacBuilder extends BaseBuilder {
constructor(options) {
super(options);
// Store the original targets value for architecture selection
this.buildArch = options.targets || 'auto';
// For macOS, targets can be architecture names or format names
// Filter out non-architecture values
const validArchs = ['intel', 'apple', 'universal', 'auto', 'x64', 'arm64'];
this.buildArch = validArchs.includes(options.targets || '') ? options.targets : 'auto';
// Use DMG by default for distribution
// Only create app bundles for testing to avoid user interaction
if (process.env.PAKE_CREATE_APP === '1') {
@@ -793,141 +860,32 @@ class MacBuilder extends BaseBuilder {
}
else {
// Auto-detect based on current architecture
arch = process.arch === 'arm64' ? 'aarch64' : process.arch;
arch = this.getArchDisplayName(this.resolveTargetArch(this.buildArch));
}
return `${name}_${tauriConfig.version}_${arch}`;
}
getBuildCommand(packageManager = 'pnpm') {
// Determine if we need universal build
const needsUniversal = this.buildArch === 'universal' || this.options.multiArch;
if (needsUniversal) {
const baseCommand = this.options.debug
? `${packageManager} run tauri build -- --debug`
: `${packageManager} run tauri build --`;
// Use temporary config directory to avoid modifying source files
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} --target universal-apple-darwin -c "${configPath}"`;
// Add features
const features = ['cli-build'];
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
const macOSVersion = this.getMacOSMajorVersion();
if (macOSVersion >= 23) {
features.push('macos-proxy');
}
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
return fullCommand;
getActualArch() {
if (this.buildArch === 'universal' || this.options.multiArch) {
return 'universal';
}
else if (this.buildArch === 'apple') {
// Build for Apple Silicon only
const baseCommand = this.options.debug
? `${packageManager} run tauri build -- --debug`
: `${packageManager} run tauri build --`;
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} --target aarch64-apple-darwin -c "${configPath}"`;
// Add features
const features = ['cli-build'];
const macOSVersion = this.getMacOSMajorVersion();
if (macOSVersion >= 23) {
features.push('macos-proxy');
}
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
return fullCommand;
return 'arm64';
}
else if (this.buildArch === 'intel') {
// Build for Intel only
const baseCommand = this.options.debug
? `${packageManager} run tauri build -- --debug`
: `${packageManager} run tauri build --`;
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} --target x86_64-apple-darwin -c "${configPath}"`;
// Add features
const features = ['cli-build'];
const macOSVersion = this.getMacOSMajorVersion();
if (macOSVersion >= 23) {
features.push('macos-proxy');
}
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
return fullCommand;
return 'x64';
}
return super.getBuildCommand();
}
getBasePath() {
const needsUniversal = this.buildArch === 'universal' || this.options.multiArch;
const basePath = this.options.debug ? 'debug' : 'release';
if (needsUniversal) {
return `src-tauri/target/universal-apple-darwin/${basePath}/bundle`;
}
else if (this.buildArch === 'apple') {
return `src-tauri/target/aarch64-apple-darwin/${basePath}/bundle`;
}
else if (this.buildArch === 'intel') {
return `src-tauri/target/x86_64-apple-darwin/${basePath}/bundle`;
}
return super.getBasePath();
}
}
class WinBuilder extends BaseBuilder {
constructor(options) {
super(options);
this.buildFormat = 'msi';
// Store the original targets value for architecture selection
this.buildArch = options.targets || 'auto';
// Set targets to msi format for Tauri
this.options.targets = this.buildFormat;
}
getFileName() {
const { name } = this.options;
const language = tauriConfig.bundle.windows.wix.language[0];
// Determine architecture name based on explicit targets option or auto-detect
let targetArch;
if (this.buildArch === 'arm64') {
targetArch = 'aarch64';
}
else if (this.buildArch === 'x64') {
targetArch = 'x64';
}
else {
// Auto-detect based on current architecture if no explicit target
const archMap = {
x64: 'x64',
arm64: 'aarch64',
};
targetArch = archMap[process.arch] || process.arch;
}
return `${name}_${tauriConfig.version}_${targetArch}_${language}`;
return this.resolveTargetArch(this.buildArch);
}
getBuildCommand(packageManager = 'pnpm') {
const baseCommand = this.options.debug
? `${packageManager} run build:debug`
: `${packageManager} run build`;
// Use temporary config directory to avoid modifying source files
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
// Determine build target based on explicit targets option or auto-detect
let buildTarget;
if (this.buildArch === 'arm64') {
buildTarget = 'aarch64-pc-windows-msvc';
const actualArch = this.getActualArch();
const buildTarget = this.getTauriTarget(actualArch, 'darwin');
if (!buildTarget) {
throw new Error(`Unsupported architecture: ${actualArch} for macOS`);
}
else if (this.buildArch === 'x64') {
buildTarget = 'x86_64-pc-windows-msvc';
}
else {
// Auto-detect based on current architecture if no explicit target
buildTarget =
process.arch === 'arm64'
? 'aarch64-pc-windows-msvc'
: 'x86_64-pc-windows-msvc';
}
fullCommand += ` --target ${buildTarget}`;
let fullCommand = this.buildBaseCommand(packageManager, configPath, buildTarget);
// Add features
const features = ['cli-build'];
const features = this.getBuildFeatures();
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
@@ -935,21 +893,42 @@ class WinBuilder extends BaseBuilder {
}
getBasePath() {
const basePath = this.options.debug ? 'debug' : 'release';
// Determine target based on explicit targets option or auto-detect
let target;
if (this.buildArch === 'arm64') {
target = 'aarch64-pc-windows-msvc';
const actualArch = this.getActualArch();
const target = this.getTauriTarget(actualArch, 'darwin');
return `src-tauri/target/${target}/${basePath}/bundle`;
}
}
class WinBuilder extends BaseBuilder {
constructor(options) {
super(options);
this.buildFormat = 'msi';
this.buildArch = this.resolveTargetArch(options.targets);
this.options.targets = this.buildFormat;
}
getFileName() {
const { name } = this.options;
const language = tauriConfig.bundle.windows.wix.language[0];
const targetArch = this.getArchDisplayName(this.buildArch);
return `${name}_${tauriConfig.version}_${targetArch}_${language}`;
}
getBuildCommand(packageManager = 'pnpm') {
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
const buildTarget = this.getTauriTarget(this.buildArch, 'win32');
if (!buildTarget) {
throw new Error(`Unsupported architecture: ${this.buildArch} for Windows`);
}
else if (this.buildArch === 'x64') {
target = 'x86_64-pc-windows-msvc';
}
else {
// Auto-detect based on current architecture if no explicit target
target =
process.arch === 'arm64'
? 'aarch64-pc-windows-msvc'
: 'x86_64-pc-windows-msvc';
let fullCommand = this.buildBaseCommand(packageManager, configPath, buildTarget);
// Add features
const features = this.getBuildFeatures();
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
return fullCommand;
}
getBasePath() {
const basePath = this.options.debug ? 'debug' : 'release';
const target = this.getTauriTarget(this.buildArch, 'win32');
return `src-tauri/target/${target}/${basePath}/bundle/`;
}
}
@@ -965,7 +944,7 @@ class LinuxBuilder extends BaseBuilder {
}
else {
this.buildFormat = target;
this.buildArch = 'auto';
this.buildArch = this.resolveTargetArch('auto');
}
// Set targets to format for Tauri
this.options.targets = this.buildFormat;
@@ -973,15 +952,16 @@ class LinuxBuilder extends BaseBuilder {
getFileName() {
const { name, targets } = this.options;
const version = tauriConfig.version;
// Determine architecture based on explicit target or auto-detect
// Determine architecture display name
let arch;
if (this.buildArch === 'arm64') {
arch = targets === 'rpm' || targets === 'appimage' ? 'aarch64' : 'arm64';
}
else {
// Auto-detect or default to current architecture
arch = process.arch === 'x64' ? 'amd64' : process.arch;
if (arch === 'arm64' && (targets === 'rpm' || targets === 'appimage')) {
const resolvedArch = this.buildArch === 'x64' ? 'amd64' : this.buildArch;
arch = resolvedArch;
if (resolvedArch === 'arm64' && (targets === 'rpm' || targets === 'appimage')) {
arch = 'aarch64';
}
}
@@ -1001,18 +981,14 @@ class LinuxBuilder extends BaseBuilder {
}
}
getBuildCommand(packageManager = 'pnpm') {
const baseCommand = this.options.debug
? `${packageManager} run build:debug`
: `${packageManager} run build`;
// Use temporary config directory to avoid modifying source files
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
// Add ARM64 target if explicitly specified
if (this.buildArch === 'arm64') {
fullCommand += ' --target aarch64-unknown-linux-gnu';
}
// Only add target if it's ARM64
const buildTarget = this.buildArch === 'arm64'
? this.getTauriTarget(this.buildArch, 'linux')
: undefined;
let fullCommand = this.buildBaseCommand(packageManager, configPath, buildTarget);
// Add features
const features = ['cli-build'];
const features = this.getBuildFeatures();
if (features.length > 0) {
fullCommand += ` --features ${features.join(',')}`;
}
@@ -1021,7 +997,8 @@ class LinuxBuilder extends BaseBuilder {
getBasePath() {
const basePath = this.options.debug ? 'debug' : 'release';
if (this.buildArch === 'arm64') {
return `src-tauri/target/aarch64-unknown-linux-gnu/${basePath}/bundle/`;
const target = this.getTauriTarget(this.buildArch, 'linux');
return `src-tauri/target/${target}/${basePath}/bundle/`;
}
return super.getBasePath();
}

View File

@@ -32,9 +32,9 @@
"scripts": {
"start": "pnpm run dev",
"dev": "pnpm run tauri dev",
"build": "pnpm run tauri build --",
"build:debug": "pnpm run tauri build -- --debug",
"build:mac": "pnpm run tauri build -- --target universal-apple-darwin",
"build": "tauri build",
"build:debug": "tauri build --debug",
"build:mac": "tauri build --target universal-apple-darwin",
"build:config": "chmod +x scripts/configure-tauri.mjs && node scripts/configure-tauri.mjs",
"analyze": "cd src-tauri && cargo bloat --release --crates",
"tauri": "tauri",