🐛 Fix pnpm packaging errors and refactor
This commit is contained in:
109
bin/builders/BaseBuilder.ts
vendored
109
bin/builders/BaseBuilder.ts
vendored
@@ -187,26 +187,88 @@ export default abstract class BaseBuilder {
|
|||||||
|
|
||||||
abstract getFileName(): string;
|
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
|
const baseCommand = this.options.debug
|
||||||
? `${packageManager} run build:debug`
|
? `${packageManager} run build:debug`
|
||||||
: `${packageManager} run build`;
|
: `${packageManager} run build`;
|
||||||
|
|
||||||
// Use temporary config directory to avoid modifying source files
|
const argSeparator = packageManager === 'npm' ? ' --' : '';
|
||||||
const configPath = path.join(
|
let fullCommand = `${baseCommand}${argSeparator} -c "${configPath}"`;
|
||||||
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 (target) {
|
||||||
if (IS_MAC && this.options.targets === 'app') {
|
fullCommand += ` --target ${target}`;
|
||||||
fullCommand += ' --bundles app';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add features
|
return fullCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取构建特性列表
|
||||||
|
*/
|
||||||
|
protected getBuildFeatures(): string[] {
|
||||||
const features = ['cli-build'];
|
const features = ['cli-build'];
|
||||||
|
|
||||||
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
|
// 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) {
|
if (features.length > 0) {
|
||||||
fullCommand += ` --features ${features.join(',')}`;
|
fullCommand += ` --features ${features.join(',')}`;
|
||||||
}
|
}
|
||||||
|
|||||||
38
bin/builders/LinuxBuilder.ts
vendored
38
bin/builders/LinuxBuilder.ts
vendored
@@ -17,7 +17,7 @@ export default class LinuxBuilder extends BaseBuilder {
|
|||||||
this.buildArch = 'arm64';
|
this.buildArch = 'arm64';
|
||||||
} else {
|
} else {
|
||||||
this.buildFormat = target;
|
this.buildFormat = target;
|
||||||
this.buildArch = 'auto';
|
this.buildArch = this.resolveTargetArch('auto');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set targets to format for Tauri
|
// Set targets to format for Tauri
|
||||||
@@ -28,14 +28,18 @@ export default class LinuxBuilder extends BaseBuilder {
|
|||||||
const { name, targets } = this.options;
|
const { name, targets } = this.options;
|
||||||
const version = tauriConfig.version;
|
const version = tauriConfig.version;
|
||||||
|
|
||||||
// Determine architecture based on explicit target or auto-detect
|
// Determine architecture display name
|
||||||
let arch: string;
|
let arch: string;
|
||||||
if (this.buildArch === 'arm64') {
|
if (this.buildArch === 'arm64') {
|
||||||
arch = targets === 'rpm' || targets === 'appimage' ? 'aarch64' : 'arm64';
|
arch = targets === 'rpm' || targets === 'appimage' ? 'aarch64' : 'arm64';
|
||||||
} else {
|
} else {
|
||||||
// Auto-detect or default to current architecture
|
// Auto-detect or default to current architecture
|
||||||
arch = process.arch === 'x64' ? 'amd64' : process.arch;
|
const resolvedArch = this.buildArch === 'x64' ? 'amd64' : this.buildArch;
|
||||||
if (arch === 'arm64' && (targets === 'rpm' || targets === 'appimage')) {
|
arch = resolvedArch;
|
||||||
|
if (
|
||||||
|
resolvedArch === 'arm64' &&
|
||||||
|
(targets === 'rpm' || targets === 'appimage')
|
||||||
|
) {
|
||||||
arch = 'aarch64';
|
arch = 'aarch64';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,21 +63,22 @@ export default class LinuxBuilder extends BaseBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getBuildCommand(packageManager: string = 'pnpm'): string {
|
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');
|
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
|
||||||
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
|
|
||||||
|
|
||||||
// Add ARM64 target if explicitly specified
|
// Only add target if it's ARM64
|
||||||
if (this.buildArch === 'arm64') {
|
const buildTarget =
|
||||||
fullCommand += ' --target aarch64-unknown-linux-gnu';
|
this.buildArch === 'arm64'
|
||||||
}
|
? this.getTauriTarget(this.buildArch, 'linux')
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
let fullCommand = this.buildBaseCommand(
|
||||||
|
packageManager,
|
||||||
|
configPath,
|
||||||
|
buildTarget,
|
||||||
|
);
|
||||||
|
|
||||||
// Add features
|
// Add features
|
||||||
const features = ['cli-build'];
|
const features = this.getBuildFeatures();
|
||||||
if (features.length > 0) {
|
if (features.length > 0) {
|
||||||
fullCommand += ` --features ${features.join(',')}`;
|
fullCommand += ` --features ${features.join(',')}`;
|
||||||
}
|
}
|
||||||
@@ -85,7 +90,8 @@ export default class LinuxBuilder extends BaseBuilder {
|
|||||||
const basePath = this.options.debug ? 'debug' : 'release';
|
const basePath = this.options.debug ? 'debug' : 'release';
|
||||||
|
|
||||||
if (this.buildArch === 'arm64') {
|
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();
|
return super.getBasePath();
|
||||||
|
|||||||
113
bin/builders/MacBuilder.ts
vendored
113
bin/builders/MacBuilder.ts
vendored
@@ -11,7 +11,12 @@ export default class MacBuilder extends BaseBuilder {
|
|||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
// Store the original targets value for architecture selection
|
// 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
|
// Use DMG by default for distribution
|
||||||
// Only create app bundles for testing to avoid user interaction
|
// Only create app bundles for testing to avoid user interaction
|
||||||
@@ -43,95 +48,51 @@ export default class MacBuilder extends BaseBuilder {
|
|||||||
arch = 'x64';
|
arch = 'x64';
|
||||||
} else {
|
} else {
|
||||||
// Auto-detect based on current architecture
|
// 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}`;
|
return `${name}_${tauriConfig.version}_${arch}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getBuildCommand(packageManager: string = 'pnpm'): string {
|
private getActualArch(): string {
|
||||||
// Determine if we need universal build
|
if (this.buildArch === 'universal' || this.options.multiArch) {
|
||||||
const needsUniversal =
|
return 'universal';
|
||||||
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;
|
|
||||||
} else if (this.buildArch === 'apple') {
|
} else if (this.buildArch === 'apple') {
|
||||||
// Build for Apple Silicon only
|
return 'arm64';
|
||||||
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;
|
|
||||||
} else if (this.buildArch === 'intel') {
|
} else if (this.buildArch === 'intel') {
|
||||||
// Build for Intel only
|
return 'x64';
|
||||||
const baseCommand = this.options.debug
|
}
|
||||||
? `${packageManager} run tauri build -- --debug`
|
return this.resolveTargetArch(this.buildArch);
|
||||||
: `${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
|
protected getBuildCommand(packageManager: string = 'pnpm'): string {
|
||||||
const features = ['cli-build'];
|
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
|
||||||
const macOSVersion = this.getMacOSMajorVersion();
|
const actualArch = this.getActualArch();
|
||||||
if (macOSVersion >= 23) {
|
|
||||||
features.push('macos-proxy');
|
|
||||||
}
|
|
||||||
if (features.length > 0) {
|
|
||||||
fullCommand += ` --features ${features.join(',')}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
protected getBasePath(): string {
|
||||||
const needsUniversal =
|
|
||||||
this.buildArch === 'universal' || this.options.multiArch;
|
|
||||||
const basePath = this.options.debug ? 'debug' : 'release';
|
const basePath = this.options.debug ? 'debug' : 'release';
|
||||||
|
const actualArch = this.getActualArch();
|
||||||
|
const target = this.getTauriTarget(actualArch, 'darwin');
|
||||||
|
|
||||||
if (needsUniversal) {
|
return `src-tauri/target/${target}/${basePath}/bundle`;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
68
bin/builders/WinBuilder.ts
vendored
68
bin/builders/WinBuilder.ts
vendored
@@ -9,61 +9,35 @@ export default class WinBuilder extends BaseBuilder {
|
|||||||
|
|
||||||
constructor(options: PakeAppOptions) {
|
constructor(options: PakeAppOptions) {
|
||||||
super(options);
|
super(options);
|
||||||
// Store the original targets value for architecture selection
|
this.buildArch = this.resolveTargetArch(options.targets);
|
||||||
this.buildArch = options.targets || 'auto';
|
|
||||||
// Set targets to msi format for Tauri
|
|
||||||
this.options.targets = this.buildFormat;
|
this.options.targets = this.buildFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileName(): string {
|
getFileName(): string {
|
||||||
const { name } = this.options;
|
const { name } = this.options;
|
||||||
const language = tauriConfig.bundle.windows.wix.language[0];
|
const language = tauriConfig.bundle.windows.wix.language[0];
|
||||||
|
const targetArch = this.getArchDisplayName(this.buildArch);
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${name}_${tauriConfig.version}_${targetArch}_${language}`;
|
return `${name}_${tauriConfig.version}_${targetArch}_${language}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getBuildCommand(packageManager: string = 'pnpm'): string {
|
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');
|
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
|
if (!buildTarget) {
|
||||||
let buildTarget: string;
|
throw new Error(
|
||||||
if (this.buildArch === 'arm64') {
|
`Unsupported architecture: ${this.buildArch} for Windows`,
|
||||||
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';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fullCommand += ` --target ${buildTarget}`;
|
let fullCommand = this.buildBaseCommand(
|
||||||
|
packageManager,
|
||||||
|
configPath,
|
||||||
|
buildTarget,
|
||||||
|
);
|
||||||
|
|
||||||
// Add features
|
// Add features
|
||||||
const features = ['cli-build'];
|
const features = this.getBuildFeatures();
|
||||||
if (features.length > 0) {
|
if (features.length > 0) {
|
||||||
fullCommand += ` --features ${features.join(',')}`;
|
fullCommand += ` --features ${features.join(',')}`;
|
||||||
}
|
}
|
||||||
@@ -73,21 +47,7 @@ export default class WinBuilder extends BaseBuilder {
|
|||||||
|
|
||||||
protected getBasePath(): string {
|
protected getBasePath(): string {
|
||||||
const basePath = this.options.debug ? 'debug' : 'release';
|
const basePath = this.options.debug ? 'debug' : 'release';
|
||||||
|
const target = this.getTauriTarget(this.buildArch, 'win32');
|
||||||
// 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';
|
|
||||||
}
|
|
||||||
|
|
||||||
return `src-tauri/target/${target}/${basePath}/bundle/`;
|
return `src-tauri/target/${target}/${basePath}/bundle/`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
301
dist/cli.js
vendored
301
dist/cli.js
vendored
@@ -54,9 +54,9 @@ var files = [
|
|||||||
var scripts = {
|
var scripts = {
|
||||||
start: "pnpm run dev",
|
start: "pnpm run dev",
|
||||||
dev: "pnpm run tauri dev",
|
dev: "pnpm run tauri dev",
|
||||||
build: "pnpm run tauri build --",
|
build: "tauri build",
|
||||||
"build:debug": "pnpm run tauri build -- --debug",
|
"build:debug": "tauri build --debug",
|
||||||
"build:mac": "pnpm run tauri build -- --target universal-apple-darwin",
|
"build:mac": "tauri build --target universal-apple-darwin",
|
||||||
"build:config": "chmod +x scripts/configure-tauri.mjs && node scripts/configure-tauri.mjs",
|
"build:config": "chmod +x scripts/configure-tauri.mjs && node scripts/configure-tauri.mjs",
|
||||||
analyze: "cd src-tauri && cargo bloat --release --crates",
|
analyze: "cd src-tauri && cargo bloat --release --crates",
|
||||||
tauri: "tauri",
|
tauri: "tauri",
|
||||||
@@ -710,18 +710,48 @@ class BaseBuilder {
|
|||||||
getFileType(target) {
|
getFileType(target) {
|
||||||
return 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
|
const baseCommand = this.options.debug
|
||||||
? `${packageManager} run build:debug`
|
? `${packageManager} run build:debug`
|
||||||
: `${packageManager} run build`;
|
: `${packageManager} run build`;
|
||||||
// Use temporary config directory to avoid modifying source files
|
const argSeparator = packageManager === 'npm' ? ' --' : '';
|
||||||
const configPath = path.join(npmDirectory, 'src-tauri', '.pake', 'tauri.conf.json');
|
let fullCommand = `${baseCommand}${argSeparator} -c "${configPath}"`;
|
||||||
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
|
if (target) {
|
||||||
// For macOS, use app bundles by default unless DMG is explicitly requested
|
fullCommand += ` --target ${target}`;
|
||||||
if (IS_MAC && this.options.targets === 'app') {
|
|
||||||
fullCommand += ' --bundles app';
|
|
||||||
}
|
}
|
||||||
// Add features
|
return fullCommand;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取构建特性列表
|
||||||
|
*/
|
||||||
|
getBuildFeatures() {
|
||||||
const features = ['cli-build'];
|
const features = ['cli-build'];
|
||||||
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
|
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
|
||||||
if (IS_MAC) {
|
if (IS_MAC) {
|
||||||
@@ -730,6 +760,18 @@ class BaseBuilder {
|
|||||||
features.push('macos-proxy');
|
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) {
|
if (features.length > 0) {
|
||||||
fullCommand += ` --features ${features.join(',')}`;
|
fullCommand += ` --features ${features.join(',')}`;
|
||||||
}
|
}
|
||||||
@@ -757,12 +799,37 @@ class BaseBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BaseBuilder.packageManagerCache = null;
|
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 {
|
class MacBuilder extends BaseBuilder {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
// Store the original targets value for architecture selection
|
// 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
|
// Use DMG by default for distribution
|
||||||
// Only create app bundles for testing to avoid user interaction
|
// Only create app bundles for testing to avoid user interaction
|
||||||
if (process.env.PAKE_CREATE_APP === '1') {
|
if (process.env.PAKE_CREATE_APP === '1') {
|
||||||
@@ -793,141 +860,32 @@ class MacBuilder extends BaseBuilder {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Auto-detect based on current architecture
|
// 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}`;
|
return `${name}_${tauriConfig.version}_${arch}`;
|
||||||
}
|
}
|
||||||
getBuildCommand(packageManager = 'pnpm') {
|
getActualArch() {
|
||||||
// Determine if we need universal build
|
if (this.buildArch === 'universal' || this.options.multiArch) {
|
||||||
const needsUniversal = this.buildArch === 'universal' || this.options.multiArch;
|
return 'universal';
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
else if (this.buildArch === 'apple') {
|
else if (this.buildArch === 'apple') {
|
||||||
// Build for Apple Silicon only
|
return 'arm64';
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
else if (this.buildArch === 'intel') {
|
else if (this.buildArch === 'intel') {
|
||||||
// Build for Intel only
|
return 'x64';
|
||||||
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 super.getBuildCommand();
|
return this.resolveTargetArch(this.buildArch);
|
||||||
}
|
|
||||||
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}`;
|
|
||||||
}
|
}
|
||||||
getBuildCommand(packageManager = 'pnpm') {
|
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');
|
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
|
||||||
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
|
const actualArch = this.getActualArch();
|
||||||
// Determine build target based on explicit targets option or auto-detect
|
const buildTarget = this.getTauriTarget(actualArch, 'darwin');
|
||||||
let buildTarget;
|
if (!buildTarget) {
|
||||||
if (this.buildArch === 'arm64') {
|
throw new Error(`Unsupported architecture: ${actualArch} for macOS`);
|
||||||
buildTarget = 'aarch64-pc-windows-msvc';
|
|
||||||
}
|
}
|
||||||
else if (this.buildArch === 'x64') {
|
let fullCommand = this.buildBaseCommand(packageManager, configPath, buildTarget);
|
||||||
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}`;
|
|
||||||
// Add features
|
// Add features
|
||||||
const features = ['cli-build'];
|
const features = this.getBuildFeatures();
|
||||||
if (features.length > 0) {
|
if (features.length > 0) {
|
||||||
fullCommand += ` --features ${features.join(',')}`;
|
fullCommand += ` --features ${features.join(',')}`;
|
||||||
}
|
}
|
||||||
@@ -935,21 +893,42 @@ class WinBuilder extends BaseBuilder {
|
|||||||
}
|
}
|
||||||
getBasePath() {
|
getBasePath() {
|
||||||
const basePath = this.options.debug ? 'debug' : 'release';
|
const basePath = this.options.debug ? 'debug' : 'release';
|
||||||
// Determine target based on explicit targets option or auto-detect
|
const actualArch = this.getActualArch();
|
||||||
let target;
|
const target = this.getTauriTarget(actualArch, 'darwin');
|
||||||
if (this.buildArch === 'arm64') {
|
return `src-tauri/target/${target}/${basePath}/bundle`;
|
||||||
target = 'aarch64-pc-windows-msvc';
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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') {
|
let fullCommand = this.buildBaseCommand(packageManager, configPath, buildTarget);
|
||||||
target = 'x86_64-pc-windows-msvc';
|
// Add features
|
||||||
}
|
const features = this.getBuildFeatures();
|
||||||
else {
|
if (features.length > 0) {
|
||||||
// Auto-detect based on current architecture if no explicit target
|
fullCommand += ` --features ${features.join(',')}`;
|
||||||
target =
|
|
||||||
process.arch === 'arm64'
|
|
||||||
? 'aarch64-pc-windows-msvc'
|
|
||||||
: 'x86_64-pc-windows-msvc';
|
|
||||||
}
|
}
|
||||||
|
return fullCommand;
|
||||||
|
}
|
||||||
|
getBasePath() {
|
||||||
|
const basePath = this.options.debug ? 'debug' : 'release';
|
||||||
|
const target = this.getTauriTarget(this.buildArch, 'win32');
|
||||||
return `src-tauri/target/${target}/${basePath}/bundle/`;
|
return `src-tauri/target/${target}/${basePath}/bundle/`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -965,7 +944,7 @@ class LinuxBuilder extends BaseBuilder {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.buildFormat = target;
|
this.buildFormat = target;
|
||||||
this.buildArch = 'auto';
|
this.buildArch = this.resolveTargetArch('auto');
|
||||||
}
|
}
|
||||||
// Set targets to format for Tauri
|
// Set targets to format for Tauri
|
||||||
this.options.targets = this.buildFormat;
|
this.options.targets = this.buildFormat;
|
||||||
@@ -973,15 +952,16 @@ class LinuxBuilder extends BaseBuilder {
|
|||||||
getFileName() {
|
getFileName() {
|
||||||
const { name, targets } = this.options;
|
const { name, targets } = this.options;
|
||||||
const version = tauriConfig.version;
|
const version = tauriConfig.version;
|
||||||
// Determine architecture based on explicit target or auto-detect
|
// Determine architecture display name
|
||||||
let arch;
|
let arch;
|
||||||
if (this.buildArch === 'arm64') {
|
if (this.buildArch === 'arm64') {
|
||||||
arch = targets === 'rpm' || targets === 'appimage' ? 'aarch64' : 'arm64';
|
arch = targets === 'rpm' || targets === 'appimage' ? 'aarch64' : 'arm64';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Auto-detect or default to current architecture
|
// Auto-detect or default to current architecture
|
||||||
arch = process.arch === 'x64' ? 'amd64' : process.arch;
|
const resolvedArch = this.buildArch === 'x64' ? 'amd64' : this.buildArch;
|
||||||
if (arch === 'arm64' && (targets === 'rpm' || targets === 'appimage')) {
|
arch = resolvedArch;
|
||||||
|
if (resolvedArch === 'arm64' && (targets === 'rpm' || targets === 'appimage')) {
|
||||||
arch = 'aarch64';
|
arch = 'aarch64';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1001,18 +981,14 @@ class LinuxBuilder extends BaseBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
getBuildCommand(packageManager = 'pnpm') {
|
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');
|
const configPath = path.join('src-tauri', '.pake', 'tauri.conf.json');
|
||||||
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
|
// Only add target if it's ARM64
|
||||||
// Add ARM64 target if explicitly specified
|
const buildTarget = this.buildArch === 'arm64'
|
||||||
if (this.buildArch === 'arm64') {
|
? this.getTauriTarget(this.buildArch, 'linux')
|
||||||
fullCommand += ' --target aarch64-unknown-linux-gnu';
|
: undefined;
|
||||||
}
|
let fullCommand = this.buildBaseCommand(packageManager, configPath, buildTarget);
|
||||||
// Add features
|
// Add features
|
||||||
const features = ['cli-build'];
|
const features = this.getBuildFeatures();
|
||||||
if (features.length > 0) {
|
if (features.length > 0) {
|
||||||
fullCommand += ` --features ${features.join(',')}`;
|
fullCommand += ` --features ${features.join(',')}`;
|
||||||
}
|
}
|
||||||
@@ -1021,7 +997,8 @@ class LinuxBuilder extends BaseBuilder {
|
|||||||
getBasePath() {
|
getBasePath() {
|
||||||
const basePath = this.options.debug ? 'debug' : 'release';
|
const basePath = this.options.debug ? 'debug' : 'release';
|
||||||
if (this.buildArch === 'arm64') {
|
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();
|
return super.getBasePath();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "pnpm run dev",
|
"start": "pnpm run dev",
|
||||||
"dev": "pnpm run tauri dev",
|
"dev": "pnpm run tauri dev",
|
||||||
"build": "pnpm run tauri build --",
|
"build": "tauri build",
|
||||||
"build:debug": "pnpm run tauri build -- --debug",
|
"build:debug": "tauri build --debug",
|
||||||
"build:mac": "pnpm run tauri build -- --target universal-apple-darwin",
|
"build:mac": "tauri build --target universal-apple-darwin",
|
||||||
"build:config": "chmod +x scripts/configure-tauri.mjs && node scripts/configure-tauri.mjs",
|
"build:config": "chmod +x scripts/configure-tauri.mjs && node scripts/configure-tauri.mjs",
|
||||||
"analyze": "cd src-tauri && cargo bloat --release --crates",
|
"analyze": "cd src-tauri && cargo bloat --release --crates",
|
||||||
"tauri": "tauri",
|
"tauri": "tauri",
|
||||||
|
|||||||
Reference in New Issue
Block a user