@osmn-byhn/electron-make-pacman
v1.0.0
Published
Electron Forge pacman package maker
Maintainers
Readme
electron-make-pacman 📦
A professional Electron Forge Maker plugin and a standalone CLI tool. It generates fully native and reliable .pkg.tar.zst (Pacman) packages for Arch Linux and its derivatives (Manjaro, EndeavourOS, etc.).
Unlike traditional builders, it directly utilizes Arch Linux's official makepkg packaging system as a child process under the hood to completely comply with Arch Linux packaging standards.
🚀 Features
- Dual Usage: Integrate it seamlessly as a maker into your Electron Forge configuration, or use it independently as a CLI tool via
npx electron-make-pacman. - Dual-Build Support: Compiled in both CommonJS (
.cjs) and ES Modules (.js- ESM) standards, ensuring full compatibility with both modern and legacy Node.js projects. - Advanced Desktop Integration: Automatically configures the
.desktoplauncher file, embedding properties likeCategoriesandStartupWMClass, and seamlessly handles system icon transitions. - Optimal Security Compliance: Automatically applies the required
setUID(4755) permission fixes for thechrome-sandbox(an Electron requirement) during themakepkgprocess. - Pino Logger: Offers a standardized, colorful, and highly readable logging infrastructure via
pinoandpino-prettyfor debugging and environment communication. - AUR & Remote Source Mode: Features an
aurOnlyoption to bypass standard packaging. Instead of building from local files, it dynamically pulls your app from a GitHub Release URL, generating only the.SRCINFOfile to prepare an Arch User Repository (AUR) structure. - Automated Repo Management: Capable of automatically executing
repo-addto register your newly compiled.pkg.tar.zstinto a specified custom Pacman repository database.
🛠️ Installation
npm install --save-dev electron-make-pacmanNote: In order for this package to successfully generate Pacman packages, the makepkg utility (Arch base system) must be installed on your host machine.
💻 1. Usage in Forge Config (Electron Forge Integration)
Add the following configuration to your forge.config.js, forge.config.cjs, or forge.config.ts:
// For CJS projects: const MakerPacman = require('electron-make-pacman').default;
import MakerPacman from 'electron-make-pacman';
export default {
// ... other forge configs
makers: [
new MakerPacman({
options: {
depends: ['gtk3', 'nss', 'libxss', 'libxtst', 'alsa-lib'], // Arch dependencies
icon: '/absolute/path/to/app-icon.png',
desktopCategories: ['Utility', 'Development'],
// aurOnly: true, // Only generates .SRCINFO for the AUR without building the package
// githubReleaseUrl: 'https://github.com/user/repo/releases/download/v1.0.0/app-linux.tar.gz'
// repoDb: '/var/lib/pacman/custom.db.tar.gz' // Automatically add to a local pacman repo
}
}),
]
};To run the maker, simply use your standard forge package command:
npm run make💻 2. CLI Usage (Standalone Packager)
If you have already packaged your application into a prebuilt uncompressed folder (like dist/linux-unpacked), you can trigger the plugin via its CLI:
# Automatically searches for standard output folders like 'dist/linux-unpacked' or 'out/'
npx electron-make-pacman
# Specify a direct path to the unpacked application folder
npx electron-make-pacman ./build-output/my-app-linux-x64
# Package the application by parsing the configuration from an external JSON file
npx electron-make-pacman ./build-output --config ./pacman-config.jsonExample pacman-config.json:
{
"options": {
"depends": ["gtk3", "nss", "alsa-lib"],
"icon": "./assets/icon.png",
"desktopCategories": ["Network", "Utility"]
}
}📂 Project Structure (What is What?)
The project is primarily driven by four core modules inside the src/ directory:
MakerPacman.ts(Entry Point & Electron Binding): The main class file extending@electron-forge/maker-base. It introduces the Maker to the Electron Forge system, performs platform validations (ensuring it only runs on Linux platforms), and dispatches Forge events to thepackager.packager.ts(Orchestrator & Controller): The primary controller responsible for creating temporary build directories (tempDir), transporting icons, copying application files, and sequentially spawning themakepkgsub-process. It enforces environment variables likePKGDESTto strictly control wheremakepkgplaces its resulting archives.pkgbuilder.ts(Text & PKGBUILD Generator): The engine responsible for generating thePKGBUILDstring output according to Arch Linux syntaxes. It orchestrates shell formatting strings to install your application systematically (/opt/[app-name]), configure the.desktopshortcuts (/usr/share/applications), parse Git URLs, and configure symlinks.cli.ts(Command Line Interface): The executed Node binary that steps in for un-forged standalone environments. It parses terminal arguments, dynamically detects compiled Electron unpacked app directories, processes external JSON configs, and initiates the pipeline towardspackager.ts.logger.ts: A robust Pino structure bringing formatted, colorful standard outputs directly to the CLI for deep and readable integrations across the environment.
⚙️ How It Works Under the Hood
- Initialization: Upon being triggered, it creates a sanitized temporary directory structure:
/tmp/pacman-[pkg-name]-[timestamp]. - Staging: Your unpacked Electron app is recursively copied into
/src/appwithin the temporary directory. - Generation:
pkgbuilder.tsmaps your system architecture architecture (e.g.,x86_64) against your providedMakerOptionsand generates a highly specificPKGBUILDfile containing step-by-step Bash sequences intended for the Arch package manager. - Execution:
packager.tsspawns a background child process callingmakepkg -cfd --noconfirm. - Packaging: The makepkg utility scopes into the temporary directory, assesses permissions (dynamically fixing
chrome-sandboxviachmod 4755), and successfully builds the standard.pkg.tar.zstpayload. - Delivery: Make Pacman parses the final
.pkg.tar.zstfrommakepkg, moves it into your requested Forgeout/makedirectory, and cleanly disposes of the/tmpenvironment variables.
