Skip to content

ext_bundler

The ext_bundler crate provides app packaging, icon management, and manifest utilities for Forge applications through the forge:bundler module.

Overview

ext_bundler provides runtime access to:

  • Icon management - Create, validate, and resize app icons
  • Manifest parsing - Parse and validate manifest.app.toml files
  • Platform info - Get platform-specific bundle requirements
  • Build configuration - Manage build settings and paths

Module: forge:bundler

import {
info,
iconCreate,
iconValidate,
iconResize,
manifestParse,
sanitizeName,
platformInfo,
iconRequirements,
pathInfo,
pathJoin
} from "forge:bundler";

Key Types

Extension Info

interface ExtensionInfo {
name: string;
version: string;
capabilities: string[];
}

Icon Types

interface IconCreateOptions {
size?: number; // Size in pixels (default: 1024)
color?: string; // Primary color (hex, default: "#3C5AB8")
}
interface IconValidation {
width: number;
height: number;
isSquare: boolean;
meetsMinimum: boolean; // >= 512px
meetsRecommended: boolean; // >= 1024px
hasTransparency: boolean;
warnings: string[];
errors: string[];
}
interface IconResizeOptions {
width: number;
height: number;
}

Manifest Types

interface AppManifest {
name: string;
identifier: string;
version: string;
icon?: string;
}

Platform Types

interface PlatformInfo {
os: string; // "macos", "windows", "linux"
arch: string; // "x86_64", "aarch64"
bundleFormat: string; // "dmg", "msix", "appimage"
supported: boolean;
}
type BundleFormat =
| "App" // macOS .app bundle
| "Dmg" // macOS .dmg disk image
| "Pkg" // macOS .pkg installer
| "Msix" // Windows .msix package
| "AppImage" // Linux AppImage
| "Tarball" // Compressed tarball
| "Zip"; // ZIP archive

Build Configuration

interface BuildConfig {
appDir: string; // App directory path
outputDir?: string; // Output directory for bundle
format?: BundleFormat; // Target bundle format
sign?: boolean; // Whether to sign the bundle
signingIdentity?: string; // Code signing identity
}

Path Utilities

interface PathInfo {
path: string;
exists: boolean;
isDir: boolean;
isFile: boolean;
extension?: string;
fileName?: string;
parent?: string;
}

Constants

const MIN_ICON_SIZE = 512; // Minimum recommended icon size
const RECOMMENDED_ICON_SIZE = 1024; // Optimal icon size for all platforms

Operations

OpTypeScriptDescription
op_bundler_infoinfo()Get extension information
op_bundler_icon_createiconCreate(opts?)Create placeholder icon PNG
op_bundler_icon_validateiconValidate(data)Validate icon dimensions and format
op_bundler_icon_resizeiconResize(data, opts)Resize icon to target dimensions
op_bundler_manifest_parsemanifestParse(content)Parse manifest.app.toml content
op_bundler_sanitize_namesanitizeName(name)Sanitize name for executables
op_bundler_platform_infoplatformInfo()Get current platform bundle info
op_bundler_icon_requirementsiconRequirements(platform)Get required icon sizes for platform
op_bundler_set_app_dirsetAppDir(path)Set current app directory
op_bundler_get_app_dirgetAppDir()Get current app directory
op_bundler_set_build_configsetBuildConfig(config)Set build configuration
op_bundler_get_build_configgetBuildConfig()Get build configuration
op_bundler_path_infopathInfo(path)Analyze a path
op_bundler_path_joinpathJoin(...components)Join path components
op_bundler_manifest_pathmanifestPath(appDir)Get manifest path for app
op_bundler_cache_manifestcacheManifest(path, manifest)Cache parsed manifest
op_bundler_get_cached_manifestgetCachedManifest(path)Get cached manifest

Usage Examples

Create a Placeholder Icon

import { iconCreate, iconValidate } from "forge:bundler";
import { writeFile } from "runtime:fs";
// Create a 1024x1024 placeholder icon
const iconData = iconCreate({ size: 1024 });
// Validate the icon
const validation = iconValidate(iconData);
console.log(`Icon size: ${validation.width}x${validation.height}`);
console.log(`Valid: ${validation.errors.length === 0}`);
// Save to file
await writeFile("app-icon.png", iconData);

Get Icon Requirements for Platform

import { iconRequirements, iconResize } from "forge:bundler";
// Get required sizes for macOS
const macosRequirements = iconRequirements("macos");
// Returns: [16x16, 32x32, 64x64, 128x128, 256x256, 512x512, 1024x1024]
// Resize icon for each required size
for (const { width, height } of macosRequirements) {
const resized = iconResize(originalIcon, { width, height });
await writeFile(`icon_${width}x${height}.png`, resized);
}

Parse App Manifest

import { manifestParse, manifestPath } from "forge:bundler";
import { readTextFile } from "runtime:fs";
// Get manifest path
const path = manifestPath("/path/to/my-app");
// Returns: "/path/to/my-app/manifest.app.toml"
// Parse manifest
const content = await readTextFile(path);
const manifest = manifestParse(content);
console.log(`App: ${manifest.name}`);
console.log(`Version: ${manifest.version}`);
console.log(`Identifier: ${manifest.identifier}`);

Configure Build

import {
setBuildConfig,
getBuildConfig,
platformInfo
} from "forge:bundler";
// Get platform info
const platform = platformInfo();
console.log(`Platform: ${platform.os}/${platform.arch}`);
console.log(`Bundle format: ${platform.bundleFormat}`);
// Configure build
setBuildConfig({
appDir: "/path/to/my-app",
outputDir: "/path/to/output",
format: "Dmg",
sign: true,
signingIdentity: "Developer ID Application: My Company"
});
// Retrieve config later
const config = getBuildConfig();

Path Utilities

import { pathInfo, pathJoin, sanitizeName } from "forge:bundler";
// Analyze a path
const info = pathInfo("/path/to/file.txt");
console.log(`Exists: ${info.exists}`);
console.log(`Extension: ${info.extension}`); // "txt"
console.log(`Filename: ${info.fileName}`); // "file.txt"
// Join paths
const fullPath = pathJoin("/path", "to", "file.txt");
// Returns: "/path/to/file.txt"
// Sanitize app name for use as executable
const sanitized = sanitizeName("My Awesome App!");
// Returns: "my-awesome-app"

Icon Size Requirements by Platform

macOS

SizeUsage
16x16Finder, Dock (retina @1x)
32x32Finder, Dock (retina @2x for 16pt)
64x64Finder
128x128Finder
256x256Finder
512x512Finder
1024x1024App Store

Windows

SizeUsage
44x44App list
50x50Start menu
150x150Start tiles
300x300Start tiles (large)
600x600Store listing

Linux

SizeUsage
16x16Tray icons
32x32Desktop icons
48x48Desktop icons
64x64Application menu
128x128High-DPI displays
256x256High-DPI displays
512x512Software center

File Structure

crates/ext_bundler/
├── src/
│ └── lib.rs # Extension implementation
├── ts/
│ └── init.ts # TypeScript module shim
├── build.rs # forge-weld build configuration
└── Cargo.toml

Dependencies

DependencyPurpose
deno_coreOp definitions
imageImage processing (resize, encode)
tomlManifest parsing
forge-weldBuild-time code generation
forge-weld-macro#[weld_op], #[weld_struct] macros
serde, serde_jsonSerialization
thiserrorError types
deno_errorJavaScript error conversion
tracingLogging
linkmeCompile-time symbol collection