Platform-Specific Configuration
Use .platform() for cross-platform tool configurations.
Platform and Architecture Enums
Section titled “Platform and Architecture Enums”import { Architecture, Platform } from "@alexgorbatchev/dotfiles";
// Platforms (bitwise flags)Platform.Linux; // 1Platform.MacOS; // 2Platform.Windows; // 4Platform.All; // All platforms (7)
// Architectures (bitwise flags)Architecture.X86_64; // 1Architecture.Arm64; // 2Architecture.All; // Both (3)Basic Usage
Section titled “Basic Usage”import { defineTool, Platform } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install() .bin("tool") .platform(Platform.MacOS, (install) => install("brew", { formula: "tool" })) .platform(Platform.Linux, (install) => install("github-release", { repo: "owner/tool", assetPattern: "*linux*.tar.gz", }), ) .platform(Platform.Windows, (install) => install("github-release", { repo: "owner/tool", assetPattern: "*windows*.zip", }), ),);With Architecture
Section titled “With Architecture”import { Architecture, defineTool, Platform } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install() .bin("tool") .platform(Platform.Linux, Architecture.X86_64, (install) => install("github-release", { repo: "owner/tool", assetPattern: "*linux-amd64*.tar.gz", }), ) .platform(Platform.Linux, Architecture.Arm64, (install) => install("github-release", { repo: "owner/tool", assetPattern: "*linux-arm64*.tar.gz", }), ) .platform(Platform.MacOS, Architecture.All, (install) => install("brew", { formula: "tool" })),);Platform Groups
Section titled “Platform Groups”There are three platforms: Linux, MacOS and Windows. Combine them with | to
share configuration between several, rather than reaching for a named alias:
export default defineTool((install) => install() .bin("tool") // One POSIX install script serves both Linux and macOS. .platform(Platform.Linux | Platform.MacOS, (install) => install("curl-script", { url: "https://example.com/install.sh", shell: "bash", }), ) .platform(Platform.Windows, (install) => install("github-release", { repo: "owner/tool", assetPattern: "*windows*.zip", }), ),);Only group platforms when the configuration is genuinely identical for each of them.
Release assets are built per operating system, so assetPattern almost always belongs
in a separate block per platform — grouping Linux with macOS there would hand a Mac a
Linux build. See the architecture example above for the per-platform form.
Platform-Specific Shell Config
Section titled “Platform-Specific Shell Config”export default defineTool((install) => install("github-release", { repo: "owner/tool" }) .bin("tool") .platform(Platform.Linux | Platform.MacOS, (install) => install().zsh((shell) => shell.env({ TOOL_CONFIG: "~/.config/tool", }), ), ) .platform(Platform.Windows, (install) => install().powershell((shell) => shell.env({ TOOL_CONFIG: "~\\.config\\tool", }), ), ),);Platform Detection in Hooks
Section titled “Platform Detection in Hooks”Root-level hooks still apply when the actual installer is defined inside .platform(...).
Use that pattern for shared lifecycle logic, then put only the platform-specific install method inside each override.
export default defineTool((install) => install("github-release", { repo: "owner/tool" }) .bin("tool") .hook("after-install", async ({ systemInfo, $ }) => { if (systemInfo.platform === Platform.MacOS) { await $`./setup-macos.sh`; } else if (systemInfo.platform === Platform.Linux) { await $`./setup-linux.sh`; }
if (systemInfo.arch === Architecture.Arm64) { await $`./configure-arm64.sh`; } }),);Common Asset Patterns
Section titled “Common Asset Patterns”| Platform | Pattern Examples |
|---|---|
| macOS | *darwin*.tar.gz, *macos*.zip |
| Linux | *linux*.tar.gz, *x86_64-unknown-linux-gnu* |
| Windows | *windows*.zip, *pc-windows-msvc* |
| x86_64 | *amd64*, *x86_64* |
| ARM64 | *arm64*, *aarch64* |