Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

feat: choose Linux default bundle target by distro family

Tw934b9bda4f06fe
diff --git a/bin/builders/LinuxBuilder.ts b/bin/builders/LinuxBuilder.ts
index 6c3138e1..b38b0111 100644
--- a/bin/builders/LinuxBuilder.ts
+++ b/bin/builders/LinuxBuilder.ts
@@ -72,19 +72,52 @@ export default class LinuxBuilder extends BaseBuilder {
}
const useTemporaryDebForZst = needsTemporaryDebForZst(targets);
+ // With a single explicit target, fail fast. With multiple targets (the
+ // distro-aware default, or an explicit comma list) keep building the rest
+ // when one fails, so a usable installer is still produced, e.g. AppImage
+ // survives a .deb bundler abort on RPM-based distros.
+ const isolateFailures = targets.length > 1;
+ const failed: string[] = [];
+ let firstError: Error | null = null;
+
for (const target of targets) {
this.currentBuildType = target;
- if (target === 'zst') {
- if (useTemporaryDebForZst) {
- await this.buildAndCopy(url, 'deb', false);
+ try {
+ if (target === 'zst') {
+ if (useTemporaryDebForZst) {
+ await this.buildAndCopy(url, 'deb', false);
+ }
+ await this.createArchPackageFromDeb({
+ removeSourceDeb: useTemporaryDebForZst,
+ });
+ } else {
+ await this.buildAndCopy(url, target);
}
- await this.createArchPackageFromDeb({
- removeSourceDeb: useTemporaryDebForZst,
- });
- } else {
- await this.buildAndCopy(url, target);
+ } catch (error) {
+ const err = error instanceof Error ? error : new Error(String(error));
+ if (!isolateFailures) {
+ throw err;
+ }
+ if (!firstError) {
+ firstError = err;
+ }
+ failed.push(target);
+ logger.warn(
+ `✼ Failed to build "${target}" target: ${err.message.split('\n')[0]}`,
+ );
}
}
+
+ // Every requested target failed: surface the first real error.
+ if (firstError && failed.length === targets.length) {
+ throw firstError;
+ }
+
+ if (failed.length > 0) {
+ logger.warn(
+ `✼ Skipped failed Linux targets: ${failed.join(', ')}. Other formats built successfully.`,
+ );
+ }
}
private async ensureArchPackagingTools() {
diff --git a/bin/defaults.ts b/bin/defaults.ts
index c079e5f1..a9539d9a 100644
--- a/bin/defaults.ts
+++ b/bin/defaults.ts
@@ -1,4 +1,5 @@
import { PakeCliOptions } from './types.js';
+import { getDefaultLinuxTargets } from './utils/platform.js';
export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
icon: '',
@@ -19,7 +20,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
targets: (() => {
switch (process.platform) {
case 'linux':
- return 'deb,appimage';
+ return getDefaultLinuxTargets();
case 'darwin':
return 'dmg';
case 'win32':
diff --git a/bin/utils/platform.ts b/bin/utils/platform.ts
index 26158161..155a5227 100644
--- a/bin/utils/platform.ts
+++ b/bin/utils/platform.ts
@@ -1,5 +1,101 @@
+import fs from 'fs';
+
const { platform } = process;
export const IS_MAC = platform === 'darwin';
export const IS_WIN = platform === 'win32';
export const IS_LINUX = platform === 'linux';
+
+export type LinuxPackageFamily = 'deb' | 'rpm';
+
+// Distro IDs / ID_LIKE families that ship an RPM-based package manager.
+const RPM_FAMILY_IDS = new Set([
+ 'rhel',
+ 'fedora',
+ 'centos',
+ 'rocky',
+ 'almalinux',
+ 'ol', // Oracle Linux
+ 'oracle',
+ 'amzn', // Amazon Linux
+ 'mariner',
+ 'azurelinux',
+ 'suse',
+ 'opensuse',
+ 'opensuse-leap',
+ 'opensuse-tumbleweed',
+ 'sles',
+]);
+
+// Distro IDs / ID_LIKE families that ship a DEB-based package manager.
+const DEB_FAMILY_IDS = new Set([
+ 'debian',
+ 'ubuntu',
+ 'linuxmint',
+ 'pop',
+ 'elementary',
+ 'kali',
+ 'raspbian',
+ 'devuan',
+]);
+
+// Parse the shell-style key=value pairs of an /etc/os-release file, stripping
+// the optional surrounding quotes around values.
+function parseOsRelease(content: string): Record<string, string> {
+ const fields: Record<string, string> = {};
+ for (const rawLine of content.split('\n')) {
+ const line = rawLine.trim();
+ if (!line || line.startsWith('#')) continue;
+ const separator = line.indexOf('=');
+ if (separator === -1) continue;
+ const key = line.slice(0, separator).trim();
+ let value = line.slice(separator + 1).trim();
+ if (
+ value.length >= 2 &&
+ ((value.startsWith('"') && value.endsWith('"')) ||
+ (value.startsWith("'") && value.endsWith("'")))
+ ) {
+ value = value.slice(1, -1);
+ }
+ if (key) fields[key] = value;
+ }
+ return fields;
+}
+
+// Detect the package family from /etc/os-release. The distro's own ID wins over
+// ID_LIKE hints, and an unknown distro falls back to 'deb' to preserve Pake's
+// historical default. Accepts content directly so the decision is unit-testable
+// without a real /etc/os-release.
+export function detectLinuxPackageFamily(
+ osReleaseContent?: string,
+): LinuxPackageFamily {
+ let content = osReleaseContent;
+ if (content === undefined) {
+ try {
+ content = fs.readFileSync('/etc/os-release', 'utf-8');
+ } catch {
+ return 'deb';
+ }
+ }
+
+ const fields = parseOsRelease(content);
+ const id = (fields.ID ?? '').toLowerCase().trim();
+ const idLike = (fields.ID_LIKE ?? '')
+ .toLowerCase()
+ .split(/\s+/)
+ .filter(Boolean);
+
+ for (const token of [id, ...idLike]) {
+ if (DEB_FAMILY_IDS.has(token)) return 'deb';
+ if (RPM_FAMILY_IDS.has(token)) return 'rpm';
+ }
+ return 'deb';
+}
+
+// Default Linux bundle targets, chosen by the host distro's package family so
+// RPM-based distros (Fedora/RHEL/Oracle/Rocky/Alma/openSUSE) get a native .rpm
+// instead of a .deb their package manager cannot install. AppImage stays as a
+// universal fallback in both cases.
+export function getDefaultLinuxTargets(): string {
+ return detectLinuxPackageFamily() === 'rpm' ? 'rpm,appimage' : 'deb,appimage';
+}
diff --git a/dist/cli.js b/dist/cli.js
index c18d529a..d954510e 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -10,14 +10,14 @@ import os from 'os';
import { execa, execaSync } from 'execa';
import crypto from 'crypto';
import ora from 'ora';
-import fs from 'fs/promises';
+import fs from 'fs';
+import fs$1 from 'fs/promises';
import { dir } from 'tmp-promise';
import { fileTypeFromBuffer } from 'file-type';
import icongen from 'icon-gen';
import sharp from 'sharp';
import * as psl from 'psl';
import { InvalidArgumentError, program as program$1, Option } from 'commander';
-import fs$1 from 'fs';
var name = "pake-cli";
var version = "3.12.1";
@@ -230,6 +230,93 @@ const { platform: platform$1 } = process;
const IS_MAC = platform$1 === 'darwin';
const IS_WIN = platform$1 === 'win32';
const IS_LINUX = platform$1 === 'linux';
+// Distro IDs / ID_LIKE families that ship an RPM-based package manager.
+const RPM_FAMILY_IDS = new Set([
+ 'rhel',
+ 'fedora',
+ 'centos',
+ 'rocky',
+ 'almalinux',
+ 'ol', // Oracle Linux
+ 'oracle',
+ 'amzn', // Amazon Linux
+ 'mariner',
+ 'azurelinux',
+ 'suse',
+ 'opensuse',
+ 'opensuse-leap',
+ 'opensuse-tumbleweed',
+ 'sles',
+]);
+// Distro IDs / ID_LIKE families that ship a DEB-based package manager.
+const DEB_FAMILY_IDS = new Set([
+ 'debian',
+ 'ubuntu',
+ 'linuxmint',
+ 'pop',
+ 'elementary',
+ 'kali',
+ 'raspbian',
+ 'devuan',
+]);
+// Parse the shell-style key=value pairs of an /etc/os-release file, stripping
+// the optional surrounding quotes around values.
+function parseOsRelease(content) {
+ const fields = {};
+ for (const rawLine of content.split('\n')) {
+ const line = rawLine.trim();
+ if (!line || line.startsWith('#'))
+ continue;
+ const separator = line.indexOf('=');
+ if (separator === -1)
+ continue;
+ const key = line.slice(0, separator).trim();
+ let value = line.slice(separator + 1).trim();
+ if (value.length >= 2 &&
+ ((value.startsWith('"') && value.endsWith('"')) ||
+ (value.startsWith("'") && value.endsWith("'")))) {
+ value = value.slice(1, -1);
+ }
+ if (key)
+ fields[key] = value;
+ }
+ return fields;
+}
+// Detect the package family from /etc/os-release. The distro's own ID wins over
+// ID_LIKE hints, and an unknown distro falls back to 'deb' to preserve Pake's
+// historical default. Accepts content directly so the decision is unit-testable
+// without a real /etc/os-release.
+function detectLinuxPackageFamily(osReleaseContent) {
+ let content = osReleaseContent;
+ if (content === undefined) {
+ try {
+ content = fs.readFileSync('/etc/os-release', 'utf-8');
+ }
+ catch {
+ return 'deb';
+ }
+ }
+ const fields = parseOsRelease(content);
+ const id = (fields.ID ?? '').toLowerCase().trim();
+ const idLike = (fields.ID_LIKE ?? '')
+ .toLowerCase()
+ .split(/\s+/)
+ .filter(Boolean);
+ for (const token of [id, ...idLike]) {
+ if (DEB_FAMILY_IDS.has(token))
+ return 'deb';
+ if (RPM_FAMILY_IDS.has(token))
+ return 'rpm';
+ }
+ return 'deb';
+}
+// Default Linux bundle targets, chosen by the host distro's package family so
+// RPM-based distros (Fedora/RHEL/Oracle/Rocky/Alma/openSUSE) get a native .rpm
+// instead of a .deb their package manager cannot install. AppImage stays as a
+// universal fallback in both cases.
+function getDefaultLinuxTargets() {
+ return detectLinuxPackageFamily() === 'rpm' ? 'rpm,appimage' : 'deb,appimage';
+}
async function shellExec(command, timeout = 300000, env) {
try {
@@ -339,7 +426,7 @@ function checkRustInstalled() {
async function combineFiles(files, output) {
const contents = await Promise.all(files.map(async (file) => {
if (file.endsWith('.css')) {
- const fileContent = await fs.readFile(file, 'utf-8');
+ const fileContent = await fs$1.readFile(file, 'utf-8');
return `window.addEventListener('DOMContentLoaded', (_event) => {
const css = ${JSON.stringify(fileContent)};
const style = document.createElement('style');
@@ -347,12 +434,12 @@ async function combineFiles(files, output) {
document.head.appendChild(style);
});`;
}
- const fileContent = await fs.readFile(file);
+ const fileContent = await fs$1.readFile(file);
return ("window.addEventListener('DOMContentLoaded', (_event) => { " +
fileContent +
' });');
}));
- await fs.writeFile(output, contents.join('\n'));
+ await fs$1.writeFile(output, contents.join('\n'));
return files;
}
@@ -1444,20 +1531,47 @@ class LinuxBuilder extends BaseBuilder {
throw new Error(`No valid Linux target in "${this.options.targets}". Valid targets: ${LINUX_TARGET_TYPES.join(', ')}.`);
}
const useTemporaryDebForZst = needsTemporaryDebForZst(targets);
+ // With a single explicit target, fail fast. With multiple targets (the
+ // distro-aware default, or an explicit comma list) keep building the rest
+ // when one fails, so a usable installer is still produced, e.g. AppImage
+ // survives a .deb bundler abort on RPM-based distros.
+ const isolateFailures = targets.length > 1;
+ const failed = [];
+ let firstError = null;
for (const target of targets) {
this.currentBuildType = target;
- if (target === 'zst') {
- if (useTemporaryDebForZst) {
- await this.buildAndCopy(url, 'deb', false);
+ try {
+ if (target === 'zst') {
+ if (useTemporaryDebForZst) {
+ await this.buildAndCopy(url, 'deb', false);
+ }
+ await this.createArchPackageFromDeb({
+ removeSourceDeb: useTemporaryDebForZst,
+ });
+ }
+ else {
+ await this.buildAndCopy(url, target);
}
- await this.createArchPackageFromDeb({
- removeSourceDeb: useTemporaryDebForZst,
- });
}
- else {
- await this.buildAndCopy(url, target);
+ catch (error) {
+ const err = error instanceof Error ? error : new Error(String(error));
+ if (!isolateFailures) {
+ throw err;
+ }
+ if (!firstError) {
+ firstError = err;
+ }
+ failed.push(target);
+ logger.warn(`✼ Failed to build "${target}" target: ${err.message.split('\n')[0]}`);
}
}
+ // Every requested target failed: surface the first real error.
+ if (firstError && failed.length === targets.length) {
+ throw firstError;
+ }
+ if (failed.length > 0) {
+ logger.warn(`✼ Skipped failed Linux targets: ${failed.join(', ')}. Other formats built successfully.`);
+ }
}
async ensureArchPackagingTools() {
const requiredTools = [
@@ -2569,7 +2683,7 @@ const DEFAULT_PAKE_OPTIONS = {
targets: (() => {
switch (process.platform) {
case 'linux':
- return 'deb,appimage';
+ return getDefaultLinuxTargets();
case 'darwin':
return 'dmg';
case 'win32':
@@ -2621,7 +2735,7 @@ function validateNumberInput(value) {
return parsedValue;
}
function validateUrlInput(url) {
- const isFile = fs$1.existsSync(url);
+ const isFile = fs.existsSync(url);
if (!isFile) {
try {
return normalizeUrl(url);
diff --git a/docs/cli-usage.md b/docs/cli-usage.md
index e5e37055..e53641d5 100644
--- a/docs/cli-usage.md
+++ b/docs/cli-usage.md
@@ -306,7 +306,7 @@ Package the application to support both Intel and M1 chips, exclusively for macO
Specify the build target architecture or format:
-- **Linux**: `deb`, `appimage`, `rpm`, `zst`, `deb-arm64`, `appimage-arm64`, `rpm-arm64`, `zst-arm64` (default: `deb`, `appimage`)
+- **Linux**: `deb`, `appimage`, `rpm`, `zst`, `deb-arm64`, `appimage-arm64`, `rpm-arm64`, `zst-arm64` (default: distro-aware, `deb, appimage` on Debian/Ubuntu and `rpm, appimage` on Fedora/RHEL/Oracle/Rocky/Alma/openSUSE)
- **Windows**: `x64`, `arm64` (auto-detects if not specified)
- **macOS**: `intel`, `apple`, `universal` (architecture, auto-detects if not specified); `app`, `dmg` (output format, default: `dmg`)
diff --git a/docs/cli-usage_CN.md b/docs/cli-usage_CN.md
index 6310d5b4..d013e2d3 100644
--- a/docs/cli-usage_CN.md
+++ b/docs/cli-usage_CN.md
@@ -304,7 +304,7 @@ pake https://github.com --name GitHub
指定构建目标架构或格式:
-- **Linux**: `deb`, `appimage`, `rpm`, `zst`, `deb-arm64`, `appimage-arm64`, `rpm-arm64`, `zst-arm64`(默认:`deb`, `appimage`)
+- **Linux**: `deb`, `appimage`, `rpm`, `zst`, `deb-arm64`, `appimage-arm64`, `rpm-arm64`, `zst-arm64`(默认:按发行版自适应,Debian/Ubuntu 为 `deb, appimage`,Fedora/RHEL/Oracle/Rocky/Alma/openSUSE 为 `rpm, appimage`)
- **Windows**: `x64`, `arm64`(未指定时自动检测)
- **macOS**: `intel`, `apple`, `universal`(架构,未指定时自动检测);`app`, `dmg`(输出格式,默认:`dmg`)
diff --git a/docs/faq.md b/docs/faq.md
index 2f96e52e..da23320f 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -9,6 +9,7 @@ Common issues and solutions when using Pake.
- [Build Issues](#build-issues)
- [Rust Version Error: "feature 'edition2024' is required"](#rust-version-error-feature-edition2024-is-required)
- [Linux: Build Error "Can't detect any appindicator library" on Ubuntu 24.04](#linux-build-error-cant-detect-any-appindicator-library-on-ubuntu-2404)
+ - [Linux: Installing on Fedora / RHEL / Oracle Linux (RPM-based distros)](#linux-installing-on-fedora--rhel--oracle-linux-rpm-based-distros)
- [Linux: AppImage Build Fails with "failed to run linuxdeploy"](#linux-appimage-build-fails-with-failed-to-run-linuxdeploy)
- [Linux: AppImage Crashes at Launch with WebKitNetworkProcess Not Found](#linux-appimage-crashes-at-launch-with-webkitnetworkprocess-not-found)
- [Linux: "cargo: command not found" After Installing Rust](#linux-cargo-command-not-found-after-installing-rust)
@@ -101,6 +102,46 @@ sudo apt-get install -y libayatana-appindicator3-dev
---
+### Linux: Installing on Fedora / RHEL / Oracle Linux (RPM-based distros)
+
+**Problem:**
+On RPM-based distros (Fedora, RHEL, Oracle Linux, Rocky, AlmaLinux, openSUSE) a
+`.deb` package cannot be installed by the system package manager, and older Pake
+versions always built a `.deb` first.
+
+**Solution:**
+
+Pake now picks the default bundle target from `/etc/os-release`: RPM-based
+distros default to `rpm, appimage`, while Debian/Ubuntu keep `deb, appimage`. So
+the basic command already produces an installable package:
+
+```bash
+pake https://github.com --name GitHub
+sudo dnf install ./GitHub.rpm # or: sudo rpm -i ./GitHub.rpm
+```
+
+You can also choose the format explicitly at any time:
+
+```bash
+pake https://github.com --name GitHub --targets rpm # RPM package
+pake https://github.com --name GitHub --targets appimage # portable AppImage
+```
+
+When several targets build (the default), one format failing no longer aborts
+the others: if the `.rpm`/`.deb` bundler fails, the AppImage is still produced as
+a portable fallback. AppImage runs without installation:
+
+```bash
+chmod +x ./GitHub.AppImage
+./GitHub.AppImage
+```
+
+> Building an `.rpm` requires `rpm-build` (`sudo dnf install rpm-build`). If you
+> only need a runnable app without packaging, add `--keep-binary` to also copy
+> the raw executable next to the installer.
+
+---
+
### Linux: AppImage Build Fails with "failed to run linuxdeploy"
**Problem:**
diff --git a/docs/faq_CN.md b/docs/faq_CN.md
index d80c00f8..e9b31172 100644
--- a/docs/faq_CN.md
+++ b/docs/faq_CN.md
@@ -9,6 +9,7 @@
- [构建问题](#构建问题)
- [Rust 版本错误:"feature 'edition2024' is required"](#rust-版本错误feature-edition2024-is-required)
- [Linux:Ubuntu 24.04 构建报错 "Can't detect any appindicator library"](#linuxubuntu-2404-构建报错-cant-detect-any-appindicator-library)
+ - [Linux:在 Fedora / RHEL / Oracle Linux 等 RPM 系发行版上安装](#linux在-fedora--rhel--oracle-linux-等-rpm-系发行版上安装)
- [Linux:AppImage 构建失败,提示 "failed to run linuxdeploy"](#linuxappimage-构建失败提示-failed-to-run-linuxdeploy)
- [Linux:AppImage 启动即崩溃,提示找不到 WebKitNetworkProcess](#linuxappimage-启动即崩溃提示找不到-webkitnetworkprocess)
- [Linux:"cargo: command not found" 即使已安装 Rust](#linuxcargo-command-not-found-即使已安装-rust)
@@ -101,6 +102,43 @@ sudo apt-get install -y libayatana-appindicator3-dev
---
+### Linux:在 Fedora / RHEL / Oracle Linux 等 RPM 系发行版上安装
+
+**问题:**
+在 RPM 系发行版(Fedora、RHEL、Oracle Linux、Rocky、AlmaLinux、openSUSE)上,
+`.deb` 包无法被系统包管理器安装,而旧版本 Pake 总是先构建 `.deb`。
+
+**解决方法:**
+
+Pake 现在会读取 `/etc/os-release` 来决定默认打包目标:RPM 系发行版默认使用
+`rpm, appimage`,Debian/Ubuntu 仍然是 `deb, appimage`。所以基础命令就能直接产出
+可安装的包:
+
+```bash
+pake https://github.com --name GitHub
+sudo dnf install ./GitHub.rpm # 或:sudo rpm -i ./GitHub.rpm
+```
+
+你也可以随时显式指定格式:
+
+```bash
+pake https://github.com --name GitHub --targets rpm # RPM 包
+pake https://github.com --name GitHub --targets appimage # 便携 AppImage
+```
+
+默认会构建多个目标,此时单个格式失败不再中断其余格式:如果 `.rpm`/`.deb` 打包失败,
+仍会产出 AppImage 作为便携回退方案。AppImage 无需安装即可运行:
+
+```bash
+chmod +x ./GitHub.AppImage
+./GitHub.AppImage
+```
+
+> 构建 `.rpm` 需要 `rpm-build`(`sudo dnf install rpm-build`)。如果你只想要一个可运行
+> 的程序而不需要打包,可加上 `--keep-binary`,它会把原始可执行文件复制到安装包旁边。
+
+---
+
### Linux:AppImage 构建失败,提示 "failed to run linuxdeploy"
**问题描述:**
diff --git a/tests/unit/linux-distro.test.ts b/tests/unit/linux-distro.test.ts
new file mode 100644
index 00000000..e9513d46
--- /dev/null
+++ b/tests/unit/linux-distro.test.ts
@@ -0,0 +1,46 @@
+import { describe, it, expect } from 'vitest';
+import { detectLinuxPackageFamily } from '../../bin/utils/platform.js';
+
+describe('detectLinuxPackageFamily', () => {
+ it('detects Debian/Ubuntu families as deb', () => {
+ expect(detectLinuxPackageFamily('ID=debian')).toBe('deb');
+ expect(detectLinuxPackageFamily('ID=ubuntu\nID_LIKE=debian')).toBe('deb');
+ expect(
+ detectLinuxPackageFamily('ID=linuxmint\nID_LIKE="ubuntu debian"'),
+ ).toBe('deb');
+ });
+
+ it('detects Fedora/RHEL families as rpm', () => {
+ expect(detectLinuxPackageFamily('ID=fedora')).toBe('rpm');
+ expect(detectLinuxPackageFamily('ID=rhel')).toBe('rpm');
+ expect(
+ detectLinuxPackageFamily('ID=rocky\nID_LIKE="rhel centos fedora"'),
+ ).toBe('rpm');
+ });
+
+ it('detects Oracle Linux (ID=ol) as rpm', () => {
+ expect(
+ detectLinuxPackageFamily('ID="ol"\nID_LIKE="fedora"\nVERSION_ID="10.1"'),
+ ).toBe('rpm');
+ });
+
+ it('detects openSUSE/SLES as rpm', () => {
+ expect(
+ detectLinuxPackageFamily('ID=opensuse-leap\nID_LIKE="suse opensuse"'),
+ ).toBe('rpm');
+ expect(detectLinuxPackageFamily('ID=sles')).toBe('rpm');
+ });
+
+ it('prefers the distro ID over ID_LIKE hints', () => {
+ // A deb-based distro that lists no rpm hint stays deb.
+ expect(detectLinuxPackageFamily('ID=ubuntu')).toBe('deb');
+ // A distro whose own ID is rpm-based wins even with mixed-looking input.
+ expect(detectLinuxPackageFamily('ID=fedora\nID_LIKE=')).toBe('rpm');
+ });
+
+ it('falls back to deb for unknown or empty os-release', () => {
+ expect(detectLinuxPackageFamily('')).toBe('deb');
+ expect(detectLinuxPackageFamily('ID=arch')).toBe('deb');
+ expect(detectLinuxPackageFamily('# just a comment')).toBe('deb');
+ });
+});